JgroupsMessageReceiver extends ReceiverAdapter implements RequestHandler { @Override public void receive(final Message msg) { try { handle(msg); } catch (Exception exception) { if (!(exception instanceof SilverWareClusteringException)) { throw new SilverWareClusteringException(PROCESSING_ERROR, exception); } throw (SilverWareClusteringException) exception; } } JgroupsMessageReceiver(Map<Class, Responder> responders, RemoteServiceHandlesStore store); void setMyAddress(Address myAddress); Responder addResponder(Class clazz, Responder responder); @Override void receive(final Message msg); @Override void viewAccepted(final View view); @Override Object handle(Message msg);  }
@Test public void testReceiveWithUnknownClassThrowsException() throws Exception { HashMap<Class, Responder> classResponderHashMap = generateRespondersMap(); JgroupsMessageReceiver jgroupsMessageReceiver = new JgroupsMessageReceiver(classResponderHashMap, new RemoteServiceHandlesStore()); assertThatThrownBy(() -> jgroupsMessageReceiver.receive(UUID_MSG)).isInstanceOf(SilverWareClusteringException.class).hasMessageContaining(UUID.class.getName()); new Verifications() {{ responder1.processMessage((Message) any); times = 0; responder2.processMessage((Message) any); times = 0; }}; }
@Test public void testAddAfterMapWasPublishedResponder() throws Exception { HashMap<Class, Responder> classResponderHashMap = generateRespondersMap(); JgroupsMessageReceiver jgroupsMessageReceiver = new JgroupsMessageReceiver(classResponderHashMap, new RemoteServiceHandlesStore()); classResponderHashMap.put(UUID.class, responder2); assertThatThrownBy(() -> jgroupsMessageReceiver.receive(UUID_MSG)).isInstanceOf(SilverWareClusteringException.class).hasMessageContaining(UUID.class.getName()); jgroupsMessageReceiver.receive(STRING_MSG); new Verifications() {{ responder1.processMessage(STRING_MSG); times = 1; }}; }
@Test public void testReceive() throws Exception { HashMap<Class, Responder> classResponderHashMap = generateRespondersMap(); classResponderHashMap.put(UUID.class, responder2); JgroupsMessageReceiver jgroupsMessageReceiver = new JgroupsMessageReceiver(classResponderHashMap, new RemoteServiceHandlesStore()); jgroupsMessageReceiver.receive(UUID_MSG); jgroupsMessageReceiver.receive(UUID_MSG); jgroupsMessageReceiver.receive(STRING_MSG); new Verifications() {{ responder2.processMessage(UUID_MSG); times = 2; responder1.processMessage(STRING_MSG); times = 1; }}; }