public void testSimpleBroadcastWithStopStartDiscoveryGroup() throws Exception { final InetAddress groupAddress = InetAddress.getByName(address1); final int groupPort = getUDPDiscoveryPort(); final int timeout = 500; final String nodeID = RandomUtil.randomString(); bg = newBroadcast(nodeID, RandomUtil.randomString(), null, -1, groupAddress, groupPort); bg.start(); TransportConfiguration live1 = generateTC(); bg.addConnector(live1); dg = newDiscoveryGroup( RandomUtil.randomString(), RandomUtil.randomString(), null, groupAddress, groupPort, timeout); dg.start(); verifyBroadcast(bg, dg); List<DiscoveryEntry> entries = dg.getDiscoveryEntries(); assertEqualsDiscoveryEntries(Arrays.asList(live1), entries); bg.stop(); dg.stop(); dg.start(); bg.start(); verifyBroadcast(bg, dg); entries = dg.getDiscoveryEntries(); assertEqualsDiscoveryEntries(Arrays.asList(live1), entries); }
public void testDiscoveryGroupNotifications() throws Exception { SimpleNotificationService notifService = new SimpleNotificationService(); SimpleNotificationService.Listener notifListener = new SimpleNotificationService.Listener(); notifService.addNotificationListener(notifListener); final InetAddress groupAddress = InetAddress.getByName(address1); final int groupPort = getUDPDiscoveryPort(); final int timeout = 500; dg = newDiscoveryGroup( RandomUtil.randomString(), RandomUtil.randomString(), null, groupAddress, groupPort, timeout, notifService); Assert.assertEquals(0, notifListener.getNotifications().size()); dg.start(); Assert.assertEquals(1, notifListener.getNotifications().size()); Notification notif = notifListener.getNotifications().get(0); Assert.assertEquals(NotificationType.DISCOVERY_GROUP_STARTED, notif.getType()); Assert.assertEquals( dg.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString()); dg.stop(); Assert.assertEquals(2, notifListener.getNotifications().size()); notif = notifListener.getNotifications().get(1); Assert.assertEquals(NotificationType.DISCOVERY_GROUP_STOPPED, notif.getType()); Assert.assertEquals( dg.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString()); }
public void testMultipleDiscoveryGroups() throws Exception { final InetAddress groupAddress = InetAddress.getByName(address1); final int groupPort = getUDPDiscoveryPort(); final int timeout = 500; String nodeID = RandomUtil.randomString(); bg = newBroadcast(nodeID, RandomUtil.randomString(), null, -1, groupAddress, groupPort); bg.start(); TransportConfiguration live1 = generateTC(); bg.addConnector(live1); dg1 = newDiscoveryGroup( RandomUtil.randomString(), RandomUtil.randomString(), null, groupAddress, groupPort, timeout); dg2 = newDiscoveryGroup( RandomUtil.randomString(), RandomUtil.randomString(), null, groupAddress, groupPort, timeout); dg3 = newDiscoveryGroup( RandomUtil.randomString(), RandomUtil.randomString(), null, groupAddress, groupPort, timeout); dg1.start(); dg2.start(); dg3.start(); bg.broadcastConnectors(); boolean ok = dg1.waitForBroadcast(1000); Assert.assertTrue(ok); List<DiscoveryEntry> entries = dg1.getDiscoveryEntries(); assertEqualsDiscoveryEntries(Arrays.asList(live1), entries); ok = dg2.waitForBroadcast(1000); Assert.assertTrue(ok); entries = dg2.getDiscoveryEntries(); assertEqualsDiscoveryEntries(Arrays.asList(live1), entries); ok = dg3.waitForBroadcast(1000); Assert.assertTrue(ok); entries = dg3.getDiscoveryEntries(); assertEqualsDiscoveryEntries(Arrays.asList(live1), entries); bg.stop(); dg1.stop(); dg2.stop(); dg3.stop(); }
private void doClose(final boolean sendClose) { if (state == STATE.CLOSED) { if (HornetQLogger.LOGGER.isDebugEnabled()) { HornetQLogger.LOGGER.debug(this + " is already closed when calling closed"); } return; } state = STATE.CLOSING; if (discoveryGroup != null) { synchronized (this) { try { discoveryGroup.stop(); } catch (Exception e) { HornetQLogger.LOGGER.failedToStopDiscovery(e); } } } else { staticConnector.disconnect(); } synchronized (connectingFactories) { for (ClientSessionFactoryInternal csf : connectingFactories) { csf.close(); } connectingFactories.clear(); } Set<ClientSessionFactoryInternal> clonedFactory; synchronized (factories) { clonedFactory = new HashSet<ClientSessionFactoryInternal>(factories); factories.clear(); } for (ClientSessionFactory factory : clonedFactory) { if (sendClose) { factory.close(); } else { factory.cleanup(); } } if (shutdownPool) { if (threadPool != null) { threadPool.shutdown(); try { if (!threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS)) { HornetQLogger.LOGGER.timedOutWaitingForTermination(); } } catch (InterruptedException ignore) { } } if (scheduledThreadPool != null) { scheduledThreadPool.shutdown(); try { if (!scheduledThreadPool.awaitTermination(10000, TimeUnit.MILLISECONDS)) { HornetQLogger.LOGGER.timedOutWaitingForScheduledPoolTermination(); } } catch (InterruptedException ignore) { } } } readOnly = false; state = STATE.CLOSED; }