Search in sources :

Example 1 with InstanceControlMsg

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);
}
Also used : Slave(com.twitter.heron.instance.Slave) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) SlaveLooper(com.twitter.heron.common.basics.SlaveLooper) Before(org.junit.Before)

Example 2 with InstanceControlMsg

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);
}
Also used : Slave(com.twitter.heron.instance.Slave) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SlaveLooper(com.twitter.heron.common.basics.SlaveLooper) Before(org.junit.Before)

Example 3 with InstanceControlMsg

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();
}
Also used : PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) HeronTuples(com.twitter.heron.proto.system.HeronTuples) Test(org.junit.Test)

Example 4 with InstanceControlMsg

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&amp;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();
}
Also used : PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) HeronTuples(com.twitter.heron.proto.system.HeronTuples) Test(org.junit.Test)

Example 5 with InstanceControlMsg

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);
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) ClosedChannelException(java.nio.channels.ClosedChannelException) IncomingPacket(com.twitter.heron.common.network.IncomingPacket) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InetSocketAddress(java.net.InetSocketAddress) REQID(com.twitter.heron.common.network.REQID) ServerSocketChannel(java.nio.channels.ServerSocketChannel) OutgoingPacket(com.twitter.heron.common.network.OutgoingPacket) Test(org.junit.Test)

Aggregations

InstanceControlMsg (com.twitter.heron.instance.InstanceControlMsg)19 Test (org.junit.Test)11 PhysicalPlanHelper (com.twitter.heron.common.utils.misc.PhysicalPlanHelper)10 SlaveLooper (com.twitter.heron.common.basics.SlaveLooper)7 Before (org.junit.Before)7 HeronTuples (com.twitter.heron.proto.system.HeronTuples)5 ByteString (com.google.protobuf.ByteString)4 Slave (com.twitter.heron.instance.Slave)4 NIOLooper (com.twitter.heron.common.basics.NIOLooper)3 IncomingPacket (com.twitter.heron.common.network.IncomingPacket)3 OutgoingPacket (com.twitter.heron.common.network.OutgoingPacket)3 REQID (com.twitter.heron.common.network.REQID)3 GatewayMetrics (com.twitter.heron.metrics.GatewayMetrics)3 InetSocketAddress (java.net.InetSocketAddress)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 ServerSocketChannel (java.nio.channels.ServerSocketChannel)3 SocketChannel (java.nio.channels.SocketChannel)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 StreamManager (com.twitter.heron.proto.stmgr.StreamManager)1 Metrics (com.twitter.heron.proto.system.Metrics)1