Search in sources :

Example 81 with ClientFixture

use of org.apache.drill.test.ClientFixture in project drill by axbaretto.

the class TestConfigLinkage method testSessionOption.

/* Test if session option takes precedence */
@Test
public void testSessionOption() throws Exception {
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher).sessionOption(ExecConstants.SLICE_TARGET, 10);
    try (ClusterFixture cluster = builder.build();
        ClientFixture client = cluster.clientFixture()) {
        String slice_target = client.queryBuilder().sql("SELECT val FROM sys.%s where name='planner.slice_target' and optionScope = 'SESSION'", SystemTable.OPTION_VAL.getTableName()).singletonString();
        assertEquals(slice_target, "10");
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) ClientFixture(org.apache.drill.test.ClientFixture) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) Test(org.junit.Test) OptionsTest(org.apache.drill.categories.OptionsTest) SlowTest(org.apache.drill.categories.SlowTest)

Example 82 with ClientFixture

use of org.apache.drill.test.ClientFixture in project drill by axbaretto.

the class TestConfigLinkage method testInternalSystemOption.

@Test
public void testInternalSystemOption() throws Exception {
    OptionDefinition optionDefinition = createMockPropOptionDefinition();
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher).putDefinition(optionDefinition).configProperty(ExecConstants.bootDefaultFor(MOCK_PROPERTY), "a").systemOption(MOCK_PROPERTY, "blah");
    try (ClusterFixture cluster = builder.build();
        ClientFixture client = cluster.clientFixture()) {
        String mockProp = client.queryBuilder().sql("SELECT string_val FROM sys.%s where name='%s'", SystemTable.INTERNAL_OPTIONS.getTableName(), MOCK_PROPERTY).singletonString();
        String mockProp2 = client.queryBuilder().sql("SELECT val FROM sys.%s where name='%s'", SystemTable.INTERNAL_OPTIONS_VAL.getTableName(), MOCK_PROPERTY).singletonString();
        assertEquals("blah", mockProp);
        assertEquals("blah", mockProp2);
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) ClientFixture(org.apache.drill.test.ClientFixture) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) Test(org.junit.Test) OptionsTest(org.apache.drill.categories.OptionsTest) SlowTest(org.apache.drill.categories.SlowTest)

Example 83 with ClientFixture

use of org.apache.drill.test.ClientFixture in project drill by axbaretto.

the class TestConfigLinkage method testDefaultInternalValue.

@Test
public void testDefaultInternalValue() throws Exception {
    OptionDefinition optionDefinition = createMockPropOptionDefinition();
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher).configProperty(ExecConstants.bootDefaultFor(MOCK_PROPERTY), "a").putDefinition(optionDefinition);
    try (ClusterFixture cluster = builder.build();
        ClientFixture client = cluster.clientFixture()) {
        String mockProp = client.queryBuilder().sql("SELECT string_val FROM sys.%s where name='%s'", SystemTable.INTERNAL_OPTIONS.getTableName(), MOCK_PROPERTY).singletonString();
        String mockProp2 = client.queryBuilder().sql("SELECT val FROM sys.%s where name='%s'", SystemTable.INTERNAL_OPTIONS_VAL.getTableName(), MOCK_PROPERTY).singletonString();
        assertEquals("a", mockProp);
        assertEquals("a", mockProp2);
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) ClientFixture(org.apache.drill.test.ClientFixture) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) Test(org.junit.Test) OptionsTest(org.apache.drill.categories.OptionsTest) SlowTest(org.apache.drill.categories.SlowTest)

Example 84 with ClientFixture

use of org.apache.drill.test.ClientFixture in project drill by apache.

the class TestOptionsAuthEnabled method testAdminUserOptions.

