コード例 #1
0
ファイル: TestStop.java プロジェクト: sebastiant/jchord
 @After
 public void cleanUp() {
   node1.stop();
   node2.stop();
   node3.stop();
   node1 = null;
   node2 = null;
   node3 = null;
 }
コード例 #2
0
ファイル: TestStop.java プロジェクト: sebastiant/jchord
 @Before
 public void setUp() {
   node1 = new MessageSender(9101);
   node2 = new MessageSender(9102);
   node3 = new MessageSender(9103);
   node1.start();
   node2.start();
   node3.start();
 }
コード例 #3
0
  @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);
  }
コード例 #4
0
  @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"));
  }
コード例 #5
0
  @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
ファイル: TestStop.java プロジェクト: sebastiant/jchord
  @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()));
    }
  }