CommunicationObserver { public void gotMessageFrom(String client, String request, String address, int port) throws MalformedObjectNameException { log.debug("Message '{}' received from client {}", request, client); createOrUpdateClientMBean(client, address, port, m -> m.onMessageReceived(new Date(), request)); } CommunicationObserver(String id);   CommunicationObserver(String id, int maxClientMBeans); void unregister(); void gotMessageFrom(String client, String request, String address, int port); void didSendSegmentBytes(String client, int size); void didSendBinariesBytes(String client, long size); String getID();  }
@Test public void shouldRegisterObservablePartnerMBean() throws Exception { observer.gotMessageFrom("client", "request", "127.0.0.1", 8080); assertEquals(1, observer.communicationPartners.size()); }
@Test public void shouldNotKeepManyObservablePartnerMBeans() throws Exception { for (int i = 0; i < 20; i++) { observer.gotMessageFrom(randomUUID().toString(), "request", "127.0.0.1", 8080); } assertEquals(10, observer.communicationPartners.size()); }
@Test public void observablePartnerMBeanShouldExposeClientName() throws Exception { observer.gotMessageFrom("client", "request", "127.0.0.1", 8080); assertEquals("client", observer.communicationPartners.get(0).getName()); }
@Test public void observablePartnerMBeanShouldExposeAddress() throws Exception { observer.gotMessageFrom("client", "request", "127.0.0.1", 8080); assertEquals("127.0.0.1", observer.communicationPartners.get(0).getRemoteAddress()); }
@Test public void observablePartnerMBeanShouldExposePort() throws Exception { observer.gotMessageFrom("client", "request", "127.0.0.1", 8080); assertEquals(8080, observer.communicationPartners.get(0).getRemotePort()); }
@Test public void observablePartnerMBeanShouldExposeLastRequest() throws Exception { observer.gotMessageFrom("client", "request", "127.0.0.1", 8080); assertEquals("request", observer.communicationPartners.get(0).getLastRequest()); }
@Test public void observablePartnerMBeanShouldUpdateLastRequest() throws Exception { observer.gotMessageFrom("client", "before", "127.0.0.1", 8080); assertEquals("before", observer.communicationPartners.get(0).getLastRequest()); observer.gotMessageFrom("client", "after", "127.0.0.1", 8080); assertEquals("after", observer.communicationPartners.get(0).getLastRequest()); }
@Test public void observablePartnerMBeanShouldExposeLastSeen() throws Exception { observer.gotMessageFrom("client", "request", "127.0.0.1", 8080); assertNotNull(observer.communicationPartners.get(0).getLastSeen()); }
@Test public void observablePartnerMBeanShouldUpdateLastSeen() throws Exception { observer.gotMessageFrom("client", "request", "127.0.0.1", 8080); Date before = observer.communicationPartners.get(0).getLastSeen(); observer.gotMessageFrom("client", "request", "127.0.0.1", 8080); Date after = observer.communicationPartners.get(0).getLastSeen(); assertNotSame(before, after); }
@Test public void observablePartnerMBeanShouldExposeLastSeenTimestamp() throws Exception { observer.gotMessageFrom("client", "request", "127.0.0.1", 8080); assertNotNull(observer.communicationPartners.get(0).getLastSeenTimestamp()); }