コード例 #1
0
  @Test
  public void testScenarios_publications() throws Exception {

    InMemoryClient client = new InMemoryClient(new InMemoryRoutingContext(), RecipientKind.DM);
    LinkedBlockingQueue<Message> queue = new LinkedBlockingQueue<>();
    client.setMessageQueue(queue);

    MessagingContext ctx = new MessagingContext(RecipientKind.AGENTS, "domain", "app");

    // Not connected, publications cannot work
    Message msg = new MsgCmdAddInstance(new Instance(""));

    Assert.assertFalse(client.isConnected());
    Assert.assertEquals(0, queue.size());
    client.publish(ctx, msg);
    Assert.assertEquals(0, queue.size());

    // Connection
    client.openConnection();
    Assert.assertTrue(client.isConnected());
    client.publish(ctx, msg);
    Assert.assertEquals(0, queue.size());

    // We need to subscribe to this context to dispatch the message.
    // The messaging tests verify routing more precisely.
    client.subscribe(ctx);
    client.publish(ctx, msg);

    Assert.assertEquals(1, queue.size());
    Assert.assertEquals(msg, queue.element());
  }
コード例 #2
0
 @Override
 public E element() {
   return queue.element();
 }