├── .gitignore ├── .idea └── codeStyleSettings.xml ├── .travis.yml ├── LICENSE ├── README.md ├── apache_license_header.txt ├── build.gradle ├── expected-result-generator ├── build.gradle ├── config │ └── pg_db.properties.example ├── log4j.properties ├── readme.md └── src │ ├── main │ └── java │ │ └── com │ │ └── teradata │ │ └── tempto │ │ └── sql │ │ ├── JdbcConnection.java │ │ └── SqlResultGenerator.java │ └── python │ └── generate_results.py ├── gradle.properties.example ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── tempto-core ├── build.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── teradata │ │ │ └── tempto │ │ │ ├── AfterTestWithContext.java │ │ │ ├── BeforeTestWithContext.java │ │ │ ├── CompositeRequirement.java │ │ │ ├── ProductTest.java │ │ │ ├── Requirement.java │ │ │ ├── Requirements.java │ │ │ ├── RequirementsProvider.java │ │ │ ├── Requires.java │ │ │ ├── assertions │ │ │ ├── ColumnValuesAssert.java │ │ │ └── QueryAssert.java │ │ │ ├── configuration │ │ │ ├── Configuration.java │ │ │ └── KeyUtils.java │ │ │ ├── context │ │ │ ├── ContextDsl.java │ │ │ ├── ContextProvider.java │ │ │ ├── ContextRunnable.java │ │ │ ├── State.java │ │ │ ├── TestContext.java │ │ │ ├── TestContextCloseCallback.java │ │ │ ├── TestContextDsl.java │ │ │ └── ThreadLocalTestContextHolder.java │ │ │ ├── dns │ │ │ ├── MapBasedNameService.java │ │ │ └── TemptoNameServiceDescriptor.java │ │ │ ├── fulfillment │ │ │ ├── RequirementFulfiller.java │ │ │ ├── TestStatus.java │ │ │ └── table │ │ │ │ ├── ImmutableTableRequirement.java │ │ │ │ ├── ImmutableTablesState.java │ │ │ │ ├── MutableTableRequirement.java │ │ │ │ ├── MutableTablesState.java │ │ │ │ ├── ReadOnlyTableManager.java │ │ │ │ ├── TableDefinition.java │ │ │ │ ├── TableDefinitionsRepository.java │ │ │ │ ├── TableHandle.java │ │ │ │ ├── TableInstance.java │ │ │ │ ├── TableManager.java │ │ │ │ ├── TableManagerDispatcher.java │ │ │ │ ├── TableRequirement.java │ │ │ │ ├── TableRequirements.java │ │ │ │ ├── TablesState.java │ │ │ │ ├── hive │ │ │ │ ├── HiveDataSource.java │ │ │ │ ├── HiveTableDefinition.java │ │ │ │ ├── InlineDataSource.java │ │ │ │ └── tpch │ │ │ │ │ ├── TpchDataSource.java │ │ │ │ │ ├── TpchTable.java │ │ │ │ │ └── TpchTableDefinitions.java │ │ │ │ └── jdbc │ │ │ │ ├── JdbcTableDataSource.java │ │ │ │ └── JdbcTableDefinition.java │ │ │ ├── hadoop │ │ │ └── hdfs │ │ │ │ └── HdfsClient.java │ │ │ ├── initialization │ │ │ ├── AutoModuleProvider.java │ │ │ ├── SuiteModuleProvider.java │ │ │ └── TestMethodModuleProvider.java │ │ │ ├── internal │ │ │ ├── DataProviders.java │ │ │ ├── DefaultRequirementsCollector.java │ │ │ ├── ReflectionHelper.java │ │ │ ├── ReflectionInjectorHelper.java │ │ │ ├── RequirementFulfillerByPriorityComparator.java │ │ │ ├── RequirementFulfillerPriorityHelper.java │ │ │ ├── RequirementsCollector.java │ │ │ ├── TestSpecificRequirementsResolver.java │ │ │ ├── configuration │ │ │ │ ├── AbstractConfiguration.java │ │ │ │ ├── ConfigurationVariableResolver.java │ │ │ │ ├── DelegateConfiguration.java │ │ │ │ ├── EmptyConfiguration.java │ │ │ │ ├── HierarchicalConfiguration.java │ │ │ │ ├── MapConfiguration.java │ │ │ │ ├── TestConfigurationFactory.java │ │ │ │ ├── TestConfigurationModuleProvider.java │ │ │ │ └── YamlConfiguration.java │ │ │ ├── context │ │ │ │ ├── GuiceTestContext.java │ │ │ │ └── TestContextStack.java │ │ │ ├── convention │ │ │ │ ├── AnnotatedFileParser.java │ │ │ │ ├── ConventionBasedTest.java │ │ │ │ ├── ConventionBasedTestFactory.java │ │ │ │ ├── ConventionBasedTestProxyGenerator.java │ │ │ │ ├── ConventionRequirements.java │ │ │ │ ├── ConventionTestsUtils.java │ │ │ │ ├── MutableTableDescriptor.java │ │ │ │ ├── ProcessUtils.java │ │ │ │ ├── SqlDescriptor.java │ │ │ │ ├── SqlQueryDescriptor.java │ │ │ │ ├── SqlResultDescriptor.java │ │ │ │ ├── SqlTestsFileUtils.java │ │ │ │ ├── generator │ │ │ │ │ └── GeneratorPathTestFactory.java │ │ │ │ ├── recursion │ │ │ │ │ └── RecursionPathTestFactory.java │ │ │ │ ├── sql │ │ │ │ │ ├── SqlPathTestFactory.java │ │ │ │ │ └── SqlQueryConventionBasedTest.java │ │ │ │ └── tabledefinitions │ │ │ │ │ ├── ConventionTableDefinitionDescriptor.java │ │ │ │ │ ├── ConventionTableDefinitionsProvider.java │ │ │ │ │ ├── FileBasedHiveDataSource.java │ │ │ │ │ ├── FileBasedJdbcDataSource.java │ │ │ │ │ ├── JdbcDataFileDescriptor.java │ │ │ │ │ └── TableType.java │ │ │ ├── fulfillment │ │ │ │ └── table │ │ │ │ │ ├── AbstractTableManager.java │ │ │ │ │ ├── DefaultTableManagerDispatcher.java │ │ │ │ │ ├── ImmutableTablesFulfiller.java │ │ │ │ │ ├── MutableTablesFulfiller.java │ │ │ │ │ ├── TableManagerDispatcherModuleProvider.java │ │ │ │ │ ├── TableName.java │ │ │ │ │ ├── TableNameGenerator.java │ │ │ │ │ ├── TableRequirementFulfiller.java │ │ │ │ │ ├── hive │ │ │ │ │ ├── HiveTableInstance.java │ │ │ │ │ ├── HiveTableManager.java │ │ │ │ │ └── tpch │ │ │ │ │ │ └── TpchEntityByteSource.java │ │ │ │ │ └── jdbc │ │ │ │ │ ├── BatchLoader.java │ │ │ │ │ ├── InsertLoader.java │ │ │ │ │ ├── JdbcTableInstance.java │ │ │ │ │ ├── JdbcTableManager.java │ │ │ │ │ ├── Loader.java │ │ │ │ │ └── LoaderFactory.java │ │ │ ├── hadoop │ │ │ │ └── hdfs │ │ │ │ │ ├── DefaultHdfsDataSourceWriter.java │ │ │ │ │ ├── HdfsDataSourceWriter.java │ │ │ │ │ ├── HdfsModuleProvider.java │ │ │ │ │ ├── HttpRequestsExecutor.java │ │ │ │ │ ├── SimpleHttpRequestsExecutor.java │ │ │ │ │ ├── SpnegoHttpRequestsExecutor.java │ │ │ │ │ ├── WebHdfsClient.java │ │ │ │ │ └── revisions │ │ │ │ │ ├── RevisionStorage.java │ │ │ │ │ ├── RevisionStorageFile.java │ │ │ │ │ ├── RevisionStorageProvider.java │ │ │ │ │ └── RevisionStorageXAttr.java │ │ │ ├── initialization │ │ │ │ ├── DelegateTestNGMethod.java │ │ │ │ ├── RequirementsAwareTestNGMethod.java │ │ │ │ ├── RequirementsExpanderInterceptor.java │ │ │ │ ├── TestInitializationListener.java │ │ │ │ └── modules │ │ │ │ │ └── TestMethodInfoModuleProvider.java │ │ │ ├── listeners │ │ │ │ ├── ProductTestAnnotationTransformer.java │ │ │ │ ├── ProgressLoggingListener.java │ │ │ │ ├── TestMetadata.java │ │ │ │ ├── TestMetadataReader.java │ │ │ │ └── TestNameGroupNameMethodSelector.java │ │ │ ├── logging │ │ │ │ └── LoggingMdcHelper.java │ │ │ ├── process │ │ │ │ └── CliProcessBase.java │ │ │ ├── query │ │ │ │ ├── JdbcConnectionsConfiguration.java │ │ │ │ ├── JdbcUtils.java │ │ │ │ ├── KerberosJdbcDataSource.java │ │ │ │ ├── NonPoolingJdbcDataSource.java │ │ │ │ ├── QueryExecutorModuleProvider.java │ │ │ │ ├── QueryResultValueComparator.java │ │ │ │ └── QueryRowMapper.java │ │ │ └── ssh │ │ │ │ ├── JSchCliProcess.java │ │ │ │ ├── JSchSshClient.java │ │ │ │ ├── JschSshClientFactory.java │ │ │ │ └── SshClientModuleProvider.java │ │ │ ├── kerberos │ │ │ └── KerberosAuthentication.java │ │ │ ├── process │ │ │ ├── CliProcess.java │ │ │ ├── CommandExecutionException.java │ │ │ ├── JavaProcessLauncher.java │ │ │ ├── LocalCliProcess.java │ │ │ └── TimeoutRuntimeException.java │ │ │ ├── query │ │ │ ├── JdbcConnectionsPool.java │ │ │ ├── JdbcConnectivityParamsState.java │ │ │ ├── JdbcQueryExecutor.java │ │ │ ├── QueryExecutionException.java │ │ │ ├── QueryExecutor.java │ │ │ ├── QueryExecutorDispatcher.java │ │ │ ├── QueryResult.java │ │ │ └── QueryType.java │ │ │ ├── sql │ │ │ ├── SqlContexts.java │ │ │ └── view │ │ │ │ ├── View.java │ │ │ │ └── ViewContextProvider.java │ │ │ ├── ssh │ │ │ ├── SshClient.java │ │ │ └── SshClientFactory.java │ │ │ ├── testmarkers │ │ │ ├── WithName.java │ │ │ └── WithTestGroups.java │ │ │ ├── threads │ │ │ ├── IndexedRunnable.java │ │ │ ├── ParallelExecution.java │ │ │ └── ParallelExecutionException.java │ │ │ └── util │ │ │ └── DateTimeUtils.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── sun.net.spi.nameservice.NameServiceDescriptor │ └── test │ ├── groovy │ └── com │ │ └── teradata │ │ └── tempto │ │ ├── assertions │ │ └── QueryAssertTest.groovy │ │ ├── convention │ │ └── SqlResultDescriptorTest.groovy │ │ ├── fulfillment │ │ └── table │ │ │ ├── JdbcTableManagerTest.groovy │ │ │ ├── TableDefinitionsRepositoryTest.groovy │ │ │ ├── TableHandleTest.groovy │ │ │ └── TablesStateTest.groovy │ │ ├── internal │ │ ├── DataProvidersTest.groovy │ │ ├── DummyTestRequirement.groovy │ │ ├── ReflectionInjectorHelperTest.groovy │ │ ├── RequirementsCollectorTest.groovy │ │ ├── configuration │ │ │ ├── AbstractConfigurationTest.groovy │ │ │ ├── ConfigurationVariableResolverTest.groovy │ │ │ ├── HierarchicalConfigurationTest.groovy │ │ │ ├── KeyUtilsTest.groovy │ │ │ ├── MapConfigurationTest.groovy │ │ │ ├── TestConfigurationFactoryTest.groovy │ │ │ └── YamlConfigurationTest.groovy │ │ ├── context │ │ │ ├── GuiceTestContextTest.groovy │ │ │ └── ThreadLocalTestContextHolderTest.groovy │ │ ├── convention │ │ │ ├── AnnotatedFileParserTest.groovy │ │ │ ├── ConventionBasedTestProxyGeneratorTest.groovy │ │ │ ├── SqlQueryDescriptorTest.groovy │ │ │ └── sql │ │ │ │ └── SqlPathTestFactoryTest.groovy │ │ ├── fulfillment │ │ │ ├── hive │ │ │ │ └── HiveTableManagerTest.groovy │ │ │ └── table │ │ │ │ ├── DefaultTableManagerDispatcherTest.groovy │ │ │ │ └── TableRequirementFulfillerTest.groovy │ │ ├── initialization │ │ │ └── TestInitializationListenerTest.groovy │ │ ├── query │ │ │ ├── JdbcConnectionsConfigurationTest.groovy │ │ │ ├── JdbcQueryExecutorTest.groovy │ │ │ ├── QueryResultValueComparatorTest.groovy │ │ │ └── QueryRowMapperTest.groovy │ │ └── ssh │ │ │ ├── JSchSshClientTest.groovy │ │ │ └── TestCommand.groovy │ │ ├── process │ │ ├── JavaProcessLauncherTest.groovy │ │ └── TestClassWithMain.groovy │ │ ├── query │ │ └── QueryResultTest.groovy │ │ ├── runner │ │ └── TestNameGroupNameMethodSelectorTest.groovy │ │ ├── sql │ │ └── view │ │ │ └── ContextDslTest.groovy │ │ ├── threads │ │ └── ParallelExecutionTest.groovy │ │ └── util │ │ └── DateTimeUtilsTest.java │ └── resources │ ├── configuration │ ├── global-configuration-tempto.yaml │ └── local-configuration-tempto.yaml │ ├── convention │ └── sample-test │ │ ├── query1.result │ │ └── query1.sql │ ├── log4j.properties │ └── ssh │ ├── ssh.pem │ └── ssh.pub ├── tempto-examples ├── README.md ├── bin │ └── run_on_docker.sh ├── build.gradle ├── docker │ ├── docker-compose.yml │ ├── presto-cli │ │ └── Dockerfile │ ├── presto-server │ │ ├── Dockerfile │ │ └── etc │ │ │ ├── catalog │ │ │ ├── blackhole.properties │ │ │ ├── hive.properties │ │ │ ├── jmx.properties │ │ │ ├── psql.properties │ │ │ ├── psql2.properties │ │ │ └── tpch.properties │ │ │ ├── config.properties │ │ │ ├── jvm.config │ │ │ └── log.properties │ ├── ssh │ │ ├── Dockerfile │ │ └── keys │ │ │ ├── key │ │ │ └── key.pub │ ├── tempto-configuration-docker-local.yaml │ └── tempto-configuration-local.yaml └── src │ └── main │ ├── java │ └── com │ │ └── teradata │ │ └── tempto │ │ └── examples │ │ ├── ExampleQueryAssertTest.java │ │ ├── ExampleSshClientUsage.java │ │ ├── HostNameMappingTest.java │ │ ├── InjectionTest.java │ │ ├── PostgresqlQueryTest.java │ │ ├── SimpleQueryTest.java │ │ ├── TemptoExamples.java │ │ └── TpchDataSourceTest.java │ └── resources │ ├── log4j.properties │ ├── sql-tests │ ├── datasets │ │ ├── no_data_jdbc_table.ddl │ │ ├── sample_hive_table.data │ │ ├── sample_hive_table.data-revision │ │ ├── sample_hive_table.ddl │ │ ├── sample_jdbc_table.data │ │ ├── sample_jdbc_table.data-revision │ │ └── sample_jdbc_table.ddl │ └── testcases │ │ ├── generated │ │ └── nation.generator │ │ ├── nation │ │ ├── after │ │ ├── allRows.sql │ │ └── before │ │ ├── sample_hive_table │ │ ├── allRows.result │ │ └── allRows.sql │ │ ├── sample_presto_table │ │ ├── allRows.sql │ │ ├── in-memory.sql │ │ ├── psqlOverPrestoAllRows.result │ │ └── psqlOverPrestoAllRows.sql │ │ ├── sample_psql_table │ │ ├── allRows.result │ │ ├── allRows.sql │ │ ├── allRowsOnPsql2.result │ │ ├── allRowsOnPsql2.sql │ │ └── noData.sql │ │ └── sample_table_insert │ │ └── insert.sql │ ├── tempto-configuration-invalid-ssh-and-psql.yaml │ ├── tempto-configuration-no-db.yaml │ ├── tempto-configuration-read-only.yaml │ └── tempto-configuration.yaml ├── tempto-ldap ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── teradata │ └── tempto │ ├── fulfillment │ └── ldap │ │ ├── LdapObjectDefinition.java │ │ ├── LdapObjectRequirement.java │ │ └── OpenLdapObjectDefinitions.java │ └── internal │ └── fulfillment │ └── ldap │ ├── DefaultLdapObjectEntryManager.java │ ├── LdapObjectEntryManager.java │ ├── LdapObjectFulfiller.java │ └── LdapObjectModuleProvider.java ├── tempto-logging-log4j ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── teradata │ │ └── logging │ │ └── TestFrameworkLoggingAppender.java │ └── resources │ └── log4j.properties-sample └── tempto-runner ├── build.gradle └── src └── main └── java └── com └── teradata └── tempto └── runner ├── TemptoRunner.java ├── TemptoRunnerCommandLineParser.java └── TemptoRunnerOptions.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Build files 2 | .gradle/ 3 | gradle.properties 4 | build/ 5 | 6 | # Ignore IntelliJ files 7 | .idea/ 8 | out/ 9 | *.iml 10 | *.eml 11 | 12 | *.pyc 13 | 14 | # vi temp files 15 | [._]*.s[a-w][a-z] 16 | [._]s[a-w][a-z] 17 | 18 | # tests logging output 19 | tempto_logs 20 | 21 | # python packaging artifacts 22 | dist/ 23 | 24 | # etc 25 | *.log 26 | *.orig 27 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | sudo: required 7 | dist: trusty 8 | 9 | services: 10 | - docker 11 | 12 | before_install: 13 | # This section can be removed once travis get equipped with docker 1.10 and docker-compose 1.6 14 | - | 15 | sudo apt-get update 16 | sudo apt-get -o "Dpkg::Options::=--force-confold" -y install docker-engine 17 | sudo rm /usr/local/bin/docker-compose 18 | curl -L https://github.com/docker/compose/releases/download/1.6.2/docker-compose-`uname -s`-`uname -m` > docker-compose 19 | chmod +x docker-compose 20 | sudo mv docker-compose /usr/local/bin 21 | 22 | install: ./gradlew build -x test 23 | 24 | script: 25 | - ./gradlew test 26 | - ./tempto-examples/bin/run_on_docker.sh -x failing 27 | - ./tempto-examples/bin/run_on_docker.sh --config tempto-configuration-read-only.yaml -g in_memory 28 | - ./tempto-examples/bin/run_on_docker.sh --config tempto-configuration-no-db.yaml -g ssh 29 | - ./tempto-examples/bin/run_on_docker.sh --config tempto-configuration-invalid-ssh-and-psql.yaml -g in_memory 30 | -------------------------------------------------------------------------------- /apache_license_header.txt: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 (the "License"); 2 | you may not use this file except in compliance with the License. 3 | You may obtain a copy of the License at 4 | 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | -------------------------------------------------------------------------------- /expected-result-generator/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | apply plugin: "java" 16 | import org.apache.tools.ant.filters.ReplaceTokens 17 | 18 | dependencies { 19 | compile libraries.commons_cli 20 | compile libraries.slf4j_api 21 | compile libraries.slf4j_log4j 22 | compile libraries.postgresql_jdbc 23 | } 24 | 25 | task wrapperScript(type: Copy, dependsOn: build) { 26 | from 'src/python/generate_results.py' 27 | into 'build' 28 | filter(ReplaceTokens, tokens: [version: tempto_version]) 29 | } 30 | 31 | task buildRunnableJar(type: Jar, dependsOn: wrapperScript) { 32 | appendix = "all" 33 | from sourceSets.main.output 34 | from { configurations.testRuntime.collect { it.isDirectory() ? it : zipTree(it) } } 35 | } 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /expected-result-generator/config/pg_db.properties.example: -------------------------------------------------------------------------------- 1 | # 2 | # This file provides the information that is needed to connect to the database. 3 | # 4 | 5 | # Database user name 6 | user=my_name 7 | 8 | #Database password 9 | password=my_pass 10 | 11 | # JDBC connection string 12 | jdbc_url=jdbc:postgresql://my-server.my-domain.com:5432/my-database 13 | 14 | # Max time allowed for executing one query, in seconds 15 | timeout=600 16 | -------------------------------------------------------------------------------- /expected-result-generator/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | # 14 | 15 | log4j.rootLogger=INFO, CONSOLE, FILE 16 | 17 | # file based appender 18 | log4j.appender.FILE=org.apache.log4j.FileAppender 19 | log4j.appender.FILE.File=../build/SqlTest.log 20 | log4j.appender.FILE.layout=org.apache.log4j.PatternLayout 21 | log4j.appender.FILE.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n 22 | 23 | # console based appender 24 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 25 | log4j.appender.CONSOLE.target=System.err 26 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 27 | log4j.appender.CONSOLE.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n 28 | log4j.appender.CONSOLE.encoding=UTF-8 29 | 30 | #log4j.logger.com.teradata.tempto.sql.JdbcConnection=WARN 31 | 32 | -------------------------------------------------------------------------------- /gradle.properties.example: -------------------------------------------------------------------------------- 1 | #skipSigning=false 2 | #signing.keyId=KEYID 3 | #signing.password=KEY_PASSWORD 4 | #signing.secretKeyRingFile=KEY_PATH 5 | 6 | #nexusUsername=SONATYPE_LOGIN 7 | #nexusPassword=SONATYPE_PASSWORD 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teradata/tempto/28d4d5fdc83b0fc4e03562c7d6a8926df510860b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | # 14 | 15 | #Wed Mar 18 11:08:11 CET 2015 16 | distributionBase=GRADLE_USER_HOME 17 | distributionPath=wrapper/dists 18 | zipStoreBase=GRADLE_USER_HOME 19 | zipStorePath=wrapper/dists 20 | distributionUrl=http://services.gradle.org/distributions/gradle-2.3-all.zip 21 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | include 'tempto-core' 15 | include 'tempto-logging-log4j' 16 | include 'tempto-examples' 17 | include 'expected-result-generator' 18 | include 'tempto-runner' 19 | include 'tempto-ldap' 20 | -------------------------------------------------------------------------------- /tempto-core/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | apply plugin: 'java' 16 | apply plugin: 'signing' 17 | apply plugin: 'maven' 18 | apply plugin: 'groovy' 19 | 20 | dependencies { 21 | compile libraries.assertj 22 | compile libraries.guava 23 | compile libraries.guice 24 | compile libraries.testng 25 | compile libraries.commons_lang3 26 | compile libraries.commons_dbcp2 27 | compile libraries.slf4j_api 28 | compile libraries.snakeyaml 29 | compile libraries.httpclient 30 | compile libraries.ioutils 31 | compile libraries.tpchgen 32 | compile libraries.bytebuddy 33 | compile libraries.reflections 34 | compile libraries.jsch 35 | compile libraries.freemarker 36 | compile libraries.joda 37 | compile libraries.jackson_databind 38 | 39 | runtime libraries.jcl_over_slf4j 40 | 41 | testCompile libraries.spock 42 | testCompile libraries.hsqldb 43 | testCompile libraries.dbutils 44 | testCompile libraries.mina_sshd 45 | testRuntime libraries.objenesis 46 | } 47 | 48 | configurations { 49 | all*.exclude group: 'commons-logging', module: 'commons-logging' 50 | } 51 | 52 | // project information 53 | ext.artifactId = 'tempto-core' 54 | archivesBaseName = artifactId 55 | 56 | license { 57 | exclude "**/convention/sample-test/**/*.sql" 58 | } 59 | 60 | // publishing to sonatype 61 | uploadArchives { 62 | repositories { 63 | mavenDeployer { 64 | pom.project { 65 | name artifactId 66 | artifactId artifactId 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/AfterTestWithContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto; 16 | 17 | import java.lang.annotation.ElementType; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Target({ElementType.METHOD}) 24 | public @interface AfterTestWithContext 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/BeforeTestWithContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto; 16 | 17 | import java.lang.annotation.ElementType; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Target({ElementType.METHOD}) 24 | public @interface BeforeTestWithContext 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/CompositeRequirement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto; 16 | 17 | import java.util.Set; 18 | 19 | /** 20 | * Specifies a sets of requirements. 21 | */ 22 | public interface CompositeRequirement 23 | extends Requirement 24 | { 25 | Set> getRequirementsSets(); 26 | } 27 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/ProductTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto; 16 | 17 | import com.teradata.tempto.internal.initialization.RequirementsExpanderInterceptor; 18 | import com.teradata.tempto.internal.initialization.TestInitializationListener; 19 | import com.teradata.tempto.internal.listeners.ProgressLoggingListener; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | import org.testng.annotations.Listeners; 23 | 24 | @Listeners({RequirementsExpanderInterceptor.class, TestInitializationListener.class, ProgressLoggingListener.class}) 25 | public class ProductTest 26 | { 27 | protected static final Logger LOGGER = LoggerFactory.getLogger(ProductTest.class); 28 | } 29 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/Requirement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto; 16 | 17 | /** 18 | * Specifies a test requirement. 19 | *

