use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class ActivateDeactivateTest method before.
@Before
public void before() throws Exception {
UnitTestHelper.addSystemConfigToSingleton();
slaveLooper = new SlaveLooper();
outStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(slaveLooper, null);
outStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
inStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(null, slaveLooper);
inStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
slaveMetricsOut = new Communicator<Metrics.MetricPublisherPublishMessage>(slaveLooper, null);
slaveMetricsOut.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
inControlQueue = new Communicator<InstanceControlMsg>(null, slaveLooper);
slave = new Slave(slaveLooper, inStreamQueue, outStreamQueue, inControlQueue, slaveMetricsOut);
threadsPool = Executors.newSingleThreadExecutor();
threadsPool.execute(slave);
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class SpoutInstanceTest method before.
@Before
public void before() throws Exception {
UnitTestHelper.addSystemConfigToSingleton();
tupleReceived = 0;
heronDataTupleList = new ArrayList<HeronTuples.HeronDataTuple>();
ackCount = new AtomicInteger(0);
failCount = new AtomicInteger(0);
testLooper = new SlaveLooper();
slaveLooper = new SlaveLooper();
outStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(slaveLooper, testLooper);
outStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
inStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(testLooper, slaveLooper);
inStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
slaveMetricsOut = new Communicator<Metrics.MetricPublisherPublishMessage>(slaveLooper, testLooper);
slaveMetricsOut.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
inControlQueue = new Communicator<InstanceControlMsg>(testLooper, slaveLooper);
slave = new Slave(slaveLooper, inStreamQueue, outStreamQueue, inControlQueue, slaveMetricsOut);
threadsPool = Executors.newSingleThreadExecutor();
threadsPool.execute(slave);
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class SpoutInstanceTest method testDoImmediateAcks.
/**
* Test with the acking immediately
*/
@Test
public void testDoImmediateAcks() throws Exception {
physicalPlan = UnitTestHelper.getPhysicalPlan(false, -1);
PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
SingletonRegistry.INSTANCE.registerSingleton(Constants.ACK_COUNT, ackCount);
inControlQueue.offer(instanceControlMsg);
Runnable task = new Runnable() {
@Override
public void run() {
while (outStreamQueue.size() != 0) {
HeronTuples.HeronTupleSet set = outStreamQueue.poll();
Assert.assertTrue(set.isInitialized());
Assert.assertTrue(set.hasData());
HeronTuples.HeronDataTupleSet dataTupleSet = set.getData();
tupleReceived += dataTupleSet.getTuplesCount();
heronDataTupleList.addAll(dataTupleSet.getTuplesList());
}
if (tupleReceived == 10) {
// We fetch it from SingletonRegistry
for (int i = 0; i < Constants.RETRY_TIMES; i++) {
if (ackCount.intValue() != 0) {
break;
}
SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
}
// Wait the bolt's finishing
SysUtils.sleep(Constants.TEST_WAIT_TIME_MS);
Assert.assertEquals(10, ackCount.intValue());
testLooper.exitLoop();
}
}
};
testLooper.addTasksOnWakeup(task);
testLooper.loop();
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class SpoutInstanceTest method testAckAndFail.
/**
* We will receive tuples and then send back the corresponding ack&fail tuples
*/
@Test
public void testAckAndFail() 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.ACK_COUNT, ackCount);
SingletonRegistry.INSTANCE.registerSingleton(Constants.FAIL_COUNT, failCount);
inControlQueue.offer(instanceControlMsg);
Runnable task = new Runnable() {
@Override
public void run() {
while (outStreamQueue.size() != 0) {
HeronTuples.HeronTupleSet set = outStreamQueue.poll();
Assert.assertTrue(set.isInitialized());
Assert.assertTrue(set.hasData());
HeronTuples.HeronDataTupleSet dataTupleSet = set.getData();
tupleReceived += dataTupleSet.getTuplesCount();
heronDataTupleList.addAll(dataTupleSet.getTuplesList());
}
if (tupleReceived == 10) {
constructAndSendAcks();
// We fetch it from SingletonRegistry
for (int i = 0; i < Constants.RETRY_TIMES; i++) {
if (ackCount.intValue() != 0 || failCount.intValue() != 0) {
break;
}
SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
}
// Wait the bolt's finishing
SysUtils.sleep(Constants.TEST_WAIT_TIME_MS);
Assert.assertEquals(5, ackCount.intValue());
Assert.assertEquals(5, failCount.intValue());
testLooper.exitLoop();
}
}
};
testLooper.addTasksOnWakeup(task);
testLooper.loop();
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class ConnectTest method testStart.
/**
* Test connection
*/
@Test
public void testStart() 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) {
nioLooper.exitLoop();
threadsPool.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());
break;
} else {
SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
}
}
} catch (ClosedChannelException ignored) {
} finally {
close(socketChannel);
}
}
Aggregations