@Test(expectedExceptions = ClassNotFoundException.class) public void testGettingNonExistentSpout() throws Exception { ReflectionUtils utils = new ReflectionUtils(); utils.getSpout("does.not.exist", null); }
@Test public void testIsIMetricsConsumer() { Assert.assertFalse(ReflectionUtils.isIMetricsConsumer(LoggingMetricsConsumer.class.getName())); Assert.assertTrue(ReflectionUtils.isIMetricsConsumer(CustomIMetricsConsumer.class.getName())); }
@Test public void testGettingSpoutWithDefaultConstructor() throws Exception { IRichSpout spout = ReflectionUtils.getSpout(CustomIRichSpout.class.getName(), null); Assert.assertTrue(spout instanceof CustomIRichSpout); }
@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 testGettingSpoutWithArguments() throws Exception { IRichSpout spout = ReflectionUtils.getSpout(TestSpout.class.getName(), Collections.singletonList("foo")); Assert.assertTrue(spout instanceof TestSpout); Assert.assertEquals(((TestSpout) spout).getArgs(), Collections.singletonList("foo")); }
if (enableMetrics) { List<String> classNames = config.getAs(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, List.class); classNames.forEach(className -> ReflectionUtils.registerMetricsConsumer(className, stormConfig, config));
/** * This submits a topology after loading the given spout with the given configuration as the source of * {@link com.yahoo.bullet.record.BulletRecord} using the given {@link TopologyBuilder}. * * @param builder The {@link TopologyBuilder} to use to add the topology to. * @param spout The name of the instance of an {@link org.apache.storm.topology.IRichSpout} to load. * @param args The arguments to pass to the constructor of this spout (otherwise the default constructor is used). * @param config The Storm settings for this Bullet topology. * @param parallelism The parallelism of the spout component. * @param cpuLoad The CPU load for the Storm RAS scheduler. * @param onHeapMemoryLoad The on heap memory load for the Storm RAS scheduler. * @param offHeapMemoryLoad The off heap memory load for the Storm RAS scheduler. * @throws Exception if there were issues creating the topology. */ public static void submit(TopologyBuilder builder, String spout, List<String> args, BulletStormConfig config, Number parallelism, Number cpuLoad, Number onHeapMemoryLoad, Number offHeapMemoryLoad) throws Exception { builder.setSpout(TopologyConstants.RECORD_COMPONENT, ReflectionUtils.getSpout(spout, args), parallelism) .setCPULoad(cpuLoad).setMemoryLoad(onHeapMemoryLoad, offHeapMemoryLoad); log.info("Added spout {} with Parallelism {}, CPU load {}, On-heap memory {}, Off-heap memory {}", spout, parallelism, cpuLoad, onHeapMemoryLoad, offHeapMemoryLoad); submit(config, TopologyConstants.RECORD_COMPONENT, builder); }
if (enableMetrics) { List<String> classNames = config.getAs(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, List.class); classNames.forEach(className -> ReflectionUtils.registerMetricsConsumer(className, stormConfig, config));
private static void addBulletSpout(BulletStormConfig config, TopologyBuilder builder) throws Exception { String bulletSpoutClassName = config.getAs(BulletStormConfig.BULLET_SPOUT_CLASS_NAME, String.class); List<String> bulletSpoutArgs = config.getAs(BulletStormConfig.BULLET_SPOUT_ARGS, List.class); Number bulletSpoutParallelism = config.getAs(BulletStormConfig.BULLET_SPOUT_PARALLELISM, Number.class); Number bulletSpoutCPULoad = config.getAs(BulletStormConfig.BULLET_SPOUT_CPU_LOAD, Number.class); Number bulletSpoutMemoryOnHeapLoad = config.getAs(BulletStormConfig.BULLET_SPOUT_MEMORY_ON_HEAP_LOAD, Number.class); Number bulletSpoutMemoryOffHeapLoad = config.getAs(BulletStormConfig.BULLET_SPOUT_MEMORY_OFF_HEAP_LOAD, Number.class); builder.setSpout(TopologyConstants.RECORD_COMPONENT, ReflectionUtils.getSpout(bulletSpoutClassName, bulletSpoutArgs), bulletSpoutParallelism) .setCPULoad(bulletSpoutCPULoad) .setMemoryLoad(bulletSpoutMemoryOnHeapLoad, bulletSpoutMemoryOffHeapLoad); log.info("Added spout with Parallelism {}, CPU load {}, On-heap memory {}, Off-heap memory {}", bulletSpoutParallelism, bulletSpoutCPULoad, bulletSpoutMemoryOnHeapLoad, bulletSpoutMemoryOffHeapLoad); }