Package org.hive2hive.core.network

Examples of org.hive2hive.core.network.NetworkManager


  @Test
  public void testNonExistingPublicKey() throws NoPeerConnectionException {
    String loggedInUserId = NetworkTestUtil.randomString();
    KeyPair loggedInUserKeys = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);

    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(loggedInUserId, loggedInUserKeys,
        node.getDataManager());

    String nonExistingUserId = NetworkTestUtil.randomString();

    try {
      publicKeyManager.getPublicKey(nonExistingUserId);
View Full Code Here


  @Test
  public void testGetFailedExceptions() throws NoPeerConnectionException {
    String loggedInUserId = NetworkTestUtil.randomString();
    KeyPair loggedInUserKeys = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);

    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(loggedInUserId, loggedInUserKeys,
        node.getDataManager());

    String otherUser = NetworkTestUtil.randomString();
    H2HTestData noPublicKey = new H2HTestData("public key");
    Parameters parameters = new Parameters().setLocationKey(otherUser)
        .setContentKey(H2HConstants.USER_PUBLIC_KEY).setData(noPublicKey);
View Full Code Here

  @Test
  public void testAllMixed() throws GetFailedException, NoPeerConnectionException {
    String loggedInUserId = NetworkTestUtil.randomString();
    KeyPair loggedInUserKeys = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);

    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(loggedInUserId, loggedInUserKeys,
        node.getDataManager());

    // create and upload some fake public keys into the network
    Map<String, PublicKey> publicKeys = new HashMap<String, PublicKey>();
    for (int i = 0; i < 5; i++) {
      String userId = NetworkTestUtil.randomString();
View Full Code Here

    network = NetworkTestUtil.createNetwork(networkSize);
  }

  @Test
  public void testStepSuccess() throws InterruptedException, NoPeerConnectionException {
    NetworkManager getter = network.get(0); // where the process runs
    NetworkManager proxy = network.get(1); // where the user profile is stored

    // create the needed objects
    String userId = proxy.getNodeId();
    Locations newLocations = new Locations(userId);
    newLocations.addPeerAddress(getter.getConnection().getPeer().getPeerAddress());

    // put the locations to the DHT
    proxy.getDataManager()
        .putUnblocked(
            new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_LOCATIONS)
                .setData(newLocations)).awaitUninterruptibly();

    GetLocationsContext context = new GetLocationsContext();
View Full Code Here

    Assert.assertEquals(getter.getConnection().getPeer().getPeerAddress(), onlinePeers.get(0));
  }

  @Test
  public void testStepSuccessWithNoLocations() throws NoPeerConnectionException {
    NetworkManager getter = network.get(0); // where the process runs
    NetworkManager proxy = network.get(1); // where the user profile is stored

    // create the needed objects, put no locations
    String userId = proxy.getNodeId();

    GetLocationsContext context = new GetLocationsContext();
    GetUserLocationsStep step = new GetUserLocationsStep(userId, context, getter.getDataManager());
    UseCaseTestUtil.executeProcess(step);
View Full Code Here

  @Test
  public void testStepSuccessful() throws InterruptedException, InvalidKeySpecException,
      DataLengthException, IllegalStateException, InvalidCipherTextException, ClassNotFoundException,
      IOException, NoPeerConnectionException {
    NetworkManager putter = network.get(0); // where the process runs
    NetworkManager client = network.get(1); // where the user profile is stored

    // create the needed objects
    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();

    UserProfile testProfile = new UserProfile(credentials.getUserId());
    IConsumeUserProfile context = new ConsumeProfileContext(testProfile);

    // initialize the process and the one and only step to test
    PutUserProfileStep step = new PutUserProfileStep(credentials, context, putter.getDataManager());
    UseCaseTestUtil.executeProcess(step);

    // get the user profile which should be stored at the proxy
    FutureGet global = client.getDataManager().getUnblocked(
        new Parameters().setLocationKey(credentials.getProfileLocationKey()).setContentKey(
            H2HConstants.USER_PROFILE));
    global.awaitUninterruptibly();
    global.getFutureRequests().awaitUninterruptibly();
    EncryptedNetworkContent found = (EncryptedNetworkContent) global.getData().object();
View Full Code Here

  }

  @Test
  public void testStepRollback() throws InterruptedException, NoPeerConnectionException,
      InvalidProcessStateException {
    NetworkManager putter = network.get(0); // where the process runs
    putter.getConnection().getPeer().getPeerBean().storage(new DenyingPutTestStorage());
    NetworkManager proxy = network.get(1); // where the user profile is stored
    proxy.getConnection().getPeer().getPeerBean().storage(new DenyingPutTestStorage());

    // create the needed objects
    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();
    UserProfile testProfile = new UserProfile(credentials.getUserId());
    IConsumeUserProfile context = new ConsumeProfileContext(testProfile);

    // initialize the process and the one and only step to test
    PutUserProfileStep step = new PutUserProfileStep(credentials, context, putter.getDataManager());
    TestProcessComponentListener listener = new TestProcessComponentListener();
    step.attachListener(listener);
    step.start();

    UseCaseTestUtil.waitTillFailed(listener, 20);

    // get the locations which should be stored at the proxy --> they should be null
    FutureGet futureGet = proxy.getDataManager().getUnblocked(
        new Parameters().setLocationKey(credentials.getProfileLocationKey()).setContentKey(
            H2HConstants.USER_LOCATIONS));
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
  }
View Full Code Here

  @Before
  public void createProfileUploadBaseFile() throws IOException, IllegalFileLocation, NoSessionException,
      NoPeerConnectionException {
    network = NetworkTestUtil.createNetwork(networkSize);
    NetworkManager registrar = network.get(0);
    uploader = network.get(1);
    downloader = network.get(2);

    userCredentials = NetworkTestUtil.generateRandomCredentials();
View Full Code Here

   */
  @Test
  public void baseMessageProcessStepTestOnSuccess() throws ClassNotFoundException, IOException,
      NoPeerConnectionException {
    // select two random nodes
    NetworkManager nodeA = network.get(random.nextInt(network.size() / 2));
    final NetworkManager nodeB = network.get(random.nextInt(network.size() / 2) + network.size() / 2);
    // generate random data and content key
    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 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
View Full Code Here

   */
  @Test
  public void baseMessageProcessStepTestOnFailure() throws NoPeerConnectionException,
      InvalidProcessStateException {
    // select two random nodes
    NetworkManager nodeA = network.get(random.nextInt(network.size() / 2));
    final NetworkManager nodeB = network.remove(random.nextInt(network.size() / 2) + network.size() / 2);
    // generate random data and content key
    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
View Full Code Here

TOP

Related Classes of org.hive2hive.core.network.NetworkManager

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.