Search in sources :

Example 21 with DatabaseConnectionConfig

use of com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig in project aws-athena-query-federation by awslabs.

the class DataLakeGen2MuxMetadataHandlerTest method setup.

@Before
public void setup() {
    this.allocator = new BlockAllocatorImpl();
    this.dataLakeGen2MetadataHandler = Mockito.mock(DataLakeGen2MetadataHandler.class);
    this.metadataHandlerMap = Collections.singletonMap("fakedatabase", this.dataLakeGen2MetadataHandler);
    this.secretsManager = Mockito.mock(AWSSecretsManager.class);
    this.athena = Mockito.mock(AmazonAthena.class);
    this.queryStatusChecker = Mockito.mock(QueryStatusChecker.class);
    this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class);
    DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", "fakedatabase", "fakedatabase://jdbc:fakedatabase://hostname/${testSecret}", "testSecret");
    this.jdbcMetadataHandler = new DataLakeGen2MuxMetadataHandler(this.secretsManager, this.athena, this.jdbcConnectionFactory, this.metadataHandlerMap, databaseConnectionConfig);
}
Also used : JdbcConnectionFactory(com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory) QueryStatusChecker(com.amazonaws.athena.connector.lambda.QueryStatusChecker) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) DatabaseConnectionConfig(com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) Before(org.junit.Before)

Example 22 with DatabaseConnectionConfig

use of com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig in project aws-athena-query-federation by awslabs.

the class HiveMuxMetadataHandlerTest method setup.

@Before
public void setup() {
    this.allocator = new BlockAllocatorImpl();
    this.hiveMetadataHandler = Mockito.mock(HiveMetadataHandler.class);
    this.metadataHandlerMap = Collections.singletonMap("metaHive", this.hiveMetadataHandler);
    this.secretsManager = Mockito.mock(AWSSecretsManager.class);
    this.athena = Mockito.mock(AmazonAthena.class);
    this.queryStatusChecker = Mockito.mock(QueryStatusChecker.class);
    this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class);
    DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", HiveConstants.HIVE_NAME, "hive2://jdbc:hive2://54.89.6.2:10000/authena;AuthMech=3;${testSecret}", "testSecret");
    this.jdbcMetadataHandler = new HiveMuxMetadataHandler(this.secretsManager, this.athena, this.jdbcConnectionFactory, this.metadataHandlerMap, databaseConnectionConfig);
}
Also used : JdbcConnectionFactory(com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory) QueryStatusChecker(com.amazonaws.athena.connector.lambda.QueryStatusChecker) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) DatabaseConnectionConfig(com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) Before(org.junit.Before)

Example 23 with DatabaseConnectionConfig

use of com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig in project aws-athena-query-federation by awslabs.

the class HiveMuxMetadataHandlerTest method maxCatalogTest.

@Test
public void maxCatalogTest() {
    Map<String, JdbcMetadataHandler> metadataHandlersMap = new HashMap<String, JdbcMetadataHandler>();
    for (int jdbcMetadataHandlerCount = 0; jdbcMetadataHandlerCount <= 100; jdbcMetadataHandlerCount++) {
        metadataHandlersMap.put("metaHive" + jdbcMetadataHandlerCount, this.hiveMetadataHandler);
    }
    DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog1", HiveConstants.HIVE_NAME, "hive2://jdbc:hive2://54.89.6.2:10000/authena;AuthMech=3;${testSecret}", "testSecret");
    try {
        new HiveMuxMetadataHandler(this.secretsManager, this.athena, this.jdbcConnectionFactory, metadataHandlersMap, databaseConnectionConfig);
    } catch (Exception e) {
        e.getMessage();
        Assert.assertTrue(e.getMessage().contains("Max 100 catalogs supported in multiplexer."));
    }
}
Also used : HashMap(java.util.HashMap) DatabaseConnectionConfig(com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig) JdbcMetadataHandler(com.amazonaws.athena.connectors.jdbc.manager.JdbcMetadataHandler) Test(org.junit.Test)

Example 24 with DatabaseConnectionConfig

use of com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig in project aws-athena-query-federation by awslabs.

the class HiveMuxRecordHandlerTest method maxCatalogTest.

