Search in sources :

Example 6 with RemoteName

use of games.strategy.engine.message.RemoteName in project triplea by triplea-game.

the class RemoteMessengerTest method testException.

@Test
public void testException() throws Exception {
    final TestRemote testRemote = new TestRemote();
    final RemoteName test = new RemoteName(ITestRemote.class, "test");
    remoteMessenger.registerRemote(testRemote, test);
    final ITestRemote remote = (ITestRemote) remoteMessenger.getRemote(test);
    try {
        remote.throwException();
    } catch (final Exception e) {
        // this is what we want
        if (e.getMessage().equals(TestRemote.EXCEPTION_STRING)) {
            return;
        }
        throw e;
    }
    fail("No exception thrown");
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) ConnectionLostException(games.strategy.engine.message.ConnectionLostException) RemoteNotFoundException(games.strategy.engine.message.RemoteNotFoundException) Test(org.junit.jupiter.api.Test)

Example 7 with RemoteName

use of games.strategy.engine.message.RemoteName in project triplea by triplea-game.

the class RemoteMessengerTest method testNoRemote.

@Test
public void testNoRemote() {
    final RemoteName test = new RemoteName(ITestRemote.class, "test");
    try {
        remoteMessenger.getRemote(test);
        final ITestRemote remote = (ITestRemote) remoteMessenger.getRemote(test);
        remote.testVoid();
        fail("No exception thrown");
    } catch (final RemoteNotFoundException rme) {
    // this is what we expect
    }
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) RemoteNotFoundException(games.strategy.engine.message.RemoteNotFoundException) Test(org.junit.jupiter.api.Test)

Example 8 with RemoteName

use of games.strategy.engine.message.RemoteName in project triplea by triplea-game.

the class RemoteMessengerTest method testRemoteCall2.

@Test
public void testRemoteCall2() throws Exception {
    final RemoteName test = new RemoteName(ITestRemote.class, "test");
    ServerMessenger server = null;
    ClientMessenger client = null;
    try {
        server = new ServerMessenger("server", 0);
        server.setAcceptNewConnections(true);
        final int serverPort = server.getLocalNode().getSocketAddress().getPort();
        final String mac = MacFinder.getHashedMacAddress();
        client = new ClientMessenger("localhost", serverPort, "client", mac);
        final RemoteMessenger serverRemoteMessenger = new RemoteMessenger(new UnifiedMessenger(server));
        final TestRemote testRemote = new TestRemote();
        serverRemoteMessenger.registerRemote(testRemote, test);
        final RemoteMessenger clientRemoteMessenger = new RemoteMessenger(new UnifiedMessenger(client));
        // call it on the client
        // should be no need to wait since the constructor should not
        // reutrn until the initial state of the messenger is good
        final int incrementedValue = ((ITestRemote) clientRemoteMessenger.getRemote(test)).increment(1);
        assertEquals(2, incrementedValue);
        assertEquals(testRemote.getLastSenderNode(), client.getLocalNode());
    } finally {
        shutdownServerAndClient(server, client);
    }
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) ClientMessenger(games.strategy.net.ClientMessenger) Test(org.junit.jupiter.api.Test)

Example 9 with RemoteName

use of games.strategy.engine.message.RemoteName in project triplea by triplea-game.

the class RemoteMessengerTest method testShutDownClient.

@Test
public void testShutDownClient() throws Exception {
    // when the client shutdown, remotes created
    // on the client should not be visible on server
    final RemoteName test = new RemoteName(ITestRemote.class, "test");
    ServerMessenger server = null;
    ClientMessenger client = null;
    try {
        server = new ServerMessenger("server", 0);
        server.setAcceptNewConnections(true);
        final int serverPort = server.getLocalNode().getSocketAddress().getPort();
        final String mac = MacFinder.getHashedMacAddress();
        client = new ClientMessenger("localhost", serverPort, "client", mac);
        final UnifiedMessenger serverUnifiedMessenger = new UnifiedMessenger(server);
        final RemoteMessenger clientRemoteMessenger = new RemoteMessenger(new UnifiedMessenger(client));
        clientRemoteMessenger.registerRemote(new TestRemote(), test);
        serverUnifiedMessenger.getHub().waitForNodesToImplement(test.getName());
        assertTrue(serverUnifiedMessenger.getHub().hasImplementors(test.getName()));
        client.shutDown();
        Interruptibles.sleep(200);
        assertTrue(!serverUnifiedMessenger.getHub().hasImplementors(test.getName()));
    } finally {
        shutdownServerAndClient(server, client);
    }
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) ClientMessenger(games.strategy.net.ClientMessenger) Test(org.junit.jupiter.api.Test)

