@Test public void test() { InMemScheduleConext context = new InMemScheduleConext(); StreamPartition partition = new StreamPartition(); partition.setType(StreamPartition.Type.GLOBAL); partition.setStreamId("s1"); partition.setColumns(Arrays.asList("f1", "f2")); StreamGroup group = new StreamGroup(); group.addStreamPartition(partition); { TestTopologyMgmtService mgmtService = new TestTopologyMgmtService(3, 3, "prefix-time1", true); SameTopologySlotStrategy strategy = new SameTopologySlotStrategy(context, group, mgmtService); List<WorkSlot> slots = strategy.reserveWorkSlots(5, false, new HashMap<String, Object>()); Assert.assertEquals(0, slots.size()); Assert.assertEquals(1, context.getTopologies().size()); } { TestTopologyMgmtService mgmtService = new TestTopologyMgmtService(5, 5, "prefix-time2", true); SameTopologySlotStrategy strategy = new SameTopologySlotStrategy(context, group, mgmtService); List<WorkSlot> slots = strategy.reserveWorkSlots(5, false, new HashMap<String, Object>()); Assert.assertEquals(5, slots.size()); LOG.info(slots.get(0).getTopologyName()); Assert.assertEquals(2, context.getTopologies().size()); Assert.assertEquals(2, context.getTopologyUsages().size()); // assert all on same topology for (WorkSlot ws : slots) { Assert.assertEquals(slots.get(0).getTopologyName(), ws.getTopologyName()); } Iterator<TopologyUsage> it = context.getTopologyUsages().values().iterator(); TopologyUsage usage = it.next(); for (AlertBoltUsage u : usage.getAlertUsages().values()) { Assert.assertTrue(u.getPartitions().size() == 0); Assert.assertTrue(u.getQueueSize() == 0); } // assert usage = it.next(); for (AlertBoltUsage u : usage.getAlertUsages().values()) { LOG.info(u.getBoltId()); Assert.assertTrue(u.getPartitions().size() == 0); Assert.assertTrue(u.getBoltId(), u.getQueueSize() == 0); } } }
@SuppressWarnings("unused") @Test public void test2_overlap() { InMemScheduleConext context = new InMemScheduleConext(); StreamPartition partition = new StreamPartition(); partition.setType(StreamPartition.Type.GLOBAL); partition.setStreamId("s1"); partition.setColumns(Arrays.asList("f1", "f2")); StreamGroup sg = new StreamGroup(); sg.addStreamPartition(partition, false); MonitoredStream ms1 = new MonitoredStream(sg); TestTopologyMgmtService mgmtService = new TestTopologyMgmtService(5, 5, "prefix-3", true); String topo1 = null; String bolt1 = null; WorkQueueBuilder wrb = new WorkQueueBuilder(context, mgmtService); StreamWorkSlotQueue queue = wrb.createQueue(ms1, false, 5, new HashMap<String, Object>()); { Assert.assertEquals(5, queue.getWorkingSlots().size()); topo1 = queue.getWorkingSlots().get(0).getTopologyName(); bolt1 = queue.getWorkingSlots().get(0).getBoltId(); Assert.assertEquals(1, context.getTopologies().size()); Assert.assertEquals(1, context.getTopologyUsages().size()); LOG.info(queue.getWorkingSlots().get(0).getTopologyName()); for (WorkSlot ws : queue.getWorkingSlots()) { Assert.assertEquals(topo1, ws.getTopologyName()); } TopologyUsage usage = context.getTopologyUsages().values().iterator().next(); for (AlertBoltUsage u : usage.getAlertUsages().values()) { Assert.assertTrue(u.getPartitions().size() > 0); Assert.assertTrue(u.getBoltId(), u.getQueueSize() > 0); } } // second partition StreamPartition partition2 = new StreamPartition(); partition2.setType(StreamPartition.Type.GLOBAL); partition2.setStreamId("s2"); partition2.setColumns(Arrays.asList("f1", "f2")); StreamGroup sg2 = new StreamGroup(); sg2.addStreamPartition(partition2); MonitoredStream ms2 = new MonitoredStream(sg2); queue = wrb.createQueue(ms2, false, 5, new HashMap<String, Object>()); { Assert.assertEquals(5, queue.getWorkingSlots().size()); Assert.assertEquals(2, context.getTopologies().size()); Assert.assertEquals(2, context.getTopologyUsages().size()); String topo2 = queue.getWorkingSlots().get(0).getTopologyName(); String bolt2 = queue.getWorkingSlots().get(0).getBoltId(); for (WorkSlot ws : queue.getWorkingSlots()) { Assert.assertEquals(topo2, ws.getTopologyName()); } Assert.assertNotEquals(topo1, topo2); } }
@Test public void testMultipleStreamsWithoutReuse() { ConfigFactory.invalidateCaches(); System.setProperty("config.resource", "/application-multiplestreams2.conf"); InMemScheduleConext context = new InMemScheduleConext(); StreamGroup group1 = createStreamGroup("s1", Arrays.asList("f1", "f2"), true); StreamGroup group2 = createStreamGroup("s2", Arrays.asList("f2", "f3"), false); StreamGroup group3 = createStreamGroup("s3", Arrays.asList("f4"), false); StreamGroup group4 = createStreamGroup("s4", Arrays.asList("f5"), false); TestTopologyMgmtService mgmtService = new TestTopologyMgmtService(3, 4, "prefix-time1", true); WorkQueueBuilder wrb = new WorkQueueBuilder(context, mgmtService); { StreamWorkSlotQueue queue = wrb.createQueue( new MonitoredStream(group1), group1.isDedicated(), 2, new HashMap<String, Object>()); print(context.getTopologyUsages().values()); TopologyUsage usage = context.getTopologyUsages().values().iterator().next(); Assert.assertTrue(getMonitorStream(usage.getMonitoredStream()).containsKey(group1)); Assert.assertEquals( 1, getMonitorStream(usage.getMonitoredStream()).get(group1).getQueues().size()); Assert.assertEquals( 2, getMonitorStream(usage.getMonitoredStream()) .get(group1) .getQueues() .get(0) .getWorkingSlots() .size()); List<String> group1Slots = new ArrayList<String>(); getMonitorStream(usage.getMonitoredStream()) .get(group1) .getQueues() .get(0) .getWorkingSlots() .forEach( slot -> { group1Slots.add(slot.getBoltId()); }); StreamWorkSlotQueue queue2 = wrb.createQueue( new MonitoredStream(group2), group2.isDedicated(), 2, new HashMap<String, Object>()); print(context.getTopologyUsages().values()); Assert.assertTrue(getMonitorStream(usage.getMonitoredStream()).containsKey(group2)); Assert.assertEquals( 1, getMonitorStream(usage.getMonitoredStream()).get(group2).getQueues().size()); Assert.assertEquals( 2, getMonitorStream(usage.getMonitoredStream()) .get(group2) .getQueues() .get(0) .getWorkingSlots() .size()); getMonitorStream(usage.getMonitoredStream()) .get(group2) .getQueues() .get(0) .getWorkingSlots() .forEach( slot -> { Assert.assertTrue(!group1Slots.contains(slot.getBoltId())); }); StreamWorkSlotQueue queue3 = wrb.createQueue( new MonitoredStream(group3), group3.isDedicated(), 2, new HashMap<String, Object>()); print(context.getTopologyUsages().values()); Assert.assertTrue(!getMonitorStream(usage.getMonitoredStream()).containsKey(group3)); StreamWorkSlotQueue queue4 = wrb.createQueue( new MonitoredStream(group4), group4.isDedicated(), 2, new HashMap<String, Object>()); print(context.getTopologyUsages().values()); Assert.assertTrue(!getMonitorStream(usage.getMonitoredStream()).containsKey(group4)); } }