Search in sources :

Example 1 with CellEndpoint

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);
}
Also used : CellMessage(dmg.cells.nucleus.CellMessage) CellEndpoint(dmg.cells.nucleus.CellEndpoint) Test(org.junit.Test)

Example 2 with CellEndpoint

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));
}
Also used : CellMessage(dmg.cells.nucleus.CellMessage) CellEndpoint(dmg.cells.nucleus.CellEndpoint) Test(org.junit.Test)

Example 3 with CellEndpoint

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());
}
Also used : CellMessage(dmg.cells.nucleus.CellMessage) CellAddressCore(dmg.cells.nucleus.CellAddressCore) CellEndpoint(dmg.cells.nucleus.CellEndpoint) CellMessage(dmg.cells.nucleus.CellMessage) Message(diskCacheV111.vehicles.Message) Test(org.junit.Test)

Example 4 with CellEndpoint

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);
}
Also used : CellMessage(dmg.cells.nucleus.CellMessage) CellAddressCore(dmg.cells.nucleus.CellAddressCore) UOID(dmg.cells.nucleus.UOID) CellEndpoint(dmg.cells.nucleus.CellEndpoint) CellMessage(dmg.cells.nucleus.CellMessage) Message(diskCacheV111.vehicles.Message) Test(org.junit.Test)

Example 5 with CellEndpoint

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);
}
Also used : CellEndpoint(dmg.cells.nucleus.CellEndpoint) Test(org.junit.Test)

Aggregations

CellEndpoint (dmg.cells.nucleus.CellEndpoint)9 CellMessage (dmg.cells.nucleus.CellMessage)8 Test (org.junit.Test)7 Message (diskCacheV111.vehicles.Message)5 CellAddressCore (dmg.cells.nucleus.CellAddressCore)4 UOID (dmg.cells.nucleus.UOID)3 CacheException (diskCacheV111.util.CacheException)2 Reply (dmg.cells.nucleus.Reply)2 Serializable (java.io.Serializable)2