Search in sources :

Example 66 with ClusterFixtureBuilder

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());
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 67 with ClusterFixtureBuilder

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
        }
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) FileSystemPlugin(org.apache.drill.exec.store.dfs.FileSystemPlugin) PluginException(org.apache.drill.exec.store.StoragePluginRegistry.PluginException) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 68 with ClusterFixtureBuilder

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);
}
Also used : PlainCredentialsProvider(org.apache.drill.common.logical.security.PlainCredentialsProvider) HashMap(java.util.HashMap) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) PlainCredentialsProvider(org.apache.drill.common.logical.security.PlainCredentialsProvider) CredentialsProvider(org.apache.drill.common.logical.security.CredentialsProvider) BeforeClass(org.junit.BeforeClass)

Example 69 with ClusterFixtureBuilder

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);
}
Also used : ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) Before(org.junit.Before)

Example 70 with ClusterFixtureBuilder

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);
}
Also used : ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) BeforeClass(org.junit.BeforeClass)

Aggregations

ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)156 ClusterFixture (org.apache.drill.test.ClusterFixture)102 Test (org.junit.Test)93 ClientFixture (org.apache.drill.test.ClientFixture)89 BeforeClass (org.junit.BeforeClass)47 SlowTest (org.apache.drill.categories.SlowTest)44 OptionsTest (org.apache.drill.categories.OptionsTest)34 BaseTest (org.apache.drill.test.BaseTest)27 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)15 DrillTest (org.apache.drill.test.DrillTest)14 OperatorTest (org.apache.drill.categories.OperatorTest)8 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)8 FileSystemConfig (org.apache.drill.exec.store.dfs.FileSystemConfig)6 StoragePluginConfig (org.apache.drill.common.logical.StoragePluginConfig)5 PluginException (org.apache.drill.exec.store.StoragePluginRegistry.PluginException)5 File (java.io.File)4 ResourceManagerTest (org.apache.drill.categories.ResourceManagerTest)4 DefaultResourceManager (org.apache.drill.exec.work.foreman.rm.DefaultResourceManager)4 DistributedResourceManager (org.apache.drill.exec.work.foreman.rm.DistributedResourceManager)4 ResourceManager (org.apache.drill.exec.work.foreman.rm.ResourceManager)4