Search in sources :

Example 1 with AllowAllAccessControlManager

use of io.trino.testing.AllowAllAccessControlManager in project trino by trinodb.

the class TestSessionPropertyDefaults method testApplyDefaultProperties.

@Test
public void testApplyDefaultProperties() {
    SessionPropertyDefaults sessionPropertyDefaults = new SessionPropertyDefaults(TEST_NODE_INFO, new AllowAllAccessControlManager());
    SessionPropertyManager sessionPropertyManager = new SessionPropertyManager();
    sessionPropertyManager.addConnectorSessionProperties(new CatalogName("testCatalog"), ImmutableList.of(PropertyMetadata.stringProperty("explicit_set", "Test property", null, false), PropertyMetadata.stringProperty("catalog_default", "Test property", null, false)));
    SessionPropertyConfigurationManagerFactory factory = new TestingSessionPropertyConfigurationManagerFactory(ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, // Will be overridden
    "2GB").put(QUERY_MAX_TOTAL_MEMORY, // Will remain default
    "2GB").buildOrThrow(), ImmutableMap.of("testCatalog", ImmutableMap.<String, String>builder().put("explicit_set", // Will be overridden
    "override").put("catalog_default", // Will remain default
    "catalog_default").buildOrThrow()));
    sessionPropertyDefaults.addConfigurationManagerFactory(factory);
    sessionPropertyDefaults.setConfigurationManager(factory.getName(), ImmutableMap.of());
    Session session = Session.builder(sessionPropertyManager).setQueryId(new QueryId("test_query_id")).setIdentity(Identity.ofUser("testUser")).setSystemProperty(QUERY_MAX_MEMORY, // Override this default system property
    "1GB").setSystemProperty(JOIN_DISTRIBUTION_TYPE, "partitioned").setSystemProperty(HASH_PARTITION_COUNT, "43").setCatalogSessionProperty("testCatalog", "explicit_set", // Override this default catalog property
    "explicit_set").build();
    assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").buildOrThrow());
    assertEquals(session.getCatalogProperties(), ImmutableMap.of("testCatalog", ImmutableMap.<String, String>builder().put("explicit_set", "explicit_set").buildOrThrow()));
    session = sessionPropertyDefaults.newSessionWithDefaultProperties(session, Optional.empty(), TEST_RESOURCE_GROUP_ID);
    assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, // User provided value overrides default value
    "1GB").put(JOIN_DISTRIBUTION_TYPE, // User provided value is used
    "partitioned").put(HASH_PARTITION_COUNT, // User provided value is used
    "43").put(QUERY_MAX_TOTAL_MEMORY, // Default value is used
    "2GB").buildOrThrow());
    assertEquals(session.getCatalogProperties(), ImmutableMap.of("testCatalog", ImmutableMap.<String, String>builder().put("explicit_set", // User provided value overrides default value
    "explicit_set").put("catalog_default", // Default value is used
    "catalog_default").buildOrThrow()));
}
Also used : AllowAllAccessControlManager(io.trino.testing.AllowAllAccessControlManager) QueryId(io.trino.spi.QueryId) SessionPropertyManager(io.trino.metadata.SessionPropertyManager) TestingSessionPropertyConfigurationManagerFactory(io.trino.spi.session.TestingSessionPropertyConfigurationManagerFactory) CatalogName(io.trino.connector.CatalogName) TestingSessionPropertyConfigurationManagerFactory(io.trino.spi.session.TestingSessionPropertyConfigurationManagerFactory) SessionPropertyConfigurationManagerFactory(io.trino.spi.session.SessionPropertyConfigurationManagerFactory) Session(io.trino.Session) Test(org.testng.annotations.Test)

Aggregations

Session (io.trino.Session)1 CatalogName (io.trino.connector.CatalogName)1 SessionPropertyManager (io.trino.metadata.SessionPropertyManager)1 QueryId (io.trino.spi.QueryId)1 SessionPropertyConfigurationManagerFactory (io.trino.spi.session.SessionPropertyConfigurationManagerFactory)1 TestingSessionPropertyConfigurationManagerFactory (io.trino.spi.session.TestingSessionPropertyConfigurationManagerFactory)1 AllowAllAccessControlManager (io.trino.testing.AllowAllAccessControlManager)1 Test (org.testng.annotations.Test)1