Search in sources :

Example 21 with PhysicalPlanHelper

use of com.twitter.heron.common.utils.misc.PhysicalPlanHelper in project incubator-heron by apache.

the class AbstractTupleRoutingTest method testRoundRobinRouting.

/**
 * Test that tuple routing occurs using round robin
 */
@Test
public void testRoundRobinRouting() throws Exception {
    PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(constructPhysicalPlan(), getComponentToVerify().getInstanceId());
    InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    slaveTester.getInControlQueue().offer(instanceControlMsg);
    SingletonRegistry.INSTANCE.registerSingleton(getInitInfoKey(getComponentToVerify().getName()), groupingInitInfo);
    final int expectedTuplesValidated = 10;
    Runnable task = new Runnable() {

        @Override
        public void run() {
            HeronServerTester.await(outStreamQueueOfferLatch);
            assertNotEquals(0, slaveTester.getOutStreamQueue().size());
            while (tupleReceived < expectedTuplesValidated) {
                if (slaveTester.getOutStreamQueue().isEmpty()) {
                    continue;
                }
                Message msg = slaveTester.getOutStreamQueue().poll();
                assertTrue(msg instanceof HeronTuples.HeronTupleSet);
                HeronTuples.HeronTupleSet set = (HeronTuples.HeronTupleSet) msg;
                assertTrue(set.isInitialized());
                assertFalse(set.hasControl());
                assertTrue(set.hasData());
                HeronTuples.HeronDataTupleSet dataTupleSet = set.getData();
                assertEquals(dataTupleSet.getStream().getId(), "default");
                assertEquals(dataTupleSet.getStream().getComponentName(), getComponentToVerify().getName());
                for (HeronTuples.HeronDataTuple dataTuple : dataTupleSet.getTuplesList()) {
                    List<Integer> destTaskIds = dataTuple.getDestTaskIdsList();
                    assertEquals(1, destTaskIds.size());
                    assertEquals((Integer) tupleReceived, destTaskIds.get(0));
                    tupleReceived++;
                }
            }
            assertEquals(expectedTuplesValidated, tupleReceived);
            assertEquals(getExpectedComponentInitInfo(), groupingInitInfo.toString());
            slaveTester.getTestLooper().exitLoop();
        }
    };
    slaveTester.getTestLooper().addTasksOnWakeup(task);
    slaveTester.getTestLooper().loop();
    assertEquals(expectedTuplesValidated, tupleReceived);
}
Also used : PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) Message(com.google.protobuf.Message) HeronTuples(com.twitter.heron.proto.system.HeronTuples) Test(org.junit.Test)

Example 22 with PhysicalPlanHelper

use of com.twitter.heron.common.utils.misc.PhysicalPlanHelper in project incubator-heron by apache.

the class BoltInstanceTest method testReadTupleAndExecute.

/**
 * Test the reading of a tuple and apply execute on that tuple
 */
@Test
public void testReadTupleAndExecute() {
    PhysicalPlans.PhysicalPlan physicalPlan = UnitTestHelper.getPhysicalPlan(false, -1);
    PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, BOLT_INSTANCE_ID);
    InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    slaveTester.getInControlQueue().offer(instanceControlMsg);
    final int expectedTuples = 10;
    CountDownLatch executeLatch = new CountDownLatch(expectedTuples);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.ACK_COUNT, ackCount);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.FAIL_COUNT, failCount);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.EXECUTE_COUNT, tupleExecutedCount);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.EXECUTE_LATCH, executeLatch);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.RECEIVED_STRING_LIST, receivedStrings);
    // Send tuples to bolt instance
    HeronTuples.HeronTupleSet.Builder heronTupleSet = HeronTuples.HeronTupleSet.newBuilder();
    heronTupleSet.setSrcTaskId(SRC_TASK_ID);
    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 < expectedTuples; 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 tupleValue = (i & 1) == 0 ? "A" : "B";
        dataTuple.addValues(ByteString.copyFrom(serializer.serialize(tupleValue)));
        dataTupleSet.addTuples(dataTuple);
    }
    heronTupleSet.setData(dataTupleSet);
    slaveTester.getInStreamQueue().offer(heronTupleSet.build());
    // Wait the bolt's finishing
    HeronServerTester.await(executeLatch);
    Assert.assertEquals(expectedTuples, tupleExecutedCount.intValue());
    Assert.assertEquals(expectedTuples / 2, ackCount.intValue());
    Assert.assertEquals(expectedTuples / 2, failCount.intValue());
    Assert.assertEquals("ABABABABAB", receivedStrings.toString());
}
Also used : InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) PhysicalPlans(com.twitter.heron.proto.system.PhysicalPlans) ByteString(com.google.protobuf.ByteString) CountDownLatch(java.util.concurrent.CountDownLatch) PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) Test(org.junit.Test)

Aggregations

PhysicalPlanHelper (com.twitter.heron.common.utils.misc.PhysicalPlanHelper)22 InstanceControlMsg (com.twitter.heron.instance.InstanceControlMsg)14 Test (org.junit.Test)14 HeronTuples (com.twitter.heron.proto.system.HeronTuples)5 ByteString (com.google.protobuf.ByteString)4 PhysicalPlans (com.twitter.heron.proto.system.PhysicalPlans)3 OutgoingPacket (com.twitter.heron.common.network.OutgoingPacket)2 REQID (com.twitter.heron.common.network.REQID)2 MetricsCollector (com.twitter.heron.common.utils.metrics.MetricsCollector)2 InetSocketAddress (java.net.InetSocketAddress)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 ServerSocketChannel (java.nio.channels.ServerSocketChannel)2 SocketChannel (java.nio.channels.SocketChannel)2 Message (com.google.protobuf.Message)1 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)1 IncomingPacket (com.twitter.heron.common.network.IncomingPacket)1 Metrics (com.twitter.heron.proto.system.Metrics)1 PhysicalPlanUtilTest (com.twitter.heron.simulator.utils.PhysicalPlanUtilTest)1 TopologyManagerTest (com.twitter.heron.simulator.utils.TopologyManagerTest)1 HashSet (java.util.HashSet)1