Package org.hive2hive.core.network

Examples of org.hive2hive.core.network.NetworkManager


    assertEquals(data3, result3);
  }

  @Test
  public void testRemovalOneContentKey() throws NoPeerConnectionException {
    NetworkManager nodeA = network.get(random.nextInt(networkSize / 2));
    NetworkManager nodeB = network.get(random.nextInt(networkSize / 2) + networkSize / 2);
    String locationKey = nodeB.getNodeId();

    H2HTestData data = new H2HTestData(NetworkTestUtil.randomString());
    Parameters parameters = new Parameters().setLocationKey(locationKey).setDomainKey("domain key")
        .setContentKey(NetworkTestUtil.randomString()).setData(data);

    // put a content
    nodeA.getDataManager().putUnblocked(parameters).awaitUninterruptibly();

    // test that it is there
    FutureGet futureGet = nodeB.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();
    assertNotNull(futureGet.getData());

    // delete it
    nodeA.getDataManager().removeUnblocked(parameters).awaitUninterruptibly();

    // check that it is gone
    futureGet = nodeB.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
  }
View Full Code Here


  }

  @Test
  public void testRemovalMultipleContentKey() throws ClassNotFoundException, IOException,
      NoPeerConnectionException {
    NetworkManager nodeA = network.get(random.nextInt(networkSize / 2));
    NetworkManager nodeB = network.get(random.nextInt(networkSize / 2) + networkSize / 2);

    String locationKey = nodeB.getNodeId();

    String contentKey1 = NetworkTestUtil.randomString();
    String testString1 = NetworkTestUtil.randomString();
    Parameters parameters1 = new Parameters().setLocationKey(locationKey).setContentKey(contentKey1)
        .setData(new H2HTestData(testString1));

    String contentKey2 = NetworkTestUtil.randomString();
    String testString2 = NetworkTestUtil.randomString();
    Parameters parameters2 = new Parameters().setLocationKey(locationKey).setContentKey(contentKey2)
        .setData(new H2HTestData(testString2));

    String contentKey3 = NetworkTestUtil.randomString();
    String testString3 = NetworkTestUtil.randomString();
    Parameters parameters3 = new Parameters().setLocationKey(locationKey).setContentKey(contentKey3)
        .setData(new H2HTestData(testString3));

    // insert them
    FuturePut put1 = nodeA.getDataManager().putUnblocked(parameters1);
    put1.awaitUninterruptibly();

    FuturePut put2 = nodeA.getDataManager().putUnblocked(parameters2);
    put2.awaitUninterruptibly();

    FuturePut put3 = nodeA.getDataManager().putUnblocked(parameters3);
    put3.awaitUninterruptibly();

    // check that they are all stored
    FutureGet futureGet = nodeB.getDataManager().getUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertEquals(testString1, ((H2HTestData) futureGet.getData().object()).getTestString());
    futureGet = nodeB.getDataManager().getUnblocked(parameters2);
    futureGet.awaitUninterruptibly();
    assertEquals(testString2, ((H2HTestData) futureGet.getData().object()).getTestString());
    futureGet = nodeB.getDataManager().getUnblocked(parameters3);
    futureGet.awaitUninterruptibly();
    assertEquals(testString3, ((H2HTestData) futureGet.getData().object()).getTestString());

    // remove 2nd one and check that 1st and 3rd are still there
    nodeA.getDataManager().removeUnblocked(parameters2).awaitUninterruptibly();
    futureGet = nodeB.getDataManager().getUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertEquals(testString1, ((H2HTestData) futureGet.getData().object()).getTestString());
    futureGet = nodeB.getDataManager().getUnblocked(parameters2);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
    futureGet = nodeB.getDataManager().getUnblocked(parameters3);
    futureGet.awaitUninterruptibly();
    assertEquals(testString3, ((H2HTestData) futureGet.getData().object()).getTestString());

    // remove 3rd one as well and check that they are gone as well
    nodeA.getDataManager().removeUnblocked(parameters1).awaitUninterruptibly();
    nodeA.getDataManager().removeUnblocked(parameters3).awaitUninterruptibly();
    futureGet = nodeB.getDataManager().getUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
    futureGet = nodeB.getDataManager().getUnblocked(parameters2);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
    futureGet = nodeB.getDataManager().getUnblocked(parameters3);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
  }
