/** * Set up the receiver. Maybe better to just code sockets here? Set up the sender for sending * the message. * <p> * @throws Exception on error */ @Override protected void setUp() throws Exception { super.setUp(); receiver = new UDPDiscoveryReceiver( null, ADDRESS, PORT ); sender = new UDPDiscoverySender( ADDRESS, PORT ); }
Object obj = waitForMessage(); log.debug( getCnt() + " messages received." );
receiver.shutdown(); udpReceiverThread.interrupt();
UDPDiscoveryReceiver receiver = new UDPDiscoveryReceiver( service, attributes.getUdpDiscoveryAddr(), attributes .getUdpDiscoveryPort() ); Thread t = new Thread( receiver ); assertTrue( "Receiver count [" + receiver.getCnt() + "] should be the at least the number sent [" + cnt + "].", cnt <= receiver.getCnt() );
/** * Test sending a request broadcast. * <p> * @throws Exception on error */ public void testRequestBroadcast() throws Exception { // DO WORK sender.requestBroadcast(); // VERIFY // grab the sent message Object obj = receiver.waitForMessage(); assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; assertEquals( "wrong message type", BroadcastType.REQUEST, msg.getMessageType() ); } }
createSocket( this.multicastAddressString, this.multicastPort );
UDPDiscoveryReceiver receiver = new UDPDiscoveryReceiver( service, attributes.getUdpDiscoveryAddr(), attributes .getUdpDiscoveryPort() ); Thread t = new Thread( receiver ); assertTrue( "Receiver count [" + receiver.getCnt() + "] should be the at least the number sent [" + cnt + "].", cnt <= receiver.getCnt() );
/** * Test sending a request broadcast. * <p> * @throws Exception on error */ public void testRequestBroadcast() throws Exception { // DO WORK sender.requestBroadcast(); // VERIFY // grab the sent message Object obj = receiver.waitForMessage(); assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; assertEquals( "wrong message type", BroadcastType.REQUEST, msg.getMessageType() ); } }
createSocket( this.multicastAddressString, this.multicastPort );
Object obj = waitForMessage(); log.debug( getCnt() + " messages received." );
/** * Test sending a live messages. * <p> * @throws Exception on error */ public void testPassiveBroadcast() throws Exception { // SETUP ArrayList<String> cacheNames = new ArrayList<String>(); // DO WORK sender.passiveBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L ); // VERIFY // grab the sent message Object obj = receiver.waitForMessage() ; assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; // disabled test because of JCS-89 // assertEquals( "wrong host", SENDING_HOST, msg.getHost() ); assertEquals( "wrong port", SENDING_PORT, msg.getPort() ); assertEquals( "wrong message type", BroadcastType.PASSIVE, msg.getMessageType() ); }
receiver.shutdown(); udpReceiverThread.interrupt();
/** * Set up the receiver. Maybe better to just code sockets here? Set up the sender for sending * the message. * <p> * @throws Exception on error */ @Override protected void setUp() throws Exception { super.setUp(); receiver = new UDPDiscoveryReceiver( null, ADDRESS, PORT ); sender = new UDPDiscoverySender( ADDRESS, PORT ); }
/** * Test sending a live messages. * <p> * @throws Exception on error */ public void testPassiveBroadcast() throws Exception { // SETUP ArrayList<String> cacheNames = new ArrayList<String>(); // DO WORK sender.passiveBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L ); // VERIFY // grab the sent message Object obj = receiver.waitForMessage() ; assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; // disabled test because of JCS-89 // assertEquals( "wrong host", SENDING_HOST, msg.getHost() ); assertEquals( "wrong port", SENDING_PORT, msg.getPort() ); assertEquals( "wrong message type", BroadcastType.PASSIVE, msg.getMessageType() ); }
/** * Kill off the sender and receiver. * <p> * @throws Exception on error */ @Override protected void tearDown() throws Exception { receiver.shutdown(); sender.destroy(); super.tearDown(); }
receiver = new UDPDiscoveryReceiver( this, getUdpDiscoveryAttributes().getUdpDiscoveryAddr(), getUdpDiscoveryAttributes().getUdpDiscoveryPort() ); udpReceiverThread = new Thread( receiver );
/** * Test sending a remove broadcast. * <p> * @throws Exception on error */ public void testRemoveBroadcast() throws Exception { // SETUP ArrayList<String> cacheNames = new ArrayList<String>(); // DO WORK sender.removeBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L ); // VERIFY // grab the sent message Object obj = receiver.waitForMessage(); assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; // disabled test because of JCS-89 // assertEquals( "wrong host", SENDING_HOST, msg.getHost() ); assertEquals( "wrong port", SENDING_PORT, msg.getPort() ); assertEquals( "wrong message type", BroadcastType.REMOVE, msg.getMessageType() ); }
/** * Kill off the sender and receiver. * <p> * @throws Exception on error */ @Override protected void tearDown() throws Exception { receiver.shutdown(); sender.destroy(); super.tearDown(); }
/** * @param attributes */ public UDPDiscoveryService( UDPDiscoveryAttributes attributes) { udpDiscoveryAttributes = (UDPDiscoveryAttributes) attributes.clone(); try { // todo, you should be able to set this udpDiscoveryAttributes.setServiceAddress( HostNameUtil.getLocalHostAddress() ); } catch ( UnknownHostException e ) { log.error( "Couldn't get localhost address", e ); } try { // todo need some kind of recovery here. receiver = new UDPDiscoveryReceiver( this, getUdpDiscoveryAttributes().getUdpDiscoveryAddr(), getUdpDiscoveryAttributes().getUdpDiscoveryPort() ); } catch ( IOException e ) { log.error( "Problem creating UDPDiscoveryReceiver, address [" + getUdpDiscoveryAttributes().getUdpDiscoveryAddr() + "] port [" + getUdpDiscoveryAttributes().getUdpDiscoveryPort() + "] we won't be able to find any other caches", e ); } // create a sender thread sender = new UDPDiscoverySenderThread( getUdpDiscoveryAttributes(), getCacheNames() ); }
/** * Test sending a remove broadcast. * <p> * @throws Exception on error */ public void testRemoveBroadcast() throws Exception { // SETUP ArrayList<String> cacheNames = new ArrayList<String>(); // DO WORK sender.removeBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L ); // VERIFY // grab the sent message Object obj = receiver.waitForMessage(); assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; // disabled test because of JCS-89 // assertEquals( "wrong host", SENDING_HOST, msg.getHost() ); assertEquals( "wrong port", SENDING_PORT, msg.getPort() ); assertEquals( "wrong message type", BroadcastType.REMOVE, msg.getMessageType() ); }