use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class ConnectTest method before.
@Before
public void before() throws Exception {
UnitTestHelper.addSystemConfigToSingleton();
nioLooper = new NIOLooper();
slaveLooper = new SlaveLooper();
inStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(nioLooper, slaveLooper);
inStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
outStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(slaveLooper, nioLooper);
outStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
inControlQueue = new Communicator<InstanceControlMsg>(nioLooper, slaveLooper);
gatewayMetrics = new GatewayMetrics();
threadsPool = Executors.newSingleThreadExecutor();
// Get an available port
serverPort = SysUtils.getFreePort();
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class HandleReadTest method before.
@Before
public void before() throws Exception {
UnitTestHelper.addSystemConfigToSingleton();
nioLooper = new NIOLooper();
slaveLooper = new SlaveLooper();
inStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(nioLooper, slaveLooper);
inStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
outStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(slaveLooper, nioLooper);
outStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
inControlQueue = new Communicator<InstanceControlMsg>(nioLooper, slaveLooper);
gatewayMetrics = new GatewayMetrics();
threadsPool = Executors.newSingleThreadExecutor();
// Get an available port
serverPort = SysUtils.getFreePort();
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class StreamManagerClient method handleAssignmentMessage.
private void handleAssignmentMessage(PhysicalPlans.PhysicalPlan pplan) {
LOG.fine("Physical Plan: " + pplan);
PhysicalPlanHelper newHelper = new PhysicalPlanHelper(pplan, instance.getInstanceId());
if (helper != null && (!helper.getMyComponent().equals(newHelper.getMyComponent()) || helper.getMyTaskId() != newHelper.getMyTaskId())) {
// we will get the new assignment
throw new RuntimeException("Our Assignment has changed. We will die to pick it");
}
if (helper == null) {
LOG.info("We received a new Physical Plan.");
} else {
LOG.info("We received a new Physical Plan with same assignment. Should be state changes.");
LOG.info(String.format("Old state: %s; new sate: %s.", helper.getTopologyState(), newHelper.getTopologyState()));
}
helper = newHelper;
LOG.info("Push to Slave");
InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(helper).build();
inControlQueue.offer(instanceControlMsg);
}
use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.
the class BoltInstanceTest method before.
@Before
public void before() throws Exception {
UnitTestHelper.addSystemConfigToSingleton();
ackCount = new AtomicInteger(0);
failCount = new AtomicInteger(0);
tupleExecutedCount = new AtomicInteger(0);
receivedStrings = new StringBuilder();
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);
inControlQueue = new Communicator<InstanceControlMsg>(testLooper, slaveLooper);
slaveMetricsOut = new Communicator<Metrics.MetricPublisherPublishMessage>(slaveLooper, testLooper);
slaveMetricsOut.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
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 HandleWriteTest method testHandleWrite.
/**
* Test write into network
*/
@Test
public void testHandleWrite() 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);
}
}
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 = new IncomingPacket();
while (incomingPacket.readFromChannel(socketChannel) != 0) {
// 1ms sleep to mitigate busy looping
SysUtils.sleep(1);
}
typeName = incomingPacket.unpackString();
rid = 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());
}
nioLooper.exitLoop();
} catch (ClosedChannelException ignored) {
} finally {
close(socketChannel);
}
}
Aggregations