View Full Code Here

    Parameters parameters = new Parameters().setLocationKey(NetworkTestUtil.randomString())
        .setContentKey(NetworkTestUtil.randomString()).setVersionKey(data.getVersionKey())
        .setData(data).setProtectionKeys(keypairOld).setNewProtectionKeys(keypairNew)
        .setTTL(data.getTimeToLive()).setHashFlag(true);

    NetworkManager node = network.get(random.nextInt(networkSize));

    // put some initial data
    FuturePut putFuture1 = node.getDataManager().putUnblocked(parameters);
    putFuture1.awaitUninterruptibly();
    Assert.assertTrue(putFuture1.isSuccess());
   
    // parameters without the data object itself
    parameters = new Parameters().setLocationKey(parameters.getLocationKey())
      .setContentKey(parameters.getContentKey()).setVersionKey(data.getVersionKey())
      .setProtectionKeys(keypairOld).setNewProtectionKeys(keypairNew)
      .setTTL(data.getTimeToLive());

    // change content protection key
    FuturePut changeFuture = node.getDataManager().changeProtectionKeyUnblocked(parameters);
    changeFuture.awaitUninterruptibly();
    Assert.assertTrue(changeFuture.isSuccess());

    // verify if content protection key has been changed
    Data resData = node.getDataManager().getUnblocked(parameters).awaitUninterruptibly().getData();
    Assert.assertEquals(keypairNew.getPublic(), resData.publicKey());
  }
View Full Code Here

  @Test
  public void testPut() throws NoPeerConnectionException {
    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));

    TestPutUserProfileTaskStep putStep = new TestPutUserProfileTaskStep(userId, userProfileTask, key.getPublic(), node);
    UseCaseTestUtil.executeProcess(putStep);

    Parameters parameters = new Parameters().setLocationKey(userId).setDomainKey(H2HConstants.USER_PROFILE_TASK_DOMAIN)
        .setContentKey(userProfileTask.getContentKey());
    FutureGet futureGet = node.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();

    assertNotNull(futureGet.getData());
  }
View Full Code Here

  @Test
  public void testPutRollback() throws InvalidProcessStateException, NoPeerConnectionException, ProcessExecutionException {
    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));

    TestPutUserProfileTaskStep putStep = new TestPutUserProfileTaskStep(userId, userProfileTask, key.getPublic(), node);

    TestProcessComponentListener listener = new TestProcessComponentListener();
    AsyncComponent component = new AsyncComponent(putStep);
    component.attachListener(listener);

    // start and cancel immediately
    component.start();
    putStep.cancel(new RollbackReason("Testing whether rollback works."));
    UseCaseTestUtil.waitTillFailed(listener, 10);

    Parameters parameters = new Parameters().setLocationKey(userId).setDomainKey(H2HConstants.USER_PROFILE_TASK_DOMAIN)
        .setContentKey(userProfileTask.getContentKey());
    FutureGet futureGet = node.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
  }
View Full Code Here

  @Test
  public void testPutGet() throws IOException, NoPeerConnectionException {
    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    SimpleGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();

    SequentialProcess process = new SequentialProcess();
View Full Code Here

  @Test
  public void testPutGetRollback() throws IOException, NoPeerConnectionException {
    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    SimpleGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();

    SequentialProcess process = new SequentialProcess();
View Full Code Here

  @Test
  public void testPutGetRemove() throws NoPeerConnectionException, IOException {
    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    SimpleGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();

    SequentialProcess process = new SequentialProcess();
    process.add(new TestPutUserProfileTaskStep(userId, userProfileTask, key.getPublic(), node));
    process.add(new GetUserProfileTaskStep(context, node));
    process.add(new RemoveUserProfileTaskStep(context, node));

    UseCaseTestUtil.executeProcess(process);

    Parameters parameters = new Parameters().setLocationKey(userId).setDomainKey(H2HConstants.USER_PROFILE_TASK_DOMAIN)
        .setContentKey(userProfileTask.getContentKey());
    FutureGet futureGet = node.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();

    assertNull(futureGet.getData());
  }
View Full Code Here

      InvalidCipherTextException, IllegalBlockSizeException, BadPaddingException, ClassNotFoundException, IOException,
      NoPeerConnectionException {
    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    // IGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();
    // HybridEncryptedContent encrypted = H2HEncryptionUtil.encryptHybrid(userProfileTask,
    // key.getPublic());
View Full Code Here

  @Test
  public void testCorrectOrder() throws DataLengthException, InvalidKeyException, IllegalStateException,
      InvalidCipherTextException, IllegalBlockSizeException, BadPaddingException, InterruptedException, IOException,
      NoPeerConnectionException {
    String userId = NetworkTestUtil.randomString();
    NetworkManager node = network.get(random.nextInt(networkSize));
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    // create some tasks
    List<TestUserProfileTask> tasks = new ArrayList<TestUserProfileTask>();
    for (int i = 0; i < 5; i++) {
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.