Пример #1
0
  @SuppressWarnings("serial")
  private void testLinker(int addressCount, int messageCount) {
    server.setMaxConnections(addressCount);
    Linker linker = new Linker();
    linker.start(reactor);
    for (int i : range(addressCount)) {
      for (int j : range(messageCount)) {
        Sender snd = linker.sender(server.address(i), null);
        assertEquals("sender per address", i + 1, linker.sendersSize());
        final int fi = i, fj = j;
        snd.send(dict("i", fi, "j", fj));
      }
    }
    linker.close();
    reactor.run();

    HashMap<Integer, ArrayList<Map<?, ?>>> by_addr = new HashMap<>();
    for (int i : range(addressCount)) {
      by_addr.put(i, new ArrayList<Map<?, ?>>());
    }
    ArrayList<Map<?, ?>> messagesDicts = sink.getMessagesDicts();
    for (Map<?, ?> m : messagesDicts) {
      assertNotNull("did not receive a dict", m);
      by_addr.get(m.get("i")).add(m);
    }
    for (int i : range(addressCount)) {
      ArrayList<Map<?, ?>> actual = by_addr.get(i);
      ArrayList<Map<?, ?>> expected = new ArrayList<>(messageCount);
      for (int j : range(messageCount)) {
        expected.add(dict("i", i, "j", j));
      }
      assertEquals(String.format("Messages for address %d", i), expected, actual);
    }
    assertEquals("total messages", addressCount * messageCount, messagesDicts.size());
  }
Пример #2
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());
 }
Пример #3
-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());
  }