use of org.apache.heron.common.network.IncomingPacket in project heron by twitter.
the class HandleWriteTest method testHandleWrite.
/**
* Test write into network
*/
@Test
public void testHandleWrite() throws IOException {
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().bind(new InetSocketAddress(HOST, getServerPort()));
SocketChannel socketChannel = null;
try {
StreamManagerClient streamManagerClient = runStreamManagerClient();
socketChannel = acceptSocketChannel(serverSocketChannel);
// Receive request
REQID rid = readIncomingPacket(socketChannel).unpackREQID();
OutgoingPacket outgoingPacket = new OutgoingPacket(rid, UnitTestHelper.getRegisterInstanceResponse());
outgoingPacket.writeToChannel(socketChannel);
HeronServerTester.await(getInControlQueueOfferLatch());
for (int i = 0; i < 10; i++) {
// We randomly choose some messages writing to stream mgr
streamManagerClient.sendMessage(UnitTestHelper.getRegisterInstanceResponse());
}
for (int i = 0; i < 10; i++) {
IncomingPacket incomingPacket = readIncomingPacket(socketChannel);
incomingPacket.unpackREQID();
StreamManager.RegisterInstanceResponse.Builder builder = StreamManager.RegisterInstanceResponse.newBuilder();
incomingPacket.unpackMessage(builder);
StreamManager.RegisterInstanceResponse response = builder.build();
Assert.assertNotNull(response);
Assert.assertTrue(response.isInitialized());
Assert.assertEquals(Common.StatusCode.OK, response.getStatus().getStatus());
Assert.assertEquals(1, response.getPplan().getStmgrsCount());
Assert.assertEquals(2, response.getPplan().getInstancesCount());
Assert.assertEquals(1, response.getPplan().getTopology().getBoltsCount());
Assert.assertEquals(1, response.getPplan().getTopology().getSpoutsCount());
Assert.assertEquals(TopologyAPI.TopologyState.RUNNING, response.getPplan().getTopology().getState());
}
getNIOLooper().exitLoop();
} catch (ClosedChannelException ignored) {
} finally {
close(socketChannel);
}
}
use of org.apache.heron.common.network.IncomingPacket in project heron by twitter.
the class AbstractNetworkTest method readIncomingPacket.
IncomingPacket readIncomingPacket(SocketChannel socketChannel) throws IOException {
// Receive request
IncomingPacket incomingPacket = new IncomingPacket();
Selector readSelector = Selector.open();
socketChannel.register(readSelector, SelectionKey.OP_READ);
readSelector.select(HeronServerTester.RESPONSE_RECEIVED_TIMEOUT.toMillis());
// and the data read
if (incomingPacket.readFromChannel(socketChannel) != 0) {
readSelector.select(HeronServerTester.RESPONSE_RECEIVED_TIMEOUT.toMillis());
assertEquals(0, incomingPacket.readFromChannel(socketChannel));
}
// Though we do not use typeName, we need to unpack it first, since the order is required.
// doing this as a convenience since none of the callers of this method need this.
incomingPacket.unpackString();
return incomingPacket;
}
Aggregations