Search in sources :

Example 11 with PluginManager

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

Example 12 with PluginManager

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()));
}
Also used : TestingPluginManager(org.apache.flink.core.plugin.TestingPluginManager) PluginManager(org.apache.flink.core.plugin.PluginManager) Configuration(org.apache.flink.configuration.Configuration) HashMap(java.util.HashMap) Iterator(java.util.Iterator) TestingPluginManager(org.apache.flink.core.plugin.TestingPluginManager) ExternalResourceDriver(org.apache.flink.api.common.externalresource.ExternalResourceDriver) Test(org.junit.Test)

Aggregations

PluginManager (org.apache.flink.core.plugin.PluginManager)12 Configuration (org.apache.flink.configuration.Configuration)8 Test (org.junit.Test)7 ExternalResourceDriver (org.apache.flink.api.common.externalresource.ExternalResourceDriver)4 TestingPluginManager (org.apache.flink.core.plugin.TestingPluginManager)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 Time (org.apache.flink.api.common.time.Time)2 HighAvailabilityServices (org.apache.flink.runtime.highavailability.HighAvailabilityServices)2 RpcService (org.apache.flink.runtime.rpc.RpcService)2 SecurityConfiguration (org.apache.flink.runtime.security.SecurityConfiguration)2 File (java.io.File)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1