use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class SpoutInstanceTest method testNextTuple.
/**
* Test the fetching of next tuple
*/
@Test
public void testNextTuple() throws Exception {
physicalPlan = UnitTestHelper.getPhysicalPlan(false, -1);
PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
inControlQueue.offer(instanceControlMsg);
Runnable task = new Runnable() {
private String streamId = "";
private String componentName = "";
private String receivedTupleStrings = "";
@Override
public void run() {
for (int i = 0; i < Constants.RETRY_TIMES; i++) {
if (outStreamQueue.size() != 0) {
HeronTuples.HeronTupleSet set = outStreamQueue.poll();
Assert.assertTrue(set.isInitialized());
Assert.assertFalse(set.hasControl());
Assert.assertTrue(set.hasData());
HeronTuples.HeronDataTupleSet dataTupleSet = set.getData();
streamId = dataTupleSet.getStream().getId();
componentName = dataTupleSet.getStream().getComponentName();
Assert.assertEquals(streamId, "default");
Assert.assertEquals(componentName, "test-spout");
Assert.assertEquals(streamId, "default");
Assert.assertEquals(componentName, "test-spout");
for (HeronTuples.HeronDataTuple dataTuple : dataTupleSet.getTuplesList()) {
for (ByteString b : dataTuple.getValuesList()) {
receivedTupleStrings += serializer.deserialize(b.toByteArray());
}
}
tupleReceived += dataTupleSet.getTuplesCount();
}
if (tupleReceived == 10) {
Assert.assertEquals("ABABABABAB", receivedTupleStrings);
testLooper.exitLoop();
break;
}
SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
}
}
};
testLooper.addTasksOnWakeup(task);
testLooper.loop();
Assert.assertEquals(tupleReceived, 10);
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class SpoutInstanceTest method testLookForTimeouts.
@Test
public void testLookForTimeouts() throws Exception {
physicalPlan = UnitTestHelper.getPhysicalPlan(true, 1);
PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
SingletonRegistry.INSTANCE.registerSingleton(Constants.FAIL_COUNT, failCount);
inControlQueue.offer(instanceControlMsg);
Runnable task = new Runnable() {
@Override
public void run() {
for (int i = 0; i < Constants.RETRY_TIMES; i++) {
if (failCount.intValue() != 0) {
break;
}
SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
}
// Wait the bolt's finishing
SysUtils.sleep(Constants.TEST_WAIT_TIME_MS);
Assert.assertEquals(10, failCount.intValue());
testLooper.exitLoop();
}
};
testLooper.addTasksOnWakeup(task);
testLooper.loop();
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class SpoutInstanceTest method testGatherMetrics.
/**
* Test the gathering of metrics
*/
@Test
public void testGatherMetrics() throws Exception {
physicalPlan = UnitTestHelper.getPhysicalPlan(false, -1);
PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
inControlQueue.offer(instanceControlMsg);
Runnable task = new Runnable() {
@Override
public void run() {
for (int i = 0; i < Constants.RETRY_TIMES; i++) {
if (!slaveMetricsOut.isEmpty()) {
Metrics.MetricPublisherPublishMessage msg = slaveMetricsOut.poll();
Set<String> metricsName = new HashSet<String>();
for (Metrics.MetricDatum metricDatum : msg.getMetricsList()) {
metricsName.add(metricDatum.getName());
}
Assert.assertTrue(metricsName.contains("__ack-count/default"));
Assert.assertTrue(metricsName.contains("__complete-latency/default"));
Assert.assertTrue(metricsName.contains("__emit-count/default"));
Assert.assertTrue(metricsName.contains("__next-tuple-latency"));
Assert.assertTrue(metricsName.contains("__next-tuple-count"));
testLooper.exitLoop();
break;
}
SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
}
}
};
testLooper.addTasksOnWakeup(task);
testLooper.loop();
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class HandleReadTest method testHandleRead.
/**
* Test reading from network
*/
@Test
public void testHandleRead() throws Exception {
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().bind(new InetSocketAddress(HOST, serverPort));
SocketChannel socketChannel = null;
try {
runStreamManagerClient();
socketChannel = serverSocketChannel.accept();
configure(socketChannel);
socketChannel.configureBlocking(false);
close(serverSocketChannel);
// Receive request
IncomingPacket incomingPacket = new IncomingPacket();
while (incomingPacket.readFromChannel(socketChannel) != 0) {
// 1ms sleep to mitigate busy looping
SysUtils.sleep(1);
}
// Send back response
// Though we do not use typeName, we need to unpack it first,
// since the order is required
String typeName = incomingPacket.unpackString();
REQID rid = incomingPacket.unpackREQID();
OutgoingPacket outgoingPacket = new OutgoingPacket(rid, UnitTestHelper.getRegisterInstanceResponse());
outgoingPacket.writeToChannel(socketChannel);
for (int i = 0; i < Constants.RETRY_TIMES; i++) {
InstanceControlMsg instanceControlMsg = inControlQueue.poll();
if (instanceControlMsg != null) {
break;
} else {
SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
}
}
outgoingPacket = new OutgoingPacket(REQID.zeroREQID, constructMockMessage());
outgoingPacket.writeToChannel(socketChannel);
for (int i = 0; i < Constants.RETRY_TIMES; i++) {
if (!inStreamQueue.isEmpty()) {
break;
}
SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
}
nioLooper.exitLoop();
Assert.assertEquals(1, inStreamQueue.size());
HeronTuples.HeronTupleSet msg = inStreamQueue.poll();
HeronTuples.HeronTupleSet 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());
String res = "";
for (HeronTuples.HeronDataTuple heronDataTuple : heronDataTupleSet.getTuplesList()) {
res += heronDataTuple.getValues(0).toStringUtf8();
Assert.assertEquals(1, heronDataTuple.getRootsCount());
}
Assert.assertEquals("ABABABABAB", res);
} catch (ClosedChannelException ignored) {
} finally {
close(socketChannel);
}
}
Aggregations