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()));
}
}
Aggregations