20 | * Requirement instances must provide proper implementation of hashCode and equals methods. 21 | * This is required so we can merge repeating requirements from different tests. 22 | */ 23 | public interface Requirement 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/RequirementsProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto; 16 | 17 | import com.teradata.tempto.configuration.Configuration; 18 | 19 | @FunctionalInterface 20 | public interface RequirementsProvider 21 | { 22 | Requirement getRequirements(Configuration configuration); 23 | } 24 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/Requires.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto; 16 | 17 | import java.lang.annotation.ElementType; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Target({ElementType.METHOD, ElementType.TYPE}) 24 | public @interface Requires 25 | { 26 | Class[] value(); 27 | } 28 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/assertions/ColumnValuesAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.assertions; 16 | 17 | import org.assertj.core.api.AbstractListAssert; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * Interface used for passing lambda expression assertions into 23 | * {@link com.teradata.tempto.assertions.QueryAssert#column} 24 | */ 25 | public interface ColumnValuesAssert 26 | { 27 | void assertColumnValues(AbstractListAssert, T> columnAssert); 28 | } 29 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/configuration/KeyUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.configuration; 16 | 17 | import com.google.common.base.Joiner; 18 | import com.google.common.base.Splitter; 19 | 20 | import java.util.List; 21 | 22 | import static com.google.common.collect.Lists.newArrayList; 23 | import static java.util.Arrays.asList; 24 | 25 | public final class KeyUtils 26 | { 27 | private KeyUtils() {} 28 | 29 | private static final char KEY_SEPARATOR = '.'; 30 | private static final Splitter KEY_SPLITTER = Splitter.on(KEY_SEPARATOR); 31 | private static final Joiner KEY_JOINER = Joiner.on(KEY_SEPARATOR).skipNulls(); 32 | 33 | public static List splitKey(String key) 34 | { 35 | return newArrayList(KEY_SPLITTER.split(key)); 36 | } 37 | 38 | public static String joinKey(List keyParts) 39 | { 40 | return KEY_JOINER.join(keyParts); 41 | } 42 | 43 | public static String joinKey(String... keyParts) 44 | { 45 | return joinKey(asList(keyParts)); 46 | } 47 | 48 | public static String getKeyPrefix(String key, int prefixLen) 49 | { 50 | List keyParts = splitKey(key); 51 | if (keyParts.size() <= prefixLen) { 52 | return key; 53 | } 54 | else { 55 | return KEY_JOINER.join(keyParts.subList(0, prefixLen)); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/context/ContextDsl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.context; 16 | 17 | /** 18 | * Helper class used for execution of instances of {@link ContextRunnable} with context generated 19 | * by {@link ContextProvider#setup()} 20 | */ 21 | public final class ContextDsl 22 | { 23 | 24 | public static void executeWith(ContextProvider provider, ContextRunnable runnable) 25 | { 26 | T context = provider.setup(); 27 | try { 28 | 29 | runnable.run(context); 30 | } 31 | finally { 32 | provider.cleanup(context); 33 | } 34 | } 35 | 36 | private ContextDsl() 37 | { 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/context/ContextProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.context; 16 | 17 | /** 18 | * Provider class used for generation and cleanup of dsl defined contexts. 19 | * 20 | * @param context class 21 | */ 22 | public interface ContextProvider 23 | { 24 | /** 25 | * Method generating new context. 26 | * 27 | * @return generated context 28 | */ 29 | T setup(); 30 | 31 | /** 32 | * Method invoked after finishing {@link ContextRunnable#run} 33 | * 34 | * @param context dls defined context 35 | */ 36 | void cleanup(T context); 37 | } 38 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/context/ContextRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.context; 16 | 17 | /** 18 | * Interface for invocation of tests in dsl defined context. 19 | */ 20 | public interface ContextRunnable 21 | { 22 | /** 23 | * Method invoked in given context T 24 | * 25 | * @param context context generated by {@link ContextProvider#setup} 26 | */ 27 | void run(T context); 28 | } 29 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/context/State.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.context; 16 | 17 | import java.util.Optional; 18 | 19 | /** 20 | * Marker interface of state objects produced by fulfillers. 21 | */ 22 | public interface State 23 | { 24 | 25 | /** 26 | * Return name for state. If non-empty optional is 27 | * returned State will be bound in TestContext with name annotation. 28 | * 29 | * @return Name 30 | */ 31 | default Optional getName() { 32 | return Optional.empty(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/context/TestContextCloseCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.context; 16 | 17 | @FunctionalInterface 18 | public interface TestContextCloseCallback 19 | { 20 | void testContextClosed(TestContext testContext); 21 | } 22 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/context/TestContextDsl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.context; 15 | 16 | import com.teradata.tempto.threads.IndexedRunnable; 17 | 18 | import static com.teradata.tempto.context.ThreadLocalTestContextHolder.popTestContext; 19 | import static com.teradata.tempto.context.ThreadLocalTestContextHolder.pushTestContext; 20 | import static com.teradata.tempto.context.ThreadLocalTestContextHolder.testContext; 21 | 22 | public final class TestContextDsl 23 | { 24 | public static IndexedRunnable withChildTestContext(IndexedRunnable runnable) 25 | { 26 | return (int threadIndex) -> { 27 | pushTestContext(testContext().createChildContext()); 28 | try { 29 | runnable.run(threadIndex); 30 | } 31 | finally { 32 | popTestContext(); 33 | } 34 | }; 35 | } 36 | 37 | public static Runnable withChildTestContext(Runnable runnable) 38 | { 39 | return () -> runWithChildTestContext(runnable); 40 | } 41 | 42 | public static void runWithChildTestContext(Runnable runnable) 43 | { 44 | runWithTestContext(testContext().createChildContext(), runnable); 45 | } 46 | 47 | public static void runWithTestContext(TestContext testContext, Runnable runnable) 48 | { 49 | pushTestContext(testContext); 50 | try { 51 | runnable.run(); 52 | } 53 | finally { 54 | popTestContext(); 55 | } 56 | } 57 | 58 | private TestContextDsl() 59 | { 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/dns/MapBasedNameService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.dns; 15 | 16 | import sun.net.spi.nameservice.NameService; 17 | 18 | import java.net.InetAddress; 19 | import java.net.UnknownHostException; 20 | import java.util.Map; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | public class MapBasedNameService 25 | implements NameService 26 | { 27 | 28 | private final Map hosts; 29 | 30 | public MapBasedNameService(Map hosts) 31 | { 32 | this.hosts = requireNonNull(hosts, "hosts is null"); 33 | } 34 | 35 | @Override 36 | public InetAddress[] lookupAllHostAddr(String host) 37 | throws UnknownHostException 38 | { 39 | if (hosts.containsKey(host)) { 40 | return InetAddress.getAllByName(hosts.get(host)); 41 | } 42 | throw new UnknownHostException(); 43 | } 44 | 45 | @Override 46 | public String getHostByAddr(byte[] bytes) 47 | throws UnknownHostException 48 | { 49 | throw new UnknownHostException(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/dns/TemptoNameServiceDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.dns; 15 | 16 | import com.teradata.tempto.configuration.Configuration; 17 | import sun.net.spi.nameservice.NameService; 18 | import sun.net.spi.nameservice.NameServiceDescriptor; 19 | 20 | import java.util.Map; 21 | 22 | import static com.teradata.tempto.internal.configuration.TestConfigurationFactory.testConfiguration; 23 | 24 | public class TemptoNameServiceDescriptor 25 | implements NameServiceDescriptor 26 | { 27 | 28 | public static final String PROVIDER_NAME = "map_based"; 29 | public static final String TYPE = "dns"; 30 | 31 | public static void enableHostMapping() 32 | { 33 | System.setProperty("sun.net.spi.nameservice.provider.1", TYPE + "," + PROVIDER_NAME); 34 | System.setProperty("sun.net.spi.nameservice.provider.2", "default"); 35 | } 36 | 37 | @Override 38 | public NameService createNameService() 39 | throws Exception 40 | { 41 | Configuration configuration = testConfiguration(); 42 | Map hosts = configuration.getSubconfiguration("hosts").asMap(); 43 | return new MapBasedNameService(hosts); 44 | } 45 | 46 | @Override 47 | public String getProviderName() 48 | { 49 | return PROVIDER_NAME; 50 | } 51 | 52 | @Override 53 | public String getType() 54 | { 55 | return TYPE; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/RequirementFulfiller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment; 16 | 17 | import com.teradata.tempto.Requirement; 18 | import com.teradata.tempto.context.State; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | import java.util.Set; 25 | 26 | public interface RequirementFulfiller 27 | { 28 | 29 | int DEFAULT_PRIORITY = 0; 30 | 31 | /** 32 | * Apply annotation to fulfillers which should be evaluated at suite level. 33 | */ 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Target({ElementType.TYPE}) 36 | public @interface AutoSuiteLevelFulfiller 37 | { 38 | /** 39 | * With priority you can manage the order of fulfiller execution. 40 | * With lower priority fulfiller will {@link com.teradata.tempto.fulfillment.RequirementFulfiller#fulfill} sooner 41 | * and {@link com.teradata.tempto.fulfillment.RequirementFulfiller#cleanup(TestStatus)} later. 42 | * 43 | * @return priority level 44 | */ 45 | int priority() default DEFAULT_PRIORITY; 46 | } 47 | 48 | /** 49 | * Apply annotation to fulfillers which should be evaluated at testLevel. 50 | */ 51 | @Retention(RetentionPolicy.RUNTIME) 52 | @Target({ElementType.TYPE}) 53 | @interface AutoTestLevelFulfiller 54 | { 55 | /** 56 | * With priority you can manage the order of fulfiller execution. 57 | * With lower priority fulfiller will {@link com.teradata.tempto.fulfillment.RequirementFulfiller#fulfill} sooner 58 | * and {@link com.teradata.tempto.fulfillment.RequirementFulfiller#cleanup(TestStatus)} later. 59 | * 60 | * @return priority level 61 | */ 62 | int priority() default DEFAULT_PRIORITY; 63 | } 64 | 65 | Set fulfill(Set requirements); 66 | 67 | void cleanup(TestStatus status); 68 | } 69 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/TestStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment; 16 | 17 | public enum TestStatus 18 | { 19 | SUCCESS, FAILURE; 20 | } 21 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/ImmutableTableRequirement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table; 16 | 17 | public class ImmutableTableRequirement 18 | extends TableRequirement 19 | { 20 | 21 | public ImmutableTableRequirement(TableDefinition tableDefinition) 22 | { 23 | this(tableDefinition, tableDefinition.getTableHandle()); 24 | } 25 | 26 | public ImmutableTableRequirement(TableDefinition tableDefinition, TableHandle tableHandle) 27 | { 28 | super(tableDefinition, tableHandle); 29 | } 30 | 31 | @Override 32 | public ImmutableTableRequirement copyWithDatabase(String databaseName) 33 | { 34 | return new ImmutableTableRequirement(getTableDefinition(), getTableHandle().inDatabase(databaseName)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/ImmutableTablesState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table; 16 | 17 | import java.util.List; 18 | 19 | import static com.teradata.tempto.context.ThreadLocalTestContextHolder.testContext; 20 | 21 | public class ImmutableTablesState 22 | extends TablesState 23 | { 24 | 25 | public static ImmutableTablesState immutableTablesState() 26 | { 27 | return testContext().getDependency(ImmutableTablesState.class); 28 | } 29 | 30 | public ImmutableTablesState(List tables) 31 | { 32 | super(tables, "immutable table"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/MutableTablesState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table; 16 | 17 | import java.util.List; 18 | 19 | import static com.teradata.tempto.context.ThreadLocalTestContextHolder.testContext; 20 | 21 | public class MutableTablesState 22 | extends TablesState 23 | { 24 | 25 | public static MutableTablesState mutableTablesState() 26 | { 27 | return testContext().getDependency(MutableTablesState.class); 28 | } 29 | 30 | public MutableTablesState(List tables) 31 | { 32 | super(tables, "mutable table"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/TableDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table; 16 | 17 | import java.util.Optional; 18 | 19 | import static java.util.Objects.requireNonNull; 20 | 21 | public abstract class TableDefinition 22 | { 23 | protected final TableHandle handle; 24 | 25 | public TableDefinition(TableHandle handle) 26 | { 27 | this.handle = requireNonNull(handle, "handle is null"); 28 | } 29 | 30 | public String getName() 31 | { 32 | return handle.getName(); 33 | } 34 | 35 | public Optional getSchema() 36 | { 37 | return handle.getSchema(); 38 | } 39 | 40 | public Optional getDatabase() 41 | { 42 | return handle.getDatabase(); 43 | } 44 | 45 | public TableHandle getTableHandle() 46 | { 47 | return handle; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/TableInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.fulfillment.table; 15 | 16 | import com.teradata.tempto.internal.fulfillment.table.TableName; 17 | 18 | import java.util.Optional; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | 22 | /** 23 | * Describes a table that is instantiated during a test run. 24 | */ 25 | public class TableInstance 26 | { 27 | private final TableName name; 28 | private final T tableDefinition; 29 | 30 | protected TableInstance(TableName name, T tableDefinition) 31 | { 32 | this.name = requireNonNull(name, "name is null"); 33 | this.tableDefinition = requireNonNull(tableDefinition, "tableDefinition is null"); 34 | } 35 | 36 | public String getName() 37 | { 38 | return name.getName(); 39 | } 40 | 41 | public String getDatabase() 42 | { 43 | return name.getDatabase(); 44 | } 45 | 46 | public Optional getSchema() 47 | { 48 | return name.getSchema(); 49 | } 50 | 51 | public String getNameInDatabase() 52 | { 53 | return name.getNameInDatabase(); 54 | } 55 | 56 | public T tableDefinition() 57 | { 58 | return tableDefinition; 59 | } 60 | 61 | public TableName getTableName() 62 | { 63 | return name; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/TableManagerDispatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.fulfillment.table; 15 | 16 | import java.util.Collection; 17 | 18 | import static com.teradata.tempto.context.ThreadLocalTestContextHolder.testContext; 19 | 20 | /** 21 | * Returns an appropriate {@link TableManager} based on table type. 22 | */ 23 | public interface TableManagerDispatcher 24 | { 25 | 26 | default TableManager getTableManagerFor(TableInstance tableInstance) 27 | { 28 | return getTableManagerFor(tableInstance.tableDefinition()); 29 | } 30 | 31 | default TableManager getTableManagerFor(T tableDefinition) { 32 | return getTableManagerFor(tableDefinition, tableDefinition.getTableHandle()); 33 | } 34 | 35 | TableManager getTableManagerFor(TableDefinition tableDefinition, TableHandle tableHandle); 36 | 37 | Collection getAllTableManagers(); 38 | 39 | static TableManagerDispatcher getTableManagerDispatcher() 40 | { 41 | return testContext().getDependency(TableManagerDispatcher.class); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/TableRequirement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table; 16 | 17 | import com.teradata.tempto.Requirement; 18 | 19 | import static java.util.Objects.requireNonNull; 20 | import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals; 21 | import static org.apache.commons.lang3.builder.HashCodeBuilder.reflectionHashCode; 22 | 23 | public abstract class TableRequirement 24 | implements Requirement 25 | { 26 | 27 | private final TableDefinition tableDefinition; 28 | private final TableHandle tableHandle; 29 | 30 | protected TableRequirement(TableDefinition tableDefinition, TableHandle tableHandle) 31 | { 32 | this.tableDefinition = requireNonNull(tableDefinition, "tableDefinition is null"); 33 | this.tableHandle = requireNonNull(tableHandle, "tableHandle is null"); 34 | } 35 | 36 | public TableDefinition getTableDefinition() 37 | { 38 | return tableDefinition; 39 | } 40 | 41 | public TableHandle getTableHandle() 42 | { 43 | return tableHandle; 44 | } 45 | 46 | public abstract T copyWithDatabase(String databaseName); 47 | 48 | @Override 49 | public boolean equals(Object o) 50 | { 51 | return reflectionEquals(this, o); 52 | } 53 | 54 | @Override 55 | public int hashCode() 56 | { 57 | return reflectionHashCode(this); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/TableRequirements.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table; 16 | 17 | import java.util.Optional; 18 | 19 | public class TableRequirements 20 | { 21 | private TableRequirements() {} 22 | 23 | /** 24 | * Requirement for mutable table. 25 | * Test code is allowed to mutate (insert/delete rows) for mutable table 26 | * 27 | * @param tableDefinition Encapsulated DDL for table 28 | * @return Requirement for mutable table 29 | */ 30 | public static MutableTableRequirement mutableTable(TableDefinition tableDefinition) 31 | { 32 | return MutableTableRequirement.builder(tableDefinition).build(); 33 | } 34 | 35 | /** 36 | * Requirement for mutable table. 37 | * Test code is allowed to mutate (insert/delete rows) for mutable table 38 | * 39 | * @param tableDefinition Encapsulated DDL for table 40 | * @param name Name for table 41 | * @param state PREPARED, CREATED, or LOADED 42 | * @return Requirement for mutable table 43 | */ 44 | public static MutableTableRequirement mutableTable(TableDefinition tableDefinition, String name, MutableTableRequirement.State state) 45 | { 46 | return MutableTableRequirement.builder(tableDefinition).withName(name).withState(state).build(); 47 | } 48 | 49 | /** 50 | * Requirement for immutable table. 51 | * 52 | * @param tableDefinition Encapsulated DDL for table 53 | * @return ImmutableTableRequirement 54 | */ 55 | public static ImmutableTableRequirement immutableTable(TableDefinition tableDefinition) 56 | { 57 | return new ImmutableTableRequirement(tableDefinition); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/hive/HiveDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table.hive; 16 | 17 | import com.teradata.tempto.hadoop.hdfs.HdfsClient.RepeatableContentProducer; 18 | 19 | import java.util.Collection; 20 | 21 | /** 22 | * Responsible for providing data. 23 | */ 24 | public interface HiveDataSource 25 | { 26 | /** 27 | * @return path suffix where data source data should be stored 28 | */ 29 | String getPathSuffix(); 30 | 31 | /** 32 | * @return collection with table files {@link RepeatableContentProducer}. 33 | * For each {@link RepeatableContentProducer} separate file will be created on HDFS 34 | */ 35 | Collection data(); 36 | 37 | /** 38 | * Revision marker is used to determine if data should be regenerated. This 39 | * method should be fast. 40 | * 41 | * @return revision marker 42 | */ 43 | String revisionMarker(); 44 | } 45 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/hive/tpch/TpchDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table.hive.tpch; 16 | 17 | import com.teradata.tempto.fulfillment.table.hive.HiveDataSource; 18 | import com.teradata.tempto.hadoop.hdfs.HdfsClient.RepeatableContentProducer; 19 | import com.teradata.tempto.internal.fulfillment.table.hive.tpch.TpchEntityByteSource; 20 | 21 | import java.util.Collection; 22 | 23 | import static java.lang.String.format; 24 | import static java.util.Collections.singleton; 25 | import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals; 26 | import static org.apache.commons.lang3.builder.HashCodeBuilder.reflectionHashCode; 27 | 28 | public class TpchDataSource 29 | implements HiveDataSource 30 | { 31 | 32 | private static final String DATA_REVISION = "v.1.0"; 33 | 34 | private final TpchTable table; 35 | private final double scaleFactor; 36 | 37 | public TpchDataSource(TpchTable table, double scaleFactor) 38 | { 39 | this.table = table; 40 | this.scaleFactor = scaleFactor; 41 | } 42 | 43 | @Override 44 | public String getPathSuffix() 45 | { 46 | // {TESTS_PATH}/tpch/sf-{scaleFactor}/{tableName} 47 | return format("tpch/sf-%.2f/%s", scaleFactor, table.name()).replaceAll("\\.", "_"); 48 | } 49 | 50 | @Override 51 | public Collection data() 52 | { 53 | @SuppressWarnings("unchecked") 54 | Iterable tableDataGenerator = table.getTpchTableEntity().createGenerator(scaleFactor, 1, 1); 55 | return singleton(() -> new TpchEntityByteSource<>(tableDataGenerator).openStream()); 56 | } 57 | 58 | @Override 59 | public String revisionMarker() 60 | { 61 | return DATA_REVISION; 62 | } 63 | 64 | @Override 65 | public boolean equals(Object o) 66 | { 67 | return reflectionEquals(this, o); 68 | } 69 | 70 | @Override 71 | public int hashCode() 72 | { 73 | return reflectionHashCode(this); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/hive/tpch/TpchTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table.hive.tpch; 16 | 17 | /** 18 | * Enum containing names of all TPCH tables. Moreover it holds reference to 19 | * {@link io.airlift.tpch.TpchTable} entity which is used for generating data. 20 | */ 21 | public enum TpchTable 22 | { 23 | NATION(io.airlift.tpch.TpchTable.NATION), 24 | REGION(io.airlift.tpch.TpchTable.REGION), 25 | PART(io.airlift.tpch.TpchTable.PART), 26 | ORDERS(io.airlift.tpch.TpchTable.ORDERS), 27 | CUSTOMER(io.airlift.tpch.TpchTable.CUSTOMER), 28 | SUPPLIER(io.airlift.tpch.TpchTable.SUPPLIER), 29 | LINE_ITEM(io.airlift.tpch.TpchTable.LINE_ITEM), 30 | PART_SUPPLIER(io.airlift.tpch.TpchTable.PART_SUPPLIER); 31 | 32 | private final io.airlift.tpch.TpchTable airliftTpchTableEntity; 33 | 34 | TpchTable(io.airlift.tpch.TpchTable airliftTpchTableEntity) 35 | { 36 | this.airliftTpchTableEntity = airliftTpchTableEntity; 37 | } 38 | 39 | public io.airlift.tpch.TpchTable getTpchTableEntity() 40 | { 41 | return airliftTpchTableEntity; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/fulfillment/table/jdbc/JdbcTableDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table.jdbc; 16 | 17 | import java.sql.PreparedStatement; 18 | import java.util.Iterator; 19 | import java.util.List; 20 | 21 | public interface JdbcTableDataSource 22 | { 23 | /** 24 | * Returns iterator over rows to be inserted to table. 25 | * Object types must match column types in table. 26 | * Object will be inserted using {@link PreparedStatement#setObject(int, Object)} method. 27 | * 28 | * @return iterator over rows to be inserted to table 29 | */ 30 | Iterator> getDataRows(); 31 | } 32 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/initialization/AutoModuleProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.initialization; 15 | 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * {@link SuiteModuleProvider}s and {@link TestMethodModuleProvider}s 23 | * annotated with this annotation will be automatically class scanned for. 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ElementType.TYPE}) 27 | public @interface AutoModuleProvider 28 | { 29 | } 30 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/initialization/SuiteModuleProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.initialization; 15 | 16 | import com.google.inject.Module; 17 | import com.teradata.tempto.configuration.Configuration; 18 | 19 | /** 20 | * Classes implementing this interface provide {@link Module}s 21 | * at suite level. 22 | */ 23 | @FunctionalInterface 24 | public interface SuiteModuleProvider 25 | { 26 | Module getModule(Configuration configuration); 27 | } 28 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/initialization/TestMethodModuleProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.initialization; 15 | 16 | import com.google.inject.Module; 17 | import com.teradata.tempto.configuration.Configuration; 18 | import org.testng.ITestResult; 19 | 20 | /** 21 | * Classes implementing this interface provide {@link Module}s 22 | * at test method level. 23 | */ 24 | @FunctionalInterface 25 | public interface TestMethodModuleProvider 26 | { 27 | Module getModule(Configuration configuration, ITestResult testResult); 28 | } 29 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/RequirementFulfillerByPriorityComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal; 16 | 17 | import com.teradata.tempto.fulfillment.RequirementFulfiller; 18 | 19 | import java.util.Comparator; 20 | 21 | import static com.teradata.tempto.internal.RequirementFulfillerPriorityHelper.getPriority; 22 | 23 | public class RequirementFulfillerByPriorityComparator 24 | implements Comparator> 25 | { 26 | 27 | @Override 28 | public int compare(Class o1, Class o2) 29 | { 30 | return getPriority(o1) - getPriority(o2); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/RequirementFulfillerPriorityHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal; 16 | 17 | import com.teradata.tempto.fulfillment.RequirementFulfiller; 18 | 19 | public class RequirementFulfillerPriorityHelper 20 | { 21 | private RequirementFulfillerPriorityHelper() {} 22 | 23 | public static int getPriority(Class c) 24 | { 25 | if (c.getAnnotation(RequirementFulfiller.AutoSuiteLevelFulfiller.class) != null) { 26 | return c.getAnnotation(RequirementFulfiller.AutoSuiteLevelFulfiller.class).priority(); 27 | } 28 | else if (c.getAnnotation(RequirementFulfiller.AutoTestLevelFulfiller.class) != null) { 29 | return c.getAnnotation(RequirementFulfiller.AutoTestLevelFulfiller.class).priority(); 30 | } 31 | else { 32 | throw new RuntimeException( 33 | String.format("Class '%s' is not annotated with '%' or '%s'.", 34 | c.getName(), RequirementFulfiller.AutoSuiteLevelFulfiller.class.getName(), RequirementFulfiller.AutoTestLevelFulfiller.class.getName())); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/RequirementsCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal; 16 | 17 | import com.teradata.tempto.CompositeRequirement; 18 | 19 | import java.lang.reflect.Method; 20 | 21 | public interface RequirementsCollector 22 | { 23 | CompositeRequirement getAnnotationBasedRequirementsFor(Method method); 24 | } 25 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/configuration/EmptyConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.configuration; 16 | 17 | import com.teradata.tempto.configuration.Configuration; 18 | 19 | import java.util.Collections; 20 | import java.util.Optional; 21 | import java.util.Set; 22 | 23 | public class EmptyConfiguration extends AbstractConfiguration 24 | { 25 | 26 | private static final EmptyConfiguration INSTANCE = new EmptyConfiguration(); 27 | 28 | public static Configuration emptyConfiguration() { 29 | return INSTANCE; 30 | } 31 | 32 | private EmptyConfiguration() {} 33 | 34 | @Override 35 | public Optional get(String key) 36 | { 37 | return Optional.empty(); 38 | } 39 | 40 | @Override 41 | public Set listKeys() 42 | { 43 | return Collections.emptySet(); 44 | } 45 | 46 | @Override 47 | public Configuration getSubconfiguration(String keyPrefix) 48 | { 49 | return emptyConfiguration(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/configuration/YamlConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.configuration; 16 | 17 | import com.teradata.tempto.configuration.Configuration; 18 | import org.apache.commons.io.IOUtils; 19 | import org.yaml.snakeyaml.Yaml; 20 | 21 | import java.io.ByteArrayInputStream; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.util.Map; 25 | 26 | import static com.google.common.base.Charsets.UTF_8; 27 | import static com.google.common.base.Preconditions.checkArgument; 28 | 29 | public class YamlConfiguration 30 | extends DelegateConfiguration 31 | { 32 | 33 | private final MapConfiguration mapConfiguration; 34 | 35 | public YamlConfiguration(String yamlString) 36 | { 37 | this(new ByteArrayInputStream(yamlString.getBytes(UTF_8))); 38 | } 39 | 40 | public YamlConfiguration(InputStream yamlInputStream) 41 | { 42 | mapConfiguration = loadConfiguration(inputStreamToStringSafe(yamlInputStream)); 43 | } 44 | 45 | private MapConfiguration loadConfiguration(String yamlString) 46 | { 47 | Yaml yaml = new Yaml(); 48 | Object loadedYaml = yaml.load(yamlString); 49 | checkArgument(loadedYaml instanceof Map, "yaml does not evaluate to map object; got %s", loadedYaml.getClass().getName()); 50 | Map loadedYamlMap = (Map) loadedYaml; 51 | return new MapConfiguration(loadedYamlMap); 52 | } 53 | 54 | @Override 55 | protected Configuration getDelegate() 56 | { 57 | return mapConfiguration; 58 | } 59 | 60 | private String inputStreamToStringSafe(InputStream yamlInputStream) 61 | { 62 | try { 63 | return IOUtils.toString(yamlInputStream, UTF_8); 64 | } 65 | catch (IOException e) { 66 | throw new RuntimeException(e); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/context/TestContextStack.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.context; 16 | 17 | import com.teradata.tempto.context.TestContext; 18 | 19 | import java.util.Iterator; 20 | import java.util.Stack; 21 | 22 | public class TestContextStack 23 | implements Iterable 24 | { 25 | private final Stack testContextStack = new Stack<>(); 26 | 27 | public void push(C testContext) 28 | { 29 | testContextStack.push(testContext); 30 | } 31 | 32 | public C pop() 33 | { 34 | return testContextStack.pop(); 35 | } 36 | 37 | public C peek() 38 | { 39 | return testContextStack.peek(); 40 | } 41 | 42 | public int size() 43 | { 44 | return testContextStack.size(); 45 | } 46 | 47 | public boolean empty() 48 | { 49 | return testContextStack.empty(); 50 | } 51 | 52 | @Override 53 | public Iterator iterator() 54 | { 55 | return testContextStack.iterator(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/convention/ConventionBasedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.convention; 16 | 17 | import com.teradata.tempto.ProductTest; 18 | import com.teradata.tempto.RequirementsProvider; 19 | import com.teradata.tempto.testmarkers.WithName; 20 | import com.teradata.tempto.testmarkers.WithTestGroups; 21 | 22 | public abstract class ConventionBasedTest 23 | extends ProductTest 24 | implements RequirementsProvider, WithName, WithTestGroups 25 | { 26 | public abstract void test(); 27 | } 28 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/convention/ConventionRequirements.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.convention; 16 | 17 | public final class ConventionRequirements 18 | { 19 | 20 | 21 | private ConventionRequirements() 22 | { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/convention/MutableTableDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.internal.convention; 15 | 16 | import com.teradata.tempto.fulfillment.table.MutableTableRequirement.State; 17 | import com.teradata.tempto.fulfillment.table.TableHandle; 18 | 19 | import static com.google.common.base.Preconditions.checkNotNull; 20 | 21 | public final class MutableTableDescriptor 22 | { 23 | public final String tableDefinitionName; 24 | public final State state; 25 | public final TableHandle tableHandle; 26 | 27 | MutableTableDescriptor(String tableDefinitionName, State state, TableHandle name) 28 | { 29 | this.tableDefinitionName = checkNotNull(tableDefinitionName); 30 | this.state = checkNotNull(state); 31 | this.tableHandle = checkNotNull(name); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/convention/ProcessUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.internal.convention; 15 | 16 | import java.io.IOException; 17 | 18 | import static com.google.common.base.Preconditions.checkState; 19 | 20 | public final class ProcessUtils 21 | { 22 | private static final int SUCCESS_EXIT_CODE = 0; 23 | 24 | public static void execute(String... cmdarray) 25 | { 26 | checkState(cmdarray.length > 0); 27 | 28 | try { 29 | Process process = Runtime.getRuntime().exec(cmdarray); 30 | process.waitFor(); 31 | checkState(process.exitValue() == SUCCESS_EXIT_CODE, "%s exited with status code: %s", cmdarray[0], process.exitValue()); 32 | } 33 | catch (IOException | InterruptedException e) { 34 | throw new RuntimeException(e); 35 | } 36 | } 37 | 38 | private ProcessUtils() 39 | { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/convention/generator/GeneratorPathTestFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.convention.generator; 16 | 17 | import com.teradata.tempto.internal.convention.ConventionBasedTest; 18 | import com.teradata.tempto.internal.convention.ConventionBasedTestFactory; 19 | 20 | import java.io.File; 21 | import java.nio.file.Path; 22 | import java.util.List; 23 | 24 | import static com.google.common.io.Files.createTempDir; 25 | import static com.teradata.tempto.internal.convention.ProcessUtils.execute; 26 | import static com.teradata.tempto.internal.convention.SqlTestsFileUtils.getExtension; 27 | import static com.teradata.tempto.internal.convention.SqlTestsFileUtils.getFilenameWithoutExtension; 28 | import static com.teradata.tempto.internal.convention.SqlTestsFileUtils.makeExecutable; 29 | 30 | public class GeneratorPathTestFactory 31 | implements ConventionBasedTestFactory.PathTestFactory 32 | { 33 | 34 | private static final String GENERATOR_SCRIPT_EXTENSION = "generator"; 35 | 36 | @Override 37 | public boolean isSupportedPath(Path path) 38 | { 39 | return GENERATOR_SCRIPT_EXTENSION.equals(getExtension(path)); 40 | } 41 | 42 | @Override 43 | public List createTestsForPath(Path path, String testNamePrefix, ConventionBasedTestFactory factory) 44 | { 45 | String newPrefix = testNamePrefix + "." + getFilenameWithoutExtension(path); 46 | File tmpTestsDirectory = createTempDir(); 47 | tmpTestsDirectory.deleteOnExit(); 48 | makeExecutable(path); 49 | execute(path.toFile().toString(), tmpTestsDirectory.toString()); 50 | return factory.createTestsForChildrenOfPath(tmpTestsDirectory.toPath(), newPrefix); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/convention/recursion/RecursionPathTestFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.convention.recursion; 16 | 17 | import com.teradata.tempto.internal.convention.ConventionBasedTest; 18 | import com.teradata.tempto.internal.convention.ConventionBasedTestFactory; 19 | 20 | import java.nio.file.Files; 21 | import java.nio.file.Path; 22 | import java.util.List; 23 | 24 | public class RecursionPathTestFactory 25 | implements ConventionBasedTestFactory.PathTestFactory 26 | { 27 | 28 | @Override 29 | public boolean isSupportedPath(Path path) 30 | { 31 | return Files.isDirectory(path); 32 | } 33 | 34 | @Override 35 | public List createTestsForPath(Path path, String testNamePrefix, ConventionBasedTestFactory factory) 36 | { 37 | String newPrefix = testNamePrefix + "." + path.getFileName(); 38 | return factory.createTestsForChildrenOfPath(path, newPrefix); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/convention/tabledefinitions/FileBasedJdbcDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.convention.tabledefinitions; 16 | 17 | import com.teradata.tempto.fulfillment.table.jdbc.JdbcTableDataSource; 18 | 19 | import java.util.Iterator; 20 | import java.util.List; 21 | 22 | import static com.google.common.base.Preconditions.checkNotNull; 23 | import static com.teradata.tempto.internal.convention.tabledefinitions.JdbcDataFileDescriptor.sqlResultDescriptorFor; 24 | import static java.util.Collections.emptyIterator; 25 | 26 | public class FileBasedJdbcDataSource 27 | implements JdbcTableDataSource 28 | { 29 | private final ConventionTableDefinitionDescriptor tableDefinitionDescriptor; 30 | 31 | public FileBasedJdbcDataSource(ConventionTableDefinitionDescriptor tableDefinitionDescriptor) 32 | { 33 | this.tableDefinitionDescriptor = checkNotNull(tableDefinitionDescriptor, "tableDefinitionDescriptor is null"); 34 | } 35 | 36 | @Override 37 | public Iterator> getDataRows() 38 | { 39 | return tableDefinitionDescriptor.getDataFile() 40 | .map(dataFile -> sqlResultDescriptorFor(dataFile).getRows().iterator()) 41 | .orElse(emptyIterator()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/convention/tabledefinitions/TableType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.convention.tabledefinitions; 16 | 17 | /** 18 | * Table types supported by convention based table definitions 19 | */ 20 | public enum TableType 21 | { 22 | HIVE, 23 | JDBC 24 | } 25 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/fulfillment/table/ImmutableTablesFulfiller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.fulfillment.table; 16 | 17 | import com.google.inject.Inject; 18 | import com.teradata.tempto.fulfillment.TestStatus; 19 | import com.teradata.tempto.fulfillment.table.ImmutableTableRequirement; 20 | import com.teradata.tempto.fulfillment.table.ImmutableTablesState; 21 | import com.teradata.tempto.fulfillment.table.TableInstance; 22 | import com.teradata.tempto.fulfillment.table.TableManager; 23 | import com.teradata.tempto.fulfillment.table.TableManagerDispatcher; 24 | import com.teradata.tempto.fulfillment.table.TablesState; 25 | 26 | import java.util.List; 27 | 28 | public class ImmutableTablesFulfiller 29 | extends TableRequirementFulfiller 30 | { 31 | 32 | @Inject 33 | public ImmutableTablesFulfiller(TableManagerDispatcher tableManagerDispatcher) 34 | { 35 | super(tableManagerDispatcher, ImmutableTableRequirement.class); 36 | } 37 | 38 | @Override 39 | protected TablesState createState(List tables) 40 | { 41 | return new ImmutableTablesState(tables); 42 | } 43 | 44 | @Override 45 | protected TableInstance createTable(TableManager tableManager, ImmutableTableRequirement tableRequirement) 46 | { 47 | return tableManager.createImmutable(tableRequirement.getTableDefinition()); 48 | } 49 | 50 | @Override 51 | public void cleanup(TestStatus status) 52 | { 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/fulfillment/table/TableNameGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.fulfillment.table; 16 | 17 | import java.util.UUID; 18 | 19 | public class TableNameGenerator 20 | { 21 | private static final String MUTABLE_TABLE_NAME_PREFIX = "tempto_mut_"; 22 | 23 | public String generateMutableTableNameInDatabase(String baseTableName) 24 | { 25 | String tableSuffix = randomUUID().replace("-", ""); 26 | return MUTABLE_TABLE_NAME_PREFIX + baseTableName + "_" + tableSuffix; 27 | } 28 | 29 | public boolean isMutableTableName(String tableNameInDatabase) 30 | { 31 | return tableNameInDatabase.startsWith(MUTABLE_TABLE_NAME_PREFIX); 32 | } 33 | 34 | private String randomUUID() 35 | { 36 | return UUID.randomUUID().toString(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/fulfillment/table/hive/HiveTableInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.internal.fulfillment.table.hive; 15 | 16 | import com.teradata.tempto.fulfillment.table.TableInstance; 17 | import com.teradata.tempto.fulfillment.table.hive.HiveTableDefinition; 18 | import com.teradata.tempto.internal.fulfillment.table.TableName; 19 | 20 | public class HiveTableInstance 21 | extends TableInstance 22 | { 23 | public HiveTableInstance(TableName tableName, HiveTableDefinition tableDefinition) 24 | { 25 | super(tableName, tableDefinition); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/fulfillment/table/jdbc/JdbcTableInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.internal.fulfillment.table.jdbc; 15 | 16 | import com.teradata.tempto.fulfillment.table.TableInstance; 17 | import com.teradata.tempto.fulfillment.table.jdbc.JdbcTableDefinition; 18 | import com.teradata.tempto.internal.fulfillment.table.TableName; 19 | 20 | public class JdbcTableInstance 21 | extends TableInstance 22 | { 23 | public JdbcTableInstance(TableName tableName, JdbcTableDefinition tableDefinition) 24 | { 25 | super(tableName, tableDefinition); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/fulfillment/table/jdbc/Loader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.fulfillment.table.jdbc; 16 | 17 | import java.sql.SQLException; 18 | import java.util.List; 19 | 20 | interface Loader 21 | extends AutoCloseable 22 | { 23 | void load(List> batch) 24 | throws SQLException; 25 | 26 | void close() 27 | throws SQLException; 28 | } 29 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/fulfillment/table/jdbc/LoaderFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.fulfillment.table.jdbc; 16 | 17 | import com.teradata.tempto.query.QueryExecutor; 18 | import org.slf4j.Logger; 19 | 20 | import java.sql.JDBCType; 21 | import java.sql.SQLException; 22 | import java.util.List; 23 | 24 | import static java.lang.String.format; 25 | import static java.util.stream.Collectors.joining; 26 | import static java.util.stream.IntStream.range; 27 | import static org.slf4j.LoggerFactory.getLogger; 28 | 29 | class LoaderFactory 30 | { 31 | private static final Logger LOGGER = getLogger(LoaderFactory.class); 32 | 33 | Loader create(QueryExecutor queryExecutor, String tableName) 34 | throws SQLException 35 | { 36 | List columnTypes = queryExecutor.executeQuery("SELECT * FROM " + tableName + " LIMIT 1").getColumnTypes(); 37 | 38 | try { 39 | return new BatchLoader(queryExecutor, tableName, columnTypes.size()); 40 | } 41 | catch (SQLException sqlException) { 42 | LOGGER.warn("Unable to insert data with PreparedStatement", sqlException); 43 | return new InsertLoader(queryExecutor, tableName, columnTypes); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/hadoop/hdfs/HdfsDataSourceWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.hadoop.hdfs; 16 | 17 | import com.teradata.tempto.fulfillment.table.hive.HiveDataSource; 18 | 19 | public interface HdfsDataSourceWriter 20 | { 21 | void ensureDataOnHdfs(String dataPath, HiveDataSource dataSource); 22 | } 23 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/hadoop/hdfs/HttpRequestsExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.hadoop.hdfs; 16 | 17 | import org.apache.http.client.methods.CloseableHttpResponse; 18 | import org.apache.http.client.methods.HttpUriRequest; 19 | 20 | import java.io.IOException; 21 | 22 | public interface HttpRequestsExecutor 23 | { 24 | CloseableHttpResponse execute(final HttpUriRequest request) 25 | throws IOException; 26 | } 27 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/hadoop/hdfs/revisions/RevisionStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.hadoop.hdfs.revisions; 16 | 17 | import java.util.Optional; 18 | 19 | /** 20 | * Store revision id for particular hdfs path 21 | */ 22 | public interface RevisionStorage 23 | { 24 | 25 | /** 26 | * Get current data revision for given {@code hdfsPath} 27 | * @param hdfsPath Path to be examined 28 | * @return data revision 29 | */ 30 | Optional get(String hdfsPath); 31 | 32 | /** 33 | * Store data revision for {@code hdfsPath} 34 | * 35 | * @param hdfsPath Path to be affected 36 | * @param revision Revision string to be associated with hdfsPath 37 | */ 38 | void put(String hdfsPath, String revision); 39 | 40 | /** 41 | * Remove information about {@code hdfsPath} data revision 42 | * If data revision hasn't been set or hdfsPath does not exist method will just return as regular 43 | * 44 | * @param hdfsPath Path to be affected 45 | */ 46 | void remove(String hdfsPath); 47 | } 48 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/hadoop/hdfs/revisions/RevisionStorageFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.hadoop.hdfs.revisions; 16 | 17 | import com.teradata.tempto.hadoop.hdfs.HdfsClient; 18 | 19 | import java.util.Optional; 20 | 21 | /** 22 | * Store table data revision as file in /tmp path with revision id as content 23 | */ 24 | public class RevisionStorageFile 25 | implements RevisionStorage 26 | { 27 | 28 | private final HdfsClient hdfsClient; 29 | private final String testDataBasePath; 30 | 31 | RevisionStorageFile(HdfsClient hdfsClient, String testDataBasePath) 32 | { 33 | this.hdfsClient = hdfsClient; 34 | this.testDataBasePath = testDataBasePath; 35 | } 36 | 37 | @Override 38 | public Optional get(String hdfsPath) 39 | { 40 | String markerFilePath = markerFilePath(hdfsPath); 41 | 42 | if (!hdfsClient.exist(markerFilePath)) { 43 | return Optional.empty(); 44 | } 45 | 46 | return Optional.of(hdfsClient.loadFile(markerFilePath)); 47 | } 48 | 49 | @Override 50 | public void put(String hdfsPath, String revision) 51 | { 52 | String markerFilePath = markerFilePath(hdfsPath); 53 | 54 | hdfsClient.delete(markerFilePath); 55 | hdfsClient.saveFile(markerFilePath, revision); 56 | } 57 | 58 | @Override 59 | public void remove(String hdfsPath) 60 | { 61 | hdfsClient.delete(markerFilePath(hdfsPath)); 62 | } 63 | 64 | private String markerFilePath(String path) 65 | { 66 | return getMarkerFilesDirectory() + path; 67 | } 68 | 69 | private String getMarkerFilesDirectory() 70 | { 71 | return testDataBasePath + "/data_revision_markers"; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/hadoop/hdfs/revisions/RevisionStorageXAttr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.hadoop.hdfs.revisions; 16 | 17 | import com.teradata.tempto.hadoop.hdfs.HdfsClient; 18 | 19 | import java.util.Optional; 20 | 21 | /** 22 | * Store table data revision as XAttr 23 | */ 24 | public class RevisionStorageXAttr 25 | implements RevisionStorage 26 | { 27 | 28 | /** 29 | * XAttr name stored on HDFS for each data source file. 30 | */ 31 | private static final String REVISON_XATTR_NAME = "user.test-data-revision"; 32 | 33 | private final HdfsClient hdfsClient; 34 | 35 | RevisionStorageXAttr(HdfsClient hdfsClient) 36 | { 37 | this.hdfsClient = hdfsClient; 38 | } 39 | 40 | @Override 41 | public Optional get(String hdfsPath) 42 | { 43 | return hdfsClient.getXAttr(hdfsPath, REVISON_XATTR_NAME); 44 | } 45 | 46 | @Override 47 | public void put(String hdfsPath, String revision) 48 | { 49 | hdfsClient.setXAttr(hdfsPath, REVISON_XATTR_NAME, revision); 50 | } 51 | 52 | @Override 53 | public void remove(String hdfsPath) 54 | { 55 | if(get(hdfsPath).isPresent()){ 56 | hdfsClient.removeXAttr(hdfsPath, REVISON_XATTR_NAME); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/initialization/RequirementsAwareTestNGMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.initialization; 16 | 17 | import com.teradata.tempto.Requirement; 18 | import org.testng.ITestNGMethod; 19 | 20 | import java.util.Set; 21 | 22 | import static com.google.common.collect.Sets.newHashSet; 23 | 24 | public class RequirementsAwareTestNGMethod 25 | extends DelegateTestNGMethod 26 | { 27 | private final Set requirements; 28 | 29 | public RequirementsAwareTestNGMethod(ITestNGMethod delegate, Set requirements) 30 | { 31 | super(delegate); 32 | this.requirements = requirements; 33 | } 34 | 35 | public Set getRequirements() { 36 | return requirements; 37 | } 38 | 39 | @Override 40 | public ITestNGMethod clone() 41 | { 42 | return new RequirementsAwareTestNGMethod(super.delegate.clone(), newHashSet(requirements)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/initialization/modules/TestMethodInfoModuleProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.internal.initialization.modules; 15 | 16 | import com.google.inject.AbstractModule; 17 | import com.google.inject.Module; 18 | import com.teradata.tempto.configuration.Configuration; 19 | import com.teradata.tempto.initialization.AutoModuleProvider; 20 | import com.teradata.tempto.initialization.TestMethodModuleProvider; 21 | import com.teradata.tempto.internal.listeners.TestMetadata; 22 | import com.teradata.tempto.internal.listeners.TestMetadataReader; 23 | import org.testng.ITestResult; 24 | 25 | @AutoModuleProvider 26 | public class TestMethodInfoModuleProvider 27 | implements TestMethodModuleProvider 28 | { 29 | private final TestMetadataReader testMetadataReader = new TestMetadataReader(); 30 | public Module getModule(Configuration configuration, ITestResult testResult) 31 | { 32 | TestMetadata testMetadata = testMetadataReader.readTestMetadata(testResult); 33 | return new AbstractModule() 34 | { 35 | @Override 36 | protected void configure() 37 | { 38 | bind(TestMetadata.class).toInstance(testMetadata); 39 | } 40 | }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/listeners/ProductTestAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.listeners; 16 | 17 | import org.slf4j.LoggerFactory; 18 | import org.testng.IAnnotationTransformer; 19 | import org.testng.annotations.ITestAnnotation; 20 | import org.slf4j.Logger; 21 | 22 | import java.lang.reflect.Constructor; 23 | import java.lang.reflect.Method; 24 | 25 | /** 26 | * Responsible for transforming the {@link org.testng.annotations.Test} annotations in the following ways: 27 | * 28 | *
    29 | *
  1. Ensure that the annotation is only on a test method and not a class or constructor
  2. 30 | *
31 | */ 32 | public class ProductTestAnnotationTransformer implements IAnnotationTransformer { 33 | private static final Logger LOGGER = LoggerFactory.getLogger(ProductTestAnnotationTransformer.class); 34 | 35 | @Override 36 | public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { 37 | ensureAnnotationIsOnlyOnTestMethod(testClass, testConstructor, testMethod); 38 | } 39 | 40 | private static void ensureAnnotationIsOnlyOnTestMethod(Class testClass, Constructor testConstructor, Method testMethod) { 41 | if (testMethod == null) { 42 | String annotatedObjectName = (testClass != null) ? testClass.getName() : testConstructor.getName(); 43 | LOGGER.error("Cannot annotate '{}' with @Test in the product tests, only a method can be a product test", annotatedObjectName); 44 | throw new IllegalStateException("Illegal @Test annotation on " + annotatedObjectName); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/listeners/TestMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.listeners; 16 | 17 | import java.util.Set; 18 | 19 | import static com.google.common.base.Preconditions.checkNotNull; 20 | import static com.google.common.collect.ImmutableSet.copyOf; 21 | 22 | public class TestMetadata 23 | { 24 | public final Set testGroups; 25 | public final String testName; 26 | 27 | public TestMetadata(Set testGroups, String testName) { 28 | this.testGroups = copyOf(checkNotNull(testGroups, "testGroups can not be null")); 29 | this.testName = checkNotNull(testName, "testName can not be null"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/listeners/TestMetadataReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.listeners; 16 | 17 | import com.teradata.tempto.testmarkers.WithName; 18 | import com.teradata.tempto.testmarkers.WithTestGroups; 19 | import org.testng.ITestNGMethod; 20 | import org.testng.ITestResult; 21 | 22 | import java.util.Set; 23 | 24 | import static com.google.common.collect.Sets.newHashSet; 25 | import static java.util.Arrays.asList; 26 | 27 | public class TestMetadataReader 28 | { 29 | 30 | public TestMetadata readTestMetadata(ITestResult testResult) { 31 | return readTestMetadata(testResult.getMethod()); 32 | } 33 | 34 | public TestMetadata readTestMetadata(ITestNGMethod testMethod) { 35 | return new TestMetadata( 36 | readTestGroups(testMethod), 37 | readTestName(testMethod)); 38 | } 39 | 40 | private Set readTestGroups(ITestNGMethod method) 41 | { 42 | if (method.isTest() && method.getInstance() instanceof WithTestGroups) { 43 | return (((WithTestGroups) method.getInstance()).getTestGroups()); 44 | } 45 | return newHashSet(asList(method.getGroups())); 46 | } 47 | 48 | private String readTestName(ITestNGMethod method) 49 | { 50 | if (method.isTest() && method.getInstance() instanceof WithName) { 51 | return ((WithName) method.getInstance()).getTestName(); 52 | } 53 | return method.getTestClass().getName() + "." + method.getMethodName(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/logging/LoggingMdcHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.logging; 16 | 17 | import com.teradata.tempto.internal.listeners.TestMetadata; 18 | import com.teradata.tempto.internal.listeners.TestMetadataReader; 19 | import org.testng.ITestResult; 20 | 21 | public class LoggingMdcHelper 22 | { 23 | private static final String MDC_TEST_ID_KEY = "test_id"; 24 | private static final TestMetadataReader testMetadataReader = new TestMetadataReader(); 25 | 26 | private LoggingMdcHelper() {} 27 | 28 | public static void setupLoggingMdcForTest(ITestResult testCase) { 29 | TestMetadata testMetadata = testMetadataReader.readTestMetadata(testCase); 30 | String testId = testMetadata.testName; 31 | org.slf4j.MDC.put("test_id", testId); 32 | } 33 | 34 | public static void cleanLoggingMdc() { 35 | org.slf4j.MDC.remove(MDC_TEST_ID_KEY); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/internal/ssh/JschSshClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.ssh; 16 | 17 | import com.jcraft.jsch.JSch; 18 | import com.jcraft.jsch.JSchException; 19 | import com.jcraft.jsch.Session; 20 | import com.teradata.tempto.ssh.SshClient; 21 | import com.teradata.tempto.ssh.SshClientFactory; 22 | import org.slf4j.Logger; 23 | 24 | import java.util.Optional; 25 | import java.util.Properties; 26 | 27 | import static org.slf4j.LoggerFactory.getLogger; 28 | 29 | public class JschSshClientFactory 30 | implements SshClientFactory 31 | { 32 | private static final Logger LOGGER = getLogger(JschSshClientFactory.class); 33 | 34 | private final JSch jSch = new JSch(); 35 | 36 | @Override 37 | public SshClient create(String host, int port, String user, Optional password) 38 | { 39 | return new JSchSshClient(() -> { 40 | try { 41 | String passwordToString = password.isPresent() ? '/' + password.get() : ""; 42 | LOGGER.debug("Allocating new SSH session to: {}{}@{}:{}", user, passwordToString, host, port); 43 | Session session = jSch.getSession(user, host, port); 44 | if (password.isPresent()) { 45 | session.setPassword(password.get()); 46 | } 47 | session.setConfig(getConfig()); 48 | return session; 49 | } 50 | catch (JSchException e) { 51 | throw new RuntimeException(e); 52 | } 53 | }); 54 | } 55 | 56 | @Override 57 | public void addIdentity(String pathToPem) 58 | { 59 | try { 60 | LOGGER.debug("Adding SSH identity: {}", pathToPem); 61 | jSch.addIdentity(pathToPem); 62 | } 63 | catch (JSchException e) { 64 | throw new RuntimeException(e); 65 | } 66 | } 67 | 68 | private Properties getConfig() 69 | { 70 | Properties config = new Properties(); 71 | config.put("StrictHostKeyChecking", "no"); 72 | return config; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/process/CliProcess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.process; 15 | 16 | import java.io.Closeable; 17 | import java.io.PrintStream; 18 | import java.time.Duration; 19 | import java.util.List; 20 | import java.util.regex.Pattern; 21 | 22 | import static java.util.stream.Collectors.toList; 23 | 24 | /** 25 | * Interface for interacting with CLI processes. 26 | */ 27 | public interface CliProcess extends Closeable 28 | { 29 | public static List trimLines(List lines) 30 | { 31 | return lines.stream().map(String::trim).collect(toList()); 32 | } 33 | 34 | List readRemainingOutputLines(); 35 | 36 | String nextOutputLine(); 37 | 38 | String nextOutputToken(); 39 | 40 | boolean hasNextOutputLine(); 41 | 42 | boolean hasNextOutput(Pattern pattern); 43 | 44 | boolean hasNextOutputToken(); 45 | 46 | List readRemainingErrorLines(); 47 | 48 | String nextErrorLine(); 49 | 50 | String nextErrorToken(); 51 | 52 | boolean hasNextErrorLine(); 53 | 54 | boolean hasNextError(Pattern pattern); 55 | 56 | boolean hasNextErrorToken(); 57 | 58 | PrintStream getProcessInput(); 59 | 60 | /** 61 | * Waits for a process to finish and ensures it returns with 0 status. If the process 62 | * fails to finish within given timeout it is killed and {@link TimeoutRuntimeException} is thrown. 63 | * 64 | * @throws InterruptedException if the thread is interrupted 65 | * @throws CommandExecutionException if command finishes with non zero status 66 | * @throws TimeoutRuntimeException 67 | */ 68 | void waitForWithTimeoutAndKill() 69 | throws InterruptedException, TimeoutRuntimeException, CommandExecutionException; 70 | 71 | void waitForWithTimeoutAndKill(Duration timeout) 72 | throws InterruptedException, TimeoutRuntimeException, CommandExecutionException; 73 | } 74 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/process/CommandExecutionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.process; 16 | 17 | public class CommandExecutionException 18 | extends RuntimeException 19 | { 20 | private final int exitStatus; 21 | 22 | public CommandExecutionException(String message, int exitStatus) 23 | { 24 | super(message); 25 | this.exitStatus = exitStatus; 26 | } 27 | 28 | public int getExitStatus() 29 | { 30 | return exitStatus; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/process/JavaProcessLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.process; 15 | 16 | import com.google.common.collect.ImmutableList; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.util.List; 21 | 22 | /** 23 | * Launches a Java class with main() method as a separate process. 24 | */ 25 | public final class JavaProcessLauncher 26 | { 27 | private final String javaBin; 28 | private final String classpath; 29 | 30 | public static JavaProcessLauncher defaultJavaProcessLauncher() 31 | { 32 | return new JavaProcessLauncher( 33 | System.getProperty("java.home") + File.separator + "bin" + File.separator + "java", 34 | System.getProperty("java.class.path") 35 | ); 36 | } 37 | 38 | public JavaProcessLauncher(String javaBin, String classpath) 39 | { 40 | this.javaBin = javaBin; 41 | this.classpath = classpath; 42 | } 43 | 44 | public Process launch(Class clazz, List arguments) 45 | throws IOException, InterruptedException 46 | { 47 | String className = clazz.getCanonicalName(); 48 | List command = ImmutableList.builder() 49 | .add(javaBin, "-cp", classpath, className) 50 | .addAll(arguments) 51 | .build(); 52 | return new ProcessBuilder(command).start(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/process/LocalCliProcess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.process; 15 | 16 | import com.teradata.tempto.internal.process.CliProcessBase; 17 | 18 | import java.time.Duration; 19 | 20 | import static java.util.concurrent.TimeUnit.MILLISECONDS; 21 | 22 | /** 23 | * Wrapping class for {@link Process} that helps interacting with CLI processes. 24 | */ 25 | public class LocalCliProcess 26 | extends CliProcessBase 27 | { 28 | private final Process process; 29 | 30 | public LocalCliProcess(Process process) 31 | { 32 | super(process.getInputStream(), process.getErrorStream(), process.getOutputStream()); 33 | this.process = process; 34 | } 35 | 36 | @Override 37 | public void waitForWithTimeoutAndKill(Duration timeout) 38 | throws InterruptedException 39 | { 40 | if (!process.waitFor(timeout.toMillis(), MILLISECONDS)) { 41 | close(); 42 | throw new RuntimeException("Child process didn't finish within given timeout"); 43 | } 44 | 45 | int exitValue = process.exitValue(); 46 | if (exitValue != 0) { 47 | throw new RuntimeException("Child process exited with non-zero code: " + exitValue); 48 | } 49 | } 50 | 51 | /** 52 | * Terminates process and closes all related streams 53 | */ 54 | @Override 55 | public void close() 56 | { 57 | // destroy process 58 | if (process.isAlive()) { 59 | process.destroy(); 60 | } 61 | 62 | // then close all related streams 63 | super.close(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/process/TimeoutRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.process; 16 | 17 | public class TimeoutRuntimeException 18 | extends RuntimeException 19 | { 20 | public TimeoutRuntimeException(String msg) 21 | { 22 | super(msg); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/query/JdbcConnectionsPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.query; 15 | 16 | import javax.sql.DataSource; 17 | 18 | import java.sql.Connection; 19 | import java.sql.SQLException; 20 | import java.sql.Statement; 21 | import java.util.Map; 22 | 23 | import static com.google.common.collect.Maps.newHashMap; 24 | import static com.teradata.tempto.internal.query.JdbcUtils.dataSource; 25 | 26 | public class JdbcConnectionsPool 27 | { 28 | private final Map dataSources = newHashMap(); 29 | 30 | public Connection connectionFor(JdbcConnectivityParamsState jdbcParamsState) 31 | throws SQLException 32 | { 33 | if (!dataSources.containsKey(jdbcParamsState)) { 34 | dataSources.put(jdbcParamsState, dataSource(jdbcParamsState)); 35 | } 36 | 37 | Connection connection = dataSources.get(jdbcParamsState).getConnection(); 38 | if (jdbcParamsState.prepareStatement.isPresent()) 39 | { 40 | try (Statement statement = connection.createStatement()) 41 | { 42 | statement.execute(jdbcParamsState.prepareStatement.get()); 43 | } 44 | } 45 | return connection; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/query/QueryExecutionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.query; 16 | 17 | public class QueryExecutionException 18 | extends RuntimeException 19 | { 20 | public QueryExecutionException(Throwable e) 21 | { 22 | super(e); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/query/QueryExecutorDispatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.query; 15 | 16 | public interface QueryExecutorDispatcher 17 | { 18 | QueryExecutor getQueryExecutor(String connectionName); 19 | } 20 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/query/QueryType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.query; 16 | 17 | public enum QueryType 18 | { 19 | SELECT, UPDATE 20 | } 21 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/sql/SqlContexts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.sql; 16 | 17 | import com.teradata.tempto.query.QueryExecutor; 18 | import com.teradata.tempto.sql.view.ViewContextProvider; 19 | 20 | import static com.teradata.tempto.query.QueryExecutor.defaultQueryExecutor; 21 | import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; 22 | 23 | public final class SqlContexts 24 | { 25 | 26 | /** 27 | * Helper method designed to be used with lambda expressions containing assertions used 28 | * on newly created view: 29 | *
30 |      *  executeWith(createViewAs("SELECT * FROM nation", view -> {
31 |      *        assertThat(query(format("SELECT * FROM %s", view.getName())))
32 |      *            .hasRowsCount(25);
33 |      *  }));
34 |      * 
35 | * 36 | * @param selectSql sql select statement used to create view 37 | * @return viewContextProvider 38 | */ 39 | public static ViewContextProvider createViewAs(String selectSql) 40 | { 41 | String viewName = generateRandomName("TEST_VIEW_"); 42 | return new ViewContextProvider(viewName, selectSql, defaultQueryExecutor()); 43 | } 44 | 45 | public static ViewContextProvider createViewAs(String viewName, String selectSql, QueryExecutor queryExecutor) 46 | { 47 | return new ViewContextProvider(viewName, selectSql, queryExecutor); 48 | } 49 | 50 | private static String generateRandomName(String prefix) 51 | { 52 | return prefix + randomAlphanumeric(4); 53 | } 54 | 55 | private SqlContexts() 56 | { 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/sql/view/View.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.sql.view; 16 | 17 | import static com.google.common.base.MoreObjects.toStringHelper; 18 | 19 | public class View 20 | { 21 | private final String name; 22 | 23 | public View(String name) 24 | { 25 | this.name = name; 26 | } 27 | 28 | public String getName() 29 | { 30 | return name; 31 | } 32 | 33 | @Override 34 | public String toString() 35 | { 36 | return toStringHelper(this) 37 | .add("name", name) 38 | .toString(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/ssh/SshClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.ssh; 15 | 16 | import com.google.common.base.Joiner; 17 | import com.teradata.tempto.process.CliProcess; 18 | 19 | import java.io.Closeable; 20 | import java.io.IOException; 21 | import java.nio.file.Path; 22 | import java.util.List; 23 | 24 | /** 25 | * Simple SSH client. 26 | */ 27 | public interface SshClient extends Closeable 28 | { 29 | 30 | default String command(String command) { 31 | try (CliProcess cliProcess = execute(command)) { 32 | String output = Joiner.on("\n").join(cliProcess.readRemainingOutputLines()); 33 | cliProcess.waitForWithTimeoutAndKill(); 34 | return output; 35 | } 36 | catch (IOException | InterruptedException e) { 37 | throw new RuntimeException(e); 38 | } 39 | } 40 | 41 | /** 42 | * Executes command on a remote machine. 43 | * 44 | * @param command Command to be executed on remote machine. 45 | * @return CLIProcess 46 | */ 47 | CliProcess execute(String command); 48 | 49 | 50 | CliProcess execute(List command); 51 | 52 | /** 53 | * Uploads file to a remote machine. It works like SCP. 54 | * 55 | * @param file Local path to file which is to be uploaded 56 | * @param remotePath Destination path for file on remote machine. 57 | */ 58 | void upload(Path file, String remotePath); 59 | } 60 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/ssh/SshClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.ssh; 16 | 17 | import java.util.Optional; 18 | 19 | public interface SshClientFactory 20 | { 21 | 22 | String DEFAULT_USER = "root"; 23 | 24 | default SshClient create(String host) { 25 | return create(host, 22, DEFAULT_USER, Optional.empty()); 26 | } 27 | 28 | default SshClient create(String host, int port) { 29 | return create(host, port, DEFAULT_USER, Optional.empty()); 30 | } 31 | 32 | default SshClient create(String host, int port, String user) { 33 | return create(host, port, user, Optional.empty()); 34 | } 35 | 36 | SshClient create(String host, int port, String user, Optional password); 37 | 38 | void addIdentity(String pathToPem); 39 | } 40 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/testmarkers/WithName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.testmarkers; 16 | 17 | import org.testng.ITest; 18 | 19 | /** 20 | * Marker interface for test classes which explicitly define dest name. 21 | */ 22 | public interface WithName 23 | extends ITest 24 | { 25 | @Override 26 | String getTestName(); 27 | } 28 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/testmarkers/WithTestGroups.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.testmarkers; 16 | 17 | import org.testng.ITest; 18 | 19 | import java.util.Set; 20 | 21 | /** 22 | * Marker interface for test classes which explicitly define list of groups test belong to. 23 | */ 24 | public interface WithTestGroups 25 | extends ITest 26 | { 27 | Set getTestGroups(); 28 | } 29 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/threads/IndexedRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.threads; 15 | 16 | /** 17 | * An interface of a runnable that has an index and can throw checked exceptions. 18 | */ 19 | @FunctionalInterface 20 | public interface IndexedRunnable 21 | { 22 | /** 23 | * @param threadIndex an index of thread that executes this {@link IndexedRunnable}. 24 | * @throws Exception if something goes wrong 25 | */ 26 | void run(int threadIndex) 27 | throws Exception; 28 | } 29 | -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/threads/ParallelExecutionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.threads; 15 | 16 | import com.google.common.base.Joiner; 17 | 18 | import java.util.List; 19 | 20 | public class ParallelExecutionException 21 | extends RuntimeException 22 | { 23 | private final List throwables; 24 | 25 | public ParallelExecutionException(List throwables) 26 | { 27 | super("Throwables when running parallel runnables:\n" + Joiner.on("-------------------\n").join(throwables)); 28 | this.throwables = throwables; 29 | } 30 | 31 | public List getThrowables() 32 | { 33 | return throwables; 34 | } 35 | } -------------------------------------------------------------------------------- /tempto-core/src/main/java/com/teradata/tempto/util/DateTimeUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.util; 16 | 17 | import org.joda.time.format.DateTimeFormat; 18 | import org.joda.time.format.DateTimeFormatter; 19 | import org.joda.time.format.DateTimeFormatterBuilder; 20 | import org.joda.time.format.DateTimeParser; 21 | import org.joda.time.format.DateTimePrinter; 22 | 23 | import java.sql.Timestamp; 24 | 25 | public class DateTimeUtils 26 | { 27 | private static DateTimeParser[] timestampWithoutTimeZoneParser = { 28 | DateTimeFormat.forPattern("yyyy-M-d").getParser(), 29 | DateTimeFormat.forPattern("yyyy-M-d H:m").getParser(), 30 | DateTimeFormat.forPattern("yyyy-M-d H:m:s").getParser(), 31 | DateTimeFormat.forPattern("yyyy-M-d H:m:s.SSS").getParser()}; 32 | private static DateTimePrinter timestampWithoutTimeZonePrinter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS").getPrinter(); 33 | private static DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder().append(timestampWithoutTimeZonePrinter, timestampWithoutTimeZoneParser).toFormatter().withZoneUTC(); 34 | 35 | private DateTimeUtils() {} 36 | 37 | /** 38 | * Parse the input date time string (pattern: yyyy-M-d H:m:s.SSS) and interpret it in UTC. 39 | * 40 | * @param value textual date time input 41 | * @return a java.sql.Timestamp object representing the input date time. 42 | */ 43 | public static Timestamp parseTimestampInUTC(String value) 44 | { 45 | return new Timestamp(DATE_TIME_FORMATTER.parseMillis(value)); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /tempto-core/src/main/resources/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor: -------------------------------------------------------------------------------- 1 | com.teradata.tempto.dns.TemptoNameServiceDescriptor 2 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/fulfillment/table/JdbcTableManagerTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.table 16 | 17 | import com.teradata.tempto.fulfillment.table.jdbc.JdbcTableDataSource 18 | import com.teradata.tempto.fulfillment.table.jdbc.JdbcTableDefinition 19 | import com.teradata.tempto.internal.configuration.EmptyConfiguration 20 | import com.teradata.tempto.internal.fulfillment.table.TableNameGenerator 21 | import com.teradata.tempto.internal.fulfillment.table.jdbc.JdbcTableManager 22 | import com.teradata.tempto.query.QueryExecutor 23 | import spock.lang.Specification 24 | 25 | import java.sql.Connection 26 | import java.sql.DatabaseMetaData 27 | import java.sql.ResultSet 28 | import java.sql.ResultSetMetaData 29 | 30 | public class JdbcTableManagerTest 31 | extends Specification 32 | { 33 | static JdbcTableDefinition tableDefinition 34 | static JdbcTableManager tableManager 35 | static String tableName 36 | 37 | def setup() 38 | { 39 | tableName = "name" 40 | tableDefinition = JdbcTableDefinition.jdbcTableDefinition(tableName, "CREATE TABLE %NAME%(col1 INT)", 41 | { Collections.>emptyList().iterator() } as JdbcTableDataSource) 42 | 43 | def mockExecutor = Mock(QueryExecutor) 44 | def mockConnection = Mock(Connection) 45 | def mockMetadata = Mock(DatabaseMetaData) 46 | mockExecutor.connection >> mockConnection 47 | mockConnection.getMetaData() >> mockMetadata 48 | 49 | def mockResultSet = Mock(ResultSet) 50 | mockMetadata.getTables(_, _, _, _) >> mockResultSet 51 | mockResultSet.getMetaData() >> Mock(ResultSetMetaData) 52 | tableManager = new JdbcTableManager(mockExecutor, new TableNameGenerator(), "db_name", EmptyConfiguration.emptyConfiguration()) 53 | } 54 | 55 | def 'table without rows does not throw'() 56 | { 57 | when: 58 | tableManager.createImmutable(tableDefinition, TableHandle.tableHandle(tableName)) 59 | 60 | then: 61 | noExceptionThrown() 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/fulfillment/table/TableDefinitionsRepositoryTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.fulfillment.table; 15 | 16 | import spock.lang.Specification; 17 | 18 | public class TableDefinitionsRepositoryTest 19 | extends Specification 20 | { 21 | 22 | def 'should add/get table definition to repository'() 23 | { 24 | setup: 25 | def tableDefinition = Mock(TableDefinition) 26 | tableDefinition.name >> "table1" 27 | 28 | def repository = new TableDefinitionsRepository() 29 | 30 | when: 31 | repository.register(tableDefinition) 32 | 33 | then: 34 | repository.getForName("table1") == tableDefinition 35 | 36 | when: 37 | repository.getForName("table2") 38 | 39 | then: 40 | def e = thrown(IllegalStateException) 41 | e.message == 'no table definition for: table2' 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/fulfillment/table/TableHandleTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.fulfillment.table 15 | 16 | import spock.lang.Specification 17 | import spock.lang.Unroll 18 | 19 | import static com.teradata.tempto.fulfillment.table.TableHandle.tableHandle 20 | 21 | class TableHandleTest 22 | extends Specification 23 | { 24 | @Unroll 25 | def 'parse #tableHandleStr to #expectedTableHandle'() 26 | { 27 | expect: 28 | TableHandle.parse(tableHandleStr) == expectedTableHandle 29 | 30 | where: 31 | tableHandleStr | expectedTableHandle 32 | 'table' | tableHandle('table') 33 | 'db.table' | tableHandle('table').inDatabase('db') 34 | 'db.sch.table' | tableHandle('table').inDatabase('db').inSchema('sch') 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/internal/DummyTestRequirement.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal 16 | 17 | import com.teradata.tempto.Requirement 18 | 19 | public final class DummyTestRequirement 20 | implements Requirement 21 | { 22 | private final String name; 23 | 24 | DummyTestRequirement(String name) 25 | { 26 | this.name = name; 27 | } 28 | 29 | public String toString() 30 | { 31 | return name; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/internal/configuration/HierarchicalConfigurationTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.configuration 16 | 17 | import com.teradata.tempto.configuration.Configuration 18 | import spock.lang.Specification 19 | 20 | import static com.google.common.collect.Sets.newHashSet 21 | 22 | class HierarchicalConfigurationTest 23 | extends Specification 24 | { 25 | 26 | def testHierarchicalConfiguration() 27 | { 28 | setup: 29 | Configuration a = new MapConfiguration([ 30 | a : 'a', 31 | ab : 'a', 32 | ac : 'a', 33 | abc: 'a', 34 | sub: [ac: 'a'] 35 | ]) 36 | 37 | Configuration b = new MapConfiguration([ 38 | b : 'b', 39 | ab : 'b', 40 | bc : 'b', 41 | abc: 'b' 42 | ]) 43 | 44 | Configuration c = new MapConfiguration([ 45 | c : 'c', 46 | ac : 'c', 47 | bc : 'c', 48 | abc: 'c', 49 | sub: [ac: 'c'] 50 | 51 | ]) 52 | 53 | when: 54 | HierarchicalConfiguration configuration = new HierarchicalConfiguration(a, b, c) 55 | 56 | then: 57 | configuration.getStringMandatory('a') == 'a' 58 | configuration.getStringMandatory('b') == 'b' 59 | configuration.getStringMandatory('c') == 'c' 60 | configuration.getStringMandatory('ab') == 'b' 61 | configuration.getStringMandatory('ac') == 'c' 62 | configuration.getStringMandatory('bc') == 'c' 63 | configuration.getStringMandatory('abc') == 'c' 64 | configuration.getStringMandatory('sub.ac') == 'c' 65 | 66 | configuration.getSubconfiguration('sub').getStringMandatory('ac') == 'c' 67 | 68 | configuration.listKeys() == newHashSet('a', 'b', 'c', 'ab', 'ac', 'bc', 'abc', 'sub.ac') 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/internal/configuration/KeyUtilsTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.configuration 16 | 17 | import spock.lang.Specification 18 | 19 | import static com.teradata.tempto.configuration.KeyUtils.getKeyPrefix 20 | import static com.teradata.tempto.configuration.KeyUtils.joinKey 21 | import static com.teradata.tempto.configuration.KeyUtils.splitKey 22 | 23 | class KeyUtilsTest 24 | extends Specification 25 | { 26 | def "test split key"() 27 | { 28 | expect: 29 | splitKey('abc') == ['abc'] 30 | splitKey('a.b.c') == ['a', 'b', 'c'] 31 | } 32 | 33 | def "join key"() 34 | { 35 | expect: 36 | joinKey(['a', 'b', 'c']) == 'a.b.c' 37 | joinKey(['a', null, 'c']) == 'a.c' 38 | joinKey([null , 'b', 'c']) == 'b.c' 39 | joinKey('a' , 'b', 'c') == 'a.b.c' 40 | } 41 | 42 | def "get key prefix"() 43 | { 44 | expect: 45 | getKeyPrefix('a.b.c', 1) == 'a' 46 | getKeyPrefix('a.b.c', 2) == 'a.b' 47 | getKeyPrefix('a.b.c', 3) == 'a.b.c' 48 | getKeyPrefix('a.b.c', 4) == 'a.b.c' 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/internal/configuration/TestConfigurationFactoryTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.configuration 16 | 17 | import com.teradata.tempto.configuration.Configuration 18 | import spock.lang.Specification 19 | 20 | import static com.teradata.tempto.internal.configuration.TestConfigurationFactory.LOCAL_TEST_CONFIGURATION_URI_KEY 21 | import static com.teradata.tempto.internal.configuration.TestConfigurationFactory.TEST_CONFIGURATION_URI_KEY 22 | 23 | class TestConfigurationFactoryTest 24 | extends Specification 25 | { 26 | 27 | def 'read test configuration'() { 28 | setup: 29 | System.setProperty(TEST_CONFIGURATION_URI_KEY, "/configuration/global-configuration-tempto.yaml"); 30 | System.setProperty(LOCAL_TEST_CONFIGURATION_URI_KEY, "/configuration/local-configuration-tempto.yaml"); 31 | 32 | when: 33 | Configuration configuration = TestConfigurationFactory.createTestConfiguration() 34 | 35 | then: 36 | configuration.getStringMandatory('value.local') == 'local' 37 | configuration.getStringMandatory('value.both') == 'local' 38 | configuration.getStringMandatory('value.global') == 'global' 39 | configuration.getStringMandatory('value.default') == 'default_value' 40 | 41 | configuration.getStringMandatory('resolve.local') == 'local' 42 | configuration.getStringMandatory('resolve.both') == 'local' 43 | configuration.getStringMandatory('resolve.global') == 'global' 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/internal/configuration/YamlConfigurationTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.configuration 16 | 17 | import spock.lang.Specification 18 | 19 | class YamlConfigurationTest 20 | extends Specification 21 | { 22 | 23 | def create() 24 | { 25 | setup: 26 | def configuration = new YamlConfiguration("""\ 27 | a: 28 | b: 29 | d: ela\${foo} 30 | x: 31 | y: 10 32 | list: 33 | - element1 34 | - element2 35 | """) 36 | expect: 37 | configuration.listKeys() == ['a.b.d', 'x.y', 'list'] as Set 38 | configuration.getInt('x.y') == Optional.of(10) 39 | configuration.getString('a.b.d') == Optional.of('ela${foo}') 40 | configuration.getString('x.y') == Optional.of('10') 41 | configuration.getStringList('list') == ['element1', 'element2'] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/internal/query/QueryRowMapperTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.internal.query 15 | 16 | import com.google.common.collect.ImmutableList 17 | import spock.lang.Specification 18 | import spock.lang.Unroll 19 | 20 | import java.sql.JDBCType 21 | 22 | class QueryRowMapperTest 23 | extends Specification 24 | { 25 | 26 | @Unroll 27 | def 'convert binary #value'() 28 | { 29 | setup: 30 | QueryRowMapper rowMapper = new QueryRowMapper(ImmutableList.of(JDBCType.BINARY)) 31 | 32 | expect: 33 | rowMapper.mapToRow(ImmutableList.of(value)).getValues()[0] == expected 34 | 35 | where: 36 | value | expected 37 | '0000' | bytes(0x00, 0x00) 38 | '0ab0' | bytes(0x0a, 0xb0) 39 | } 40 | 41 | def 'should fail when incorrect hex'() 42 | { 43 | setup: 44 | QueryRowMapper rowMapper = new QueryRowMapper(ImmutableList.of(JDBCType.BINARY)) 45 | 46 | when: 47 | rowMapper.mapToRow(ImmutableList.of('1a0')) 48 | 49 | then: 50 | thrown(IllegalArgumentException) 51 | } 52 | 53 | private byte[] bytes(int ... bytes) 54 | { 55 | return bytes 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/internal/ssh/TestCommand.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.internal.ssh 15 | 16 | import org.apache.sshd.server.Command 17 | import org.apache.sshd.server.Environment 18 | import org.apache.sshd.server.ExitCallback 19 | 20 | class TestCommand 21 | implements Command 22 | { 23 | private final String response; 24 | private final int errorCode; 25 | 26 | private InputStream input; 27 | private OutputStream output; 28 | private OutputStream error; 29 | private ExitCallback callback; 30 | 31 | public TestCommand(String response, int errorCode) 32 | { 33 | this.response = response; 34 | this.errorCode = errorCode; 35 | } 36 | 37 | public void setInputStream(InputStream input) 38 | { 39 | this.input = input; 40 | } 41 | 42 | public void setOutputStream(OutputStream out) 43 | { 44 | this.output = out; 45 | } 46 | 47 | public void setErrorStream(OutputStream err) 48 | { 49 | this.error = err; 50 | } 51 | 52 | public void setExitCallback(ExitCallback callback) 53 | { 54 | this.callback = callback; 55 | } 56 | 57 | public void start(Environment env) 58 | throws IOException 59 | { 60 | output.write(response.getBytes()); 61 | output.flush(); 62 | callback.onExit(errorCode, response); 63 | } 64 | 65 | public void destroy() 66 | { 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/process/JavaProcessLauncherTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.process 15 | 16 | import spock.lang.Specification 17 | 18 | import static JavaProcessLauncher.defaultJavaProcessLauncher 19 | import static com.teradata.tempto.process.TestClassWithMain.* 20 | 21 | class JavaProcessLauncherTest 22 | extends Specification 23 | { 24 | def 'test execute CLI Java process'() 25 | throws IOException, InterruptedException 26 | { 27 | setup: 28 | LocalCliProcess child = new LocalCliProcess(defaultJavaProcessLauncher().launch(TestClassWithMain.class, [EXPECTED_ARGUMENT])) 29 | child.getProcessInput().println(EXPECTED_LINE) 30 | 31 | expect: 32 | child.readRemainingOutputLines() == [PRODUCED_LINE] 33 | child.waitForWithTimeoutAndKill() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/process/TestClassWithMain.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.process 15 | 16 | import static org.assertj.core.api.Assertions.assertThat 17 | 18 | class TestClassWithMain 19 | { 20 | public static final String EXPECTED_ARGUMENT = "foo"; 21 | public static final String EXPECTED_LINE = "hello"; 22 | public static final String PRODUCED_LINE = "world"; 23 | 24 | public static void main(String[] args) 25 | { 26 | assertThat(args.length).isEqualTo(1) 27 | assertThat(args[0]).isEqualTo(EXPECTED_ARGUMENT) 28 | 29 | Scanner scanner = new Scanner(System.in) 30 | assertThat(scanner.nextLine()).isEqualTo(EXPECTED_LINE) 31 | System.out.println(PRODUCED_LINE) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/query/QueryResultTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.query 16 | 17 | import spock.lang.Specification 18 | 19 | import java.sql.JDBCType 20 | import java.sql.ResultSet 21 | 22 | class QueryResultTest 23 | extends Specification 24 | { 25 | def "test QueryResult project"() 26 | { 27 | setup: 28 | def jdbcResultSet = Mock(ResultSet) 29 | def columnTypes = [JDBCType.CHAR, JDBCType.DOUBLE, JDBCType.INTEGER] 30 | def columnNames = ['char', 'double', 'integer'] 31 | def builder = new QueryResult.QueryResultBuilder(columnTypes, columnNames) 32 | builder.addRow('aaa', 1.0, 1) 33 | builder.addRow('bbb', 2.0, 2) 34 | builder.setJdbcResultSet(jdbcResultSet) 35 | def queryResult = builder.build() 36 | def projection = queryResult.project(1, 3) 37 | 38 | expect: 39 | projection.rows() == [['aaa', 1], ['bbb', 2]] 40 | projection.columnsCount == 2 41 | projection.column(1) == ['aaa', 'bbb'] 42 | projection.column(2) == [1, 2] 43 | projection.getJdbcResultSet().get() == jdbcResultSet 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/sql/view/ContextDslTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.sql.view 16 | 17 | import com.teradata.tempto.context.ContextDsl 18 | import com.teradata.tempto.context.ContextRunnable 19 | import com.teradata.tempto.internal.configuration.TestConfigurationFactory 20 | import com.teradata.tempto.query.QueryExecutor 21 | import com.teradata.tempto.query.QueryResult 22 | import spock.lang.Specification 23 | 24 | import static com.teradata.tempto.internal.configuration.TestConfigurationFactory.TEST_CONFIGURATION_URI_KEY 25 | import static com.teradata.tempto.query.QueryType.UPDATE 26 | 27 | class ContextDslTest 28 | extends Specification 29 | { 30 | def setupSpec() 31 | { 32 | System.setProperty(TEST_CONFIGURATION_URI_KEY, "/configuration/global-configuration-tempto.yaml"); 33 | } 34 | 35 | def 'executeWithView'() 36 | { 37 | setup: 38 | String viewName = "test_view"; 39 | String selectSql = "SELECT * FROM nation" 40 | ContextRunnable testRunnable = Mock(ContextRunnable) 41 | QueryExecutor queryExecutor = Mock(QueryExecutor) 42 | queryExecutor.executeQuery("DROP VIEW test_view", UPDATE) >> QueryResult.forSingleIntegerValue(1) 43 | queryExecutor.executeQuery("CREATE VIEW test_view AS SELECT * FROM nation", UPDATE) >> QueryResult.forSingleIntegerValue(1) 44 | queryExecutor.executeQuery("DROP VIEW test_view", UPDATE) >> QueryResult.forSingleIntegerValue(1) 45 | 46 | ViewContextProvider contextProvider = new ViewContextProvider(viewName, selectSql, queryExecutor) 47 | 48 | when: 49 | ContextDsl.executeWith(contextProvider, testRunnable) 50 | 51 | then: 52 | 1 * testRunnable.run(_) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tempto-core/src/test/groovy/com/teradata/tempto/util/DateTimeUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.util; 16 | 17 | import org.assertj.core.api.Assertions; 18 | import org.testng.annotations.Test; 19 | 20 | import java.sql.Timestamp; 21 | 22 | import static com.teradata.tempto.util.DateTimeUtils.parseTimestampInUTC; 23 | import static org.assertj.core.api.Assertions.assertThat; 24 | import static org.testng.Assert.*; 25 | 26 | public class DateTimeUtilsTest 27 | { 28 | 29 | @Test 30 | public void shouldParseMultipleFormatsInUTC() 31 | throws Exception 32 | { 33 | assertThat(parseTimestampInUTC("2015-05-10 12:15:35.123").getTime()).isEqualTo(1431260135123l); 34 | assertThat(parseTimestampInUTC("2015-05-10 12:15:35").getTime()).isEqualTo(1431260135000l); 35 | assertThat(parseTimestampInUTC("2015-05-10 12:15").getTime()).isEqualTo(1431260100000l); 36 | assertThat(parseTimestampInUTC("2015-05-10").getTime()).isEqualTo(1431216000000l); 37 | } 38 | } -------------------------------------------------------------------------------- /tempto-core/src/test/resources/configuration/global-configuration-tempto.yaml: -------------------------------------------------------------------------------- 1 | value: 2 | default: ${not.exisiting.key:-default_value} 3 | both: global 4 | global: global 5 | 6 | resolve: 7 | both: ${value.both} 8 | global: ${value.global} 9 | local: ${value.local} 10 | -------------------------------------------------------------------------------- /tempto-core/src/test/resources/configuration/local-configuration-tempto.yaml: -------------------------------------------------------------------------------- 1 | value: 2 | both: local 3 | local: local 4 | -------------------------------------------------------------------------------- /tempto-core/src/test/resources/convention/sample-test/query1.result: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teradata/tempto/28d4d5fdc83b0fc4e03562c7d6a8926df510860b/tempto-core/src/test/resources/convention/sample-test/query1.result -------------------------------------------------------------------------------- /tempto-core/src/test/resources/convention/sample-test/query1.sql: -------------------------------------------------------------------------------- 1 | -- groups: tpch,quarantine -------------------------------------------------------------------------------- /tempto-core/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | # 14 | 15 | # Set root logger to INFO and add a custom appender. 16 | log4j.rootLogger=TRACE, TEST_FRAMEWORK_LOGGING_APPENDER, CONSOLE 17 | log4j.appender.TEST_FRAMEWORK_LOGGING_APPENDER=com.teradata.logging.TestFrameworkLoggingAppender 18 | 19 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 20 | log4j.appender.CONSOLE.Target=System.out 21 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 22 | log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L [%X{test_id}] - %m%n 23 | 24 | 25 | log4j.category.org.apache.http=INFO 26 | log4j.category.com.jayway.jsonpath=WARN 27 | log4j.category.org.apache.thrift=WARN 28 | log4j.category.org.apache.hive=WARN 29 | log4j.category.org.reflections=WARN 30 | -------------------------------------------------------------------------------- /tempto-core/src/test/resources/ssh/ssh.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpQIBAAKCAQEAqACaXCACnn8FmwklRVq56p/PgEAPbt5NbXDzKxmHtqbzkvPL 3 | UJZIaeCrvjbAUxj8mrl2LqYIsPTAIhmzWL08XjVpBRVSbNemYPJ6P28IN699qjmw 4 | 9SSqRZXahRni7hhFwGZfAQJool9dbxGycEbGTmwOmSZB07l3yKBlJffSys0jSzTz 5 | Hnz0ZA50aVNGfs2nIPY4JFpJmn5MDYjT4naH6eJ/TPws6+BjyGwrkgSTlmE/E6Fi 6 | UeJyDhdSV0OLeL+pHH1/LAWy1XrOZXEYgRfxTP51tBRqSsL431aQVEV3p8AFmyzu 7 | LtoyqhkZlkhpnNiEoK/Es/8yGl1tw1NwtZXLtQIDAQABAoIBAQCds8syNT4gJ95M 8 | NR6OZubkblVq7zdNfFG0LPWmfJWfiEJWrJEquZeKA8NTj7OjjW35k6Rzj5nS+jyt 9 | BfELmL9lM7+8bNJtp1Tf5l2I1CIjm5FbzEHnLB7FqTByBuW1WIWJYM9HdEpiOSDM 10 | 1RDqQhV+ogJmErpyE8R0SNQJ+wMdKEPd8OO8ClPEMz+EJNZhPFI/N/eLlzFdkWBX 11 | FW4MUNO1kzH+y14UB/PK0ndkLQMRLNPFLEHUM45wWPhMwqaKNYazL3iWMw/4ysnS 12 | vP6j59ZJL6uGYlk/CZJpx9WPRc8R6bBd6SFYdsRdY36xLhYSy+xsXM2M024w5OuC 13 | ZSlr2jE1AoGBANGKCfccNBQZW6brkqENzGrocv4V2mM8w/IS9j9Xx2IxjSn7XHDB 14 | XE1SVSXbTxKRghTNyp7Ke0EDnBn8hDjAZ+kj+6T7SEE6a88dn0Cvg5QG0s4XM6m0 15 | fubOMclVnGbf0Ja50qnUgShvpMFqNZI6rOVuu5BOuXBWY07jotx/im3TAoGBAM1A 16 | 1GwMab42a5huzKhlSa113KvMuylOWUoGzKrheAwY30H6Iovo6JWR0vNcEMb7glwU 17 | YJ2eD1KdZigyfKDjB37AaoiCYM/qCYXCdWbo/Caj3NyGEf6jj+NL5XDQP2qog6IQ 18 | 7lea1/TmpFlZ5iB/j9Et/t3Hg06N0jqB/aOTGwNXAoGBAJQdBABFUlamug9aUzI+ 19 | o7EqECakYdNl34fceW266XfyWLtFL0mQlGMfgIqa4+DXM+Dqun/V1pvVJmGECh5n 20 | esvkoHs1GBTra8tiP/CkX9ihnh8JbX5W1KDnPW/4cO6S5Em2nj9ns8hWalpBbg6o 21 | JRCkXjaaPyA2IEpiQ/uit8H7AoGAVB858H616AuN1Y+zuWCp7bnck1z5aFiAJ+LZ 22 | hz+ZX/vhpLzL4+O1T3fQqYUWKzdxmiOP5YmeZhG0iM0IXzgtHjnmb8RfwVb+SCAG 23 | 1gKvNXb7UjZwsZh/pHy6sJ3pH+Go8YdW5/jCgdD1ktlRhAhD/UuIpYTbwBpIC0qz 24 | lZL5A0kCgYEAq5DTU6hI4J1OaGKzNMKl5M3Stu9rstjtAVxu3HTt9/+OSA4Q7a6n 25 | fIt22PcLwQKJ9/DUGTT2r9BdPRwe0d2H45slBN0SelY4u9WUcKSfYRvEGMvrI2n1 26 | 8POWoOlZKLMFs2xtqO+SnErU4cUAhL09r+Ppinak4LYP5kBI0VRVpvc= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /tempto-core/src/test/resources/ssh/ssh.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoAJpcIAKefwWbCSVFWrnqn8+AQA9u3k1tcPMrGYe2pvOS88tQlkhp4Ku+NsBTGPyauXYupgiw9MAiGbNYvTxeNWkFFVJs16Zg8no/bwg3r32qObD1JKpFldqFGeLuGEXAZl8BAmiiX11vEbJwRsZObA6ZJkHTuXfIoGUl99LKzSNLNPMefPRkDnRpU0Z+zacg9jgkWkmafkwNiNPidofp4n9M/Czr4GPIbCuSBJOWYT8ToWJR4nIOF1JXQ4t4v6kcfX8sBbLVes5lcRiBF/FM/nW0FGpKwvjfVpBURXenwAWbLO4u2jKqGRmWSGmc2ISgr8Sz/zIaXW3DU3C1lcu1 kogut@haxu 2 | -------------------------------------------------------------------------------- /tempto-examples/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | plugins { 16 | id 'java' // or 'groovy' Must be explicitly applied 17 | id 'com.github.johnrengelman.shadow' version '1.2.2' 18 | } 19 | 20 | apply plugin: 'com.github.johnrengelman.shadow' 21 | apply plugin: 'java' 22 | 23 | dependencies { 24 | compile tempto_runner 25 | compile libraries.slf4j_api 26 | 27 | runtime tempto_logging_log4j 28 | runtime libraries.slf4j_log4j 29 | runtime libraries.postgresql_jdbc 30 | runtime libraries.presto_jdbc 31 | runtime libraries.hive_jdbc 32 | } 33 | 34 | jar { 35 | manifest { 36 | attributes 'Main-Class': 'com.teradata.tempto.examples.TemptoExamples' 37 | } 38 | } 39 | 40 | shadowJar { 41 | version = '' 42 | } 43 | 44 | build.dependsOn.add([shadowJar]) 45 | 46 | license { 47 | exclude "sql-tests/**/*.sql" 48 | } 49 | -------------------------------------------------------------------------------- /tempto-examples/docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | hadoop-master: 4 | hostname: hadoop-master 5 | image: 'teradatalabs/cdh5-hive:4' 6 | ports: 7 | - '1080:1080' 8 | - '8020:8020' 9 | - '8088:8088' 10 | - '9083:9083' 11 | - '10000:10000' 12 | - '50070:50070' 13 | - '50075:50075' 14 | 15 | psql1: 16 | hostname: psql1 17 | image: 'postgres' 18 | ports: 19 | - '15432:5432' 20 | environment: 21 | POSTGRES_USER: blah 22 | POSTGRES_PASSWORD: blah 23 | 24 | psql2: 25 | hostname: psql2 26 | image: 'postgres' 27 | ports: 28 | - '15433:5432' 29 | environment: 30 | POSTGRES_USER: blah 31 | POSTGRES_PASSWORD: blah 32 | 33 | ssh: 34 | hostname: ssh 35 | build: 'ssh' 36 | ports: 37 | - '2222:22' 38 | 39 | presto-master: 40 | hostname: presto-master 41 | build: 'presto-server' 42 | ports: 43 | - '8080:8080' 44 | depends_on: 45 | - 'hadoop-master' 46 | - 'psql1' 47 | - 'psql2' 48 | 49 | presto-cli: 50 | build: 'presto-cli' 51 | depends_on: 52 | - 'presto-master' 53 | 54 | runner: 55 | image: 'teradatalabs/centos6-java8-oracle' 56 | ports: 57 | - '5005:5005' 58 | volumes: 59 | - '..:/workspace' 60 | depends_on: 61 | - 'presto-master' 62 | 63 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-cli/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM teradatalabs/centos6-java8-oracle 2 | MAINTAINER Grzegorz Kokosiński 3 | 4 | RUN curl -SL http://central.maven.org/maven2/com/facebook/presto/presto-cli/0.151/presto-cli-0.151-executable.jar -o presto-cli.jar 5 | 6 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM teradatalabs/centos6-java8-oracle 2 | MAINTAINER Grzegorz Kokosiński 3 | 4 | RUN yum install -y tar 5 | 6 | RUN curl -SL http://central.maven.org/maven2/com/facebook/presto/presto-server/0.151/presto-server-0.151.tar.gz \ 7 | | tar xz \ 8 | && mv $(find -type d -name 'presto-server*') presto-server 9 | 10 | RUN mkdir /presto-server/etc 11 | 12 | COPY etc /presto-server/etc/ 13 | 14 | CMD /presto-server/bin/launcher run 15 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/etc/catalog/blackhole.properties: -------------------------------------------------------------------------------- 1 | connector.name=blackhole 2 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/etc/catalog/hive.properties: -------------------------------------------------------------------------------- 1 | connector.name=hive-cdh5 2 | hive.metastore.uri=thrift://hadoop-master:9083 3 | hive.allow-drop-table=true 4 | hive.allow-rename-table=true 5 | hive.metastore-cache-ttl=0s 6 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/etc/catalog/jmx.properties: -------------------------------------------------------------------------------- 1 | connector.name=jmx 2 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/etc/catalog/psql.properties: -------------------------------------------------------------------------------- 1 | connector.name=postgresql 2 | connection-url=jdbc:postgresql://psql1:5432/postgres 3 | connection-user=blah 4 | connection-password=blah 5 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/etc/catalog/psql2.properties: -------------------------------------------------------------------------------- 1 | connector.name=postgresql 2 | connection-url=jdbc:postgresql://psql2:5432/postgres 3 | connection-user=blah 4 | connection-password=blah 5 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/etc/catalog/tpch.properties: -------------------------------------------------------------------------------- 1 | connector.name=tpch 2 | tpch.splits-per-node=4 3 | 4 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/etc/config.properties: -------------------------------------------------------------------------------- 1 | node.id=presto-master 2 | node.environment=test 3 | 4 | coordinator=true 5 | node-scheduler.include-coordinator=true 6 | http-server.http.port=8080 7 | query.max-memory=256MB 8 | query.max-memory-per-node=128MB 9 | discovery-server.enabled=true 10 | discovery.uri=http://presto-master:8080 11 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/etc/jvm.config: -------------------------------------------------------------------------------- 1 | -server 2 | -Xmx512M 3 | -XX:+UseG1GC 4 | -XX:+UseGCOverheadLimit 5 | -XX:+ExplicitGCInvokesConcurrent 6 | -XX:+CMSClassUnloadingEnabled 7 | -XX:+AggressiveOpts 8 | -XX:+HeapDumpOnOutOfMemoryError 9 | -XX:OnOutOfMemoryError=kill -9 %p 10 | -DHADOOP_USER_NAME=hive 11 | -Duser.timezone=UTC 12 | -Xdebug 13 | -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 14 | -------------------------------------------------------------------------------- /tempto-examples/docker/presto-server/etc/log.properties: -------------------------------------------------------------------------------- 1 | com.facebook.presto=INFO 2 | com.sun.jersey.guice.spi.container.GuiceComponentProviderFactory=WARN 3 | com.ning.http.client=DEBUG 4 | com.facebook.presto.server.PluginManager=DEBUG 5 | io.airlift.discovery.client=INFO 6 | -------------------------------------------------------------------------------- /tempto-examples/docker/ssh/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM teradatalabs/centos6-java8-oracle 2 | MAINTAINER Grzegorz Kokosiński 3 | 4 | RUN yum install -y openssh-server openssh-clients passwd 5 | RUN echo s3cr37_p@55 | passwd --stdin root 6 | 7 | RUN mkdir /var/run/sshd && mkdir /root/.ssh 8 | 9 | RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' 10 | 11 | COPY keys/key.pub /root/.ssh/authorized_keys 12 | 13 | RUN chmod 400 /root/.ssh/authorized_keys 14 | 15 | EXPOSE 22 16 | 17 | CMD /usr/sbin/sshd -D 18 | -------------------------------------------------------------------------------- /tempto-examples/docker/ssh/keys/key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAnQ2UUCYAq5cqmO+hdKv2UoO6CSBQGhp+bp5B8P3ZArhz/NkQ 3 | ZMWp5haW82mBn5d7ioTGUHQWttqs5WQbUsOFbpQydYI5d2YUBHc6g9c6QFBDjx8C 4 | sJ0cpfkczeRsCoXu6a+VboXl2BPD7jGXSSGJQxFrKGzhywg1NOKaOklmljYKz3gS 5 | 3BLGiBeJ04oceUMTKLKWs7UEnNqBaV/7y0GqYnhWsvxNKYvzkCuZEavYyLU+H6JA 6 | l/03HbKmUesPUSaurfk67/VHEH1vXICFnNvQ/LB9mvZJpcmuOFTdG0mukdta7rad 7 | kVNCHp6xrq5h6RCHA3Ivx7yP3HIDjvRPdV694wIDAQABAoIBAFFTo9axJy2z9OIH 8 | TPNOzRpDjkWFjxVFXO1JVFpICWVIQP/RI5UbanR0hCx+GRqcZeQAB3XH968uo9OR 9 | uDhueR0e7tY83ic/G+SIHSwCeu6s4Z8ubsUoRpqH2muf+nakjmhCfT4jZjczXQVu 10 | dqnvDNZHIddoMrBhirPdGAJQ2iez+sm+R57rYxPYuf5HCUISxtdBGLBHuffz6Hok 11 | ydSqmt3gkS3aYvqtA+yKcDxDJsGCx/VX2dXZANOeBm0gcgTl92IW8jOfldWJl4ZU 12 | 7GW655Yc6pnMJNr6FsIKzUUOAnAGeN8xcLMyx3f8zKIJSgmOsvgMvOeMRfnX18TP 13 | O5mjXVkCgYEAy7pT9/1VaDpDsqlUl2d8YYVXykA2LLhgH/ozBjJBSDlQO1Njb7Bf 14 | SYb50hrVUAB1un73QUMZgw1UKdwzlQWdLSbrQdnAu27oTW++XScaB3qJJ4F1++hm 15 | kERGL3CUIcModd7pr6oVcljxsqvSM/P6FTAI7fz/bjVkVWLz8sZSt+UCgYEAxVl2 16 | BBCd1kekteng+hyhfZS4kikZdVNQYiC8yhOQLdYQHlekYpk90DdjLjhq1lLBecZm 17 | xB5Gy7kOM5ja0y8LvY6zevT8W9ukC5rCJw1PFmfUuxe5DiIN2yfYlRdv/wtTYZNP 18 | Qds8fnil8Do03dkFTVUyh7HC5AHRHg7cfXnSMicCgYA2vtRPoKDxyC5m9T/JC8MN 19 | xbJIpCaqr8UM8sQBV0HZsaUQvCDNY5zHemDph9JolCcOvY2d2PUjFVLXiNfHpOGO 20 | v5WadXRoKa59GJkUGSzSc6glmJFm5xWgkOg3WU5FIFdgDU3IqbDnsGUKuUdcNKSw 21 | St8rbMALEofqthON2qNhzQKBgQCmQhP2oLkYSQsuZnauv2gdkClemVllSmcyBDqI 22 | U6rnsquppFRM7KTywXbA/a6kGNv+Z3M0Tf1+q8yXE3Nm7v+JFquGLtZb3NJ7JEnk 23 | 9IVobtj9NaMlkPLzasI/+JrV1wjL73qaFMUGF0ZU9/SJ4cdhuyDyyINT62PtWr/O 24 | xc6biQKBgGT3rab4YTD/L3LKJfCYnojRLAfqJKYeQSjrlSHgoj61OGuH05tJ2fZG 25 | OOyScySWsqUUEqkd0IJ/3uVHPjGrff/CraerTW8xHSrQcImdm2d7p2IP2CMUUC0p 26 | H/jEYfrjCTz9TShBjtxbv1O/85tJRKl6Irtu9J+tLGkByeK/qQ/8 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /tempto-examples/docker/ssh/keys/key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCdDZRQJgCrlyqY76F0q/ZSg7oJIFAaGn5unkHw/dkCuHP82RBkxanmFpbzaYGfl3uKhMZQdBa22qzlZBtSw4VulDJ1gjl3ZhQEdzqD1zpAUEOPHwKwnRyl+RzN5GwKhe7pr5VuheXYE8PuMZdJIYlDEWsobOHLCDU04po6SWaWNgrPeBLcEsaIF4nTihx5QxMospaztQSc2oFpX/vLQapieFay/E0pi/OQK5kRq9jItT4fokCX/TcdsqZR6w9RJq6t+Trv9UcQfW9cgIWc29D8sH2a9kmlya44VN0bSa6R21rutp2RU0IenrGurmHpEIcDci/HvI/ccgOO9E91Xr3j kogut@haxu 2 | -------------------------------------------------------------------------------- /tempto-examples/docker/tempto-configuration-docker-local.yaml: -------------------------------------------------------------------------------- 1 | cluster: 2 | presto: presto-master 3 | hadoop: hadoop-master 4 | psql1: psql1 5 | psql2: psql2 6 | ssh: ssh 7 | 8 | psql1: 9 | port: 5432 10 | psql2: 11 | port: 5432 12 | 13 | ssh: 14 | identity: /workspace/docker/ssh/keys/key 15 | roles: 16 | host_by_identity: 17 | user: root 18 | host_by_password: 19 | user: root 20 | password: s3cr37_p@55 21 | -------------------------------------------------------------------------------- /tempto-examples/docker/tempto-configuration-local.yaml: -------------------------------------------------------------------------------- 1 | hosts: 2 | hadoop-master: ${DOCKER_MACHINE} 3 | ssh: 4 | identity: ssh/keys/key 5 | roles: 6 | host_by_identity: 7 | port: 2222 8 | user: root 9 | host_by_password: 10 | port: 2222 11 | user: root 12 | password: s3cr37_p@55 13 | -------------------------------------------------------------------------------- /tempto-examples/src/main/java/com/teradata/tempto/examples/HostNameMappingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.teradata.tempto.examples; 15 | 16 | import com.teradata.tempto.ProductTest; 17 | import org.testng.annotations.Test; 18 | 19 | import java.net.Inet4Address; 20 | import java.net.UnknownHostException; 21 | 22 | import static org.assertj.core.api.Assertions.assertThat; 23 | 24 | public class HostNameMappingTest 25 | extends ProductTest 26 | { 27 | @Test(groups = "dns") 28 | public void localhostAlias() 29 | throws UnknownHostException 30 | { 31 | assertThat(Inet4Address.getAllByName("localhost_alias")).isEqualTo(Inet4Address.getAllByName("localhost")); 32 | assertThat(Inet4Address.getAllByName("teradata_alias")).isEqualTo(Inet4Address.getAllByName("teradata.com")); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tempto-examples/src/main/java/com/teradata/tempto/examples/InjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.examples; 16 | 17 | import com.google.inject.Inject; 18 | import com.teradata.tempto.AfterTestWithContext; 19 | import com.teradata.tempto.BeforeTestWithContext; 20 | import com.teradata.tempto.ProductTest; 21 | import com.teradata.tempto.fulfillment.table.ImmutableTablesState; 22 | import com.teradata.tempto.fulfillment.table.MutableTablesState; 23 | import org.testng.annotations.Test; 24 | 25 | import javax.inject.Named; 26 | 27 | import static org.assertj.core.api.Assertions.assertThat; 28 | 29 | public class InjectionTest 30 | extends ProductTest 31 | { 32 | @Inject 33 | MutableTablesState mutableTablesState; 34 | 35 | @BeforeTestWithContext 36 | @Inject 37 | public void setUp( 38 | ImmutableTablesState immutableTablesState, 39 | @Named("hdfs.username") String hdfsUsername 40 | ) 41 | { 42 | testMethodInjection(immutableTablesState, hdfsUsername); 43 | } 44 | 45 | @Inject 46 | @Test(groups = "injection") 47 | public void testInjection() 48 | { 49 | assertThat(mutableTablesState).isNotNull(); 50 | } 51 | 52 | @AfterTestWithContext 53 | @Inject 54 | public void tearDown( 55 | ImmutableTablesState immutableTablesState, 56 | @Named("hdfs.username") String hdfsUsername 57 | ) 58 | { 59 | testMethodInjection(immutableTablesState, hdfsUsername); 60 | } 61 | 62 | private void testMethodInjection(ImmutableTablesState immutableTablesState, String hdfsUsername) 63 | { 64 | assertThat(immutableTablesState).isNotNull(); 65 | assertThat(hdfsUsername).isEqualTo("hdfs"); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tempto-examples/src/main/java/com/teradata/tempto/examples/TemptoExamples.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.examples; 16 | 17 | import com.teradata.tempto.runner.TemptoRunner; 18 | import com.teradata.tempto.runner.TemptoRunnerCommandLineParser; 19 | 20 | import static com.teradata.tempto.internal.configuration.TestConfigurationFactory.DEFAULT_TEST_CONFIGURATION_LOCATION; 21 | 22 | public class TemptoExamples 23 | { 24 | public static void main(String[] args) 25 | { 26 | TemptoRunnerCommandLineParser parser = TemptoRunnerCommandLineParser 27 | .builder("tempto examples") 28 | .setTestsPackage("com.teradata.tempto.examples", false) 29 | .setConfigFile(DEFAULT_TEST_CONFIGURATION_LOCATION, true) 30 | .build(); 31 | TemptoRunner.runTempto(parser, args); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tempto-examples/src/main/java/com/teradata/tempto/examples/TpchDataSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.examples; 16 | 17 | import com.teradata.tempto.ProductTest; 18 | import com.teradata.tempto.fulfillment.table.hive.tpch.TpchDataSource; 19 | import com.teradata.tempto.hadoop.hdfs.HdfsClient; 20 | import com.teradata.tempto.internal.fulfillment.table.hive.tpch.TpchEntityByteSource; 21 | import io.airlift.tpch.TpchEntity; 22 | import org.apache.commons.io.IOUtils; 23 | import org.testng.annotations.Test; 24 | 25 | import java.io.IOException; 26 | 27 | import static com.teradata.tempto.context.ThreadLocalTestContextHolder.testContext; 28 | import static com.teradata.tempto.fulfillment.table.hive.tpch.TpchTable.REGION; 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | 31 | public class TpchDataSourceTest 32 | extends ProductTest 33 | { 34 | 35 | @Test(groups = "example_smoketest") 36 | public void testDataSource() 37 | throws IOException 38 | { 39 | TpchDataSource dataSource = new TpchDataSource(REGION, 1.0); 40 | 41 | String path = "/tempto/" + dataSource.getPathSuffix(); 42 | 43 | assertThat(path).isEqualTo("/tempto/tpch/sf-1_00/REGION"); 44 | 45 | HdfsClient hdfsClient = testContext().getDependency(HdfsClient.class); 46 | 47 | Iterable generator = REGION.getTpchTableEntity().createGenerator(1.0, 1, 1); 48 | String expectedData = IOUtils.toString(new TpchEntityByteSource<>(generator).openStream()); 49 | hdfsClient.saveFile(path + "/data_0", new TpchEntityByteSource<>(generator).openStream()); 50 | String storedData = hdfsClient.loadFile(path + "/data_0"); 51 | 52 | assertThat(expectedData).isEqualTo(storedData); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | # 14 | 15 | log4j.rootLogger=INFO, TEST_FRAMEWORK_LOGGING_APPENDER, CONSOLE 16 | log4j.appender.TEST_FRAMEWORK_LOGGING_APPENDER=com.teradata.logging.TestFrameworkLoggingAppender 17 | log4j.appender.TEST_FRAMEWORK_LOGGING_APPENDER.layout=org.apache.log4j.PatternLayout 18 | log4j.appender.TEST_FRAMEWORK_LOGGING_APPENDER.layout.conversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] [%p] %c{10}: %m%n 19 | 20 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 21 | log4j.appender.CONSOLE.Target=System.out 22 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 23 | log4j.appender.CONSOLE.layout.conversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] [%X{test_id}] %m%n 24 | log4j.appender.CONSOLE.Threshold=INFO 25 | 26 | log4j.category.com.teradata.tempto=DEBUG 27 | log4j.category.org.reflections=WARN 28 | 29 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/datasets/no_data_jdbc_table.ddl: -------------------------------------------------------------------------------- 1 | -- type: jdbc 2 | CREATE TABLE %NAME% ( 3 | id INT, 4 | name VARCHAR(100) 5 | ) 6 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/datasets/sample_hive_table.data: -------------------------------------------------------------------------------- 1 | 1|A| 2 | 2|B| 3 | 3|C| 4 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/datasets/sample_hive_table.data-revision: -------------------------------------------------------------------------------- 1 | v.1.0 2 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/datasets/sample_hive_table.ddl: -------------------------------------------------------------------------------- 1 | -- type: hive 2 | CREATE TABLE %NAME% ( 3 | id INT, 4 | name STRING 5 | ) 6 | ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' 7 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/datasets/sample_jdbc_table.data: -------------------------------------------------------------------------------- 1 | -- delimiter: |; types: INTEGER|VARCHAR 2 | 3|A| 3 | 2|null| 4 | 1|C| 5 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/datasets/sample_jdbc_table.data-revision: -------------------------------------------------------------------------------- 1 | v.1.0 2 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/datasets/sample_jdbc_table.ddl: -------------------------------------------------------------------------------- 1 | -- type: jdbc 2 | CREATE TABLE %NAME% ( 3 | id BIGINT, 4 | name VARCHAR(100) 5 | ) 6 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/generated/nation.generator: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cat >$1/generated_nation.sql << EOF 4 | -- database: hive; tables: sample_hive_table; groups: generated 5 | SELECT * FROM sample_hive_table 6 | EOF 7 | 8 | cat >$1/generated_nation.result << EOF 9 | -- delimiter: |; ignoreOrder: false; types: INTEGER|VARCHAR; groups: generated 10 | 1|A| 11 | 2|B| 12 | 3|C| 13 | EOF 14 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/nation/after: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo hello world after 3 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/nation/before: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo hello world before -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_hive_table/allRows.result: -------------------------------------------------------------------------------- 1 | -- delimiter: |; ignoreOrder: false; types: INTEGER|VARCHAR 2 | 1|A| 3 | 2|B| 4 | 3|C| 5 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_hive_table/allRows.sql: -------------------------------------------------------------------------------- 1 | -- database: hive; tables: sample_hive_table; groups: hive_convention 2 | SELECT * FROM sample_hive_table; 3 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_presto_table/allRows.sql: -------------------------------------------------------------------------------- 1 | -- database: presto; tables: sample_jdbc_table; groups: presto_convention 2 | -- delimiter: |; ignoreOrder: false; types: BIGINT|LONGNVARCHAR 3 | --! 4 | SELECT * FROM sample_jdbc_table ORDER BY id; 5 | --! 6 | 1|C| 7 | 2|null| 8 | 3|A| 9 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_presto_table/in-memory.sql: -------------------------------------------------------------------------------- 1 | -- database: presto; groups: presto_convention, in_memory 2 | --! 3 | SELECT count(*) FROM tpch.tiny.nation 4 | --! 5 | 25| 6 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_presto_table/psqlOverPrestoAllRows.result: -------------------------------------------------------------------------------- 1 | -- delimiter: |; ignoreOrder: false; types: BIGINT|LONGNVARCHAR 2 | 3|A| 3 | 2|null| 4 | 1|C| 5 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_presto_table/psqlOverPrestoAllRows.sql: -------------------------------------------------------------------------------- 1 | -- database: presto; tables: psql.sample_jdbc_table; groups: presto_convention 2 | SELECT * FROM psql.public.sample_jdbc_table 3 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_psql_table/allRows.result: -------------------------------------------------------------------------------- 1 | -- delimiter: |; ignoreOrder: false; types: BIGINT|VARCHAR 2 | 3|A| 3 | 2|null| 4 | 1|C| 5 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_psql_table/allRows.sql: -------------------------------------------------------------------------------- 1 | -- database: psql; tables: sample_jdbc_table; groups: psql_convention 2 | SELECT * FROM sample_jdbc_table 3 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_psql_table/allRowsOnPsql2.result: -------------------------------------------------------------------------------- 1 | -- delimiter: |; ignoreOrder: false; types: BIGINT|VARCHAR 2 | 3|A| 3 | 2|null| 4 | 1|C| 5 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_psql_table/allRowsOnPsql2.sql: -------------------------------------------------------------------------------- 1 | -- database: psql2; tables: sample_jdbc_table; groups: psql_convention 2 | SELECT * FROM sample_jdbc_table 3 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_psql_table/noData.sql: -------------------------------------------------------------------------------- 1 | -- database: psql; tables: no_data_jdbc_table; groups: psql_convention 2 | -- delimiter: |; ignoreOrder: false; types: INTEGER|VARCHAR 3 | --! 4 | SELECT * FROM no_data_jdbc_table 5 | --! 6 | --! 7 | SELECT * FROM no_data_jdbc_table WHERE true 8 | --! 9 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/sql-tests/testcases/sample_table_insert/insert.sql: -------------------------------------------------------------------------------- 1 | -- database: hive; tables: sample_hive_table; mutable_tables: sample_hive_table|created|sample_table_created, sample_hive_table|prepared|sample_table_prepared; groups: insert 2 | -- delimiter: |; ignoreOrder: false; types: INTEGER|VARCHAR 3 | --! 4 | INSERT INTO TABLE ${mutableTables.hive.sample_table_created} SELECT * from sample_hive_table; 5 | SELECT * from ${mutableTables.hive.sample_table_created} 6 | --! 7 | 1|A| 8 | 2|B| 9 | 3|C| 10 | --! 11 | CREATE TABLE ${mutableTables.hive.sample_table_prepared} ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' AS SELECT * from sample_hive_table; 12 | SELECT * from ${mutableTables.hive.sample_table_prepared} 13 | --! 14 | 1|A| 15 | 2|B| 16 | 3|C| 17 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/tempto-configuration-invalid-ssh-and-psql.yaml: -------------------------------------------------------------------------------- 1 | # This configuration contains only presto and hive configured correctly 2 | # psql instances configuration and ssh configuration is wrongly configured 3 | # in purpouse to test that not needed configuration is not used. 4 | # So when running test only for particular database, only configuration for 5 | # this database is needed. 6 | 7 | DOCKER_MACHINE: localhost 8 | 9 | cluster: 10 | presto: ${DOCKER_MACHINE} 11 | hadoop: ${DOCKER_MACHINE} 12 | psql1: wrong 13 | psql2: wrong 14 | 15 | hdfs: 16 | username: hdfs 17 | webhdfs: 18 | host: ${cluster.hadoop} 19 | port: 50070 20 | 21 | psql1: 22 | port: 15432 23 | psql2: 24 | port: 15433 25 | 26 | databases: 27 | default: 28 | alias: presto 29 | 30 | hive: 31 | path: /user/hive/warehouse 32 | jdbc_driver_class: org.apache.hive.jdbc.HiveDriver 33 | jdbc_url: jdbc:hive2://${cluster.hadoop}:10000 34 | jdbc_user: hdfs 35 | jdbc_password: na 36 | jdbc_pooling: false 37 | table_manager_type: hive 38 | 39 | presto: 40 | jdbc_driver_class: com.facebook.presto.jdbc.PrestoDriver 41 | jdbc_url: jdbc:presto://${cluster.presto}:8080/hive/default 42 | jdbc_user: hdfs 43 | jdbc_password: na 44 | jdbc_pooling: false 45 | 46 | psql: 47 | jdbc_driver_class: org.postgresql.Driver 48 | jdbc_url: jdbc:postgresql://${cluster.psql1}:${psql1.port}/postgres 49 | jdbc_user: blah 50 | jdbc_password: blah 51 | jdbc_pooling: true 52 | table_manager_type: jdbc 53 | 54 | psql2: 55 | jdbc_driver_class: org.postgresql.Driver 56 | jdbc_url: jdbc:postgresql://${cluster.psql2}:${psql2.port}/postgres 57 | jdbc_user: blah 58 | jdbc_password: blah 59 | jdbc_pooling: true 60 | table_manager_type: jdbc 61 | 62 | tests: 63 | hdfs: 64 | path: /tempto 65 | 66 | ssh: 67 | identity: wrong 68 | roles: 69 | host_by_password: 70 | host: wrong 71 | port: 22 72 | user: ${USER_A} 73 | password: ${USER_A_PASSWORD} 74 | 75 | host_by_identity: 76 | host: wrong 77 | port: 22 78 | user: ${USER_B} 79 | 80 | hosts: 81 | localhost_alias: localhost 82 | teradata_alias: teradata.com 83 | 84 | list: 85 | string: 86 | - ala 87 | - ma 88 | - kota 89 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/tempto-configuration-no-db.yaml: -------------------------------------------------------------------------------- 1 | DOCKER_MACHINE: localhost 2 | 3 | cluster: 4 | ssh: ${DOCKER_MACHINE} 5 | 6 | ssh: 7 | identity: ${IDENTITY} 8 | roles: 9 | host_by_password: 10 | host: ${cluster.ssh} 11 | port: 22 12 | user: ${USER_A} 13 | password: ${USER_A_PASSWORD} 14 | 15 | host_by_identity: 16 | host: ${cluster.ssh} 17 | port: 22 18 | user: ${USER_B} 19 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/tempto-configuration-read-only.yaml: -------------------------------------------------------------------------------- 1 | DOCKER_MACHINE: localhost 2 | 3 | cluster: 4 | presto: ${DOCKER_MACHINE} 5 | ssh: ${DOCKER_MACHINE} 6 | 7 | databases: 8 | default: 9 | alias: presto 10 | 11 | presto: 12 | jdbc_driver_class: com.facebook.presto.jdbc.PrestoDriver 13 | jdbc_url: jdbc:presto://${cluster.presto}:8080/hive/default 14 | jdbc_user: hdfs 15 | jdbc_password: na 16 | 17 | ssh: 18 | identity: ${IDENTITY} 19 | roles: 20 | host_by_password: 21 | host: ${cluster.ssh} 22 | password: ${USER_A_PASSWORD} 23 | 24 | host_by_identity: 25 | host: ${cluster.ssh} 26 | -------------------------------------------------------------------------------- /tempto-examples/src/main/resources/tempto-configuration.yaml: -------------------------------------------------------------------------------- 1 | DOCKER_MACHINE: localhost 2 | 3 | cluster: 4 | presto: ${DOCKER_MACHINE} 5 | hadoop: ${DOCKER_MACHINE} 6 | psql1: ${DOCKER_MACHINE} 7 | psql2: ${DOCKER_MACHINE} 8 | ssh: ${DOCKER_MACHINE} 9 | 10 | hdfs: 11 | username: hdfs 12 | webhdfs: 13 | host: ${cluster.hadoop} 14 | port: 50070 15 | 16 | psql1: 17 | port: 15432 18 | psql2: 19 | port: 15433 20 | 21 | databases: 22 | default: 23 | alias: presto 24 | 25 | hive: 26 | path: /user/hive/warehouse 27 | jdbc_driver_class: org.apache.hive.jdbc.HiveDriver 28 | jdbc_url: jdbc:hive2://${cluster.hadoop}:10000 29 | jdbc_user: hdfs 30 | jdbc_password: na 31 | jdbc_pooling: false 32 | table_manager_type: hive 33 | 34 | presto: 35 | jdbc_driver_class: com.facebook.presto.jdbc.PrestoDriver 36 | jdbc_url: jdbc:presto://${cluster.presto}:8080/hive/default 37 | jdbc_user: hdfs 38 | jdbc_password: na 39 | jdbc_pooling: false 40 | table_manager_type: jdbc 41 | 42 | psql: 43 | jdbc_driver_class: org.postgresql.Driver 44 | jdbc_url: jdbc:postgresql://${cluster.psql1}:${psql1.port}/postgres 45 | jdbc_user: blah 46 | jdbc_password: blah 47 | jdbc_pooling: true 48 | table_manager_type: jdbc 49 | 50 | psql2: 51 | jdbc_driver_class: org.postgresql.Driver 52 | jdbc_url: jdbc:postgresql://${cluster.psql2}:${psql2.port}/postgres 53 | jdbc_user: blah 54 | jdbc_password: blah 55 | jdbc_pooling: true 56 | table_manager_type: jdbc 57 | 58 | tests: 59 | hdfs: 60 | path: /tempto 61 | 62 | ssh: 63 | identity: ${IDENTITY} 64 | roles: 65 | host_by_password: 66 | host: ${cluster.ssh} 67 | port: 22 68 | user: ${USER_A} 69 | password: ${USER_A_PASSWORD} 70 | 71 | host_by_identity: 72 | host: ${cluster.ssh} 73 | port: 22 74 | user: ${USER_B} 75 | 76 | hosts: 77 | localhost_alias: localhost 78 | teradata_alias: teradata.com 79 | 80 | list: 81 | string: 82 | - ala 83 | - ma 84 | - kota 85 | -------------------------------------------------------------------------------- /tempto-ldap/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | apply plugin: 'java' 16 | 17 | dependencies { 18 | compile tempto_core 19 | } 20 | 21 | // project information 22 | ext.artifactId = 'tempto-ldap' 23 | archivesBaseName = artifactId 24 | 25 | // publishing to sonatype 26 | uploadArchives { 27 | repositories { 28 | mavenDeployer { 29 | pom.project { 30 | name artifactId 31 | artifactId artifactId 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tempto-ldap/src/main/java/com/teradata/tempto/fulfillment/ldap/LdapObjectRequirement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.ldap; 16 | 17 | import com.google.common.collect.ImmutableList; 18 | import com.teradata.tempto.Requirement; 19 | 20 | import java.util.List; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals; 24 | import static org.apache.commons.lang3.builder.HashCodeBuilder.reflectionHashCode; 25 | 26 | public class LdapObjectRequirement 27 | implements Requirement 28 | { 29 | private final List ldapObjectDefinitions; 30 | 31 | public LdapObjectRequirement(List ldapObjectDefinitions) 32 | { 33 | this.ldapObjectDefinitions = ImmutableList.copyOf(requireNonNull(ldapObjectDefinitions, "ldapObjectDefinition is null")); 34 | } 35 | 36 | public List getLdapObjectDefinitions() 37 | { 38 | return ldapObjectDefinitions; 39 | } 40 | 41 | @Override 42 | public boolean equals(Object o) 43 | { 44 | return reflectionEquals(this, o); 45 | } 46 | 47 | @Override 48 | public int hashCode() 49 | { 50 | return reflectionHashCode(this); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tempto-ldap/src/main/java/com/teradata/tempto/fulfillment/ldap/OpenLdapObjectDefinitions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.fulfillment.ldap; 16 | 17 | import java.util.Arrays; 18 | import java.util.Map; 19 | 20 | import static com.google.common.collect.Maps.newHashMap; 21 | 22 | public class OpenLdapObjectDefinitions 23 | { 24 | public static final LdapObjectDefinition TEST_ORG = 25 | LdapObjectDefinition.builder("TestOrg") 26 | .setDistinguishedName("ou=Test,dc=tempto,dc=com") 27 | .setAttributes(newHashMap()) 28 | .addObjectClasses(Arrays.asList("organizationalUnit")) 29 | .build(); 30 | 31 | public static final LdapObjectDefinition TEST_GROUP = 32 | LdapObjectDefinition.builder("TestGroup") 33 | .setDistinguishedName("cn=TestGroup,ou=Test,dc=tempto,dc=com") 34 | .setAttributes(testGroupAttributes()) 35 | .addObjectClasses(Arrays.asList("groupOfNames")) 36 | .build(); 37 | 38 | private static Map testGroupAttributes() 39 | { 40 | Map attributes = newHashMap(); 41 | attributes.put("cn", "Test Group"); 42 | attributes.put("member", "uid=testuser,ou=Test,dc=tempto,dc=com"); 43 | return attributes; 44 | } 45 | 46 | public static final LdapObjectDefinition TEST_USER = 47 | LdapObjectDefinition.builder("TestUser") 48 | .setDistinguishedName("uid=testuser,ou=Test,dc=tempto,dc=com") 49 | .setAttributes(testUserAttributes()) 50 | .addObjectClasses(Arrays.asList("person", "inetOrgPerson")) 51 | .build(); 52 | 53 | private static Map testUserAttributes() 54 | { 55 | Map attributes = newHashMap(); 56 | attributes.put("cn", "Test User"); 57 | attributes.put("sn", "User"); 58 | attributes.put("password", "testp@ss"); 59 | return attributes; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tempto-ldap/src/main/java/com/teradata/tempto/internal/fulfillment/ldap/LdapObjectEntryManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.fulfillment.ldap; 16 | 17 | import com.teradata.tempto.fulfillment.ldap.LdapObjectDefinition; 18 | 19 | import java.util.List; 20 | 21 | interface LdapObjectEntryManager 22 | { 23 | List addLdapDefinitions(List ldapObjectDefinitions); 24 | } 25 | -------------------------------------------------------------------------------- /tempto-ldap/src/main/java/com/teradata/tempto/internal/fulfillment/ldap/LdapObjectFulfiller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.fulfillment.ldap; 16 | 17 | import com.google.inject.Inject; 18 | import com.teradata.tempto.Requirement; 19 | import com.teradata.tempto.context.State; 20 | import com.teradata.tempto.fulfillment.RequirementFulfiller; 21 | import com.teradata.tempto.fulfillment.TestStatus; 22 | import com.teradata.tempto.fulfillment.ldap.LdapObjectRequirement; 23 | 24 | import java.util.Set; 25 | 26 | import static com.google.common.collect.Sets.newHashSet; 27 | 28 | @RequirementFulfiller.AutoSuiteLevelFulfiller 29 | public class LdapObjectFulfiller 30 | implements RequirementFulfiller 31 | { 32 | @Inject 33 | LdapObjectEntryManager ldapObjectEntryManager; 34 | 35 | @Override 36 | public Set fulfill(Set requirements) 37 | { 38 | requirements.stream() 39 | .filter(requirement -> requirement.getClass().isAssignableFrom(LdapObjectRequirement.class)) 40 | .map(requirement -> (T) requirement) 41 | .map(requirement -> requirement.getLdapObjectDefinitions()) 42 | .distinct() 43 | .forEach(ldapObjectEntryManager::addLdapDefinitions); 44 | 45 | return newHashSet(); 46 | } 47 | 48 | @Override 49 | public void cleanup(TestStatus status) 50 | { 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tempto-ldap/src/main/java/com/teradata/tempto/internal/fulfillment/ldap/LdapObjectModuleProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.teradata.tempto.internal.fulfillment.ldap; 16 | 17 | import com.google.inject.AbstractModule; 18 | import com.google.inject.Module; 19 | import com.google.inject.Scopes; 20 | import com.teradata.tempto.configuration.Configuration; 21 | import com.teradata.tempto.initialization.AutoModuleProvider; 22 | import com.teradata.tempto.initialization.SuiteModuleProvider; 23 | 24 | @AutoModuleProvider 25 | public class LdapObjectModuleProvider 26 | implements SuiteModuleProvider 27 | { 28 | public Module getModule(Configuration configuration) 29 | { 30 | return new AbstractModule() 31 | { 32 | @Override 33 | protected void configure() 34 | { 35 | bind(LdapObjectEntryManager.class).to(DefaultLdapObjectEntryManager.class); 36 | } 37 | }; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tempto-logging-log4j/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | apply plugin: 'java' 16 | apply plugin: 'groovy' 17 | 18 | dependencies { 19 | compile tempto_core 20 | compile libraries.ioutils 21 | compile libraries.log4j 22 | compile libraries.slf4j_api 23 | compile libraries.reflections 24 | } 25 | 26 | // project information 27 | ext.artifactId = 'tempto-logging-log4j' 28 | archivesBaseName = artifactId 29 | 30 | // publishing to sonatype 31 | uploadArchives { 32 | repositories { 33 | mavenDeployer { 34 | pom.project { 35 | name artifactId 36 | artifactId artifactId 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tempto-logging-log4j/src/main/resources/log4j.properties-sample: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015, Teradata, Inc. All rights reserved. 3 | # 4 | 5 | # Set root logger to INFO and add a custom appender. 6 | log4j.rootLogger=TRACE, CONSOLE, TEST_FRAMEWORK_LOGGING_APPENDER 7 | 8 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 9 | log4j.appender.CONSOLE.Target=System.out 10 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c{1}:%L] [%X{test_id}] - %m%n 12 | log4j.appender.CONSOLE.Threshold=INFO 13 | 14 | log4j.appender.TEST_FRAMEWORK_LOGGING_APPENDER=com.teradata.logging.TestFrameworkLoggingAppender 15 | log4j.appender.TEST_FRAMEWORK_LOGGING_APPENDER.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.TEST_FRAMEWORK_LOGGING_APPENDER.layout.conversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] [%p] %c{10}: %m%n 17 | 18 | 19 | log4j.category.org.apache.http=INFO 20 | log4j.category.com.jayway.jsonpath=WARN 21 | log4j.category.org.apache.thrift=WARN 22 | log4j.category.org.apache.hive=WARN 23 | log4j.category.org.reflections=WARN 24 | -------------------------------------------------------------------------------- /tempto-runner/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | apply plugin: 'java' 15 | apply plugin: 'signing' 16 | apply plugin: 'maven' 17 | apply plugin: 'groovy' 18 | 19 | dependencies { 20 | compile tempto_core 21 | compile libraries.commons_cli 22 | } 23 | 24 | configurations { 25 | all*.exclude group: 'commons-logging', module: 'commons-logging' 26 | } 27 | 28 | // project information 29 | ext.artifactId = 'tempto-runner' 30 | archivesBaseName = artifactId 31 | 32 | // publishing to sonatype 33 | uploadArchives { 34 | repositories { 35 | mavenDeployer { 36 | pom.project { 37 | name artifactId 38 | artifactId artifactId 39 | } 40 | } 41 | } 42 | } 43 | --------------------------------------------------------------------------------