use of org.apache.heron.common.network.OutgoingPacket 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.OutgoingPacket in project heron by twitter.
the class HandleReadTest method testHandleRead.
/**
* Test reading from network
*/
@Test
public void testHandleRead() throws IOException {
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().bind(new InetSocketAddress(HOST, getServerPort()));
SocketChannel socketChannel = null;
try {
runStreamManagerClient();
socketChannel = acceptSocketChannel(serverSocketChannel);
// Receive request
REQID rid = readIncomingPacket(socketChannel).unpackREQID();
OutgoingPacket outgoingPacket = new OutgoingPacket(rid, UnitTestHelper.getRegisterInstanceResponse());
outgoingPacket.writeToChannel(socketChannel);
HeronServerTester.await(getInControlQueueOfferLatch());
outgoingPacket = new OutgoingPacket(REQID.zeroREQID, constructMockMessage());
outgoingPacket.writeToChannel(socketChannel);
HeronServerTester.await(getInStreamQueueOfferLatch());
getNIOLooper().exitLoop();
Assert.assertEquals(1, getInStreamQueue().size());
Message msg = getInStreamQueue().poll();
Assert.assertTrue(msg instanceof HeronTuples.HeronTupleSet);
HeronTuples.HeronTupleSet heronTupleSet = (HeronTuples.HeronTupleSet) msg;
Assert.assertTrue(heronTupleSet.hasData());
Assert.assertFalse(heronTupleSet.hasControl());
HeronTuples.HeronDataTupleSet heronDataTupleSet = heronTupleSet.getData();
Assert.assertEquals("test-spout", heronDataTupleSet.getStream().getComponentName());
Assert.assertEquals("default", heronDataTupleSet.getStream().getId());
StringBuilder response = new StringBuilder();
for (HeronTuples.HeronDataTuple heronDataTuple : heronDataTupleSet.getTuplesList()) {
response.append(heronDataTuple.getValues(0).toStringUtf8());
Assert.assertEquals(1, heronDataTuple.getRootsCount());
}
Assert.assertEquals("ABABABABAB", response.toString());
} catch (ClosedChannelException ignored) {
} finally {
close(socketChannel);
}
}
use of org.apache.heron.common.network.OutgoingPacket in project heron by twitter.
the class ConnectTest method testStart.
/**
* Test connection
*/
@Test
public void testStart() throws IOException {
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().bind(new InetSocketAddress(HOST, getServerPort()));
SocketChannel socketChannel = null;
try {
runStreamManagerClient();
socketChannel = acceptSocketChannel(serverSocketChannel);
// Receive request
REQID rid = readIncomingPacket(socketChannel).unpackREQID();
OutgoingPacket outgoingPacket = new OutgoingPacket(rid, UnitTestHelper.getRegisterInstanceResponse());
outgoingPacket.writeToChannel(socketChannel);
HeronServerTester.await(getInControlQueueOfferLatch());
InstanceControlMsg instanceControlMsg = getInControlQueue().poll();
assertNotNull(instanceControlMsg);
getNIOLooper().exitLoop();
getThreadPool().shutdownNow();
PhysicalPlanHelper physicalPlanHelper = instanceControlMsg.getNewPhysicalPlanHelper();
Assert.assertEquals("test-bolt", physicalPlanHelper.getMyComponent());
Assert.assertEquals(InetAddress.getLocalHost().getHostName(), physicalPlanHelper.getMyHostname());
Assert.assertEquals(0, physicalPlanHelper.getMyInstanceIndex());
Assert.assertEquals(1, physicalPlanHelper.getMyTaskId());
} catch (ClosedChannelException ignored) {
} finally {
close(socketChannel);
}
}
Aggregations