Search in sources :

Example 11 with InstanceControlMsg

use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.

the class HandleWriteTest 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();
}
Also used : InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) SlaveLooper(com.twitter.heron.common.basics.SlaveLooper) NIOLooper(com.twitter.heron.common.basics.NIOLooper) GatewayMetrics(com.twitter.heron.metrics.GatewayMetrics) Before(org.junit.Before)

Example 12 with InstanceControlMsg

use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.

the class CustomGroupingTest method before.

@Before
public void before() throws Exception {
    UnitTestHelper.addSystemConfigToSingleton();
    tupleReceived = 0;
    customGroupingInfoInPrepare = 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);
}
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 13 with InstanceControlMsg

use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.

the class CustomGroupingTest method testCustomGrouping.

/**
   * Test custom grouping
   */
@Test
public void testCustomGrouping() throws Exception {
    final MyCustomGrouping myCustomGrouping = new MyCustomGrouping();
    final String expectedCustomGroupingStringInPrepare = "test-spout+test-spout+default+[1]";
    physicalPlan = constructPhysicalPlan(myCustomGrouping);
    PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
    InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    inControlQueue.offer(instanceControlMsg);
    SingletonRegistry.INSTANCE.registerSingleton(CUSTOM_GROUPING_INFO, customGroupingInfoInPrepare);
    Runnable task = new Runnable() {

        @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();
                    Assert.assertEquals(dataTupleSet.getStream().getId(), "default");
                    Assert.assertEquals(dataTupleSet.getStream().getComponentName(), "test-spout");
                    for (HeronTuples.HeronDataTuple dataTuple : dataTupleSet.getTuplesList()) {
                        List<Integer> destTaskIds = dataTuple.getDestTaskIdsList();
                        Assert.assertEquals(destTaskIds.size(), 1);
                        Assert.assertEquals(destTaskIds.get(0), (Integer) tupleReceived);
                        tupleReceived++;
                    }
                }
                if (tupleReceived == 10) {
                    Assert.assertEquals(expectedCustomGroupingStringInPrepare, customGroupingInfoInPrepare.toString());
                    testLooper.exitLoop();
                    break;
                }
                SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
            }
        }
    };
    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 14 with InstanceControlMsg

use of com.twitter.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() throws Exception {
    physicalPlan = UnitTestHelper.getPhysicalPlan(false, -1);
    PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, BOLT_INSTANCE_ID);
    InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    inControlQueue.offer(instanceControlMsg);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.ACK_COUNT, ackCount);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.FAIL_COUNT, failCount);
    SingletonRegistry.INSTANCE.registerSingleton("execute-count", tupleExecutedCount);
    SingletonRegistry.INSTANCE.registerSingleton("received-string-list", receivedStrings);
    // Send tuples to bolt instance
    HeronTuples.HeronTupleSet.Builder heronTupleSet = HeronTuples.HeronTupleSet.newBuilder();
    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 < 10; 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 s = "";
        if ((i & 1) == 0) {
            s = "A";
        } else {
            s = "B";
        }
        ByteString byteString = ByteString.copyFrom(serializer.serialize(s));
        dataTuple.addValues(byteString);
        dataTupleSet.addTuples(dataTuple);
    }
    heronTupleSet.setData(dataTupleSet);
    inStreamQueue.offer(heronTupleSet.build());
    for (int i = 0; i < Constants.RETRY_TIMES; i++) {
        if (tupleExecutedCount.intValue() == 10) {
            break;
        }
        SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
    }
    // Wait the bolt's finishing
    SysUtils.sleep(Constants.TEST_WAIT_TIME_MS);
    Assert.assertEquals(10, tupleExecutedCount.intValue());
    Assert.assertEquals(5, ackCount.intValue());
    Assert.assertEquals(5, failCount.intValue());
    Assert.assertEquals("ABABABABAB", receivedStrings.toString());
}
Also used : InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) Test(org.junit.Test)

Example 15 with InstanceControlMsg

use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.

the class ActivateDeactivateTest method testActivateAndDeactivate.

/**
   * We will test whether spout would pull activate/deactivate state change and
   * invoke activate()/deactivate()
   */
@Test
public void testActivateAndDeactivate() throws Exception {
    physicalPlan = UnitTestHelper.getPhysicalPlan(true, -1, TopologyAPI.TopologyState.RUNNING);
    PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
    InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    inControlQueue.offer(instanceControlMsg);
    AtomicInteger activateCount = new AtomicInteger(0);
    AtomicInteger deactivateCount = new AtomicInteger(0);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.ACTIVATE_COUNT, activateCount);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.DEACTIVATE_COUNT, deactivateCount);
    // Now the activateCount and deactivateCount should be 0
    // And we start the test
    physicalPlan = UnitTestHelper.getPhysicalPlan(true, -1, TopologyAPI.TopologyState.PAUSED);
    physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
    instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    inControlQueue.offer(instanceControlMsg);
    Thread.sleep(Constants.TEST_WAIT_TIME_MS);
    Assert.assertEquals(1, deactivateCount.get());
    physicalPlan = UnitTestHelper.getPhysicalPlan(true, -1, TopologyAPI.TopologyState.RUNNING);
    physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
    instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    inControlQueue.offer(instanceControlMsg);
    Thread.sleep(Constants.TEST_WAIT_TIME_MS);
    Assert.assertEquals(1, activateCount.get());
    Assert.assertEquals(1, deactivateCount.get());
}
Also used : PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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