@Test
public void maxCatalogTest() {
    Map<String, JdbcRecordHandler> recorddataHandlersMap = new HashMap<String, JdbcRecordHandler>();
    for (int jdbcHandlerCount = 0; jdbcHandlerCount <= 100; jdbcHandlerCount++) {
        recorddataHandlersMap.put("recordHive" + jdbcHandlerCount, this.hiveRecordHandler);
    }
    DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog1", HiveConstants.HIVE_NAME, "hive2://jdbc:hive2://54.89.6.2:10000/authena;AuthMech=3;${testSecret}", "testSecret");
    try {
        new HiveMuxRecordHandler(this.amazonS3, this.secretsManager, this.athena, this.jdbcConnectionFactory, databaseConnectionConfig, recorddataHandlersMap);
    } catch (Exception e) {
        e.getMessage();
        Assert.assertTrue(e.getMessage().contains("Max 100 catalogs supported in multiplexer."));
    }
}
Also used : HashMap(java.util.HashMap) DatabaseConnectionConfig(com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig) JdbcRecordHandler(com.amazonaws.athena.connectors.jdbc.manager.JdbcRecordHandler) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 25 with DatabaseConnectionConfig

use of com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig in project aws-athena-query-federation by awslabs.

the class JdbcRecordHandlerTest method setup.

@Before
public void setup() throws SQLException {
    this.connection = Mockito.mock(Connection.class, Mockito.RETURNS_DEEP_STUBS);
    this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class);
    Mockito.when(this.jdbcConnectionFactory.getConnection(Mockito.any(JdbcCredentialProvider.class))).thenReturn(this.connection);
    this.amazonS3 = Mockito.mock(AmazonS3.class);
    this.secretsManager = Mockito.mock(AWSSecretsManager.class);
    this.athena = Mockito.mock(AmazonAthena.class);
    this.queryStatusChecker = Mockito.mock(QueryStatusChecker.class);
    Mockito.when(this.secretsManager.getSecretValue(Mockito.eq(new GetSecretValueRequest().withSecretId("testSecret")))).thenReturn(new GetSecretValueResult().withSecretString("{\"username\": \"testUser\", \"password\": \"testPassword\"}"));
    this.preparedStatement = Mockito.mock(PreparedStatement.class);
    Mockito.when(this.connection.prepareStatement("someSql")).thenReturn(this.preparedStatement);
    DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", "fakedatabase", "fakedatabase://jdbc:fakedatabase://hostname/${testSecret}", "testSecret");
    this.jdbcRecordHandler = new JdbcRecordHandler(this.amazonS3, this.secretsManager, this.athena, databaseConnectionConfig, this.jdbcConnectionFactory) {

        @Override
        public PreparedStatement buildSplitSql(Connection jdbcConnection, String catalogName, TableName tableName, Schema schema, Constraints constraints, Split split) throws SQLException {
            return jdbcConnection.prepareStatement("someSql");
        }
    };
    this.federatedIdentity = Mockito.mock(FederatedIdentity.class);
}
Also used : JdbcConnectionFactory(com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory) AmazonS3(com.amazonaws.services.s3.AmazonS3) SQLException(java.sql.SQLException) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) Schema(org.apache.arrow.vector.types.pojo.Schema) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DatabaseConnectionConfig(com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) Constraints(com.amazonaws.athena.connector.lambda.domain.predicate.Constraints) QueryStatusChecker(com.amazonaws.athena.connector.lambda.QueryStatusChecker) FederatedIdentity(com.amazonaws.athena.connector.lambda.security.FederatedIdentity) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) JdbcCredentialProvider(com.amazonaws.athena.connectors.jdbc.connection.JdbcCredentialProvider) Split(com.amazonaws.athena.connector.lambda.domain.Split) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) Before(org.junit.Before)

Aggregations

DatabaseConnectionConfig (com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig)62 JdbcConnectionFactory (com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory)44 AmazonAthena (com.amazonaws.services.athena.AmazonAthena)43 AWSSecretsManager (com.amazonaws.services.secretsmanager.AWSSecretsManager)43 Before (org.junit.Before)43 QueryStatusChecker (com.amazonaws.athena.connector.lambda.QueryStatusChecker)30 AmazonS3 (com.amazonaws.services.s3.AmazonS3)28 Test (org.junit.Test)16 JdbcCredentialProvider (com.amazonaws.athena.connectors.jdbc.connection.JdbcCredentialProvider)15 Connection (java.sql.Connection)15 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)14 JDBCUtil (com.amazonaws.athena.connectors.jdbc.manager.JDBCUtil)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 HashMap (java.util.HashMap)6 GetSecretValueRequest (com.amazonaws.services.secretsmanager.model.GetSecretValueRequest)5 GetSecretValueResult (com.amazonaws.services.secretsmanager.model.GetSecretValueResult)5 JdbcMetadataHandler (com.amazonaws.athena.connectors.jdbc.manager.JdbcMetadataHandler)4 JdbcRecordHandler (com.amazonaws.athena.connectors.jdbc.manager.JdbcRecordHandler)4 SQLException (java.sql.SQLException)4 FederatedIdentity (com.amazonaws.athena.connector.lambda.security.FederatedIdentity)2