Search in sources :

Example 1 with StaticPluginLocator

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));
}
Also used : ChainedPluginLocator(org.apache.apex.engine.plugin.loaders.ChainedPluginLocator) StaticPluginLocator(org.apache.apex.engine.plugin.loaders.StaticPluginLocator) DAGExecutionPlugin(org.apache.apex.engine.api.plugin.DAGExecutionPlugin) Test(org.junit.Test)

Example 2 with StaticPluginLocator

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());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Attribute(com.datatorrent.api.Attribute) StramEvent(com.datatorrent.stram.api.StramEvent) StaticPluginLocator(org.apache.apex.engine.plugin.loaders.StaticPluginLocator) StramTestSupport(com.datatorrent.stram.support.StramTestSupport) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) DAGExecutionEvent(org.apache.apex.engine.api.plugin.DAGExecutionEvent) Test(org.junit.Test)

Aggregations

StaticPluginLocator (org.apache.apex.engine.plugin.loaders.StaticPluginLocator)2 Test (org.junit.Test)2 Attribute (com.datatorrent.api.Attribute)1 StramEvent (com.datatorrent.stram.api.StramEvent)1 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)1 StramTestSupport (com.datatorrent.stram.support.StramTestSupport)1 DAGExecutionEvent (org.apache.apex.engine.api.plugin.DAGExecutionEvent)1 DAGExecutionPlugin (org.apache.apex.engine.api.plugin.DAGExecutionPlugin)1 ChainedPluginLocator (org.apache.apex.engine.plugin.loaders.ChainedPluginLocator)1 Configuration (org.apache.hadoop.conf.Configuration)1