示例#1
0
  @Test
  public void testSettingTheBootstrapNodeAsBootStrapped() throws Exception {
    Context dht = (Context) MojitoFactory.createDHT("bootstrap");
    dht.bind(new InetSocketAddress("localhost", 8080));
    dht.setBootstrapped(true);
    dht.start();

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

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

    node.put(Keys.of("key"), value).get();

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

    assertTrue(result.isSuccess());
    assertEquals(1, result.getEntities().size());
    assertEquals(
        "hello world", new String(result.getEntities().iterator().next().getValue().getValue()));

    node.close();
    dht.close();
  }