Beispiel #1
0
  @Test
  public void testCreatorAddressIsCorrect() throws Exception {
    Context root = (Context) MojitoFactory.createDHT("bootstrap");
    root.bind(new InetSocketAddress("localhost", 8081));
    root.start();

    Context dht = (Context) MojitoFactory.createDHT("dht");
    dht.bind(new InetSocketAddress("localhost", 8080));
    dht.start();
    dht.bootstrap(new InetSocketAddress("localhost", 8081)).get();
    assertTrue(dht.isBootstrapped());

    DHTValueImpl value =
        new DHTValueImpl(DHTValueType.TEXT, Version.ZERO, "hello world".getBytes());

    StoreResult store = dht.put(Keys.of("key"), value).get();

    assertEquals(2, store.getLocations().size());

    FindValueResult result =
        dht.get(EntityKey.createEntityKey(Keys.of("key"), DHTValueType.TEXT)).get();

    assertTrue(result.isSuccess());
    assertEquals(1, result.getEntities().size());
    DHTValueEntity entity = result.getEntities().iterator().next();
    assertEquals(
        InetSocketAddress.createUnresolved("localhost", 8080),
        entity.getCreator().getContactAddress());
    assertEquals(
        InetSocketAddress.createUnresolved("localhost", 8081),
        entity.getSender().getContactAddress());

    root.close();
    dht.close();
  }