@Test public void testCustomConfig() { BulletStormConfig config = new BulletStormConfig("src/test/resources/test_config.yaml"); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_NAME), "test"); Assert.assertEquals(config.get(BulletStormConfig.QUERY_DEFAULT_DURATION), 1000L); Assert.assertEquals(config.get(BulletStormConfig.QUERY_MAX_DURATION), 10000L); Assert.assertEquals(config.get("fake.setting"), "bar"); // Defaulted Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_ENABLE), false); Assert.assertEquals(config.get(BulletStormConfig.AGGREGATION_MAX_SIZE), BulletConfig.DEFAULT_AGGREGATION_MAX_SIZE); Assert.assertEquals(config.get(BulletStormConfig.QUERY_SPOUT_CPU_LOAD), BulletStormConfig.DEFAULT_QUERY_SPOUT_CPU_LOAD); }
Boolean enableMetrics = (Boolean) config.get(BulletStormConfig.TOPOLOGY_METRICS_ENABLE); if (enableMetrics) { List<String> classNames = config.getAs(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, List.class);
Boolean enableMetrics = (Boolean) config.get(BulletStormConfig.TOPOLOGY_METRICS_ENABLE); if (enableMetrics) { List<String> classNames = config.getAs(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, List.class);
@Test public void testDefaultInitialization() { BulletStormConfig config = new BulletStormConfig(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_NAME), BulletStormConfig.DEFAULT_TOPOLOGY_NAME); Assert.assertEquals(config.get(BulletStormConfig.QUERY_MAX_DURATION), BulletStormConfig.DEFAULT_QUERY_MAX_DURATION); Assert.assertEquals(config.get(BulletStormConfig.AGGREGATION_MAX_SIZE), BulletStormConfig.DEFAULT_AGGREGATION_MAX_SIZE); }
@Test public void testSwitchingIntoQueryPublishing() { Assert.assertEquals(publisher.getContext(), PubSub.Context.QUERY_SUBMISSION); // Config is modified in place Assert.assertEquals(config.get("fake.setting"), "foo"); // But original setting is preserved Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_NAME), "test"); }
@Test public void testNoFiles() { BulletStormConfig config = new BulletStormConfig((String) null); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_NAME), BulletStormConfig.DEFAULT_TOPOLOGY_NAME); Assert.assertEquals(config.get(BulletStormConfig.QUERY_MAX_DURATION), BulletStormConfig.DEFAULT_QUERY_MAX_DURATION); Assert.assertEquals(config.get(BulletStormConfig.AGGREGATION_MAX_SIZE), BulletStormConfig.DEFAULT_AGGREGATION_MAX_SIZE); config = new BulletStormConfig(""); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_NAME), BulletStormConfig.DEFAULT_TOPOLOGY_NAME); }
@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); }
@Test public void testRegisteringIMetricsConsumer() { Config config = new Config(); BulletStormConfig bulletStormConfig = new BulletStormConfig(); Assert.assertNull(bulletStormConfig.get(CustomIMetricsConsumer.CUSTOM_METRICS_REGISTERED)); ReflectionUtils.registerMetricsConsumer(LoggingMetricsConsumer.class.getName(), config, bulletStormConfig); Assert.assertNull(config.get(Config.TOPOLOGY_METRICS_CONSUMER_REGISTER)); ReflectionUtils.registerMetricsConsumer(CustomIMetricsConsumer.class.getName(), config, bulletStormConfig); Assert.assertNotNull(config.get(Config.TOPOLOGY_METRICS_CONSUMER_REGISTER)); Assert.assertTrue((Boolean) bulletStormConfig.get(CustomIMetricsConsumer.CUSTOM_METRICS_REGISTERED)); } }
@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)); }
@Test public void testProperMetricsConsumers() { BulletStormConfig config = new BulletStormConfig((Config) null); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_CLASSES), BulletStormConfig.DEFAULT_TOPOLOGY_METRICS_CLASSES); // Test removing all metrics config.set(BulletStormConfig.TOPOLOGY_METRICS_ENABLE, true); config.set(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, new ArrayList<>()); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_CLASSES), new ArrayList<>()); config.set(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, singletonList(1)); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_CLASSES), BulletStormConfig.DEFAULT_TOPOLOGY_METRICS_CLASSES); config.set(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, singletonList("foo")); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_CLASSES), BulletStormConfig.DEFAULT_TOPOLOGY_METRICS_CLASSES); config.set(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, singletonList(CustomIMetricsConsumer.class.getName())); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_CLASSES), singletonList(CustomIMetricsConsumer.class.getName())); }
@Test public void testIntervalMappingNotPresent() { BulletStormConfig config = new BulletStormConfig((Config) null); config.set(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_ENABLE, true); config.set(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING, new HashMap<>()); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING), BulletStormConfig.DEFAULT_TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING); config.set(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_ENABLE, false); config.set(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING, new HashMap<>()); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING), emptyMap()); }
@Test public void testPreStartDelayIsEnoughForWindowMinEmit() { BulletStormConfig config = new BulletStormConfig((Config) null); config.set(BulletStormConfig.TICK_SPOUT_INTERVAL, 100); config.set(BulletStormConfig.JOIN_BOLT_WINDOW_PRE_START_DELAY_TICKS, 2); config.set(BulletStormConfig.WINDOW_MIN_EMIT_EVERY, 400); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TICK_SPOUT_INTERVAL), 100); Assert.assertEquals(config.get(BulletStormConfig.JOIN_BOLT_WINDOW_PRE_START_DELAY_TICKS), 2); Assert.assertEquals(config.get(BulletStormConfig.WINDOW_MIN_EMIT_EVERY), 400); config.set(BulletStormConfig.TICK_SPOUT_INTERVAL, 100); config.set(BulletStormConfig.JOIN_BOLT_WINDOW_PRE_START_DELAY_TICKS, 5); config.set(BulletStormConfig.WINDOW_MIN_EMIT_EVERY, 700); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TICK_SPOUT_INTERVAL), 100); Assert.assertEquals(config.get(BulletStormConfig.JOIN_BOLT_WINDOW_PRE_START_DELAY_TICKS), 5); Assert.assertEquals(config.get(BulletStormConfig.WINDOW_MIN_EMIT_EVERY), 700); config.set(BulletStormConfig.TICK_SPOUT_INTERVAL, 20); config.set(BulletStormConfig.JOIN_BOLT_WINDOW_PRE_START_DELAY_TICKS, 3); config.set(BulletStormConfig.WINDOW_MIN_EMIT_EVERY, 100); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TICK_SPOUT_INTERVAL), 20); Assert.assertEquals(config.get(BulletStormConfig.JOIN_BOLT_WINDOW_PRE_START_DELAY_TICKS), 3); Assert.assertEquals(config.get(BulletStormConfig.WINDOW_MIN_EMIT_EVERY), 100); }
@Test public void testLoopBoltOverridesIsAMapWithStringKeys() { BulletStormConfig config = new BulletStormConfig((Config) null); config.set(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES, null); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES), BulletStormConfig.DEFAULT_LOOP_BOLT_PUBSUB_OVERRIDES); config.set(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES, new HashMap<>()); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES), BulletStormConfig.DEFAULT_LOOP_BOLT_PUBSUB_OVERRIDES); config.set(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES, singletonMap(1, "foo")); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES), BulletStormConfig.DEFAULT_LOOP_BOLT_PUBSUB_OVERRIDES); config.set(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES, singletonMap("foo", singletonList("bar"))); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES), singletonMap("foo", singletonList("bar"))); Map<String, Object> overrides = new HashMap<>(); overrides.put("foo", 1L); overrides.put("bar", new ArrayList<>()); config.set(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES, overrides); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES), overrides); }
Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING), BulletStormConfig.DEFAULT_TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING), BulletStormConfig.DEFAULT_TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING); singletonMap(TopologyConstants.LATENCY_METRIC, "foo")); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING), BulletStormConfig.DEFAULT_TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING); singletonMap("foo", 50)); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING), BulletStormConfig.DEFAULT_TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING); singletonMap(TopologyConstants.LATENCY_METRIC, 60)); config.validate(); Assert.assertEquals(config.get(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING), singletonMap(TopologyConstants.LATENCY_METRIC, 60));