Esempio n. 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());
  }
Esempio n. 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());
 }