@Test public void testProducerServerForClient() throws UnknownHostException, RemoteServiceInitFailedException { ProducerServerForClient producerServerForClient = new ProducerServerForClient(); int port = 4000; producerServerForClient.setPort(port); producerServerForClient.setRemoteServiceName("remoteService"); Assert.assertEquals(port, producerServerForClient.getPort()); producerServerForClient.start(); PktProducerGreet pktProducerGreet = new PktProducerGreet("0.6.0", "Unit Test"); SwallowMessage swallowMessage = new SwallowMessage(); swallowMessage.setContent("UnitTest"); swallowMessage.setGeneratedTime(new Date()); swallowMessage.setSourceIp("192.168.32.194"); swallowMessage.setVersion("0.6.0"); PktMessage pktMessage = new PktMessage(Destination.topic("UnitTest"), swallowMessage); PktSwallowPACK ACK = null; ACK = (PktSwallowPACK) producerServerForClient.sendMessage(pktProducerGreet); Assert.assertEquals(PacketType.SWALLOW_P_ACK, ACK.getPacketType()); Assert.assertEquals(IPUtil.getFirstNoLoopbackIP4Address(), ACK.getShaInfo()); MessageDAO messageDAO = mock(MessageDAO.class); producerServerForClient.setMessageDAO(messageDAO); ACK = (PktSwallowPACK) producerServerForClient.sendMessage(pktMessage); Assert.assertEquals(PacketType.SWALLOW_P_ACK, ACK.getPacketType()); Assert.assertEquals(SHAUtil.generateSHA(swallowMessage.getContent()), ACK.getShaInfo()); doThrow(new RuntimeException()).when(messageDAO).saveMessage(Matchers.anyString(), (SwallowMessage) Matchers.anyObject()); ACK = null; try { ACK = (PktSwallowPACK) producerServerForClient.sendMessage(pktMessage); } catch (ServerDaoException e) { } Assert.assertNull(ACK); System.out.println(producerServerForClient.getRemoteServiceName()); }
public ProducerServerForClient() { HawkJMXUtil.unregisterMBean("ProducerServerForClient"); HawkJMXUtil.registerMBean("ProducerServerForClient", new HawkMBean(this)); }
ProducerServerForClient implements ProducerSwallowService { public ProducerServerForClient() { HawkJMXUtil.unregisterMBean("ProducerServerForClient"); HawkJMXUtil.registerMBean("ProducerServerForClient", new HawkMBean(this)); } }
ProducerServerForClient implements ProducerSwallowService { public ProducerServerForClient() { HawkJMXUtil.unregisterMBean("ProducerServerForClient"); HawkJMXUtil.registerMBean("ProducerServerForClient", new HawkMBean(this)); } ProducerServerForClient(); }
ProducerServerForClient implements ProducerSwallowService { public ProducerServerForClient() { HawkJMXUtil.unregisterMBean("ProducerServerForClient"); HawkJMXUtil.registerMBean("ProducerServerForClient", new HawkMBean(this)); } ProducerServerForClient(); void start(); @Override Packet sendMessage(Packet pkt); int getPort(); void setPort(int port); void setMessageDAO(MessageDAO messageDAO); String getRemoteServiceName(); void setRemoteServiceName(String remoteServiceName); }
ProducerServerForClient implements ProducerSwallowService { public ProducerServerForClient() { HawkJMXUtil.unregisterMBean("ProducerServerForClient"); HawkJMXUtil.registerMBean("ProducerServerForClient", new HawkMBean(this)); } ProducerServerForClient(); void start(); @Override Packet sendMessage(Packet pkt); int getPort(); void setPort(int port); void setMessageDAO(MessageDAO messageDAO); String getRemoteServiceName(); void setRemoteServiceName(String remoteServiceName); static final String producerServerIP; }