*/
@Test
public void baseDirectMessageProcessStepTestWithARequestMessage() throws ClassNotFoundException,
IOException, NoPeerConnectionException {
// select two random nodes
final NetworkManager nodeA = network.get(random.nextInt(network.size() / 2));
final NetworkManager nodeB = network.get(random.nextInt(network.size() / 2) + network.size() / 2);
// generate a random content key
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 = nodeB.getDataManager().getUnblocked(parametersA);
futureGet.awaitUninterruptibly();
assertNull(futureGet.getData());
futureGet = nodeA.getDataManager().getUnblocked(parametersB);
futureGet.awaitUninterruptibly();
assertNull(futureGet.getData());
// create a message with target node B
final TestDirectMessageWithReply message = new TestDirectMessageWithReply(nodeB.getConnection()
.getPeer().getPeerAddress(), contentKey);
// initialize the process and the one and only step to test
BaseDirectMessageProcessStep step = new BaseDirectMessageProcessStep(nodeA.getMessageManager()) {
@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();
}
}
@Override
protected void doExecute() throws InvalidProcessStateException {
try {
sendDirect(message, getPublicKey(nodeB));
} catch (SendFailedException e) {
Assert.fail();
}
}
};
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 = nodeB.getDataManager().getUnblocked(parametersB);
futureGet.awaitUninterruptibly();
String originalSecret = ((H2HTestData) futureGet.getData().object()).getTestString();
assertEquals(originalSecret, receivedSecret);
}