assertTrue("Failed to connect", connector1.awaitJoined(5, TimeUnit.SECONDS));
assertTrue("Failed to connect", connector2.awaitJoined(5, TimeUnit.SECONDS));
DistributedCommandBus bus1 = new DistributedCommandBus(connector1, new AnnotationRoutingStrategy(
UnresolvedRoutingKeyPolicy.RANDOM_KEY));
CommandGateway gateway1 = new DefaultCommandGateway(bus1);
doThrow(new RuntimeException("Mock")).when(serializer).deserialize(argThat(new TypeSafeMatcher<SerializedObject<byte[]>>() {
@Override
protected boolean matchesSafely(SerializedObject<byte[]> item) {
return Arrays.equals("<string>Try this!</string>".getBytes(Charset.forName("UTF-8")), item.getData());
}
@Override
public void describeTo(Description description) {
}
}));
try {
gateway1.sendAndWait("Try this!");
fail("Expected exception");
} catch (RuntimeException e) {
assertEquals("Mock", e.getMessage());
}
}