String data = NetworkTestUtil.randomString();
String contentKey = NetworkTestUtil.randomString();
Parameters parameters = new Parameters().setLocationKey(nodeB.getNodeId()).setContentKey(contentKey);
// check if selected location is empty
FutureGet futureGet = nodeA.getDataManager().getUnblocked(parameters);
futureGet.awaitUninterruptibly();
assertNull(futureGet.getData());
// create a message with target node B
final TestMessage message = new TestMessage(nodeB.getNodeId(), contentKey, new H2HTestData(data));
// 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) {
Assert.fail("Should be not used.");
}
};
UseCaseTestUtil.executeProcess(step);
// wait till message gets handled
H2HWaiter w = new H2HWaiter(10);
do {
w.tickASecond();
futureGet = nodeA.getDataManager().getUnblocked(parameters);
futureGet.awaitUninterruptibly();
} while (futureGet.getData() == null);
// verify that data arrived
String result = ((H2HTestData) futureGet.getData().object()).getTestString();
assertEquals(data, result);
}