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