Search in sources :

Example 16 with InstanceControlMsg

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

Example 17 with InstanceControlMsg

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

Example 18 with InstanceControlMsg

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();
}
Also used : Metrics(com.twitter.heron.proto.system.Metrics) PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) ByteString(com.google.protobuf.ByteString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with InstanceControlMsg

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);
    }
}
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) InetSocketAddress(java.net.InetSocketAddress) ByteString(com.google.protobuf.ByteString) HeronTuples(com.twitter.heron.proto.system.HeronTuples) 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