Package net.tomp2p.futures

Examples of net.tomp2p.futures.FutureGet


    String data = NetworkTestUtil.randomString();
    String contentKey = NetworkTestUtil.randomString();
    Parameters parameters = new Parameters().setLocationKey(nodeB.getNodeId()).setContentKey(contentKey);

    // check if selected location is empty
    FutureGet futureGet = nodeA.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());

    // assign a denying message handler at target node
    nodeB.getConnection().getPeer().setObjectDataReply(new DenyingMessageReplyHandler());

    // create a message with target node B
    final TestMessage message = new TestMessage(nodeB.getNodeId(), contentKey, new H2HTestData(data));

    // initialize the process and the one and only step to test
    BaseMessageProcessStep step = new BaseMessageProcessStep(nodeA.getMessageManager()) {

      @Override
      protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
        try {
          send(message, getPublicKey(nodeB));
          Assert.fail();
        } catch (SendFailedException e) {
          // expected
          throw new ProcessExecutionException("Expected behavior.", e);
        }
      }

      @Override
      public void handleResponseMessage(ResponseMessage responseMessage) {
        Assert.fail("Should be not used.");
      }
    };
    TestProcessComponentListener listener = new TestProcessComponentListener();
    step.attachListener(listener);
    step.start();
    // wait for the process to finish
    UseCaseTestUtil.waitTillFailed(listener, 10);

    // check if selected location is still empty
    futureGet = nodeA.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
  }
View Full Code Here


    final String contentKey = NetworkTestUtil.randomString();
    final Parameters parametersA = new Parameters().setLocationKey(nodeA.getNodeId()).setContentKey(contentKey);
    final Parameters parametersB = new Parameters().setLocationKey(nodeB.getNodeId()).setContentKey(contentKey);
   
    // check if selected locations are empty
    FutureGet futureGet = nodeA.getDataManager().getUnblocked(parametersB);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
    futureGet = nodeB.getDataManager().getUnblocked(parametersA);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());

    // create a message with target node B
    final TestMessageWithReply message = new TestMessageWithReply(nodeB.getNodeId(), contentKey);

    // initialize the process and the one and only step to test
    BaseMessageProcessStep step = new BaseMessageProcessStep(nodeA.getMessageManager()) {

      @Override
      protected void doExecute() throws InvalidProcessStateException {
        try {
          send(message, getPublicKey(nodeB));
        } catch (SendFailedException e) {
          Assert.fail(e.getMessage());
        }
      }

      @Override
      public void handleResponseMessage(ResponseMessage responseMessage) {
        // locally store on requesting node received data
        String receivedSecret = (String) responseMessage.getContent();
        try {
          nodeA.getDataManager().putUnblocked(parametersA.setData(new H2HTestData(receivedSecret)))
              .awaitUninterruptibly();
        } catch (NoPeerConnectionException e) {
          Assert.fail(e.getMessage());
        }
      }
    };
    UseCaseTestUtil.executeProcess(step);

    // wait till response message gets handled
    H2HWaiter waiter = new H2HWaiter(10);
    do {
      waiter.tickASecond();
      futureGet = nodeA.getDataManager().getUnblocked(parametersA);
      futureGet.awaitUninterruptibly();
    } while (futureGet.getData() == null);

    // load and verify if same secret was shared
    String receivedSecret = ((H2HTestData) futureGet.getData().object()).getTestString();
    futureGet = nodeA.getDataManager().getUnblocked(parametersB);
    futureGet.awaitUninterruptibly();
    String originalSecret = ((H2HTestData) futureGet.getData().object()).getTestString();

    assertEquals(originalSecret, receivedSecret);
  }
