protected void putPiEntityIntoDht(PiEntityBase piEntity, PId id) {
    BlockingDhtWriter dhtWriter = dhtClientFactory.createBlockingWriter();
    dhtWriter.update(
        id,
        piEntity,
        new UpdateResolvingPiContinuation<PiEntityBase>() {
          @Override
          public void handleResult(PiEntityBase result) {}

          @Override
          public PiEntityBase update(PiEntityBase existingEntity, PiEntityBase requestedEntity) {
            if (existingEntity != null) requestedEntity.setVersion(existingEntity.getVersion());

            return requestedEntity;
          }
        });
    System.err.println("Value written: " + dhtWriter.getValueWritten() + " to PId" + id);
  }
  @Before
  public void setup() {
    when(piIdBuilder.getPIdForEc2AvailabilityZone(uri)).thenReturn(instancePId);
    when(piIdBuilder.getGlobalAvailabilityZoneCodeFromEc2Id(instanceId)).thenReturn(globalAvzCode);
    when(piIdBuilder.getPId(SecurityGroup.getUrl(userId, securityGroupName)))
        .thenReturn(securityGroupPId);
    when(piIdBuilder.getPiQueuePId(PiQueue.INSTANCE_NETWORK_MANAGER_TEARDOWN))
        .thenReturn(instanceNetworkManagerTeardownQueueId);
    when(securityGroupPId.forGlobalAvailablityZoneCode(globalAvzCode)).thenReturn(securityGroupPId);

    when(instanceNetworkManagerTeardownQueueId.forLocalScope(
            PiQueue.TERMINATE_INSTANCE.getNodeScope()))
        .thenReturn(instanceNetworkManagerTeardownQueueId);
    when(messageContextFactory.newMessageContext()).thenReturn(messageContext);
    when(dhtClientFactory.createReader()).thenReturn(dhtReader);

    when(resultInstance.getInstanceId()).thenReturn(instanceId);
    when(resultInstance.getNodeId()).thenReturn(instanceNodeId);
    when(resultInstance.getUserId()).thenReturn(userId);
    when(resultInstance.getSecurityGroupName()).thenReturn(securityGroupName);
  }
 private void setupDht() {
   when(dhtClientFactory.createReader()).thenReturn(dhtReader);
   setupInstancesInDht();
 }
 protected PiEntityBase getPiEntityFromDht(PId id) {
   return (PiEntityBase) dhtClientFactory.createBlockingReader().get(id);
 }