@Test public void testTwoComets() throws Exception { Server server1 = startServer(0); int groupPort = ((NetworkConnector) server1.getConnectors()[0]).getLocalPort(); Oort oort1 = startOort(server1); startConfigurer(oort1, groupPort); Server server2 = startServer(0); Oort oort2 = startOort(server2); startConfigurer(oort2, groupPort); // Give some time to advertise Thread.sleep(1000); Assert.assertEquals(1, oort1.getKnownComets().size()); Assert.assertEquals(1, oort2.getKnownComets().size()); }
@Test public void testThreeComets() throws Exception { Server server1 = startServer(0); int groupPort = ((NetworkConnector) server1.getConnectors()[0]).getLocalPort(); Oort oort1 = startOort(server1); startConfigurer(oort1, groupPort); Server server2 = startServer(0); Oort oort2 = startOort(server2); final OortMulticastConfigurer configurer2 = startConfigurer(oort2, groupPort); // Give some time to advertise Thread.sleep(1000); Assert.assertEquals(1, oort1.getKnownComets().size()); Assert.assertEquals(1, oort2.getKnownComets().size()); // Create another comet Server server3 = startServer(0); Oort oort3 = startOort(server3); startConfigurer(oort3, groupPort); // Give some time to advertise Thread.sleep(1000); Assert.assertEquals(2, oort1.getKnownComets().size()); Assert.assertEquals(2, oort2.getKnownComets().size()); Assert.assertEquals(2, oort3.getKnownComets().size()); stopConfigurer(configurer2); stopOort(oort2); stopServer(server2); // Give some time to advertise Thread.sleep(1000); Assert.assertEquals(1, oort1.getKnownComets().size()); Assert.assertEquals(oort3.getURL(), oort1.getKnownComets().iterator().next()); Assert.assertEquals(1, oort3.getKnownComets().size()); Assert.assertEquals(oort1.getURL(), oort3.getKnownComets().iterator().next()); }
protected void receive(String cometURL) { if (!oort.getKnownComets().contains(cometURL)) { if (logger.isDebugEnabled()) logger.debug("Received comet URL via multicast: {}", cometURL); OortComet oortComet = oort.observeComet(cometURL); if (oortComet != null) { boolean elapsed = !oortComet.waitFor( getConnectTimeout(), BayeuxClient.State.CONNECTED, BayeuxClient.State.DISCONNECTED); // If we could not connect, let's disconnect, we will be advertised again if (elapsed) { if (logger.isDebugEnabled()) logger.debug("Interrupting attempts to connect to {}", cometURL); oort.deobserveComet(cometURL); } } } }