use of org.apache.heron.instance.InstanceControlMsg 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);
}
}
use of org.apache.heron.instance.InstanceControlMsg in project heron by twitter.
the class BoltInstanceTest method testReadTupleAndExecute.
/**
* Test the reading of a tuple and apply execute on that tuple
*/
@Test
public void testReadTupleAndExecute() {
PhysicalPlans.PhysicalPlan physicalPlan = UnitTestHelper.getPhysicalPlan(false, -1);
PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, BOLT_INSTANCE_ID);
InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
executorTester.getInControlQueue().offer(instanceControlMsg);
final int expectedTuples = 10;
CountDownLatch executeLatch = new CountDownLatch(expectedTuples);
SingletonRegistry.INSTANCE.registerSingleton(Constants.ACK_COUNT, ackCount);
SingletonRegistry.INSTANCE.registerSingleton(Constants.FAIL_COUNT, failCount);
SingletonRegistry.INSTANCE.registerSingleton(Constants.EXECUTE_COUNT, tupleExecutedCount);
SingletonRegistry.INSTANCE.registerSingleton(Constants.EXECUTE_LATCH, executeLatch);
SingletonRegistry.INSTANCE.registerSingleton(Constants.RECEIVED_STRING_LIST, receivedStrings);
// Send tuples to bolt instance
HeronTuples.HeronTupleSet.Builder heronTupleSet = HeronTuples.HeronTupleSet.newBuilder();
heronTupleSet.setSrcTaskId(SRC_TASK_ID);
HeronTuples.HeronDataTupleSet.Builder dataTupleSet = HeronTuples.HeronDataTupleSet.newBuilder();
TopologyAPI.StreamId.Builder streamId = TopologyAPI.StreamId.newBuilder();
streamId.setComponentName("test-spout");
streamId.setId("default");
dataTupleSet.setStream(streamId);
// We will add 10 tuples to the set
for (int i = 0; i < expectedTuples; i++) {
HeronTuples.HeronDataTuple.Builder dataTuple = HeronTuples.HeronDataTuple.newBuilder();
dataTuple.setKey(19901017 + i);
HeronTuples.RootId.Builder rootId = HeronTuples.RootId.newBuilder();
rootId.setKey(19901017 + i);
rootId.setTaskid(0);
dataTuple.addRoots(rootId);
String tupleValue = (i & 1) == 0 ? "A" : "B";
dataTuple.addValues(ByteString.copyFrom(serializer.serialize(tupleValue)));
dataTupleSet.addTuples(dataTuple);
}
heronTupleSet.setData(dataTupleSet);
executorTester.getInStreamQueue().offer(heronTupleSet.build());
// Wait the bolt's finishing
HeronServerTester.await(executeLatch);
Assert.assertEquals(expectedTuples, tupleExecutedCount.intValue());
Assert.assertEquals(expectedTuples / 2, ackCount.intValue());
Assert.assertEquals(expectedTuples / 2, failCount.intValue());
Assert.assertEquals("ABABABABAB", receivedStrings.toString());
}
Aggregations