View Full Code Here

  }

  public int getArrivedMessageCount() {
    int counter = 0;
    for (String contentKey : testContentKeys) {
      FutureGet futureGet = null;
      try {
        futureGet = sender.getDataManager().getUnblocked(
            new Parameters().setLocationKey(sender.getNodeId()).setContentKey(contentKey));
        futureGet.awaitUninterruptibly();
      } catch (NoPeerConnectionException e1) {
        Assert.fail();
      }

      if (futureGet.getData() == null) {
        continue;
      }

      try {
        H2HTestData gotData = (H2HTestData) futureGet.getData().object();
        if (gotData.getTestString().equalsIgnoreCase(data.getTestString())) {
          counter++;
        }
      } catch (ClassNotFoundException | IOException e) {
        Assert.fail();
View Full Code Here

    Assert.assertNotNull(client.getSession());
    Assert.assertEquals(userCredentials.getUserId(), client.getUserId());

    // verify the locations map
    FutureGet futureGet = client.getDataManager().getUnblocked(
        new Parameters().setLocationKey(userCredentials.getUserId()).setContentKey(H2HConstants.USER_LOCATIONS));
    futureGet.awaitUninterruptibly();

    Locations locations = (Locations) futureGet.getData().object();
    Assert.assertEquals(1, locations.getPeerAddresses().size());
  }
View Full Code Here

    String data = NetworkTestUtil.randomString();
    String contentKey = NetworkTestUtil.randomString();
    Parameters parameters = new Parameters().setLocationKey(nodeB.getNodeId()).setContentKey(contentKey);

    // check if selected location is empty
    FutureGet futureGet = nodeA.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());

    // create a message with target node B
    final TestDirectMessage message = new TestDirectMessage(nodeB.getNodeId(), nodeB.getConnection()
        .getPeer().getPeerAddress(), contentKey, new H2HTestData(data), false);

    // initialize the process and the one and only step to test
    BaseDirectMessageProcessStep step = new BaseDirectMessageProcessStep(nodeA.getMessageManager()) {
      @Override
      public void handleResponseMessage(ResponseMessage responseMessage) {
        Assert.fail("Should be not used.");
      }

      @Override
      protected void doExecute() throws InvalidProcessStateException {
        try {
          sendDirect(message, getPublicKey(nodeB));
        } catch (SendFailedException e) {
          Assert.fail();
        }
      }
    };
    UseCaseTestUtil.executeProcess(step);

    // wait till message gets handled
    H2HWaiter w = new H2HWaiter(10);
    do {
      w.tickASecond();
      futureGet = nodeB.getDataManager().getUnblocked(parameters);
      futureGet.awaitUninterruptibly();
    } while (futureGet.getData() == null);

    // verify that data arrived
    String result = ((H2HTestData) futureGet.getData().object()).getTestString();
    assertNotNull(result);
    assertEquals(data, result);
  }
View Full Code Here

    String data = NetworkTestUtil.randomString();
    String contentKey = NetworkTestUtil.randomString();
    Parameters parameters = new Parameters().setLocationKey(nodeB.getNodeId()).setContentKey(contentKey);

    // check if selected location is empty
    FutureGet futureGet = nodeA.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());

    // assign a denying message handler at target node
    nodeB.getConnection().getPeer().setObjectDataReply(new DenyingMessageReplyHandler());

    // create a message with target node B
    final TestDirectMessage message = new TestDirectMessage(nodeB.getNodeId(), nodeB.getConnection()
        .getPeer().getPeerAddress(), contentKey, new H2HTestData(data), false);

    // initialize the process and the one and only step to test
    BaseDirectMessageProcessStep step = new BaseDirectMessageProcessStep(nodeA.getMessageManager()) {
      @Override
      public void handleResponseMessage(ResponseMessage responseMessage) {
        Assert.fail("Should be not used.");
      }

      @Override
      protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
        try {
          sendDirect(message, getPublicKey(nodeB));
          Assert.fail();
        } catch (SendFailedException e) {
          throw new ProcessExecutionException("Expected behavior.", e);
        }
      }
    };
    TestProcessComponentListener listener = new TestProcessComponentListener();
    step.attachListener(listener);
    step.start();
    // wait for the process to finish
    UseCaseTestUtil.waitTillFailed(listener, 10);

    // check if selected location is still empty
    futureGet = nodeB.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
  }
