예제 #1
0
 @After
 public void cleanUp() {
   node1.stop();
   node2.stop();
   node3.stop();
   node1 = null;
   node2 = null;
   node3 = null;
 }
예제 #2
0
 @Before
 public void setUp() {
   node1 = new MessageSender(9101);
   node2 = new MessageSender(9102);
   node3 = new MessageSender(9103);
   node1.start();
   node2.start();
   node3.start();
 }
  @Test
  public void shouldMapReceiveAttributes() throws JMSException {
    // Given
    Mapping mapping = MessageSender.getJmsMappingFor(MappedApi.class);

    MapMessage message = createPayload(OPERATION_FIELD_NAME, "mappedCall", "A", "value1", "B", 0L);

    // When
    receive(message, mapping);

    // Then
    verify(serviceMock).mappedCall("value1", 0L);
  }
  @Test
  public void shouldMapSendAttributes() throws JMSException {
    // Given
    MappedApi proxy = MessageSender.of(MappedApi.class);

    // When
    proxy.mappedCall("a", 0L);

    // Then
    MapMessage message = (MapMessage) captureMessage();
    assertEquals("a", message.getObject("A"));
    assertEquals("0", message.getObject("B"));
  }
  @Test
  public void shouldCallServiceWhenSendingAsMapMessage() {
    // Given
    MappedApi sendProxy = MessageSender.of(MappedApi.class);
    Mapping receiveMapping =
        new MappingBuilder(OPERATION_FIELD_NAME) //
            .mapField("s1", FieldMapping.map("A")) //
            .mapField("s2", FieldMapping.map("B")) //
            .build();

    // When
    sendProxy.mappedCall("a", 0L);
    receive(captureMessage(), receiveMapping);

    // Then
    verify(serviceMock).mappedCall("a", 0L);
  }
예제 #6
0
  @Test
  public void test() {
    node2.registerMessageObserver(
        new ConcreteObserver<Message>() {
          @Override
          public void notifyObserver(Message e) {
            if (e.has("content") && e.getString("content").equals("message1")) {
              recievedMessage1 = true;
            }
            if (e.has("content") && e.getString("content").equals("message3")) {
              fail("Recieved message while being in stopped state.");
            }
          }
        });
    node3.registerMessageObserver(
        new ConcreteObserver<Message>() {
          @Override
          public void notifyObserver(Message e) {
            if (e.has("content") && e.getString("content").equals("message2")) {
              recievedMessage2 = true;
            }
            if (e.has("content") && e.getString("content").equals("message4")) {
              recievedMessage4 = true;
            }
            if (e.has("content") && e.getString("content").equals("message5")) {
              fail("Recieved message from stopped node");
            }
          }
        });

    Message message = new Message();
    message.setDestinationAddress(node2.getAddress());
    message.setKey("content", "message1");
    node1.send(message);
    message = new Message();
    message.setDestinationAddress(node3.getAddress());
    message.setKey("content", "message2");
    node2.send(message);
    node2.stop();
    message = new Message();
    message.setDestinationAddress(node2.getAddress());
    message.setKey("content", "message3");
    node1.send(message);
    message = new Message();
    message.setDestinationAddress(node3.getAddress());
    message.setKey("content", "message4");
    node1.send(message);
    message = new Message();
    message.setDestinationAddress(node3.getAddress());
    message.setKey("content", "message5");
    assertFalse(node2.send(message));
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e1) {
      fail(e1.getMessage());
    }
    assertTrue(recievedMessage1);
    assertTrue(recievedMessage2);
    assertTrue(recievedMessage4);
    assertTrue(node2.getConnections().size() == 0);
    for (Entry<Address, Connection> e : node1.getConnections().entrySet()) {
      assertEquals(e.getKey(), e.getValue().getAddress());
      assertFalse(e.getKey().equals(node2.getAddress()));
    }
    for (Entry<Address, Connection> e : node3.getConnections().entrySet()) {
      assertEquals(e.getKey(), e.getValue().getAddress());
      assertFalse(e.getKey().equals(node3.getAddress()));
    }
  }