use of org.apache.apex.engine.plugin.loaders.StaticPluginLocator in project apex-core by apache.
the class PluginTests method testStaticPluginLoader.
@Test
public void testStaticPluginLoader() {
DAGExecutionPlugin plugin1 = new NoOpPlugin();
DAGExecutionPlugin plugin2 = new DebugPlugin();
StaticPluginLocator<DAGExecutionPlugin> locator1 = new StaticPluginLocator<>(plugin1);
StaticPluginLocator<DAGExecutionPlugin> locator2 = new StaticPluginLocator<>(plugin2);
Collection<DAGExecutionPlugin> discovered1 = locator1.discoverPlugins(conf);
Assert.assertEquals("Number of plugins discovered ", 1, discovered1.size());
Assert.assertEquals("Type is NoOpPlugin", discovered1.iterator().next().getClass(), NoOpPlugin.class);
Assert.assertEquals("Type is NoOpPlugin", discovered1.iterator().next(), plugin1);
Collection<DAGExecutionPlugin> discovered2 = locator2.discoverPlugins(conf);
Assert.assertEquals("Number of plugins discovered ", 1, discovered2.size());
Assert.assertEquals("Type is NoOpPlugin", discovered2.iterator().next().getClass(), DebugPlugin.class);
Assert.assertEquals("Type is NoOpPlugin", discovered2.iterator().next(), plugin2);
ChainedPluginLocator<DAGExecutionPlugin> chained = new ChainedPluginLocator<>(locator1, locator2);
Collection<DAGExecutionPlugin> chainedDiscovered = chained.discoverPlugins(conf);
Assert.assertEquals("Number of plugins discovered ", 2, chainedDiscovered.size());
Assert.assertTrue(chainedDiscovered.contains(plugin1));
Assert.assertTrue(chainedDiscovered.contains(plugin2));
}
use of org.apache.apex.engine.plugin.loaders.StaticPluginLocator in project apex-core by apache.
the class PluginTests method testDispatch.
@Test
public void testDispatch() throws InterruptedException {
DebugPlugin debugPlugin = new DebugPlugin();
StaticPluginLocator<? extends DAGExecutionPlugin> locator = new StaticPluginLocator<>(debugPlugin);
ApexPluginDispatcher pluginManager = new DefaultApexPluginDispatcher(locator, new StramTestSupport.TestAppContext(new Attribute.AttributeMap.DefaultAttributeMap()), null, null);
pluginManager.init(new Configuration());
pluginManager.dispatch(new DAGExecutionEvent.StramExecutionEvent(new StramEvent(StramEvent.LogLevel.DEBUG) {
@Override
public String getType() {
return "TestEvent";
}
}));
pluginManager.dispatch(new DAGExecutionEvent.CommitExecutionEvent(1234));
pluginManager.dispatch(new DAGExecutionEvent.HeartbeatExecutionEvent(new StreamingContainerUmbilicalProtocol.ContainerHeartbeat()));
LogicalPlan plan = new LogicalPlan();
pluginManager.dispatch(new ApexPluginDispatcher.DAGChangeEvent(plan));
debugPlugin.waitForEventDelivery(10);
pluginManager.stop();
Assert.assertEquals(1, debugPlugin.getEventCount());
Assert.assertEquals(1, debugPlugin.getHeartbeatCount());
Assert.assertEquals(1, debugPlugin.getCommitCount());
Assert.assertEquals(plan, debugPlugin.getLogicalPlan());
}
Aggregations