View Full Code Here

        contentKey);
    final Parameters parametersB = new Parameters().setLocationKey(nodeB.getNodeId()).setContentKey(
        contentKey);

    // check if selected locations are empty
    FutureGet futureGet = nodeB.getDataManager().getUnblocked(parametersA);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
    futureGet = nodeA.getDataManager().getUnblocked(parametersB);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());

    // create a message with target node B
    final TestDirectMessageWithReply message = new TestDirectMessageWithReply(nodeB.getConnection()
        .getPeer().getPeerAddress(), contentKey);

    // initialize the process and the one and only step to test
    BaseDirectMessageProcessStep step = new BaseDirectMessageProcessStep(nodeA.getMessageManager()) {
      @Override
      public void handleResponseMessage(ResponseMessage responseMessage) {
        // locally store on requesting node received data
        String receivedSecret = (String) responseMessage.getContent();
        try {
          nodeA.getDataManager().putUnblocked(parametersA.setData(new H2HTestData(receivedSecret)))
              .awaitUninterruptibly();
        } catch (NoPeerConnectionException e) {
          Assert.fail();
        }
      }

      @Override
      protected void doExecute() throws InvalidProcessStateException {
        try {
          sendDirect(message, getPublicKey(nodeB));
        } catch (SendFailedException e) {
          Assert.fail();
        }
      }
    };
    UseCaseTestUtil.executeProcess(step);

    // wait till response message gets handled
    H2HWaiter waiter = new H2HWaiter(10);
    do {
      waiter.tickASecond();
      futureGet = nodeA.getDataManager().getUnblocked(parametersA);
      futureGet.awaitUninterruptibly();
    } while (futureGet.getData() == null);

    // load and verify if same secret was shared
    String receivedSecret = ((H2HTestData) futureGet.getData().object()).getTestString();
    futureGet = nodeB.getDataManager().getUnblocked(parametersB);
    futureGet.awaitUninterruptibly();
    String originalSecret = ((H2HTestData) futureGet.getData().object()).getTestString();
    assertEquals(originalSecret, receivedSecret);
  }
View Full Code Here

    MetaFile metaDocument = UseCaseTestUtil.getMetaFile(client, metaKeyPair, false);
    Assert.assertNull(metaDocument);

    for (FileVersion version : metaDocumentBeforeDeletion.getVersions()) {
      for (MetaChunk metaChunks : version.getMetaChunks()) {
        FutureGet get = client.getDataManager().getUnblocked(
            new Parameters().setLocationKey(metaChunks.getChunkId()).setContentKey(
                H2HConstants.FILE_CHUNK));
        get.awaitUninterruptibly();
        get.getFutureRequests().awaitUninterruptibly();

        // chunk should not exist
        Assert.assertNull(get.getData());
      }
    }
  }
View Full Code Here

    // initialize the process and the one and only step to test
    TestRemoveProcessStep putStep = new TestRemoveProcessStep(locationKey, contentKey, network.get(0)
        .getDataManager());
    UseCaseTestUtil.executeProcess(putStep);

    FutureGet futureGet = network.get(0).getDataManager()
        .getUnblocked(new Parameters().setLocationKey(locationKey).setContentKey(contentKey));
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
  }
View Full Code Here

    // initialize the process and the one and only step to test
    TestPutProcessStep putStep = new TestPutProcessStep(locationKey, contentKey, new H2HTestData(data),
        putter.getDataManager());
    UseCaseTestUtil.executeProcess(putStep);

    FutureGet futureGet = proxy.getDataManager().getUnblocked(
        new Parameters().setLocationKey(locationKey).setContentKey(contentKey));
    futureGet.awaitUninterruptibly();
    assertEquals(data, ((H2HTestData) futureGet.getData().object()).getTestString());
  }
View Full Code Here

TOP

Related Classes of net.tomp2p.futures.FutureGet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.