Example 10 with RemoteName

use of games.strategy.engine.message.RemoteName in project triplea by triplea-game.

the class RemoteMessengerTest method testRemoteCall.

@Test
public void testRemoteCall() throws Exception {
    final RemoteName test = new RemoteName(ITestRemote.class, "test");
    ServerMessenger server = null;
    ClientMessenger client = null;
    try {
        server = new ServerMessenger("server", 0);
        server.setAcceptNewConnections(true);
        final int serverPort = server.getLocalNode().getSocketAddress().getPort();
        final String mac = MacFinder.getHashedMacAddress();
        client = new ClientMessenger("localhost", serverPort, "client", mac);
        final UnifiedMessenger serverUnifiedMessenger = new UnifiedMessenger(server);
        unifiedMessengerHub = serverUnifiedMessenger.getHub();
        final RemoteMessenger serverRemoteMessenger = new RemoteMessenger(serverUnifiedMessenger);
        final RemoteMessenger clientRemoteMessenger = new RemoteMessenger(new UnifiedMessenger(client));
        // register it on the server
        final TestRemote testRemote = new TestRemote();
        serverRemoteMessenger.registerRemote(testRemote, test);
        // since the registration must go over a socket
        // and through a couple threads, wait for the
        // client to get it
        int waitCount = 0;
        while (!unifiedMessengerHub.hasImplementors(test.getName()) && waitCount < 20) {
            waitCount++;
            Interruptibles.sleep(50);
        }
        // call it on the client
        final int incrementedValue = ((ITestRemote) clientRemoteMessenger.getRemote(test)).increment(1);
        assertEquals(2, incrementedValue);
        assertEquals(testRemote.getLastSenderNode(), client.getLocalNode());
    } finally {
        shutdownServerAndClient(server, client);
    }
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) ClientMessenger(games.strategy.net.ClientMessenger) Test(org.junit.jupiter.api.Test)

Aggregations

RemoteName (games.strategy.engine.message.RemoteName)28 Test (org.junit.jupiter.api.Test)14 INode (games.strategy.net.INode)7 ClientMessenger (games.strategy.net.ClientMessenger)5 IChannelSubscribor (games.strategy.engine.message.IChannelSubscribor)4 RemoteMessenger (games.strategy.engine.message.RemoteMessenger)4 RemoteNotFoundException (games.strategy.engine.message.RemoteNotFoundException)4 IServerMessenger (games.strategy.net.IServerMessenger)4 ServerMessenger (games.strategy.net.ServerMessenger)4 ConnectionLostException (games.strategy.engine.message.ConnectionLostException)2 RemoteMethodCall (games.strategy.engine.message.RemoteMethodCall)2 GameOverException (games.strategy.engine.GameOverException)1 PlayerID (games.strategy.engine.data.PlayerID)1 PlayerList (games.strategy.engine.data.PlayerList)1 IDelegate (games.strategy.engine.delegate.IDelegate)1 DefaultPlayerBridge (games.strategy.engine.gamePlayer.DefaultPlayerBridge)1 IGamePlayer (games.strategy.engine.gamePlayer.IGamePlayer)1 IPlayerBridge (games.strategy.engine.gamePlayer.IPlayerBridge)1 ChannelMessenger (games.strategy.engine.message.ChannelMessenger)1 HubInvoke (games.strategy.engine.message.HubInvoke)1