/** * Test the broadcasted packages length.<br> * Broadcast and MultiCast techniques are commonly limited in size by * underlying hardware. Broadcast and MultiCast protocols are typically not * guaranteed (UDP) and as such large packages may be silently discarded by * underlying hardware.<br> * This test validates that Artemis Server does not broadcast packages above * a size of 1500 bytes. The limit is not derived from any normative * documents, but is rather derived from common MTU for network equipment. */ @Test public void testBroadcastDatagramLength() throws Throwable { BroadcastEndpointFactoryImpl befi; befi = new BroadcastEndpointFactoryImpl(); InVMNodeManager node; node = new InVMNodeManager(false); String name; name = "BroadcastGroupImplTest"; BroadcastGroupImpl test; test = new BroadcastGroupImpl(node, name, 1000, null, befi); TransportConfiguration tcon; tcon = new TransportConfiguration(getClass().getName()); test.addConnector(tcon); // Broadcast test.broadcastConnectors(); // Make sure we sent one package assertEquals("Incorrect number of sent datagrams", 1, befi.sent); } }
bg = new BroadcastGroupImpl(new FakeNodeManager("test-nodeID"), RandomUtil.randomString(), 1, scheduledExecutorService, new UDPBroadcastEndpointFactory().setGroupAddress(address1). setGroupPort(groupPort)); bg.start(); bg.addConnector(generateTC()); bg.stop();
private BroadcastGroup createBroadcastGroup(BroadcastGroupConfiguration config) throws Exception { BroadcastGroup group = broadcastGroups.get(config.getName()); if (group == null) { group = new BroadcastGroupImpl(nodeManager, config.getName(), config.getBroadcastPeriod(), scheduledExecutor, config.getEndpointFactory()); for (String connectorInfo : config.getConnectorInfos()) { TransportConfiguration connector = configuration.getConnectorConfigurations().get(connectorInfo); if (connector == null) { logWarnNoConnector(connectorInfo, config.getName()); return null; } group.addConnector(connector); } } if (group.size() == 0) { logWarnNoConnector(config.getConnectorInfos().toString(), group.getName()); return null; } broadcastGroups.put(config.getName(), group); return group; }
@Override public void run() { if (!started) { return; } try { broadcastConnectors(); loggedBroadcastException = false; } catch (Exception e) { // only log the exception at ERROR level once, even if it fails multiple times in a row - HORNETQ-919 if (!loggedBroadcastException) { ActiveMQServerLogger.LOGGER.errorBroadcastingConnectorConfigs(e); loggedBroadcastException = true; } else { logger.debug("Failed to broadcast connector configs...again", e); } } }
@Override public synchronized void start() throws Exception { if (started) { return; } endpoint.openBroadcaster(); started = true; if (notificationService != null) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(new SimpleString("name"), new SimpleString(name)); Notification notification = new Notification(nodeManager.getNodeId().toString(), CoreNotificationType.BROADCAST_GROUP_STARTED, props); notificationService.sendNotification(notification); } activate(); }
/** * This method is here just to facilitate creating the Broadcaster for this test */ protected BroadcastGroupImpl newBroadcast(final String nodeID, final String name, final InetAddress localAddress, int localPort, final InetAddress groupAddress, final int groupPort) throws Exception { return new BroadcastGroupImpl(new FakeNodeManager(nodeID), name, 0, null, new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress.getHostAddress()).setGroupPort(groupPort).setLocalBindAddress(localAddress != null ? localAddress.getHostAddress() : "localhost").setLocalBindPort(localPort)); }
@Test public void testSimpleBroadcast() throws Exception { final InetAddress groupAddress = InetAddress.getByName(address1); final int groupPort = getUDPDiscoveryPort(); final int timeout = 500; final String nodeID = RandomUtil.randomString(); bg = new BroadcastGroupImpl(new FakeNodeManager(nodeID), RandomUtil.randomString(), 0, null, new UDPBroadcastEndpointFactory().setGroupAddress(address1).setGroupPort(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); }
@Test public void testSimpleBroadcastJGropus() throws Exception { final String nodeID = RandomUtil.randomString(); bg = new BroadcastGroupImpl(new FakeNodeManager(nodeID), "broadcast", 100, null, new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE)); bg.start(); TransportConfiguration live1 = generateTC(); bg.addConnector(live1); dg = new DiscoveryGroup(nodeID + "1", "broadcast", 5000L, new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE), null); dg.start(); verifyBroadcast(bg, dg); List<DiscoveryEntry> entries = dg.getDiscoveryEntries(); assertEqualsDiscoveryEntries(Arrays.asList(live1), entries); }