@BeforeMethod public void setup() { BulletStormConfig config = new BulletStormConfig("src/test/resources/test_config.yaml"); bolt = new ResultBolt(config); collector = new CustomCollector(); ComponentUtils.prepare(bolt, collector); publisher = (CustomPublisher) bolt.getPublisher(); }
@Test public void testCleanupClosesPublisher() { Assert.assertFalse(publisher.isClosed()); Assert.assertFalse(publisher.isThrown()); bolt.cleanup(); Assert.assertTrue(publisher.isClosed()); Assert.assertFalse(publisher.isThrown()); // bolt cleanup catches publisher throw bolt.cleanup(); Assert.assertTrue(publisher.isClosed()); Assert.assertTrue(publisher.isThrown()); }
@Test public void testDeclareOutputFields() { CustomOutputFieldsDeclarer declarer = new CustomOutputFieldsDeclarer(); bolt.declareOutputFields(declarer); Assert.assertTrue(!declarer.areFieldsDeclared()); } }
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = ".*Cannot create PubSub.*") public void testFailingToCreatePubSub() { BulletStormConfig config = new BulletStormConfig("src/test/resources/test_config.yaml"); config.set(BulletConfig.PUBSUB_CLASS_NAME, "fake.class"); ComponentUtils.prepare(new ResultBolt(config), collector); }
@Override public void execute(Tuple tuple) { String id = tuple.getString(TopologyConstants.ID_POSITION); String result = tuple.getString(TopologyConstants.RESULT_POSITION); Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.RESULT_METADATA_POSITION); publish(new PubSubMessage(id, result, metadata), tuple); } }
@Test public void testExecuteStillAcksWhenPublisherThrows() throws Exception { // Execute a few tuples // Closing the publisher will cause CustomPublisher to throw publisher.close(); bolt.execute(makeTuple("42", "This is a PubSubMessage", new Metadata())); bolt.execute(makeTuple("43", "This is also a PubSubMessage", new Metadata())); bolt.execute(makeTuple("44", "This is still a PubSubMessage", new Metadata())); // Assert that no tuples were sent, committed, or acked Assert.assertTrue(publisher.getSent().isEmpty()); Assert.assertEquals(collector.getAckedCount(), 3); }
.setCPULoad(joinBoltCPULoad).setMemoryLoad(joinBoltMemoryOnHeapLoad, joinBoltMemoryOffHeapLoad); builder.setBolt(TopologyConstants.RESULT_COMPONENT, new ResultBolt(config), resultBoltParallelism) .shuffleGrouping(JOIN_COMPONENT, RESULT_STREAM) .setCPULoad(resultBoltCPULoad).setMemoryLoad(resultBoltMemoryOnHeapLoad, resultBoltMemoryOffHeapLoad);
@Override public void execute(Tuple tuple) { String id = tuple.getString(TopologyConstants.ID_POSITION); String result = tuple.getString(TopologyConstants.RESULT_POSITION); Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.RESULT_METADATA_POSITION); publish(new PubSubMessage(id, result, metadata), tuple); } }
@Test public void testExecuteMessagesAreSent() { List<PubSubMessage> expected = asList(new PubSubMessage("42", "This is a PubSubMessage", new Metadata()), new PubSubMessage("43", "This is also a PubSubMessage", new Metadata()), new PubSubMessage("44", "This is still a PubSubMessage", new Metadata())); List<Tuple> tuples = new ArrayList<>(); expected.forEach(m -> tuples.add(makeTuple(m.getId(), m.getContent(), m.getMetadata()))); for (int i = 0; i < tuples.size(); i++) { bolt.execute(tuples.get(i)); Assert.assertEquals(publisher.getSent().get(i).getId(), expected.get(i).getId()); Assert.assertEquals(publisher.getSent().get(i).getContent(), expected.get(i).getContent()); Assert.assertEquals(publisher.getSent().get(i).getMetadata(), expected.get(i).getMetadata()); Assert.assertTrue(collector.wasNthAcked(tuples.get(i), i + 1)); Assert.assertEquals(collector.getAckedCount(), i + 1); } }
.setCPULoad(joinBoltCPULoad).setMemoryLoad(joinBoltMemoryOnHeapLoad, joinBoltMemoryOffHeapLoad); builder.setBolt(TopologyConstants.RESULT_COMPONENT, new ResultBolt(config), resultBoltParallelism) .shuffleGrouping(JOIN_COMPONENT, RESULT_STREAM) .setCPULoad(resultBoltCPULoad).setMemoryLoad(resultBoltMemoryOnHeapLoad, resultBoltMemoryOffHeapLoad);