diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/repository/DerbyRepositoryProvider.java b/common-test/src/main/java/org/apache/sqoop/common/test/repository/DerbyRepositoryProvider.java new file mode 100644 index 00000000..760f74e5 --- /dev/null +++ b/common-test/src/main/java/org/apache/sqoop/common/test/repository/DerbyRepositoryProvider.java @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.sqoop.common.test.repository; + +import java.util.HashMap; +import java.util.Map; + +/** +This class encapsulates the logic around generating properties for using +derby as repository provider in Integration Tests + */ +public class DerbyRepositoryProvider extends RepositoryProviderBase { + @Override + public Map getPropertiesMap() { + Map properties = new HashMap(); + + properties.put("org.apache.sqoop.repository.provider", "org.apache.sqoop.repository.JdbcRepositoryProvider"); + properties.put("org.apache.sqoop.repository.schema.immutable", "false"); + properties.put("org.apache.sqoop.repository.jdbc.handler", "org.apache.sqoop.repository.derby.DerbyRepositoryHandler"); + properties.put("org.apache.sqoop.repository.jdbc.transaction.isolation", "READ_COMMITTED"); + properties.put("org.apache.sqoop.repository.jdbc.maximum.connections", "10"); + properties.put("org.apache.sqoop.repository.jdbc.url=jdbc:derby:memory:myDB;create", "true"); + properties.put("org.apache.sqoop.repository.jdbc.driver", "org.apache.derby.jdbc.EmbeddedDriver"); + properties.put("org.apache.sqoop.repository.jdbc.user", "sa"); + properties.put("org.apache.sqoop.repository.jdbc.password", ""); + + return properties; + } +} diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/repository/PostgresqlRepositoryProvider.java b/common-test/src/main/java/org/apache/sqoop/common/test/repository/PostgresqlRepositoryProvider.java new file mode 100644 index 00000000..8aa17a6b --- /dev/null +++ b/common-test/src/main/java/org/apache/sqoop/common/test/repository/PostgresqlRepositoryProvider.java @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.sqoop.common.test.repository; + +import java.util.HashMap; +import java.util.Map; + +public class PostgresqlRepositoryProvider extends RepositoryProviderBase { + + private static final String DRIVER = "org.postgresql.Driver"; + + private static final String CONNECTION = System.getProperties().getProperty( + "sqoop.repository.postgresql.jdbc.url", + "jdbc:postgresql://localhost/test" + ); + + private static final String USERNAME = System.getProperties().getProperty( + "sqoop.repository.postgresql.username", + "sqoop" + ); + + private static final String PASSWORD = System.getProperties().getProperty( + "sqoop.repository.postgresql.password", + "sqoop" + ); + + @Override + public Map getPropertiesMap() { + Map properties = new HashMap(); + properties.put("org.apache.sqoop.repository.provider", "org.apache.sqoop.repository.JdbcRepositoryProvider"); + properties.put("org.apache.sqoop.repository.schema.immutable", "false"); + properties.put("org.apache.sqoop.repository.jdbc.handler", "org.apache.sqoop.repository.postgresql.PostgresqlRepositoryHandler"); + properties.put("org.apache.sqoop.repository.jdbc.transaction.isolation", "READ_COMMITTED"); + properties.put("org.apache.sqoop.repository.jdbc.maximum.connections", "10"); + properties.put("org.apache.sqoop.repository.jdbc.url", CONNECTION); + properties.put("org.apache.sqoop.repository.jdbc.driver", DRIVER); + properties.put("org.apache.sqoop.repository.jdbc.user", USERNAME); + properties.put("org.apache.sqoop.repository.jdbc.password", PASSWORD); + + return properties; + } +} diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/repository/RepositoryProviderBase.java b/common-test/src/main/java/org/apache/sqoop/common/test/repository/RepositoryProviderBase.java new file mode 100644 index 00000000..1581625b --- /dev/null +++ b/common-test/src/main/java/org/apache/sqoop/common/test/repository/RepositoryProviderBase.java @@ -0,0 +1,25 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.sqoop.common.test.repository; + +import java.util.Map; + +public abstract class RepositoryProviderBase { + public abstract Map getPropertiesMap(); +} diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/repository/RepositoryProviderFactory.java b/common-test/src/main/java/org/apache/sqoop/common/test/repository/RepositoryProviderFactory.java new file mode 100644 index 00000000..db53a627 --- /dev/null +++ b/common-test/src/main/java/org/apache/sqoop/common/test/repository/RepositoryProviderFactory.java @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.sqoop.common.test.repository; + +import java.util.Map; + +/** + * Instantiate the right class for handling repository specific properties + */ +public class RepositoryProviderFactory { + + public static final String REPOSITORY_CLASS_PROPERTY = "sqoop.repository.handler.class"; + + public static Map getRepositoryProperties() throws ClassNotFoundException, IllegalAccessException, InstantiationException { + String className = System.getProperty(REPOSITORY_CLASS_PROPERTY); + RepositoryProviderBase repoProvider; + if(className == null) { + repoProvider = new DerbyRepositoryProvider(); + } else { + Class klass = Class.forName(className); + repoProvider = (RepositoryProviderBase) klass.newInstance(); + } + return repoProvider.getPropertiesMap(); + } +} diff --git a/test/src/main/java/org/apache/sqoop/test/minicluster/SqoopMiniCluster.java b/test/src/main/java/org/apache/sqoop/test/minicluster/SqoopMiniCluster.java index 6ec68837..758eb2fa 100644 --- a/test/src/main/java/org/apache/sqoop/test/minicluster/SqoopMiniCluster.java +++ b/test/src/main/java/org/apache/sqoop/test/minicluster/SqoopMiniCluster.java @@ -20,6 +20,7 @@ import org.apache.commons.io.FileUtils; import org.apache.hadoop.conf.Configuration; import org.apache.sqoop.core.ConfigurationConstants; +import org.apache.sqoop.common.test.repository.RepositoryProviderFactory; import java.io.File; import java.io.IOException; @@ -104,7 +105,7 @@ public String getLogPath() { * * @throws IOException */ - protected void prepareTemporaryPath() throws IOException { + protected void prepareTemporaryPath() throws Exception { File tmpDir = new File(getTemporaryPath()); File configDir = new File(getConfigurationPath()); File logDir = new File(getLogPath()); @@ -168,20 +169,8 @@ protected Map getLoggerConfiguration() { return properties; } - protected Map getRepositoryConfiguration() { - Map properties = new HashMap(); - - properties.put("org.apache.sqoop.repository.provider", "org.apache.sqoop.repository.JdbcRepositoryProvider"); - properties.put("org.apache.sqoop.repository.schema.immutable", "false"); - properties.put("org.apache.sqoop.repository.jdbc.handler", "org.apache.sqoop.repository.derby.DerbyRepositoryHandler"); - properties.put("org.apache.sqoop.repository.jdbc.transaction.isolation", "READ_COMMITTED"); - properties.put("org.apache.sqoop.repository.jdbc.maximum.connections", "10"); - properties.put("org.apache.sqoop.repository.jdbc.url=jdbc:derby:memory:myDB;create", "true"); - properties.put("org.apache.sqoop.repository.jdbc.driver", "org.apache.derby.jdbc.EmbeddedDriver"); - properties.put("org.apache.sqoop.repository.jdbc.user", "sa"); - properties.put("org.apache.sqoop.repository.jdbc.password", ""); - - return properties; + protected Map getRepositoryConfiguration() throws Exception { + return RepositoryProviderFactory.getRepositoryProperties(); } protected Map getSubmissionEngineConfiguration() {