Exemplo n.º 1
0
 private void testSender(int count) {
   ArrayList<String> expected = new ArrayList<String>(count);
   for (int i = 0; i < count; i++) {
     expected.add(template.render(i));
   }
   server.setMaxConnections(1);
   Sender snd = Sender.Builder().withTarget(server.address()).create();
   reactor.getHandler().add(snd);
   snd.start(reactor);
   for (String msg : expected) {
     snd.send(msg);
   }
   snd.close();
   reactor.run();
   assertEquals("messages received", expected, sink.getMessages());
 }
Exemplo n.º 2
-1
  private void testSampler(final int count, float frequency) {
    server.setMaxConnections(1);
    final ArrayList<String> expected = new ArrayList<String>(count);
    Timeout gen =
        new Timeout() {
          Tag tag = new SimpleTag(0);
          int sent = 0;

          @Override
          public void onSample(DatawireEvent e) {
            String body = template.render(sent);
            expected.add(body);
            Message message = Message.Factory.create();
            message.setBody(new AmqpValue(body));
            DatawireUtils.send(e.getLink(), tag, message);
            sent += 1;
            if (sent >= count) {
              e.getLink().close();
              cancel();
            }
          }
        };
    Sender snd =
        Sender.Builder()
            .withTarget(server.address())
            .withHandlers(new Sampler(gen, frequency))
            .create();
    reactor.getHandler().add(snd);
    gen.setTimeout(reactor, 2000);
    snd.start(reactor);
    reactor.run();
    assertTrue("Sampling timed out", gen.isCancelled());
    assertEquals("Expected messages", expected, sink.getMessages());
  }