Package org.hive2hive.core.network

Examples of org.hive2hive.core.network.NetworkManager


  }

  @Test
  public void testGetProcessStepSuccess() throws NoPeerConnectionException {
    H2HTestData data = new H2HTestData(NetworkTestUtil.randomString());
    NetworkManager getter = network.get(0);
    NetworkManager holder = network.get(1);

    String locationKey = holder.getNodeId();
    String contentKey = NetworkTestUtil.randomString();

    // put in the memory of 2nd peer
    holder.getDataManager()
        .putUnblocked(
            new Parameters().setLocationKey(holder.getNodeId()).setContentKey(contentKey)
                .setData(data)).awaitUninterruptibly();

    TestGetProcessStep getStep = new TestGetProcessStep(locationKey, contentKey, getter.getDataManager());
    UseCaseTestUtil.executeProcess(getStep);
View Full Code Here


    Assert.assertEquals(data.getTestString(), ((H2HTestData) getStep.getContent()).getTestString());
  }

  @Test
  public void testGetProcessStepRollBack() throws NoPeerConnectionException, InvalidProcessStateException {
    NetworkManager getter = network.get(0);
    NetworkManager holder = network.get(1);

    String locationKey = holder.getNodeId();
    String contentKey = NetworkTestUtil.randomString();

    TestGetProcessStepRollBack getStepRollBack = new TestGetProcessStepRollBack(locationKey, contentKey,
        getter.getDataManager());
    TestProcessComponentListener listener = new TestProcessComponentListener();
View Full Code Here

  public void uploadFile() throws Exception {
    /** create a network, register a user and add a file **/
    network = NetworkTestUtil.createNetwork(networkSize);

    userCredentials = NetworkTestUtil.generateRandomCredentials();
    NetworkManager uploader = network.get(networkSize - 1);
    downloader = network.get(new Random().nextInt(networkSize - 2));

    // register and login both users
    File uploaderRoot = FileTestUtil.getTempDirectory();
    UseCaseTestUtil.registerAndLogin(userCredentials, uploader, uploaderRoot);
View Full Code Here

  }

  @Test
  public void testRootToDirectory() throws IOException, IllegalFileLocation, GetFailedException,
      InterruptedException, NoSessionException, NoPeerConnectionException {
    NetworkManager client = network.get(1);
    UseCaseTestUtil.login(userCredentials, client, root);

    // add a file to the network
    File file = FileTestUtil.createFileRandomContent(3, root, CHUNK_SIZE);
    UseCaseTestUtil.uploadNewFile(client, file);
View Full Code Here

  }

  @Test
  public void testDirectoryToRoot() throws IOException, IllegalFileLocation, GetFailedException,
      InterruptedException, NoSessionException, NoPeerConnectionException {
    NetworkManager client = network.get(1);
    UseCaseTestUtil.login(userCredentials, client, root);

    // add the source folder
    File folder = new File(root, "folder");
    folder.mkdir();
View Full Code Here

  }

  @Test
  public void testDirectoryToDirectory() throws IOException, IllegalFileLocation, GetFailedException,
      InterruptedException, NoSessionException, NoPeerConnectionException {
    NetworkManager client = network.get(1);
    UseCaseTestUtil.login(userCredentials, client, root);

    // add the source folder
    File sourceFolder = new File(root, "source-folder");
    sourceFolder.mkdir();
View Full Code Here

  }

  @Test
  public void testRename() throws IOException, IllegalFileLocation, GetFailedException,
      InterruptedException, NoSessionException, NoPeerConnectionException {
    NetworkManager client = network.get(1);
    UseCaseTestUtil.login(userCredentials, client, root);

    // add a file to the network
    File file = new File(root, "test-file");
    FileUtils.write(file, NetworkTestUtil.randomString());
View Full Code Here

    network = NetworkTestUtil.createNetwork(networkSize);
  }

  @Test
  public void testPutProcessSuccess() throws ClassNotFoundException, IOException, NoPeerConnectionException {
    NetworkManager putter = network.get(0);
    putter.getConnection().getPeer().getPeerBean().storage(new H2HStorageMemory());
    NetworkManager proxy = network.get(1);
    proxy.getConnection().getPeer().getPeerBean().storage(new H2HStorageMemory());

    String locationKey = proxy.getNodeId();
    String contentKey = NetworkTestUtil.randomString();
    String data = NetworkTestUtil.randomString();

    // 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

    assertEquals(data, ((H2HTestData) futureGet.getData().object()).getTestString());
  }

  @Test
  public void testPutProcessFailure() throws NoPeerConnectionException, InvalidProcessStateException {
    NetworkManager putter = network.get(0);
    putter.getConnection().getPeer().getPeerBean().storage(new DenyingPutTestStorage());
    NetworkManager proxy = network.get(1);
    proxy.getConnection().getPeer().getPeerBean().storage(new DenyingPutTestStorage());

    String locationKey = proxy.getNodeId();
    String contentKey = NetworkTestUtil.randomString();
    String data = NetworkTestUtil.randomString();

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

    // wait for the process to finish
    UseCaseTestUtil.waitTillFailed(listener, 10);

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

  @Test(expected = NoSessionException.class)
  public void testUploadNoSession() throws IOException, IllegalFileLocation, NoSessionException,
      InvalidProcessStateException, NoPeerConnectionException {
    // skip the login and continue with the newfile process
    NetworkManager client = network.get(2);

    File file = FileTestUtil.createFileRandomContent(1, uploaderRoot, CHUNK_SIZE);
    IProcessComponent process = ProcessFactory.instance().createNewFileProcess(file, client);
    TestProcessComponentListener listener = new TestProcessComponentListener();
    process.attachListener(listener);
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.