ClusteredServer extends DefaultServer { public Action<Map<String, Object>> messageAction() { return messageAction; }  @Override Server find(ServerSocketPredicate predicate, SerializableAction<ServerSocket> action); Server onpublish(Action<Map<String, Object>> action); Action<Map<String, Object>> messageAction();  }
@Test public void messageAction() { Set<ClusteredServer> servers = new LinkedHashSet<>(); ClusteredServer server1 = new ClusteredServer(); DefaultServerSocket socketA = mock(DefaultServerSocket.class); DefaultServerSocket socketB = mock(DefaultServerSocket.class); when(socketA.id()).thenReturn("A"); when(socketB.id()).thenReturn("B"); server1.sockets.put(socketA.id(), socketA); server1.sockets.put(socketB.id(), socketB); servers.add(server1); ClusteredServer server2 = new ClusteredServer(); DefaultServerSocket socketC = mock(DefaultServerSocket.class); DefaultServerSocket socketD = mock(DefaultServerSocket.class); when(socketC.id()).thenReturn("C"); when(socketD.id()).thenReturn("D"); server2.sockets.put(socketC.id(), socketC); server2.sockets.put(socketD.id(), socketD); servers.add(server2); Action<Map<String, Object>> pubAction = map -> servers.forEach(server -> server.messageAction().on(map)); servers.forEach(server -> server.onpublish(pubAction)); Set<String> ids = new LinkedHashSet<>(); server1.find(all(), socket -> ids.add(socket.id())); assertEquals(new LinkedHashSet<>(Arrays.asList("A", "B", "C", "D")), ids); ids.clear(); server2.find(id("A"), socket -> ids.add(socket.id())); assertEquals(new LinkedHashSet<>(Arrays.asList("A")), ids); }