Search in sources :

Example 1 with TestingPluginManager

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

the class ExternalResourceUtilsTest method testConstructExternalResourceDriversFromConfig.

@Test
public void testConstructExternalResourceDriversFromConfig() {
    final Configuration config = new Configuration();
    final String driverFactoryClassName = TestingExternalResourceDriverFactory.class.getName();
    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));
    config.setString(ExternalResourceOptions.getExternalResourceDriverFactoryConfigOptionForResource(RESOURCE_NAME_1), driverFactoryClassName);
    final Map<String, ExternalResourceDriver> externalResourceDrivers = ExternalResourceUtils.externalResourceDriversFromConfig(config, testingPluginManager);
    assertThat(externalResourceDrivers.size(), is(1));
    assertThat(externalResourceDrivers.get(RESOURCE_NAME_1), instanceOf(TestingExternalResourceDriver.class));
}
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)

Example 2 with TestingPluginManager

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

the class ExternalResourceUtilsTest method testFactoryFailedToCreateDriver.

@Test
public void testFactoryFailedToCreateDriver() {
    final Configuration config = new Configuration();
    final String driverFactoryClassName = TestingFailedExternalResourceDriverFactory.class.getName();
    final Map<Class<?>, Iterator<?>> plugins = new HashMap<>();
    plugins.put(ExternalResourceDriverFactory.class, IteratorUtils.singletonIterator(new TestingFailedExternalResourceDriverFactory()));
    final PluginManager testingPluginManager = new TestingPluginManager(plugins);
    config.set(ExternalResourceOptions.EXTERNAL_RESOURCE_LIST, Collections.singletonList(RESOURCE_NAME_1));
    config.setString(ExternalResourceOptions.getExternalResourceDriverFactoryConfigOptionForResource(RESOURCE_NAME_1), driverFactoryClassName);
    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)

Example 3 with TestingPluginManager

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

the class ExternalResourceUtilsTest method testFactoryPluginDoesNotExist.

@Test
public void testFactoryPluginDoesNotExist() {
    final Configuration config = new Configuration();
    final String driverFactoryClassName = TestingExternalResourceDriverFactory.class.getName();
    final PluginManager testingPluginManager = new TestingPluginManager(Collections.emptyMap());
    config.set(ExternalResourceOptions.EXTERNAL_RESOURCE_LIST, Collections.singletonList(RESOURCE_NAME_1));
    config.setString(ExternalResourceOptions.getExternalResourceDriverFactoryConfigOptionForResource(RESOURCE_NAME_1), driverFactoryClassName);
    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) TestingPluginManager(org.apache.flink.core.plugin.TestingPluginManager) ExternalResourceDriver(org.apache.flink.api.common.externalresource.ExternalResourceDriver) Test(org.junit.Test)

Example 4 with TestingPluginManager

use of org.apache.flink.core.plugin.TestingPluginManager 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)

Example 5 with TestingPluginManager

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

the class ReporterSetupTest method testReflectionInterception.

/**
 * Verifies that the factory approach is used if the factory is annotated with {@link
 * org.apache.flink.metrics.reporter.InterceptInstantiationViaReflection}.
 */
@Test
public void testReflectionInterception() {
    final Configuration config = new Configuration();
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, InstantiationTypeTrackingTestReporter.class.getName());
    final List<ReporterSetup> reporterSetups = ReporterSetup.fromConfiguration(config, new TestingPluginManager(Collections.singletonMap(MetricReporterFactory.class, Collections.singletonList(new InterceptingInstantiationTypeTrackingTestReporterFactory()).iterator())));
    assertEquals(1, reporterSetups.size());
    final ReporterSetup reporterSetup = reporterSetups.get(0);
    final InstantiationTypeTrackingTestReporter metricReporter = (InstantiationTypeTrackingTestReporter) reporterSetup.getReporter();
    assertTrue(metricReporter.createdByFactory);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) TestingPluginManager(org.apache.flink.core.plugin.TestingPluginManager) Test(org.junit.Test)

Aggregations

Configuration (org.apache.flink.configuration.Configuration)5 TestingPluginManager (org.apache.flink.core.plugin.TestingPluginManager)5 Test (org.junit.Test)5 ExternalResourceDriver (org.apache.flink.api.common.externalresource.ExternalResourceDriver)4 PluginManager (org.apache.flink.core.plugin.PluginManager)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3