final String contentKey = NetworkTestUtil.randomString();
final Parameters parametersA = new Parameters().setLocationKey(nodeA.getNodeId()).setContentKey(contentKey);
final Parameters parametersB = new Parameters().setLocationKey(nodeB.getNodeId()).setContentKey(contentKey);
// check if selected locations are empty
FutureGet futureGet = nodeA.getDataManager().getUnblocked(parametersB);
futureGet.awaitUninterruptibly();
assertNull(futureGet.getData());
futureGet = nodeB.getDataManager().getUnblocked(parametersA);
futureGet.awaitUninterruptibly();
assertNull(futureGet.getData());
// create a message with target node B
final TestMessageWithReply message = new TestMessageWithReply(nodeB.getNodeId(), contentKey);
// initialize the process and the one and only step to test
BaseMessageProcessStep step = new BaseMessageProcessStep(nodeA.getMessageManager()) {
@Override
protected void doExecute() throws InvalidProcessStateException {
try {
send(message, getPublicKey(nodeB));
} catch (SendFailedException e) {
Assert.fail(e.getMessage());
}
}
@Override
public void handleResponseMessage(ResponseMessage responseMessage) {
// locally store on requesting node received data
String receivedSecret = (String) responseMessage.getContent();
try {
nodeA.getDataManager().putUnblocked(parametersA.setData(new H2HTestData(receivedSecret)))
.awaitUninterruptibly();
} catch (NoPeerConnectionException e) {
Assert.fail(e.getMessage());
}
}
};
UseCaseTestUtil.executeProcess(step);
// wait till response message gets handled
H2HWaiter waiter = new H2HWaiter(10);
do {
waiter.tickASecond();
futureGet = nodeA.getDataManager().getUnblocked(parametersA);
futureGet.awaitUninterruptibly();
} while (futureGet.getData() == null);
// load and verify if same secret was shared
String receivedSecret = ((H2HTestData) futureGet.getData().object()).getTestString();
futureGet = nodeA.getDataManager().getUnblocked(parametersB);
futureGet.awaitUninterruptibly();
String originalSecret = ((H2HTestData) futureGet.getData().object()).getTestString();
assertEquals(originalSecret, receivedSecret);
}