use of org.apache.drill.test.ClusterFixtureBuilder in project drill by apache.
the class TestPluginRegistry method testEnableWithPut.
/**
* Tests the other way to enable/disabled plugins: make a **COPY** of the
* config and set the enable/disable status. Note: race conditions happen
* if a client modifies a stored config. Old code would do that, but the
* results are undefined. Either use setEnabled(), or make a copy of the
* config. This case also models where the user edits the config by hand
* in the Web Console to disable the plugin: the deserialize/serialize
* steps make the copy.
*/
@Test
public void testEnableWithPut() throws Exception {
ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
try (ClusterFixture cluster = builder.build()) {
StoragePluginRegistry registry = cluster.storageRegistry();
FileSystemConfig pConfig1 = myConfig1();
registry.put(MY_PLUGIN_NAME, pConfig1);
assertTrue(registry.getStoredConfig(MY_PLUGIN_NAME).isEnabled());
// Enable the same plugin using a different, but equal, config.
// The original config remains in place.
StoragePluginConfig pConfig2 = registry.copyConfig(MY_PLUGIN_NAME);
pConfig2.setEnabled(true);
assertEquals(pConfig1, pConfig2);
registry.put(MY_PLUGIN_NAME, pConfig2);
StoragePluginConfig savedConfig = registry.getStoredConfig(MY_PLUGIN_NAME);
assertEquals(pConfig1, savedConfig);
assertTrue(savedConfig.isEnabled());
// Force resolution of the plugin so there is something to cache
StoragePlugin plugin = registry.getPlugin(MY_PLUGIN_NAME);
assertNotNull(plugin);
// Disable an enabled plugin. The old plugin lives in ephemeral
// store, but is not visible by name. If requested, the
// registry obtains a new copy from persistent storage.
StoragePluginConfig pConfig3 = registry.copyConfig(MY_PLUGIN_NAME);
pConfig3.setEnabled(false);
registry.put(MY_PLUGIN_NAME, pConfig3);
savedConfig = registry.getStoredConfig(MY_PLUGIN_NAME);
assertEquals(pConfig1, savedConfig);
assertFalse(savedConfig.isEnabled());
// OK to disable twice
StoragePluginConfig pConfig4 = registry.copyConfig(MY_PLUGIN_NAME);
pConfig4.setEnabled(false);
registry.put(MY_PLUGIN_NAME, pConfig4);
savedConfig = registry.getStoredConfig(MY_PLUGIN_NAME);
assertEquals(pConfig1, savedConfig);
assertFalse(savedConfig.isEnabled());
// Disabled plugins appear in the stored config map
Map<String, StoragePluginConfig> configMap = registry.storedConfigs();
assertTrue(configMap.containsKey(MY_PLUGIN_KEY));
assertEquals(pConfig3, configMap.get(MY_PLUGIN_KEY));
// Re-enable, the original plugin instance reappears.
StoragePluginConfig pConfig5 = registry.copyConfig(MY_PLUGIN_NAME);
pConfig5.setEnabled(true);
registry.put(MY_PLUGIN_NAME, pConfig5);
assertSame(plugin, registry.getPlugin(MY_PLUGIN_NAME));
assertTrue(plugin.getConfig().isEnabled());
}
}
use of org.apache.drill.test.ClusterFixtureBuilder in project drill by apache.
the class TestPluginRegistry method testLifecycle.
@Test
public void testLifecycle() throws Exception {
ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
try (ClusterFixture cluster = builder.build()) {
StoragePluginRegistry registry = cluster.storageRegistry();
// Bootstrap file loaded.
// Normal
assertNotNull(registry.getPlugin(CP_PLUGIN_NAME));
// System
assertNotNull(registry.getPlugin(SYS_PLUGIN_NAME));
// Not editable
assertNull(registry.getStoredConfig(SYS_PLUGIN_NAME));
assertNull(registry.getPlugin("bogus"));
// Enabled plugins
Map<String, StoragePluginConfig> configMap = registry.enabledConfigs();
assertTrue(configMap.containsKey(CP_PLUGIN_NAME));
// Disabled, but still appears
assertFalse(configMap.containsKey(S3_PLUGIN_NAME));
assertFalse(configMap.containsKey(SYS_PLUGIN_NAME));
assertNotNull(registry.getDefinedConfig(CP_PLUGIN_NAME));
assertNull(registry.getDefinedConfig(S3_PLUGIN_NAME));
assertNotNull(registry.getDefinedConfig(SYS_PLUGIN_NAME));
// All stored plugins, including disabled
configMap = registry.storedConfigs();
assertTrue(configMap.containsKey(CP_PLUGIN_NAME));
// Disabled, but still appears
assertTrue(configMap.containsKey(S3_PLUGIN_NAME));
assertNotNull(configMap.get(S3_PLUGIN_NAME));
assertSame(registry.getStoredConfig(S3_PLUGIN_NAME), configMap.get(S3_PLUGIN_NAME));
assertFalse(configMap.containsKey(SYS_PLUGIN_NAME));
int bootstrapCount = configMap.size();
// Enabled only
configMap = registry.storedConfigs(PluginFilter.ENABLED);
assertTrue(configMap.containsKey(CP_PLUGIN_NAME));
assertFalse(configMap.containsKey(S3_PLUGIN_NAME));
// Disabled only
configMap = registry.storedConfigs(PluginFilter.DISABLED);
assertFalse(configMap.containsKey(CP_PLUGIN_NAME));
assertTrue(configMap.containsKey(S3_PLUGIN_NAME));
// Create a new plugin
FileSystemConfig pConfig1 = myConfig1();
registry.put(MY_PLUGIN_NAME, pConfig1);
StoragePlugin plugin1 = registry.getPlugin(MY_PLUGIN_NAME);
assertNotNull(plugin1);
assertSame(plugin1, registry.getPluginByConfig(pConfig1));
configMap = registry.storedConfigs();
// Names converted to lowercase in persistent storage
assertTrue(configMap.containsKey(MY_PLUGIN_KEY));
assertEquals(bootstrapCount + 1, configMap.size());
// Names are case-insensitive
assertSame(plugin1, registry.getPlugin(MY_PLUGIN_KEY));
assertSame(plugin1, registry.getPlugin(MY_PLUGIN_NAME.toUpperCase()));
// Update the plugin
FileSystemConfig pConfig2 = myConfig2();
registry.put(MY_PLUGIN_NAME, pConfig2);
StoragePlugin plugin2 = registry.getPlugin(MY_PLUGIN_NAME);
assertNotSame(plugin1, plugin2);
assertTrue(plugin2 instanceof FileSystemPlugin);
FileSystemPlugin fsStorage = (FileSystemPlugin) plugin2;
assertSame(pConfig2, fsStorage.getConfig());
assertSame(plugin2, registry.getPluginByConfig(pConfig2));
// Cannot create/update a plugin with null or blank name
FileSystemConfig pConfig3 = myConfig1();
try {
registry.put(null, pConfig3);
fail();
} catch (PluginException e) {
// Expected
}
try {
registry.put(" ", pConfig3);
fail();
} catch (PluginException e) {
// Expected
}
}
}
use of org.apache.drill.test.ClusterFixtureBuilder in project drill by apache.
the class TestOAuthProcess method setup.
@BeforeClass
public static void setup() throws Exception {
ACCESS_TOKEN_RESPONSE = Files.asCharSource(DrillFileUtils.getResourceAsFile("/data/oauth_access_token_response.json"), Charsets.UTF_8).read();
REFRESH_TOKEN_RESPONSE = Files.asCharSource(DrillFileUtils.getResourceAsFile("/data/token_refresh.json"), Charsets.UTF_8).read();
TEST_JSON_RESPONSE_WITH_DATATYPES = Files.asCharSource(DrillFileUtils.getResourceAsFile("/data/response2.json"), Charsets.UTF_8).read();
ClusterFixtureBuilder builder = new ClusterFixtureBuilder(dirTestWatcher).configProperty(ExecConstants.HTTP_ENABLE, true).configProperty(ExecConstants.HTTP_PORT_HUNT, true);
startCluster(builder);
int portNumber = cluster.drillbit().getWebServerPort();
hostname = "http://localhost:" + portNumber + "/storage/" + CONNECTION_NAME;
Map<String, String> creds = new HashMap<>();
creds.put("clientID", "12345");
creds.put("clientSecret", "54321");
creds.put("accessToken", null);
creds.put("refreshToken", null);
creds.put(OAuthTokenCredentials.TOKEN_URI, "http://localhost:" + MOCK_SERVER_PORT + "/get_access_token");
CredentialsProvider credentialsProvider = new PlainCredentialsProvider(creds);
HttpApiConfig connectionConfig = HttpApiConfig.builder().url("http://localhost:" + MOCK_SERVER_PORT + "/getdata").method("get").requireTail(false).inputType("json").build();
HttpOAuthConfig oAuthConfig = HttpOAuthConfig.builder().callbackURL(hostname + "/update_oath2_authtoken").build();
Map<String, HttpApiConfig> configs = new HashMap<>();
configs.put("test", connectionConfig);
// Add storage plugin for test OAuth
HttpStoragePluginConfig mockStorageConfigWithWorkspace = new HttpStoragePluginConfig(false, configs, TIMEOUT, "", 80, "", "", "", oAuthConfig, credentialsProvider);
mockStorageConfigWithWorkspace.setEnabled(true);
cluster.defineStoragePlugin("localOauth", mockStorageConfigWithWorkspace);
}
use of org.apache.drill.test.ClusterFixtureBuilder in project drill by apache.
the class TestProjectWithFunctions method setup.
@Before
public void setup() throws Exception {
ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
startCluster(builder);
}
use of org.apache.drill.test.ClusterFixtureBuilder in project drill by apache.
the class TestSchemaCommands method setup.
@BeforeClass
public static void setup() throws Exception {
ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
startCluster(builder);
}
Aggregations