Search in sources :

Example 1 with StoragePluginFixtureConfig

use of org.apache.drill.exec.store.BasePluginRegistryTest.StoragePluginFixtureConfig in project drill by apache.

the class TestPluginRegistry method testBadPlugin.

/**
 * Test to illustrate problems discussed in DRILL-7624
 */
@Test
public void testBadPlugin() throws Exception {
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
    builder.configBuilder().put(ExecConstants.PRIVATE_CONNECTORS, Collections.singletonList(StoragePluginFixture.class.getName()));
    try (ClusterFixture cluster = builder.build()) {
        StoragePluginRegistry registry = cluster.storageRegistry();
        // Create a config that causes a crash because the plugin
        // is not created on update.
        StoragePluginFixtureConfig badConfig = new StoragePluginFixtureConfig("crash-ctor");
        badConfig.setEnabled(true);
        // instantiating the plugin.
        try {
            registry.validatedPut("bad", badConfig);
            fail();
        } catch (PluginException e) {
        // Expected
        }
        assertNull(registry.getStoredConfig("bad"));
        assertFalse(registry.availablePlugins().contains("bad"));
        // Try the same with JSON
        String json = registry.encode(badConfig);
        try {
            registry.putJson("bad", json);
            fail();
        } catch (PluginException e) {
        // Expected
        }
        assertFalse(registry.availablePlugins().contains("bad"));
        // Now, lets pretend the plugin was valid when we did the above,
        // but later the external system failed.
        registry.put("bad", badConfig);
        assertEquals(badConfig, registry.getStoredConfig("bad"));
        assertTrue(registry.availablePlugins().contains("bad"));
        // Ask for the actual plugin. Now will fail.
        try {
            registry.getPlugin("bad");
            fail();
        } catch (UserException e) {
            assertTrue(e.getMessage().contains("bad"));
        }
        assertTrue(registry.availablePlugins().contains("bad"));
        // No plugin created. Will fail the next time also.
        try {
            registry.getPlugin("bad");
            fail();
        } catch (UserException e) {
        // Expected
        }
        assertTrue(registry.availablePlugins().contains("bad"));
        // The iterator used to find planning rules will skip the failed
        // plugin. (That the planner uses all rules is, itself, a bug.)
        int n = registry.availablePlugins().size();
        int count = 0;
        for (@SuppressWarnings("unused") Entry<String, StoragePlugin> entry : registry) {
            count++;
        }
        assertEquals(n - 1, count);
        // Reset to known good state
        registry.remove("bad");
        // Get tricky. Create a good plugin, then replace with
        // a disabled bad one.
        StoragePluginFixtureConfig goodConfig = new StoragePluginFixtureConfig("ok");
        goodConfig.setEnabled(true);
        json = registry.encode(goodConfig);
        registry.putJson("test", json);
        assertTrue(registry.availablePlugins().contains("test"));
        assertEquals(goodConfig, registry.getPlugin("test").getConfig());
        // Replace with a disabled bad plugin
        badConfig = new StoragePluginFixtureConfig("crash-ctor");
        badConfig.setEnabled(false);
        json = registry.encode(badConfig);
        registry.putJson("test", json);
        assertFalse(registry.availablePlugins().contains("test"));
        assertNull(registry.getPlugin("test"));
        assertNotNull(registry.getStoredConfig("test"));
        assertEquals(badConfig, registry.getStoredConfig("test"));
        // Attempt to disable a disabled plugin. Should be OK.
        registry.setEnabled("test", false);
        // system, fix that system first.)
        try {
            registry.setEnabled("test", true);
            fail();
        } catch (PluginException e) {
        // Expected
        }
        assertFalse(registry.availablePlugins().contains("test"));
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) PluginException(org.apache.drill.exec.store.StoragePluginRegistry.PluginException) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) StoragePluginFixtureConfig(org.apache.drill.exec.store.BasePluginRegistryTest.StoragePluginFixtureConfig) UserException(org.apache.drill.common.exceptions.UserException) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Aggregations

UserException (org.apache.drill.common.exceptions.UserException)1 StoragePluginFixtureConfig (org.apache.drill.exec.store.BasePluginRegistryTest.StoragePluginFixtureConfig)1 PluginException (org.apache.drill.exec.store.StoragePluginRegistry.PluginException)1 BaseTest (org.apache.drill.test.BaseTest)1 ClusterFixture (org.apache.drill.test.ClusterFixture)1 ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)1 Test (org.junit.Test)1