use of org.apache.flink.core.plugin.PluginManager 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()));
}
}
use of org.apache.flink.core.plugin.PluginManager in project flink by apache.
the class ExternalResourceUtilsTest method testNotConfiguredFactoryClass.
@Test
public void testNotConfiguredFactoryClass() {
final Configuration config = new Configuration();
final Map<Class<?>, Iterator<?>> plugins = new HashMap<>();
plugins.put(ExternalResourceDriverFactory.class, IteratorUtils.singletonIterator(new TestingExternalResourceDriverFactory()));
final PluginManager testingPluginManager = new TestingPluginManager(plugins);
config.set(ExternalResourceOptions.EXTERNAL_RESOURCE_LIST, Collections.singletonList(RESOURCE_NAME_1));
final Map<String, ExternalResourceDriver> externalResourceDrivers = ExternalResourceUtils.externalResourceDriversFromConfig(config, testingPluginManager);
assertThat(externalResourceDrivers.entrySet(), is(empty()));
}
Aggregations