@Test
public void testAdminUserOptions() throws Exception {
    try (ClusterFixture cluster = ClusterFixture.standardCluster(dirTestWatcher);
        ClientFixture client = cluster.clientFixture()) {
        OptionManager optionManager = cluster.drillbit().getContext().getOptionManager();
        // Admin Users Tests
        // config file should have the 'fake' default admin user and it should be returned
        // by the option manager if the option has not been set by the user
        String configAdminUser = optionManager.getOption(ExecConstants.ADMIN_USERS_VALIDATOR);
        assertEquals(configAdminUser, ExecConstants.ADMIN_USERS_VALIDATOR.DEFAULT_ADMIN_USERS);
        // Option accessor should never return the 'fake' default from the config
        String adminUser1 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        assertNotEquals(adminUser1, ExecConstants.ADMIN_USERS_VALIDATOR.DEFAULT_ADMIN_USERS);
        // Change testAdminUser if necessary
        String testAdminUser = "ronswanson";
        if (adminUser1.equals(testAdminUser)) {
            testAdminUser += "thefirst";
        }
        // Check if the admin option accessor honors a user-supplied value
        client.alterSystem(ExecConstants.ADMIN_USERS_KEY, testAdminUser);
        String adminUser2 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        assertEquals(adminUser2, testAdminUser);
        // Ensure that the default admin users have admin privileges
        client.resetSystem(ExecConstants.ADMIN_USERS_KEY);
        client.resetSystem(ExecConstants.ADMIN_USER_GROUPS_KEY);
        String systemAdminUsersList0 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        String systemAdminUserGroupsList0 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        for (String user : systemAdminUsersList0.split(",")) {
            assertTrue(ImpersonationUtil.hasAdminPrivileges(user, systemAdminUsersList0, systemAdminUserGroupsList0));
        }
        // test if admin users, set by the user, have admin privileges
        // test if we can handle a user-supplied list that is not well formatted
        String crummyTestAdminUsersList = " alice, bob bob, charlie  ,, dave ";
        client.alterSystem(ExecConstants.ADMIN_USERS_KEY, crummyTestAdminUsersList);
        String[] sanitizedAdminUsers = { "alice", "bob bob", "charlie", "dave" };
        // also test the CSV sanitizer
        assertEquals(Joiner.on(",").join(sanitizedAdminUsers), DrillStringUtils.sanitizeCSV(crummyTestAdminUsersList));
        String systemAdminUsersList1 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        String systemAdminUserGroupsList1 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        for (String user : sanitizedAdminUsers) {
            assertTrue(ImpersonationUtil.hasAdminPrivileges(user, systemAdminUsersList1, systemAdminUserGroupsList1));
        }
        // Admin User Groups Tests
        // config file should have the 'fake' default admin user and it should be returned
        // by the option manager if the option has not been set by the user
        String configAdminUserGroups = optionManager.getOption(ExecConstants.ADMIN_USER_GROUPS_VALIDATOR);
        assertEquals(configAdminUserGroups, ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.DEFAULT_ADMIN_USER_GROUPS);
        // Option accessor should never return the 'fake' default from the config
        String adminUserGroups1 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        assertNotEquals(adminUserGroups1, ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.DEFAULT_ADMIN_USER_GROUPS);
        // Change testAdminUserGroups if necessary
        String testAdminUserGroups = "yakshavers";
        if (adminUserGroups1.equals(testAdminUserGroups)) {
            testAdminUserGroups += ",wormracers";
        }
        // Check if the admin option accessor honors a user-supplied values
        client.alterSystem(ExecConstants.ADMIN_USER_GROUPS_KEY, testAdminUserGroups);
        String adminUserGroups2 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        assertEquals(adminUserGroups2, testAdminUserGroups);
        // Test if we can handle a user-supplied admin user groups list that is not well formatted
        String crummyTestAdminUserGroupsList = " g1, g 2, g4 ,, g5 ";
        client.alterSystem(ExecConstants.ADMIN_USER_GROUPS_KEY, crummyTestAdminUserGroupsList);
        String systemAdminUserGroupsList2 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        // for admin privileges
        for (String group : systemAdminUserGroupsList2.split(",")) {
            assertTrue(group.length() != 0);
            assertTrue(group.trim().equals(group));
        }
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) ClientFixture(org.apache.drill.test.ClientFixture) OptionManager(org.apache.drill.exec.server.options.OptionManager) Test(org.junit.Test)

Example 85 with ClientFixture

use of org.apache.drill.test.ClientFixture in project drill by apache.

the class TestConfigLinkage method testAlterSystem.

/* Test if altering system option takes precedence over config option */
@Test
public void testAlterSystem() throws Exception {
    try (ClusterFixture cluster = ClusterFixture.standardCluster(dirTestWatcher);
        ClientFixture client = cluster.clientFixture()) {
        client.queryBuilder().sql("ALTER SYSTEM SET `planner.slice_target` = 10000").run();
        String slice_target = client.queryBuilder().sql("SELECT val FROM sys.%s where name='planner.slice_target' and optionScope = 'SYSTEM'", SystemTable.OPTIONS.getTableName()).singletonString();
        assertEquals(slice_target, "10000");
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) ClientFixture(org.apache.drill.test.ClientFixture) Test(org.junit.Test) OptionsTest(org.apache.drill.categories.OptionsTest) BaseTest(org.apache.drill.test.BaseTest) SlowTest(org.apache.drill.categories.SlowTest)

Aggregations

ClientFixture (org.apache.drill.test.ClientFixture)122 Test (org.junit.Test)102 ClusterFixture (org.apache.drill.test.ClusterFixture)99 ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)89 SlowTest (org.apache.drill.categories.SlowTest)46 OptionsTest (org.apache.drill.categories.OptionsTest)36 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)28 BaseTest (org.apache.drill.test.BaseTest)20 ClusterTest (org.apache.drill.test.ClusterTest)16 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)12 DrillTest (org.apache.drill.test.DrillTest)10 OperatorTest (org.apache.drill.categories.OperatorTest)8 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)7 RestClientFixture (org.apache.drill.test.RestClientFixture)4 ArrayList (java.util.ArrayList)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)3 BigIntVector (org.apache.drill.exec.vector.BigIntVector)3 File (java.io.File)2 PlanFragment (org.apache.drill.exec.proto.BitControl.PlanFragment)2