Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.Locations


    NetworkContent loadedContent = get(userId, H2HConstants.USER_LOCATIONS);

    if (loadedContent == null) {
      context.provideLocations(null);
    } else {
      Locations locations = (Locations) loadedContent;
      if (!locations.getUserId().equalsIgnoreCase(userId))
        throw new ProcessExecutionException(String.format(
            "The wrong locations have been loaded. Required: %s. Got: %s.", userId,
            locations.getUserId()));

      context.provideLocations(locations);
    }
  }
View Full Code Here


    this.protectionKeyContext = protectionKeyContext;
  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    Locations locations = locationsContext.consumeLocations();

    locations.setBasedOnKey(locations.getVersionKey());
    try {
      locations.generateVersionKey();
    } catch (IOException e) {
      throw new ProcessExecutionException("Could not generate version key.", e);
    }

    try {
      put(locations.getUserId(), H2HConstants.USER_LOCATIONS, locations,
          protectionKeyContext.consumeProtectionKeys());
    } catch (PutFailedException e) {
      throw new ProcessExecutionException(e);
    }
  }
View Full Code Here

   * @throws NoSessionException
   * @throws NoPeerConnectionException
   */
  @Test
  public void allClientsAreAlive() throws NoSessionException, NoPeerConnectionException {
    Locations fakedLocations = new Locations(userId);
    fakedLocations.addPeerAddress(network.get(0).getConnection().getPeer().getPeerAddress());
    // responding nodes
    fakedLocations.addPeerAddress(network.get(1).getConnection().getPeer().getPeerAddress());
    fakedLocations.addPeerAddress(network.get(2).getConnection().getPeer().getPeerAddress());
    fakedLocations.addPeerAddress(network.get(3).getConnection().getPeer().getPeerAddress());

    Locations result = runProcessStep(fakedLocations,
        isInitialClient(fakedLocations, network.get(0).getConnection().getPeer().getPeerAddress()));

    assertEquals(4, result.getPeerAddresses().size());
    PeerAddress newClientsEntry = null;
    for (PeerAddress address : result.getPeerAddresses()) {
      if (address.equals(network.get(0).getConnection().getPeer().getPeerAddress())) {
        newClientsEntry = address;
        break;
      }
    }
View Full Code Here

    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)
View Full Code Here

   * @throws NoSessionException
   * @throws NoPeerConnectionException
   */
  @Test
  public void notAllClientsAreAlive() throws NoSessionException, NoPeerConnectionException {
    Locations fakedLocations = new Locations(userId);
    fakedLocations.addPeerAddress(network.get(0).getConnection().getPeer().getPeerAddress());
    fakedLocations.addPeerAddress(network.get(1).getConnection().getPeer().getPeerAddress());
    // not responding nodes
    fakedLocations.addPeerAddress(network.get(4).getConnection().getPeer().getPeerAddress());
    fakedLocations.addPeerAddress(network.get(5).getConnection().getPeer().getPeerAddress());

    Locations result = runProcessStep(fakedLocations,
        isInitialClient(fakedLocations, network.get(0).getConnection().getPeer().getPeerAddress()));

    assertEquals(2, result.getPeerAddresses().size());
    PeerAddress newClientsEntry = null;
    for (PeerAddress address : result.getPeerAddresses()) {
      if (address.equals(network.get(0).getConnection().getPeer().getPeerAddress())) {
        newClientsEntry = address;
        break;
      }
    }
View Full Code Here

   * @throws NoSessionException
   * @throws NoPeerConnectionException
   */
  @Test
  public void noOtherClientsOrDeadClients() throws NoSessionException, NoPeerConnectionException {
    Locations fakedLocations = new Locations(userId);
    fakedLocations.addPeerAddress(network.get(0).getConnection().getPeer().getPeerAddress());

    Locations result = runProcessStep(fakedLocations, true);

    assertEquals(1, result.getPeerAddresses().size());
    assertEquals(network.get(0).getConnection().getPeer().getPeerAddress(), result.getPeerAddresses().iterator().next());
  }
View Full Code Here

   * @throws NoSessionException
   * @throws NoPeerConnectionException
   */
  @Test
  public void allOtherClientsAreDead() throws NoSessionException, NoPeerConnectionException {
    Locations fakedLocations = new Locations(userId);
    fakedLocations.addPeerAddress(network.get(0).getConnection().getPeer().getPeerAddress());
    // not responding nodes
    fakedLocations.addPeerAddress(network.get(4).getConnection().getPeer().getPeerAddress());
    fakedLocations.addPeerAddress(network.get(5).getConnection().getPeer().getPeerAddress());

    Locations result = runProcessStep(fakedLocations, true);

    assertEquals(1, result.getPeerAddresses().size());
    assertEquals(network.get(0).getConnection().getPeer().getPeerAddress(), result.getPeerAddresses().iterator().next());
  }
View Full Code Here

   * @throws NoSessionException
   * @throws NoPeerConnectionException
   */
  @Test
  public void emptyLocations() throws NoSessionException, NoPeerConnectionException {
    Locations fakedLocations = new Locations(userId);

    Locations result = runProcessStep(fakedLocations, true);

    assertEquals(1, result.getPeerAddresses().size());
    assertEquals(network.get(0).getConnection().getPeer().getPeerAddress(), result.getPeerAddresses().iterator().next());
  }
View Full Code Here

   * @throws NoSessionException
   * @throws NoPeerConnectionException
   */
  @Test
  public void notCompleteLocations() throws NoSessionException, NoPeerConnectionException {
    Locations fakedLocations = new Locations(userId);
    fakedLocations.addPeerAddress(network.get(1).getConnection().getPeer().getPeerAddress());

    Locations result = runProcessStep(fakedLocations,
        isInitialClient(fakedLocations, network.get(0).getConnection().getPeer().getPeerAddress()));

    assertEquals(2, result.getPeerAddresses().size());
    PeerAddress newClientsEntry = null;
    for (PeerAddress address : result.getPeerAddresses()) {
      if (address.equals(network.get(0).getConnection().getPeer().getPeerAddress())) {
        newClientsEntry = address;
        break;
      }
    }
View Full Code Here

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

TOP

Related Classes of org.hive2hive.core.model.Locations

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.