+RMITests & put remote classes in package

This commit is contained in:
bfrasure 2016-09-05 21:28:31 -06:00
parent 13a6e2c5e6
commit 6df70d51b3
5 changed files with 33 additions and 0 deletions

View File

@ -4,6 +4,8 @@
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Uses remote object PerfectTime
// {ValidateByHand}
package remote;
import java.rmi.registry.*;
public class DisplayPerfectTime {

View File

@ -3,6 +3,8 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// The PerfectTime remote interface
package remote;
import java.rmi.*;
public interface PerfectTime extends Remote {

View File

@ -3,6 +3,8 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Implementing the PerfectTime remote object
package remote;
import java.rmi.RemoteException;
public class PerfectTimeImpl implements PerfectTime {

View File

@ -4,6 +4,8 @@
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Server for the PerfectTime remote object
// {ValidateByHand}
package remote;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;

View File

@ -0,0 +1,25 @@
// remote/tests/RMITests.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
package remote;
import java.rmi.registry.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.TestInfo;
public class RMITests {
@Test
void test_remote_time() throws Exception {
LocateRegistry.createRegistry(1099);
PerfectTimeServer timeServer = new PerfectTimeServer();
timeServer.main(null);
Registry reg =
LocateRegistry.getRegistry("localhost");
PerfectTime pt =
(PerfectTime) reg.lookup("PerfectTime");
for (int i = 0; i < 10; i++)
System.out.println("Time: " + pt.getPerfectTime());
}
}