Search in sources :

Example 1 with DefaultPluginManager

use of org.apache.flink.core.plugin.DefaultPluginManager in project flink by apache.

the class DefaultPluginManagerTest method testPluginLoading.

@Test
public void testPluginLoading() {
    String[] parentPatterns = { TestSpi.class.getName(), OtherTestSpi.class.getName() };
    final PluginManager pluginManager = new DefaultPluginManager(descriptors, PARENT_CLASS_LOADER, parentPatterns);
    final List<TestSpi> serviceImplList = Lists.newArrayList(pluginManager.load(TestSpi.class));
    Assert.assertEquals(2, serviceImplList.size());
    // check that all impl have unique classloader
    final Set<ClassLoader> classLoaders = Collections.newSetFromMap(new IdentityHashMap<>(3));
    classLoaders.add(PARENT_CLASS_LOADER);
    for (TestSpi testSpi : serviceImplList) {
        Assert.assertNotNull(testSpi.testMethod());
        Assert.assertTrue(classLoaders.add(testSpi.getClass().getClassLoader()));
    }
    final List<OtherTestSpi> otherServiceImplList = Lists.newArrayList(pluginManager.load(OtherTestSpi.class));
    Assert.assertEquals(1, otherServiceImplList.size());
    for (OtherTestSpi otherTestSpi : otherServiceImplList) {
        Assert.assertNotNull(otherTestSpi.otherTestMethod());
        Assert.assertTrue(classLoaders.add(otherTestSpi.getClass().getClassLoader()));
    }
}
Also used : DefaultPluginManager(org.apache.flink.core.plugin.DefaultPluginManager) PluginManager(org.apache.flink.core.plugin.PluginManager) DefaultPluginManager(org.apache.flink.core.plugin.DefaultPluginManager) Test(org.junit.Test)

Aggregations

DefaultPluginManager (org.apache.flink.core.plugin.DefaultPluginManager)1 PluginManager (org.apache.flink.core.plugin.PluginManager)1 Test (org.junit.Test)1