Search in sources :

Example 1 with ListSchemasRequest

use of com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest in project aws-athena-query-federation by awslabs.

the class CompositeHandlerTest method doListSchemaNames.

@Test
public void doListSchemaNames() throws Exception {
    ListSchemasRequest req = mock(ListSchemasRequest.class);
    when(req.getRequestType()).thenReturn(MetadataRequestType.LIST_SCHEMAS);
    compositeHandler.handleRequest(allocator, req, new ByteArrayOutputStream(), objectMapper);
    verify(mockMetadataHandler, times(1)).doListSchemaNames(any(BlockAllocatorImpl.class), any(ListSchemasRequest.class));
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with ListSchemasRequest

use of com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest in project aws-athena-query-federation by awslabs.

the class GlueMetadataHandlerTest method doListSchemaNames.

@Test
public void doListSchemaNames() throws Exception {
    List<Database> databases = new ArrayList<>();
    databases.add(new Database().withName("db1"));
    databases.add(new Database().withName("db2"));
    when(mockGlue.getDatabases(any(GetDatabasesRequest.class))).thenAnswer((InvocationOnMock invocationOnMock) -> {
        GetDatabasesRequest request = (GetDatabasesRequest) invocationOnMock.getArguments()[0];
        assertEquals(accountId, request.getCatalogId());
        GetDatabasesResult mockResult = mock(GetDatabasesResult.class);
        if (request.getNextToken() == null) {
            when(mockResult.getDatabaseList()).thenReturn(databases);
            when(mockResult.getNextToken()).thenReturn("next");
        } else {
            // only return real info on 1st call
            when(mockResult.getDatabaseList()).thenReturn(new ArrayList<>());
            when(mockResult.getNextToken()).thenReturn(null);
        }
        return mockResult;
    });
    ListSchemasRequest req = new ListSchemasRequest(IdentityUtil.fakeIdentity(), queryId, catalog);
    ListSchemasResponse res = handler.doListSchemaNames(allocator, req);
    logger.info("doListSchemas - {}", res.getSchemas());
    assertEquals(databases.stream().map(next -> next.getName()).collect(Collectors.toList()), new ArrayList<>(res.getSchemas()));
    verify(mockGlue, times(2)).getDatabases(any(GetDatabasesRequest.class));
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Database(com.amazonaws.services.glue.model.Database) ArrayList(java.util.ArrayList) GetDatabasesResult(com.amazonaws.services.glue.model.GetDatabasesResult) GetDatabasesRequest(com.amazonaws.services.glue.model.GetDatabasesRequest) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) Test(org.junit.Test)

Example 3 with ListSchemasRequest

use of com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest in project aws-athena-query-federation by awslabs.

the class ExampleMetadataHandlerTest method doListSchemas.

@Test
public void doListSchemas() {
    logger.info("doListSchemas - enter");
    ListSchemasRequest req = new ListSchemasRequest(IdentityUtil.fakeIdentity(), "queryId", "default");
    ObjectMapperUtil.assertSerialization(req);
    ListSchemasResponse res = metadataHandler.doListSchemaNames(allocator, req);
    ObjectMapperUtil.assertSerialization(res);
    logger.info("doListSchemas - {}", res.getSchemas());
    assertFalse(res.getSchemas().isEmpty());
    logger.info("doListSchemas - exit");
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) Test(org.junit.Test)

Example 4 with ListSchemasRequest

use of com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest in project aws-athena-query-federation by awslabs.

the class HbaseMetadataHandlerTest method doListSchemaNames.

@Test
public void doListSchemaNames() throws IOException {
    NamespaceDescriptor[] schemaNames = { NamespaceDescriptor.create("schema1").build(), NamespaceDescriptor.create("schema2").build(), NamespaceDescriptor.create("schema3").build() };
    when(mockClient.listNamespaceDescriptors()).thenReturn(schemaNames);
    ListSchemasRequest req = new ListSchemasRequest(IDENTITY, QUERY_ID, DEFAULT_CATALOG);
    ListSchemasResponse res = handler.doListSchemaNames(allocator, req);
    logger.info("doListSchemas - {}", res.getSchemas());
    Set<String> expectedSchemaName = new HashSet<>();
    expectedSchemaName.add("schema1");
    expectedSchemaName.add("schema2");
    expectedSchemaName.add("schema3");
    assertEquals(expectedSchemaName, new HashSet<>(res.getSchemas()));
    logger.info("doListSchemaNames: exit");
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ListSchemasRequest

use of com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest in project aws-athena-query-federation by awslabs.

the class ListSchemasRequestSerDeTest method beforeTest.

@Before
public void beforeTest() throws IOException {
    expected = new ListSchemasRequest(federatedIdentity, "test-query-id", "test-catalog");
    String expectedSerDeFile = utils.getResourceOrFail("serde/v2", "ListSchemasRequest.json");
    expectedSerDeText = utils.readAllAsString(expectedSerDeFile).trim();
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) Before(org.junit.Before)

Aggregations

ListSchemasRequest (com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest)31 Test (org.junit.Test)29 ListSchemasResponse (com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse)15 ArrayList (java.util.ArrayList)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 FederationRequest (com.amazonaws.athena.connector.lambda.request.FederationRequest)2 Database (com.amazonaws.services.glue.model.Database)2 GetDatabasesResult (com.amazonaws.services.glue.model.GetDatabasesResult)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)1 TypedSerDeTest (com.amazonaws.athena.connector.lambda.serde.TypedSerDeTest)1 GetDatabasesRequest (com.amazonaws.services.glue.model.GetDatabasesRequest)1 DescribeLogGroupsRequest (com.amazonaws.services.logs.model.DescribeLogGroupsRequest)1 DescribeLogGroupsResult (com.amazonaws.services.logs.model.DescribeLogGroupsResult)1 LogGroup (com.amazonaws.services.logs.model.LogGroup)1 Database (com.amazonaws.services.timestreamwrite.model.Database)1 ListDatabasesRequest (com.amazonaws.services.timestreamwrite.model.ListDatabasesRequest)1