@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { // Add the Storm Config and the context as is, in case any PubSubs need it. config.set(BulletStormConfig.STORM_CONFIG, conf); config.set(BulletStormConfig.STORM_CONTEXT, context); this.collector = collector; }
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { // Add the Storm Config and the context as is, in case any PubSubs need it. config.set(BulletStormConfig.STORM_CONFIG, conf); config.set(BulletStormConfig.STORM_CONTEXT, context); this.collector = collector; }
@Override public void prepare(Map conf, TopologyContext context, OutputCollector collector) { // Add the Storm Config and the context as is, in case any PubSubs need it. config.set(BulletStormConfig.STORM_CONFIG, conf); config.set(BulletStormConfig.STORM_CONTEXT, context); this.collector = collector; try { this.publisher = createPublisher(); } catch (PubSubException e) { throw new RuntimeException("Cannot create PubSub instance or a Publisher for it.", e); } }
@Override public void prepare(Map conf, TopologyContext context, OutputCollector collector) { // Add the Storm Config and the context as is, in case any PubSubs need it. config.set(BulletStormConfig.STORM_CONFIG, conf); config.set(BulletStormConfig.STORM_CONTEXT, context); this.collector = collector; try { this.publisher = createPublisher(); } catch (PubSubException e) { throw new RuntimeException("Cannot create PubSub instance or a Publisher for it.", e); } }
private static void enableMetadataInConfig(BulletStormConfig config, String metaConcept, String key) { Map<String, String> metadataConfig = (Map<String, String>) config.getOrDefault(BulletStormConfig.RESULT_METADATA_METRICS, new HashMap<>()); metadataConfig.put(metaConcept, key); config.set(BulletStormConfig.RESULT_METADATA_ENABLE, true); config.set(BulletStormConfig.RESULT_METADATA_METRICS, metadataConfig); }
@Test(expectedExceptions = IllegalStateException.class) public void testPreStartDelayIsTooSmall() { BulletStormConfig config = new BulletStormConfig((Config) null); config.set(BulletStormConfig.TICK_SPOUT_INTERVAL, 100); config.set(BulletStormConfig.JOIN_BOLT_WINDOW_PRE_START_DELAY_TICKS, 3); config.set(BulletStormConfig.WINDOW_MIN_EMIT_EVERY, 400); config.validate(); }
private static BulletStormConfig configWithRawMaxAndEmptyMeta() { BulletStormConfig config = new BulletStormConfig(); config.set(BulletStormConfig.RAW_AGGREGATION_MAX_SIZE, RAW_MAX_SIZE); config.set(BulletStormConfig.RESULT_METADATA_ENABLE, true); config.validate(); config.set(BulletStormConfig.RESULT_METADATA_METRICS, new HashMap<>()); return config; }
@Test(expectedExceptions = IllegalStateException.class) public void testWindowMinEmitIsTooSmall() { BulletStormConfig config = new BulletStormConfig((Config) null); config.set(BulletStormConfig.TICK_SPOUT_INTERVAL, 100); config.set(BulletStormConfig.JOIN_BOLT_WINDOW_PRE_START_DELAY_TICKS, 3); config.set(BulletStormConfig.WINDOW_MIN_EMIT_EVERY, 100); config.validate(); } }
public static void register(Config stormConfig, BulletStormConfig bulletStormConfig) { bulletStormConfig.set(CUSTOM_METRICS_REGISTERED, true); stormConfig.registerMetricsConsumer(CustomIMetricsConsumer.class); } }
@Test public void testGettingNonStormSettingsOnly() { BulletStormConfig config = new BulletStormConfig((Config) null); config.set(BulletStormConfig.CUSTOM_STORM_SETTING_PREFIX + "storm.foo", "bar"); config.set(BulletStormConfig.CUSTOM_STORM_SETTING_PREFIX + "bar", "baz"); Map<String, Object> settings = config.getCustomStormSettings(); Assert.assertEquals(settings.size(), 2); Assert.assertEquals(settings.get("storm.foo"), "bar"); Assert.assertEquals(settings.get("bar"), "baz"); }
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = ".*Cannot create PubSub.*") public void testFailingToCreatePubSub() { config.set(BulletConfig.PUBSUB_CLASS_NAME, "fake.class"); ComponentUtils.prepare(new LoopBolt(config), collector); }
@Test public void testTickIntervalIsHighEnough() { BulletStormConfig config = new BulletStormConfig((Config) null); config.set(BulletStormConfig.TICK_SPOUT_INTERVAL, 1); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TICK_SPOUT_INTERVAL), BulletStormConfig.DEFAULT_TICK_SPOUT_INTERVAL); config.set(BulletStormConfig.TICK_SPOUT_INTERVAL, BulletStormConfig.TICK_INTERVAL_MINIMUM); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TICK_SPOUT_INTERVAL), BulletStormConfig.TICK_INTERVAL_MINIMUM); }
private static BulletStormConfig oneRecordConfig() { BulletStormConfig config = new BulletStormConfig(); // Set aggregation default size to 1 since most queries here are RAW with filtering and projections. This // makes them isClosedForPartition even if they are not done. immediately. config.set(BulletStormConfig.AGGREGATION_DEFAULT_SIZE, 1); config.validate(); return config; }
@Test public void testHookingInCustomMetricsConsumer() { builder.setSpout("source", new CustomIRichSpout(), 10); config.set(BulletStormConfig.TOPOLOGY_METRICS_ENABLE, true); config.set(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, singletonList(CustomIMetricsConsumer.class.getName())); Assert.assertNull(config.get(CustomIMetricsConsumer.CUSTOM_METRICS_REGISTERED)); Assert.assertFalse(builder.isTopologyCreated()); submitWithTopology("source"); Assert.assertTrue(builder.isTopologyCreated()); Assert.assertTrue((Boolean) config.get(CustomIMetricsConsumer.CUSTOM_METRICS_REGISTERED)); }
private static DRPCConfig makeEmpty() { BulletStormConfig config = new BulletStormConfig(); config.set(BulletStormConfig.WINDOW_DISABLE, true); return new DRPCConfig(config); }
@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); }
@Test public void testImproperQueryCountingMetrics() { config.set(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_ENABLE, true); setup(new JoinBolt(config)); Assert.assertEquals(context.getLongMetric(TopologyConstants.CREATED_QUERIES_METRIC), Long.valueOf(0)); Assert.assertEquals(context.getLongMetric(TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(0)); Assert.assertEquals(context.getLongMetric(TopologyConstants.IMPROPER_QUERIES_METRIC), Long.valueOf(0)); Tuple badQuery = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{", EMPTY); bolt.execute(badQuery); bolt.execute(badQuery); Assert.assertEquals(context.getLongMetric(TopologyConstants.CREATED_QUERIES_METRIC), Long.valueOf(0)); Assert.assertEquals(context.getLongMetric(TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(0)); Assert.assertEquals(context.getLongMetric(TopologyConstants.IMPROPER_QUERIES_METRIC), Long.valueOf(2)); }
@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"); QuerySpout spout = new QuerySpout(config); ComponentUtils.open(spout, emitter); spout.activate(); }
@Test public void testStatisticsReporting() { config.set(BulletStormConfig.FILTER_BOLT_STATS_REPORT_TICKS, 10); config.validate(); bolt = ComponentUtils.prepare(new HashMap<>(), new FilterBolt(TopologyConstants.RECORD_COMPONENT, config), collector); Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE); for (int i = 0; i < 10; ++i) { Assert.assertEquals(bolt.getStatsTickCount(), i); bolt.execute(tick); } Assert.assertEquals(bolt.getStatsTickCount(), 0); } }