Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*-
* #%L
* Amazon Athena Query Federation Integ Test
* %%
* Copyright (C) 2019 - 2020 Amazon Web Services
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.amazonaws.athena.connector.integ;
import com.amazonaws.athena.connector.integ.clients.CloudFormationClient;
import com.amazonaws.athena.connector.integ.data.ConnectorVpcAttributes;
import com.amazonaws.athena.connector.integ.data.SecretsManagerCredentials;
import com.amazonaws.athena.connector.integ.data.TestConfig;
import com.amazonaws.athena.connector.integ.providers.ConnectorVpcAttributesProvider;
import com.amazonaws.athena.connector.integ.providers.SecretsManagerCredentialsProvider;
import com.amazonaws.services.athena.AmazonAthena;
import com.amazonaws.services.athena.AmazonAthenaClientBuilder;
import com.amazonaws.services.athena.model.Datum;
import com.amazonaws.services.athena.model.GetQueryExecutionRequest;
import com.amazonaws.services.athena.model.GetQueryExecutionResult;
import com.amazonaws.services.athena.model.GetQueryResultsRequest;
import com.amazonaws.services.athena.model.GetQueryResultsResult;
import com.amazonaws.services.athena.model.ListDatabasesRequest;
import com.amazonaws.services.athena.model.ListDatabasesResult;
import com.amazonaws.services.athena.model.ResultConfiguration;
import com.amazonaws.services.athena.model.Row;
import com.amazonaws.services.athena.model.StartQueryExecutionRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.services.iam.PolicyDocument;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;
/**
* The Integration-Tests base class from which all connector-specific integration test modules should subclass.
*/
public abstract class IntegrationTestBase
{
private static final Logger logger = LoggerFactory.getLogger(IntegrationTestBase.class);
private static final String TEST_CONFIG_WORK_GROUP = "athena_work_group";
private static final String TEST_CONFIG_RESULT_LOCATION = "athena_result_location";
private static final String TEST_CONFIG_USER_SETTINGS = "user_settings";
private static final String ATHENA_QUERY_QUEUED_STATE = "QUEUED";
private static final String ATHENA_QUERY_RUNNING_STATE = "RUNNING";
private static final String ATHENA_QUERY_FAILED_STATE = "FAILED";
private static final String ATHENA_QUERY_CANCELLED_STATE = "CANCELLED";
// Data for common tests
protected static final String INTEG_TEST_DATABASE_NAME = "datatypes";
protected static final String TEST_NULL_TABLE_NAME = "null_table";
protected static final String TEST_EMPTY_TABLE_NAME = "empty_table";
protected static final String TEST_DATATYPES_TABLE_NAME = "datatypes_table";
protected static final int TEST_DATATYPES_INT_VALUE = Integer.MIN_VALUE;
protected static final short TEST_DATATYPES_SHORT_VALUE = Short.MIN_VALUE;
protected static final long TEST_DATATYPES_LONG_VALUE = Long.MIN_VALUE;
protected static final String TEST_DATATYPES_VARCHAR_VALUE = "John Doe";
protected static final boolean TEST_DATATYPES_BOOLEAN_VALUE = true;
protected static final float TEST_DATATYPES_SINGLE_PRECISION_VALUE = 1E-37f; // unfortunately, redshift can't handle smaller numbers
protected static final double TEST_DATATYPES_DOUBLE_PRECISION_VALUE = 1E-307; // unfortunately, redshift can't handle smaller numbers
protected static final String TEST_DATATYPES_DATE_VALUE = "2013-06-01";
protected static final String TEST_DATATYPES_TIMESTAMP_VALUE = "2016-06-22T19:10:25";
protected static final byte[] TEST_DATATYPES_BYTE_ARRAY_VALUE = new byte[] {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF};
protected static final String TEST_DATATYPES_VARCHAR_ARRAY_VALUE = "[(408)-589-5846, (408)-589-5555]";
private static final long sleepTimeMillis = 5000L;
private final ConnectorStackProvider connectorStackProvider;
private final String lambdaFunctionName;
private final AmazonAthena athenaClient;
private final TestConfig testConfig;
private final Optional vpcAttributes;
private final Optional secretCredentials;
private final String athenaWorkgroup;
private final String athenaResultLocation;
private CloudFormationClient cloudFormationClient;
public IntegrationTestBase()
{
testConfig = new TestConfig();
vpcAttributes = ConnectorVpcAttributesProvider.getAttributes(testConfig);
secretCredentials = SecretsManagerCredentialsProvider.getCredentials(testConfig);
connectorStackProvider = new ConnectorStackProvider(this.getClass().getSimpleName(), testConfig) {
@Override
protected Optional getAccessPolicy()
{
return getConnectorAccessPolicy();
}
@Override
protected void setEnvironmentVars(final Map environmentVars)
{
setConnectorEnvironmentVars(environmentVars);
}
@Override
protected void setSpecificResource(final Stack stack)
{
setUpStackData(stack);
}
};
lambdaFunctionName = connectorStackProvider.getLambdaFunctionName();
athenaClient = AmazonAthenaClientBuilder.defaultClient();
athenaWorkgroup = getAthenaWorkgroup();
athenaResultLocation = getAthenaResultLocation();
}
/**
* Gets the athena_work_group from the test-config.json JSON file.
* @return A String containing the name of the workgroup.
* @throws RuntimeException The athena_work_group is missing from test-config.json, or its value is empty.
*/
private String getAthenaWorkgroup()
throws RuntimeException
{
String athenaWorkgroup = testConfig.getStringItem(TEST_CONFIG_WORK_GROUP).orElseThrow(() ->
new RuntimeException(TEST_CONFIG_WORK_GROUP + " must be specified in test-config.json."));
logger.info("Athena Workgroup: {}", athenaWorkgroup);
return athenaWorkgroup;
}
private String getAthenaResultLocation()
throws RuntimeException
{
String athenaResultLocation = "s3://" + testConfig.getStringItem(TEST_CONFIG_RESULT_LOCATION).orElseThrow(() ->
new RuntimeException(TEST_CONFIG_RESULT_LOCATION + " must be specified in test-config.json."));
logger.info("Athena Result Location: {}", athenaResultLocation);
return athenaResultLocation;
}
/**
* Public accessor for the framework generate lambda function name used in generating the lambda function.
* @return The name of the lambda function.
*/
public String getLambdaFunctionName()
{
return lambdaFunctionName;
}
/**
* Public accessor for the VPC attributes used in generating the lambda function.
* @return Optional VPC attributes object.
*/
public Optional getVpcAttributes()
{
return vpcAttributes;
}
/**
* Public accessor for the user_settings attribute (stored in the test-config.json file) that are customizable to
* any user-specific purpose.
* @return Optional Map(String, Object) containing all the user attributes as defined in the test configuration file,
* or an empty Optional if the user_settings attribute does not exist in the file.
*/
public Optional