use of dmg.cells.nucleus.CellEndpoint in project dcache by dCache.
the class MessageReplyTest method shouldNotSendIfDeliveringWithoutMessage.
@Test
public void shouldNotSendIfDeliveringWithoutMessage() {
MessageReply messageReply = new MessageReply();
CellMessage envelope = new CellMessage();
CellEndpoint endpoint = mock(CellEndpoint.class);
messageReply.deliver(endpoint, envelope);
verify(endpoint, times(0)).sendMessage(envelope);
}
use of dmg.cells.nucleus.CellEndpoint in project dcache by dCache.
the class MessageReplyTest method shouldBeInvalidIfDelayIsBiggerThanTimeToLiveOfEnvelope.
@Test
public void shouldBeInvalidIfDelayIsBiggerThanTimeToLiveOfEnvelope() {
MessageReply messageReply = new MessageReply();
CellMessage envelope = new CellMessage();
CellEndpoint endpoint = mock(CellEndpoint.class);
messageReply.deliver(endpoint, envelope);
long ttl = TimeUnit.HOURS.toMillis(1);
envelope.setTtl(ttl);
long delay = TimeUnit.MINUTES.toMillis(5);
assertFalse(messageReply.isValidIn(ttl + delay));
}
use of dmg.cells.nucleus.CellEndpoint in project dcache by dCache.
the class MessageReplyTest method shouldSendIfReplyingWithAnEnvelope.
@Test
public void shouldSendIfReplyingWithAnEnvelope() throws ExecutionException, InterruptedException {
MessageReply<Message> messageReply = new MessageReply<>();
Message message = new Message();
CellMessage envelope = new CellMessage();
CellAddressCore pathSource = new CellAddressCore("foo", "source");
envelope.addSourceAddress(pathSource);
CellEndpoint endpoint = mock(CellEndpoint.class);
messageReply.deliver(endpoint, envelope);
messageReply.reply(message);
verify(endpoint, times(1)).sendMessage(envelope);
assertEquals(messageReply.get(), message);
assertTrue(message.isReply());
}
use of dmg.cells.nucleus.CellEndpoint in project dcache by dCache.
the class MessageReplyTest method shouldSendAMessageIfEverythingIsSet.
@Test
public void shouldSendAMessageIfEverythingIsSet() {
MessageReply<Message> messageReply = new MessageReply<>();
Message message = new Message();
CellMessage envelope = new CellMessage();
CellEndpoint endpoint = mock(CellEndpoint.class);
CellAddressCore pathSource = new CellAddressCore("foo", "source");
UOID umit = envelope.getUOID();
envelope.addSourceAddress(pathSource);
messageReply.reply(message);
messageReply.deliver(endpoint, envelope);
verify(endpoint, times(1)).sendMessage(envelope);
// TODO Mocking of final classes (like CellMessage) is an incubating feature
// and can be done by using a Mockito extension. This would simplify the tests.
assertEquals("[>foo@source]", envelope.getDestinationPath().toString());
assertEquals("[empty]", envelope.getSourcePath().toString());
assertEquals(umit, envelope.getLastUOID());
assertNotEquals(umit, envelope.getUOID());
assertTrue(envelope.isReply());
assertEquals(envelope.getMessageObject(), message);
}
use of dmg.cells.nucleus.CellEndpoint in project dcache by dCache.
the class MessageReplyTest method shouldThrowAnExceptionIfDeliveringWithoutEnvelope.
@Test(expected = NullPointerException.class)
public void shouldThrowAnExceptionIfDeliveringWithoutEnvelope() {
MessageReply messageReply = new MessageReply();
CellEndpoint endpoint = mock(CellEndpoint.class);
messageReply.deliver(endpoint, null);
}
Aggregations