You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ab...@apache.org on 2015/05/15 05:11:08 UTC

sqoop git commit: SQOOP-2341: Sqoop2: Test repository infrastructure

Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 ad632361b -> d2cf56680


SQOOP-2341: Sqoop2: Test repository infrastructure

(Syed Hashmi via Abraham Elmahrek)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/d2cf5668
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/d2cf5668
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/d2cf5668

Branch: refs/heads/sqoop2
Commit: d2cf56680ad3dc91dddbbe28fff44b4c84caa16b
Parents: ad63236
Author: Abraham Elmahrek <ab...@apache.org>
Authored: Thu May 14 20:10:13 2015 -0700
Committer: Abraham Elmahrek <ab...@apache.org>
Committed: Thu May 14 20:10:13 2015 -0700

----------------------------------------------------------------------
 .../repository/DerbyRepositoryProvider.java     | 45 +++++++++++++++
 .../PostgresqlRepositoryProvider.java           | 58 ++++++++++++++++++++
 .../test/repository/RepositoryProviderBase.java | 25 +++++++++
 .../repository/RepositoryProviderFactory.java   | 41 ++++++++++++++
 .../test/minicluster/SqoopMiniCluster.java      | 19 ++-----
 5 files changed, 173 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/d2cf5668/common-test/src/main/java/org/apache/sqoop/common/test/repository/DerbyRepositoryProvider.java
----------------------------------------------------------------------
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 0000000..760f74e
--- /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<String,String> getPropertiesMap() {
+    Map<String, String> properties = new HashMap<String, String>();
+
+    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;
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d2cf5668/common-test/src/main/java/org/apache/sqoop/common/test/repository/PostgresqlRepositoryProvider.java
----------------------------------------------------------------------
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 0000000..8aa17a6
--- /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<String,String> getPropertiesMap() {
+    Map<String, String> properties = new HashMap<String, String>();
+    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;
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d2cf5668/common-test/src/main/java/org/apache/sqoop/common/test/repository/RepositoryProviderBase.java
----------------------------------------------------------------------
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 0000000..1581625
--- /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<String,String> getPropertiesMap();
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d2cf5668/common-test/src/main/java/org/apache/sqoop/common/test/repository/RepositoryProviderFactory.java
----------------------------------------------------------------------
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 0000000..db53a62
--- /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<String, String> 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();
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d2cf5668/test/src/main/java/org/apache/sqoop/test/minicluster/SqoopMiniCluster.java
----------------------------------------------------------------------
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 6ec6883..758eb2f 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 @@ package org.apache.sqoop.test.minicluster;
 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 abstract class SqoopMiniCluster {
    *
    * @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 @@ public abstract class SqoopMiniCluster {
     return properties;
   }
 
-  protected Map<String, String> getRepositoryConfiguration() {
-    Map<String, String> properties = new HashMap<String, String>();
-
-    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<String, String> getRepositoryConfiguration() throws Exception {
+    return RepositoryProviderFactory.getRepositoryProperties();
   }
 
   protected Map<String, String> getSubmissionEngineConfiguration() {