You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by an...@apache.org on 2018/01/18 14:03:49 UTC
[03/32] sqoop git commit: SQOOP-3273: Removing com.cloudera.sqoop
packages
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/db2/DB2JobToolTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/db2/DB2JobToolTest.java b/src/test/org/apache/sqoop/metastore/db2/DB2JobToolTest.java
new file mode 100644
index 0000000..b2b1fb6
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/db2/DB2JobToolTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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.metastore.db2;
+
+import org.apache.sqoop.metastore.JobToolTestBase;
+
+/**
+ * Test that the Job Tool works in DB2
+ *
+ * This uses JDBC to store and retrieve metastore data from a DB2 server
+ *
+ * Since this requires a DB2 installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=DB2JobToolTest or -Dthirdparty=true.
+ *
+ * You need to put DB2 JDBC driver library (db2jcc4.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running DB2 database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.db2.connectstring.host_url, -Dsqoop.test.db2.connectstring.database,
+ * -Dsqoop.test.db2.connectstring.username and -Dsqoop.test.db2.connectstring.password respectively
+ */
+
+public class DB2JobToolTest extends JobToolTestBase {
+
+ private static final String HOST_URL = System.getProperty(
+ "sqoop.test.db2.connectstring.host_url",
+ "jdbc:db2://db2host:50000");
+
+ private static final String DATABASE_NAME = System.getProperty(
+ "sqoop.test.db2.connectstring.database",
+ "SQOOP");
+ private static final String DATABASE_USER = System.getProperty(
+ "sqoop.test.db2.connectstring.username",
+ "SQOOP");
+ private static final String DATABASE_PASSWORD = System.getProperty(
+ "sqoop.test.db2.connectstring.password",
+ "SQOOP");
+ private static final String CONNECT_STRING = HOST_URL
+ + "/" + DATABASE_NAME
+ + ":currentSchema=" + DATABASE_USER +";";
+
+ public DB2JobToolTest() {
+ super(CONNECT_STRING, DATABASE_USER, DATABASE_PASSWORD);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/db2/DB2MetaConnectIncrementalImportTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/db2/DB2MetaConnectIncrementalImportTest.java b/src/test/org/apache/sqoop/metastore/db2/DB2MetaConnectIncrementalImportTest.java
new file mode 100644
index 0000000..e7969fa
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/db2/DB2MetaConnectIncrementalImportTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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.metastore.db2;
+
+import org.apache.sqoop.metastore.MetaConnectIncrementalImportTestBase;
+
+/**
+ * Test that Incremental-Import values are stored correctly in DB2
+ *
+ * This uses JDBC to store and retrieve metastore data from a DB2 server
+ *
+ * Since this requires a DB2 installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=DB2MetaConnectIncrementalImportTest or -Dthirdparty=true.
+ *
+ * You need to put DB2 JDBC driver library (db2jcc4.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running DB2 database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.db2.connectstring.host_url, -Dsqoop.test.db2.connectstring.database,
+ * -Dsqoop.test.db2.connectstring.username and -Dsqoop.test.db2.connectstring.password respectively
+ */
+
+public class DB2MetaConnectIncrementalImportTest extends MetaConnectIncrementalImportTestBase {
+
+ private static final String HOST_URL = System.getProperty(
+ "sqoop.test.db2.connectstring.host_url",
+ "jdbc:db2://db2host:50000");
+
+ private static final String DATABASE_NAME = System.getProperty(
+ "sqoop.test.db2.connectstring.database",
+ "SQOOP");
+ private static final String DATABASE_USER = System.getProperty(
+ "sqoop.test.db2.connectstring.username",
+ "SQOOP");
+ private static final String DATABASE_PASSWORD = System.getProperty(
+ "sqoop.test.db2.connectstring.password",
+ "SQOOP");
+ private static final String CONNECT_STRING = HOST_URL
+ + "/" + DATABASE_NAME
+ + ":currentSchema=" + DATABASE_USER +";";
+
+ public DB2MetaConnectIncrementalImportTest() {
+ super(CONNECT_STRING, DATABASE_USER, DATABASE_PASSWORD);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/db2/DB2SavedJobsTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/db2/DB2SavedJobsTest.java b/src/test/org/apache/sqoop/metastore/db2/DB2SavedJobsTest.java
new file mode 100644
index 0000000..caf753c
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/db2/DB2SavedJobsTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.metastore.db2;
+
+import org.apache.sqoop.metastore.SavedJobsTestBase;
+import org.apache.sqoop.manager.JdbcDrivers;
+
+/**
+ * Test of GenericJobStorage compatibility with DB2
+ *
+ * This uses JDBC to store and retrieve metastore data from a DB2 server
+ *
+ * Since this requires a DB2 installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=DB2SavedJobsTest or -Dthirdparty=true.
+ *
+ * You need to put DB2 JDBC driver library (db2jcc4.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running DB2 database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.db2.connectstring.host_url, -Dsqoop.test.db2.connectstring.database,
+ * -Dsqoop.test.db2.connectstring.username and -Dsqoop.test.db2.connectstring.password respectively
+ */
+
+public class DB2SavedJobsTest extends SavedJobsTestBase {
+
+ private static final String HOST_URL = System.getProperty(
+ "sqoop.test.db2.connectstring.host_url",
+ "jdbc:db2://db2host:50000");
+
+ private static final String DATABASE_NAME = System.getProperty(
+ "sqoop.test.db2.connectstring.database",
+ "SQOOP");
+ private static final String DATABASE_USER = System.getProperty(
+ "sqoop.test.db2.connectstring.username",
+ "SQOOP");
+ private static final String DATABASE_PASSWORD = System.getProperty(
+ "sqoop.test.db2.connectstring.password",
+ "SQOOP");
+ private static final String CONNECT_STRING = HOST_URL
+ + "/" + DATABASE_NAME
+ + ":currentSchema=" + DATABASE_USER +";";
+
+ public DB2SavedJobsTest() {
+ super(CONNECT_STRING, DATABASE_USER, DATABASE_PASSWORD, JdbcDrivers.DB2.getDriverClass());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbJobToolTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbJobToolTest.java b/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbJobToolTest.java
new file mode 100644
index 0000000..bc829b7
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbJobToolTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.metastore.hsqldb;
+
+import org.apache.sqoop.metastore.JobToolTestBase;
+
+/**
+ * Test that the Job Tool works in Hsqldb
+ *
+ * This class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=HsqldbJobToolTest or -Dthirdparty=true.
+ *
+ * This uses JDBC to store and retrieve metastore data from a local Hsqldb server
+ */
+
+public class HsqldbJobToolTest extends JobToolTestBase {
+
+ public HsqldbJobToolTest() {
+ super( "jdbc:hsqldb:mem:sqoopmetastore", "SA" , "");
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbMetaConnectIncrementalImportTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbMetaConnectIncrementalImportTest.java b/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbMetaConnectIncrementalImportTest.java
new file mode 100644
index 0000000..9a8ee24
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbMetaConnectIncrementalImportTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.metastore.hsqldb;
+
+import org.apache.sqoop.metastore.MetaConnectIncrementalImportTestBase;
+
+/**
+ * Test that Incremental-Import values are stored correctly in Hsqldb
+ *
+ * This class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=HsqldbMetaConnectIncrementalImportTest or -Dthirdparty=true.
+ *
+ * This uses JDBC to store and retrieve metastore data from a local Hsqldb server
+ */
+
+public class HsqldbMetaConnectIncrementalImportTest extends MetaConnectIncrementalImportTestBase {
+
+ public HsqldbMetaConnectIncrementalImportTest() {
+ super( "jdbc:hsqldb:mem:sqoopmetastore", "SA" , "");
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbSavedJobsTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbSavedJobsTest.java b/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbSavedJobsTest.java
new file mode 100644
index 0000000..f072881
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/hsqldb/HsqldbSavedJobsTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.metastore.hsqldb;
+
+import org.apache.sqoop.metastore.SavedJobsTestBase;
+import org.apache.sqoop.manager.JdbcDrivers;
+
+/**
+ * Test of GenericJobStorage compatibility with Hsqldb
+ *
+ * This class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=HsqldbSavedJobsTest or -Dthirdparty=true.
+ *
+ * This uses JDBC to store and retrieve metastore data from a local Hsqldb server
+ */
+
+public class HsqldbSavedJobsTest extends SavedJobsTestBase {
+
+ public HsqldbSavedJobsTest() {
+ super("jdbc:hsqldb:mem:sqoopmetastore",
+ "SA" , "", JdbcDrivers.HSQLDB.getDriverClass());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/mysql/MySqlJobToolTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/mysql/MySqlJobToolTest.java b/src/test/org/apache/sqoop/metastore/mysql/MySqlJobToolTest.java
new file mode 100644
index 0000000..2ec9648
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/mysql/MySqlJobToolTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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.metastore.mysql;
+
+import org.apache.sqoop.manager.mysql.MySQLTestUtils;
+import org.apache.sqoop.metastore.JobToolTestBase;
+
+/**
+ * Test that the Job Tool works in MySql
+ *
+ * This uses JDBC to store and retrieve metastore data from a MySql server
+ *
+ * Since this requires a MySql installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=MySqlJobToolTest or -Dthirdparty=true.
+ *
+ * You need to put MySql JDBC driver library (mysql-connector-java-5.1.38-bin.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running MySql database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.mysql.connectstring.host_url, -Dsqoop.test.mysql.databasename,
+ * -Dsqoop.test.mysql.username and -Dsqoop.test.mysql.password respectively
+ */
+
+public class MySqlJobToolTest extends JobToolTestBase {
+
+ private static MySQLTestUtils mySQLTestUtils = new MySQLTestUtils();
+
+ public MySqlJobToolTest() {
+ super(mySQLTestUtils.getMySqlConnectString(), mySQLTestUtils.getUserName(),
+ mySQLTestUtils.getUserPass());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/mysql/MySqlMetaConnectIncrementalImportTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/mysql/MySqlMetaConnectIncrementalImportTest.java b/src/test/org/apache/sqoop/metastore/mysql/MySqlMetaConnectIncrementalImportTest.java
new file mode 100644
index 0000000..e19bbc8
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/mysql/MySqlMetaConnectIncrementalImportTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.metastore.mysql;
+
+
+import org.apache.sqoop.manager.mysql.MySQLTestUtils;
+import org.apache.sqoop.metastore.MetaConnectIncrementalImportTestBase;
+
+/**
+ * Test that Incremental-Import values are stored correctly in MySql
+ *
+ * This uses JDBC to store and retrieve metastore data from a MySql server
+ *
+ * Since this requires a DB2 installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=MySqlMetaConnectIncrementalImportTest or -Dthirdparty=true.
+ *
+ * You need to put MySql JDBC driver library (mysql-connector-java-5.1.38-bin.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running MySql database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.mysql.connectstring.host_url, -Dsqoop.test.mysql.databasename,
+ * -Dsqoop.test.mysql.username and -Dsqoop.test.mysql.password respectively
+ */
+
+public class MySqlMetaConnectIncrementalImportTest extends MetaConnectIncrementalImportTestBase {
+
+ private static MySQLTestUtils mySQLTestUtils = new MySQLTestUtils();
+
+ public MySqlMetaConnectIncrementalImportTest() {
+ super(mySQLTestUtils.getMySqlConnectString(), mySQLTestUtils.getUserName(),
+ mySQLTestUtils.getUserPass());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/mysql/MySqlSavedJobsTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/mysql/MySqlSavedJobsTest.java b/src/test/org/apache/sqoop/metastore/mysql/MySqlSavedJobsTest.java
new file mode 100644
index 0000000..e15c322
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/mysql/MySqlSavedJobsTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.metastore.mysql;
+
+import org.apache.sqoop.manager.mysql.MySQLTestUtils;
+import org.apache.sqoop.metastore.SavedJobsTestBase;
+import org.apache.sqoop.manager.JdbcDrivers;
+
+/**
+ * Test of GenericJobStorage compatibility with MySql
+ *
+ * This uses JDBC to store and retrieve metastore data from a MySql server
+ *
+ * Since this requires a MySql installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=MySqlSavedJobsTest or -Dthirdparty=true.
+ *
+ * You need to put MySql JDBC driver library (mysql-connector-java-5.1.38-bin.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running MySql database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.mysql.connectstring.host_url, -Dsqoop.test.mysql.databasename,
+ * -Dsqoop.test.mysql.username and -Dsqoop.test.mysql.password respectively
+ */
+
+public class MySqlSavedJobsTest extends SavedJobsTestBase {
+
+ private static MySQLTestUtils mySQLTestUtils = new MySQLTestUtils();
+
+ public MySqlSavedJobsTest() {
+ super(mySQLTestUtils.getMySqlConnectString(), mySQLTestUtils.getUserName(),
+ mySQLTestUtils.getUserPass(), JdbcDrivers.MYSQL.getDriverClass());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/oracle/OracleJobToolTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/oracle/OracleJobToolTest.java b/src/test/org/apache/sqoop/metastore/oracle/OracleJobToolTest.java
new file mode 100644
index 0000000..a3e61e9
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/oracle/OracleJobToolTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.metastore.oracle;
+
+import org.apache.sqoop.manager.oracle.util.OracleUtils;
+import org.apache.sqoop.metastore.JobToolTestBase;
+
+/**
+ * Test that the Job Tool works in Oracle
+ *
+ * This uses JDBC to store and retrieve metastore data from an Oracle server
+ *
+ * Since this requires an Oracle installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=OracleJobToolTest or -Dthirdparty=true.
+ *
+ * You need to put Oracle JDBC driver library (ojdbc6.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running Oracle database,
+ * Set server URL, username, and password with system variables
+ * -Dsqoop.test.oracle.connectstring, -Dsqoop.test.oracle.username
+ * and -Dsqoop.test.oracle.password respectively
+ */
+
+public class OracleJobToolTest extends JobToolTestBase {
+
+ public OracleJobToolTest() {
+ super(OracleUtils.CONNECT_STRING,
+ OracleUtils.ORACLE_USER_NAME,
+ OracleUtils.ORACLE_USER_PASS);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/oracle/OracleMetaConnectIncrementalImportTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/oracle/OracleMetaConnectIncrementalImportTest.java b/src/test/org/apache/sqoop/metastore/oracle/OracleMetaConnectIncrementalImportTest.java
new file mode 100644
index 0000000..37beaa4
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/oracle/OracleMetaConnectIncrementalImportTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.metastore.oracle;
+
+import org.apache.sqoop.manager.oracle.util.OracleUtils;
+import org.apache.sqoop.metastore.MetaConnectIncrementalImportTestBase;
+
+/**
+ * Test that Incremental-Import values are stored correctly in Oracle
+ *
+ * This uses JDBC to store and retrieve metastore data from an Oracle server
+ *
+ * Since this requires an Oracle installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=OracleMetaConnectIncrementalImportTest or -Dthirdparty=true.
+ *
+ * You need to put Oracle JDBC driver library (ojdbc6.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running Oracle database,
+ * Set server URL, username, and password with system variables
+ * -Dsqoop.test.oracle.connectstring, -Dsqoop.test.oracle.username
+ * and -Dsqoop.test.oracle.password respectively
+ */
+
+public class OracleMetaConnectIncrementalImportTest extends MetaConnectIncrementalImportTestBase {
+
+ public OracleMetaConnectIncrementalImportTest() {
+ super(OracleUtils.CONNECT_STRING,
+ OracleUtils.ORACLE_USER_NAME,
+ OracleUtils.ORACLE_USER_PASS);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/oracle/OracleSavedJobsTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/oracle/OracleSavedJobsTest.java b/src/test/org/apache/sqoop/metastore/oracle/OracleSavedJobsTest.java
new file mode 100644
index 0000000..4691530
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/oracle/OracleSavedJobsTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.metastore.oracle;
+
+import org.apache.sqoop.manager.oracle.util.OracleUtils;
+import org.apache.sqoop.metastore.SavedJobsTestBase;
+import org.apache.sqoop.manager.JdbcDrivers;
+
+/**
+ * Test of GenericJobStorage compatibility with Oracle
+ *
+ * This uses JDBC to store and retrieve metastore data from an Oracle server
+ *
+ * Since this requires an Oracle installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=OracleSavedJobsTest or -Dthirdparty=true.
+ *
+ * You need to put Oracle JDBC driver library (ojdbc6.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running Oracle database,
+ * Set server URL, username, and password with system variables
+ * -Dsqoop.test.oracle.connectstring, -Dsqoop.test.oracle.username
+ * and -Dsqoop.test.oracle.password respectively
+ */
+
+public class OracleSavedJobsTest extends SavedJobsTestBase {
+
+ public OracleSavedJobsTest() {
+ super(OracleUtils.CONNECT_STRING,
+ OracleUtils.ORACLE_USER_NAME,
+ OracleUtils.ORACLE_USER_PASS,
+ JdbcDrivers.ORACLE.getDriverClass());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/postgres/PostgresJobToolTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/postgres/PostgresJobToolTest.java b/src/test/org/apache/sqoop/metastore/postgres/PostgresJobToolTest.java
new file mode 100644
index 0000000..065e1bb
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/postgres/PostgresJobToolTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.metastore.postgres;
+
+import org.apache.sqoop.metastore.JobToolTestBase;
+
+/**
+ * Test that the Job Tool works in PostgreSQL
+ *
+ * This uses JDBC to store and retrieve metastore data from a Postgres server
+ *
+ * Since this requires a Postgres installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=PostgresJobToolTest or -Dthirdparty=true.
+ *
+ * Once you have a running Postgres database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.postgresql.connectstring.host_url, -Dsqoop.test.postgresql.database,
+ * -Dsqoop.test.postgresql.username and -Dsqoop.test.postgresql.password respectively
+ */
+
+public class PostgresJobToolTest extends JobToolTestBase {
+
+ private static final String HOST_URL = System.getProperty("sqoop.test.postgresql.connectstring.host_url",
+ "jdbc:postgresql://localhost/");
+ private static final String DATABASE_USER = System.getProperty(
+ "sqoop.test.postgresql.username", "sqooptest");
+ private static final String DATABASE_NAME = System.getProperty(
+ "sqoop.test.postgresql.database", "sqooptest");
+ private static final String PASSWORD = System.getProperty("sqoop.test.postgresql.password");
+ private static final String CONNECT_STRING = HOST_URL + DATABASE_NAME;
+
+ public PostgresJobToolTest() {
+ super(CONNECT_STRING, DATABASE_USER, PASSWORD);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/postgres/PostgresMetaConnectIncrementalImportTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/postgres/PostgresMetaConnectIncrementalImportTest.java b/src/test/org/apache/sqoop/metastore/postgres/PostgresMetaConnectIncrementalImportTest.java
new file mode 100644
index 0000000..0ffbf5a
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/postgres/PostgresMetaConnectIncrementalImportTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.metastore.postgres;
+
+import org.apache.sqoop.metastore.MetaConnectIncrementalImportTestBase;
+
+/**
+ * Test that Incremental-Import values are stored correctly in PostgreSQL
+ *
+ * This uses JDBC to store and retrieve metastore data from a Postgres server
+ *
+ * Since this requires a Postgres installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=PostgresMetaConnectIncrementalImportTest or -Dthirdparty=true.
+ *
+ * Once you have a running Postgres database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.postgresql.connectstring.host_url, -Dsqoop.test.postgresql.database,
+ * -Dsqoop.test.postgresql.username and -Dsqoop.test.postgresql.password respectively
+ */
+
+public class PostgresMetaConnectIncrementalImportTest extends MetaConnectIncrementalImportTestBase {
+
+ private static final String HOST_URL = System.getProperty("sqoop.test.postgresql.connectstring.host_url",
+ "jdbc:postgresql://localhost/");
+ private static final String DATABASE_USER = System.getProperty(
+ "sqoop.test.postgresql.username", "sqooptest");
+ private static final String DATABASE_NAME = System.getProperty(
+ "sqoop.test.postgresql.database", "sqooptest");
+ private static final String PASSWORD = System.getProperty("sqoop.test.postgresql.password");
+ private static final String CONNECT_STRING = HOST_URL + DATABASE_NAME;
+
+ public PostgresMetaConnectIncrementalImportTest() {
+ super(CONNECT_STRING, DATABASE_USER, PASSWORD);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/postgres/PostgresSavedJobsTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/postgres/PostgresSavedJobsTest.java b/src/test/org/apache/sqoop/metastore/postgres/PostgresSavedJobsTest.java
new file mode 100644
index 0000000..ee3f005
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/postgres/PostgresSavedJobsTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.metastore.postgres;
+
+import org.apache.sqoop.metastore.SavedJobsTestBase;
+import org.apache.sqoop.manager.JdbcDrivers;
+
+/**
+ * Test of GenericJobStorage compatibility with PostgreSQL
+ *
+ * This uses JDBC to store and retrieve metastore data from a Postgres server
+ *
+ * Since this requires a Postgres installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=PostgresSavedJobsTest or -Dthirdparty=true.
+ *
+ * Once you have a running Postgres database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.postgresql.connectstring.host_url, -Dsqoop.test.postgresql.database,
+ * -Dsqoop.test.postgresql.username and -Dsqoop.test.postgresql.password respectively
+ */
+
+public class PostgresSavedJobsTest extends SavedJobsTestBase {
+
+ private static final String HOST_URL = System.getProperty("sqoop.test.postgresql.connectstring.host_url",
+ "jdbc:postgresql://localhost/");
+ private static final String DATABASE_USER = System.getProperty(
+ "sqoop.test.postgresql.username", "sqooptest");
+ private static final String DATABASE_NAME = System.getProperty(
+ "sqoop.test.postgresql.database", "sqooptest");
+ private static final String PASSWORD = System.getProperty("sqoop.test.postgresql.password");
+ private static final String CONNECT_STRING = HOST_URL + DATABASE_NAME;
+
+ public PostgresSavedJobsTest() {
+ super(CONNECT_STRING, DATABASE_USER, PASSWORD, JdbcDrivers.POSTGRES.getDriverClass());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerJobToolTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerJobToolTest.java b/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerJobToolTest.java
new file mode 100644
index 0000000..87d7b34
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerJobToolTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.metastore.sqlserver;
+
+import org.apache.sqoop.metastore.JobToolTestBase;
+import org.apache.sqoop.manager.sqlserver.MSSQLTestUtils;
+
+/**
+ * Test that the Job Tool works in SQLServer
+ *
+ * This uses JDBC to store and retrieve metastore data from an SQLServer
+ *
+ * Since this requires an SQLServer installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=SqlServerJobToolTest or -Dthirdparty=true.
+ *
+ * You need to put SQL Server JDBC driver library (sqljdbc4.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running SQLServer database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.sqlserver.connectstring.host_url, -Dsqoop.test.sqlserver.database,
+ * -Dms.sqlserver.username and -Dms.sqlserver.password respectively
+ */
+
+public class SqlServerJobToolTest extends JobToolTestBase {
+
+ private static MSSQLTestUtils msSQLTestUtils = new MSSQLTestUtils();
+
+ public SqlServerJobToolTest() {
+ super(msSQLTestUtils.getDBConnectString(),
+ msSQLTestUtils.getDBUserName(),
+ msSQLTestUtils.getDBPassWord());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerMetaConnectIncrementalImportTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerMetaConnectIncrementalImportTest.java b/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerMetaConnectIncrementalImportTest.java
new file mode 100644
index 0000000..f1a2a66
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerMetaConnectIncrementalImportTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.metastore.sqlserver;
+
+import org.apache.sqoop.metastore.MetaConnectIncrementalImportTestBase;
+import org.apache.sqoop.manager.sqlserver.MSSQLTestUtils;
+
+/**
+ * Test that Incremental-Import values are stored correctly in SQLServer
+ *
+ * This uses JDBC to store and retrieve metastore data from an SQLServer
+ *
+ * Since this requires an SQLServer installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=SqlServerJobToolTest or -Dthirdparty=true.
+ *
+ * You need to put SQL Server JDBC driver library (sqljdbc4.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running SQLServer database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.sqlserver.connectstring.host_url, -Dsqoop.test.sqlserver.database,
+ * -Dms.sqlserver.username and -Dms.sqlserver.password respectively
+ */
+
+public class SqlServerMetaConnectIncrementalImportTest extends MetaConnectIncrementalImportTestBase {
+
+ private static MSSQLTestUtils msSQLTestUtils = new MSSQLTestUtils();
+
+ public SqlServerMetaConnectIncrementalImportTest() {
+ super(msSQLTestUtils.getDBConnectString(),
+ msSQLTestUtils.getDBUserName(),
+ msSQLTestUtils.getDBPassWord());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerSavedJobsTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerSavedJobsTest.java b/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerSavedJobsTest.java
new file mode 100644
index 0000000..b37623b
--- /dev/null
+++ b/src/test/org/apache/sqoop/metastore/sqlserver/SqlServerSavedJobsTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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.metastore.sqlserver;
+
+import org.apache.sqoop.metastore.SavedJobsTestBase;
+import org.apache.sqoop.manager.JdbcDrivers;
+import org.apache.sqoop.manager.sqlserver.MSSQLTestUtils;
+
+/**
+ * Test of GenericJobStorage compatibility with SQLServer
+ *
+ * This uses JDBC to store and retrieve metastore data from an SQLServer
+ *
+ * Since this requires an SQLServer installation,
+ * this class is named in such a way that Sqoop's default QA process does
+ * not run it. You need to run this manually with
+ * -Dtestcase=SqlServerJobToolTest or -Dthirdparty=true.
+ *
+ * You need to put SQL Server JDBC driver library (sqljdbc4.jar) in a location
+ * where Sqoop will be able to access it (since this library cannot be checked
+ * into Apache's tree for licensing reasons) and set it's path through -Dsqoop.thirdparty.lib.dir.
+ *
+ * Once you have a running SQLServer database,
+ * Set server URL, database name, username, and password with system variables
+ * -Dsqoop.test.sqlserver.connectstring.host_url, -Dsqoop.test.sqlserver.database,
+ * -Dms.sqlserver.username and -Dms.sqlserver.password respectively
+ */
+
+public class SqlServerSavedJobsTest extends SavedJobsTestBase {
+
+ private static MSSQLTestUtils msSQLTestUtils = new MSSQLTestUtils();
+
+ public SqlServerSavedJobsTest() {
+ super(msSQLTestUtils.getDBConnectString(),
+ msSQLTestUtils.getDBUserName(),
+ msSQLTestUtils.getDBPassWord(),
+ JdbcDrivers.SQLSERVER.getDriverClass());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/orm/TestClassWriter.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/orm/TestClassWriter.java b/src/test/org/apache/sqoop/orm/TestClassWriter.java
new file mode 100644
index 0000000..0cc07cf
--- /dev/null
+++ b/src/test/org/apache/sqoop/orm/TestClassWriter.java
@@ -0,0 +1,737 @@
+/**
+ * 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.orm;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.SQLException;
+import java.util.Random;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.util.Shell;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.sqoop.SqoopOptions;
+import org.apache.sqoop.TestConnFactory.DummyManager;
+import org.apache.sqoop.manager.ConnManager;
+import org.apache.sqoop.testutil.DirUtil;
+import org.apache.sqoop.testutil.HsqldbTestServer;
+import org.apache.sqoop.testutil.ImportJobTestCase;
+import org.apache.sqoop.tool.ImportTool;
+import org.apache.sqoop.util.ClassLoaderStack;
+import org.junit.rules.ExpectedException;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Test that the ClassWriter generates Java classes based on the given table,
+ * which compile.
+ */
+public class TestClassWriter {
+
+ public static final Log LOG =
+ LogFactory.getLog(TestClassWriter.class.getName());
+ private static final String WIDE_TABLE_NAME = "WIDETABLE";
+ private static final int WIDE_TABLE_COLUMN_COUNT = 800;
+ private static final int WIDE_TABLE_ROW_COUNT = 20_000;
+
+ // instance variables populated during setUp, used during tests
+ private HsqldbTestServer testServer;
+ private ConnManager manager;
+ private SqoopOptions options;
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Before
+ public void setUp() {
+ testServer = new HsqldbTestServer();
+ org.apache.log4j.Logger root = org.apache.log4j.Logger.getRootLogger();
+ root.setLevel(org.apache.log4j.Level.DEBUG);
+ try {
+ testServer.resetServer();
+ } catch (SQLException sqlE) {
+ LOG.error("Got SQLException: " + sqlE.toString());
+ fail("Got SQLException: " + sqlE.toString());
+ } catch (ClassNotFoundException cnfe) {
+ LOG.error("Could not find class for db driver: " + cnfe.toString());
+ fail("Could not find class for db driver: " + cnfe.toString());
+ }
+
+ manager = testServer.getManager();
+ options = testServer.getSqoopOptions();
+
+ // sanity check: make sure we're in a tmp dir before we blow anything away.
+ assertTrue("Test generates code in non-tmp dir!",
+ CODE_GEN_DIR.startsWith(ImportJobTestCase.TEMP_BASE_DIR));
+ assertTrue("Test generates jars in non-tmp dir!",
+ JAR_GEN_DIR.startsWith(ImportJobTestCase.TEMP_BASE_DIR));
+
+ // start out by removing these directories ahead of time
+ // to ensure that this is truly generating the code.
+ File codeGenDirFile = new File(CODE_GEN_DIR);
+ File classGenDirFile = new File(JAR_GEN_DIR);
+
+ if (codeGenDirFile.exists()) {
+ LOG.debug("Removing code gen dir: " + codeGenDirFile);
+ if (!DirUtil.deleteDir(codeGenDirFile)) {
+ LOG.warn("Could not delete " + codeGenDirFile + " prior to test");
+ }
+ }
+
+ if (classGenDirFile.exists()) {
+ LOG.debug("Removing class gen dir: " + classGenDirFile);
+ if (!DirUtil.deleteDir(classGenDirFile)) {
+ LOG.warn("Could not delete " + classGenDirFile + " prior to test");
+ }
+ }
+ }
+
+ @After
+ public void tearDown() {
+ try {
+ manager.close();
+ } catch (SQLException sqlE) {
+ LOG.error("Got SQLException: " + sqlE.toString());
+ fail("Got SQLException: " + sqlE.toString());
+ }
+ }
+
+ static final String CODE_GEN_DIR = ImportJobTestCase.TEMP_BASE_DIR
+ + "sqoop/test/codegen";
+ static final String JAR_GEN_DIR = ImportJobTestCase.TEMP_BASE_DIR
+ + "sqoop/test/jargen";
+
+ private File runGenerationTest(String[] argv, String classNameToCheck) {
+ return runGenerationTest(argv, classNameToCheck, HsqldbTestServer.getTableName());
+ }
+
+ /**
+ * Run a test to verify that we can generate code and it emits the output
+ * files where we expect them.
+ * @return
+ */
+ private File runGenerationTest(String[] argv, String classNameToCheck, String tableName) {
+ File codeGenDirFile = new File(CODE_GEN_DIR);
+ File classGenDirFile = new File(JAR_GEN_DIR);
+
+ try {
+ options = new ImportTool().parseArguments(argv,
+ null, options, true);
+ } catch (Exception e) {
+ LOG.error("Could not parse options: " + e.toString());
+ }
+
+ CompilationManager compileMgr = new CompilationManager(options);
+ ClassWriter writer = new ClassWriter(options, manager,
+ tableName, compileMgr);
+
+ try {
+ writer.generate();
+ compileMgr.compile();
+ compileMgr.jar();
+ } catch (IOException ioe) {
+ LOG.error("Got IOException: " + ioe.toString());
+ fail("Got IOException: " + ioe.toString());
+ }
+
+ String classFileNameToCheck = classNameToCheck.replace('.',
+ File.separatorChar);
+ LOG.debug("Class file to check for: " + classFileNameToCheck);
+
+ // Check that all the files we expected to generate (.java, .class, .jar)
+ // exist.
+ File tableFile = new File(codeGenDirFile, classFileNameToCheck + ".java");
+ assertTrue("Cannot find generated source file for table!",
+ tableFile.exists());
+ LOG.debug("Found generated source: " + tableFile);
+
+ File tableClassFile = new File(classGenDirFile, classFileNameToCheck
+ + ".class");
+ assertTrue("Cannot find generated class file for table!",
+ tableClassFile.exists());
+ LOG.debug("Found generated class: " + tableClassFile);
+
+ File jarFile = new File(compileMgr.getJarFilename());
+ assertTrue("Cannot find compiled jar", jarFile.exists());
+ LOG.debug("Found generated jar: " + jarFile);
+
+ // check that the .class file made it into the .jar by enumerating
+ // available entries in the jar file.
+ boolean foundCompiledClass = false;
+ if (Shell.WINDOWS) {
+ // In Windows OS, elements in jar files still need to have a path
+ // separator of '/' rather than the default File.separator which is '\'
+ classFileNameToCheck = classFileNameToCheck.replace(File.separator, "/");
+ }
+ try {
+ JarInputStream jis = new JarInputStream(new FileInputStream(jarFile));
+
+ LOG.debug("Jar file has entries:");
+ while (true) {
+ JarEntry entry = jis.getNextJarEntry();
+ if (null == entry) {
+ // no more entries.
+ break;
+ }
+
+ if (entry.getName().equals(classFileNameToCheck + ".class")) {
+ foundCompiledClass = true;
+ LOG.debug(" * " + entry.getName());
+ } else {
+ LOG.debug(" " + entry.getName());
+ }
+ }
+
+ jis.close();
+ } catch (IOException ioe) {
+ fail("Got IOException iterating over Jar file: " + ioe.toString());
+ }
+
+ assertTrue("Cannot find .class file " + classFileNameToCheck
+ + ".class in jar file", foundCompiledClass);
+
+ LOG.debug("Found class in jar - test success!");
+ return jarFile;
+ }
+
+ /**
+ * Test that we can generate code. Test that we can redirect the --outdir
+ * and --bindir too.
+ */
+ @Test
+ public void testCodeGen() {
+
+ // Set the option strings in an "argv" to redirect our srcdir and bindir.
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ };
+
+ runGenerationTest(argv, HsqldbTestServer.getTableName());
+ }
+
+ private static final String OVERRIDE_CLASS_NAME = "override";
+
+ /**
+ * Test that we can generate code with a custom class name.
+ */
+ @Test
+ public void testSetClassName() {
+
+ // Set the option strings in an "argv" to redirect our srcdir and bindir
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ "--class-name",
+ OVERRIDE_CLASS_NAME,
+ };
+
+ runGenerationTest(argv, OVERRIDE_CLASS_NAME);
+ }
+
+ private static final String OVERRIDE_CLASS_AND_PACKAGE_NAME =
+ "override.pkg.prefix.classname";
+
+ /**
+ * Test that we can generate code with a custom class name that includes a
+ * package.
+ */
+ @Test
+ public void testSetClassAndPackageName() {
+
+ // Set the option strings in an "argv" to redirect our srcdir and bindir
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ "--class-name",
+ OVERRIDE_CLASS_AND_PACKAGE_NAME,
+ };
+
+ runGenerationTest(argv, OVERRIDE_CLASS_AND_PACKAGE_NAME);
+ }
+
+ private static final String OVERRIDE_PACKAGE_NAME =
+ "special.userpackage.name";
+
+ /**
+ * Test that we can generate code with a custom class name that includes a
+ * package.
+ */
+ @Test
+ public void testSetPackageName() {
+
+ // Set the option strings in an "argv" to redirect our srcdir and bindir
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ "--package-name",
+ OVERRIDE_PACKAGE_NAME,
+ };
+
+ runGenerationTest(argv, OVERRIDE_PACKAGE_NAME + "."
+ + HsqldbTestServer.getTableName());
+ }
+
+
+ // Test the SQL identifier -> Java identifier conversion.
+ @Test
+ public void testJavaIdentifierConversion() {
+ assertNull(ClassWriter.getIdentifierStrForChar(' '));
+ assertNull(ClassWriter.getIdentifierStrForChar('\t'));
+ assertNull(ClassWriter.getIdentifierStrForChar('\r'));
+ assertNull(ClassWriter.getIdentifierStrForChar('\n'));
+ assertEquals("x", ClassWriter.getIdentifierStrForChar('x'));
+ assertEquals("_", ClassWriter.getIdentifierStrForChar('-'));
+ assertEquals("_", ClassWriter.getIdentifierStrForChar('_'));
+
+ assertEquals("foo", ClassWriter.toJavaIdentifier("foo"));
+
+ assertEquals("_abstract", ClassWriter.toJavaIdentifier("abstract"));
+ assertEquals("_assert", ClassWriter.toJavaIdentifier("assert"));
+ assertEquals("_boolean", ClassWriter.toJavaIdentifier("boolean"));
+ assertEquals("_break", ClassWriter.toJavaIdentifier("break"));
+ assertEquals("_byte", ClassWriter.toJavaIdentifier("byte"));
+ assertEquals("_case", ClassWriter.toJavaIdentifier("case"));
+ assertEquals("_catch", ClassWriter.toJavaIdentifier("catch"));
+ assertEquals("_char", ClassWriter.toJavaIdentifier("char"));
+ assertEquals("_class", ClassWriter.toJavaIdentifier("class"));
+ assertEquals("_const", ClassWriter.toJavaIdentifier("const"));
+ assertEquals("_continue", ClassWriter.toJavaIdentifier("continue"));
+ assertEquals("_default", ClassWriter.toJavaIdentifier("default"));
+ assertEquals("_do", ClassWriter.toJavaIdentifier("do"));
+ assertEquals("_double", ClassWriter.toJavaIdentifier("double"));
+ assertEquals("_else", ClassWriter.toJavaIdentifier("else"));
+ assertEquals("_enum", ClassWriter.toJavaIdentifier("enum"));
+ assertEquals("_extends", ClassWriter.toJavaIdentifier("extends"));
+ assertEquals("_false", ClassWriter.toJavaIdentifier("false"));
+ assertEquals("_final", ClassWriter.toJavaIdentifier("final"));
+ assertEquals("_finally", ClassWriter.toJavaIdentifier("finally"));
+ assertEquals("_float", ClassWriter.toJavaIdentifier("float"));
+ assertEquals("_for", ClassWriter.toJavaIdentifier("for"));
+ assertEquals("_goto", ClassWriter.toJavaIdentifier("goto"));
+ assertEquals("_if", ClassWriter.toJavaIdentifier("if"));
+ assertEquals("_implements", ClassWriter.toJavaIdentifier("implements"));
+ assertEquals("_import", ClassWriter.toJavaIdentifier("import"));
+ assertEquals("_instanceof", ClassWriter.toJavaIdentifier("instanceof"));
+ assertEquals("_int", ClassWriter.toJavaIdentifier("int"));
+ assertEquals("_interface", ClassWriter.toJavaIdentifier("interface"));
+ assertEquals("_long", ClassWriter.toJavaIdentifier("long"));
+ assertEquals("_native", ClassWriter.toJavaIdentifier("native"));
+ assertEquals("_new", ClassWriter.toJavaIdentifier("new"));
+ assertEquals("_null", ClassWriter.toJavaIdentifier("null"));
+ assertEquals("_package", ClassWriter.toJavaIdentifier("package"));
+ assertEquals("_private", ClassWriter.toJavaIdentifier("private"));
+ assertEquals("_protected", ClassWriter.toJavaIdentifier("protected"));
+ assertEquals("_public", ClassWriter.toJavaIdentifier("public"));
+ assertEquals("_return", ClassWriter.toJavaIdentifier("return"));
+ assertEquals("_short", ClassWriter.toJavaIdentifier("short"));
+ assertEquals("_static", ClassWriter.toJavaIdentifier("static"));
+ assertEquals("_strictfp", ClassWriter.toJavaIdentifier("strictfp"));
+ assertEquals("_super", ClassWriter.toJavaIdentifier("super"));
+ assertEquals("_switch", ClassWriter.toJavaIdentifier("switch"));
+ assertEquals("_synchronized", ClassWriter.toJavaIdentifier("synchronized"));
+ assertEquals("_this", ClassWriter.toJavaIdentifier("this"));
+ assertEquals("_throw", ClassWriter.toJavaIdentifier("throw"));
+ assertEquals("_throws", ClassWriter.toJavaIdentifier("throws"));
+ assertEquals("_transient", ClassWriter.toJavaIdentifier("transient"));
+ assertEquals("_true", ClassWriter.toJavaIdentifier("true"));
+ assertEquals("_try", ClassWriter.toJavaIdentifier("try"));
+ assertEquals("_void", ClassWriter.toJavaIdentifier("void"));
+ assertEquals("_volatile", ClassWriter.toJavaIdentifier("volatile"));
+ assertEquals("_while", ClassWriter.toJavaIdentifier("while"));
+
+ assertEquals("_class", ClassWriter.toJavaIdentifier("cla ss"));
+ assertEquals("_int", ClassWriter.toJavaIdentifier("int"));
+ assertEquals("thisismanywords", ClassWriter.toJavaIdentifier(
+ "this is many words"));
+ assertEquals("_9isLegalInSql", ClassWriter.toJavaIdentifier(
+ "9isLegalInSql"));
+ assertEquals("____", ClassWriter.toJavaIdentifier("___"));
+ assertEquals("__class", ClassWriter.toJavaIdentifier("_class"));
+ //Checking Java identifier for Constant PROTOCOL_VERSION
+ assertEquals("_PROTOCOL_VERSION", ClassWriter.toJavaIdentifier("PROTOCOL_VERSION"));
+ }
+
+ @Test
+ public void testWeirdColumnNames() throws SQLException {
+ // Recreate the table with column names that aren't legal Java identifiers.
+ String tableName = HsqldbTestServer.getTableName();
+ Connection connection = testServer.getConnection();
+ Statement st = connection.createStatement();
+ try {
+ st.executeUpdate("DROP TABLE " + tableName + " IF EXISTS");
+ st.executeUpdate("CREATE TABLE " + tableName
+ + " (class INT, \"9field\" INT)");
+ st.executeUpdate("INSERT INTO " + tableName + " VALUES(42, 41)");
+ connection.commit();
+ } finally {
+ st.close();
+ connection.close();
+ }
+
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ "--package-name",
+ OVERRIDE_PACKAGE_NAME,
+ };
+
+ runGenerationTest(argv, OVERRIDE_PACKAGE_NAME + "."
+ + HsqldbTestServer.getTableName());
+ }
+
+ // Test For checking Codegneration perfroming successfully
+ // in case of Table with Column name as PROTOCOL_VERSION
+ @Test
+ public void testColumnNameAsProtocolVersion() throws SQLException {
+ // Recreate the table with column name as PROTOCOL_VERSION.
+ String tableName = HsqldbTestServer.getTableName();
+ Connection connection = testServer.getConnection();
+ Statement st = connection.createStatement();
+ try {
+ st.executeUpdate("DROP TABLE " + tableName + " IF EXISTS");
+ st.executeUpdate("CREATE TABLE " + tableName
+ + " (PROTOCOL_VERSION INT)");
+ st.executeUpdate("INSERT INTO " + tableName + " VALUES(42)");
+ connection.commit();
+ } finally {
+ st.close();
+ connection.close();
+ }
+
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ "--package-name",
+ OVERRIDE_PACKAGE_NAME,
+ };
+
+ runGenerationTest(argv, OVERRIDE_PACKAGE_NAME + "."
+ + HsqldbTestServer.getTableName());
+ }
+
+ @Test
+ public void testCloningTableWithVarbinaryDoesNotThrowNPE() throws SQLException,
+ IOException, ClassNotFoundException, NoSuchMethodException,
+ SecurityException, InstantiationException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException {
+ String tableName = HsqldbTestServer.getTableName();
+ Connection connection = testServer.getConnection();
+ Statement st = connection.createStatement();
+ try {
+ st.executeUpdate("DROP TABLE " + tableName + " IF EXISTS");
+ st.executeUpdate("CREATE TABLE " + tableName
+ + " (id INT, test VARBINARY(10))");
+ connection.commit();
+ } finally {
+ st.close();
+ connection.close();
+ }
+
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ "--package-name",
+ OVERRIDE_PACKAGE_NAME,
+ };
+
+ String className = OVERRIDE_PACKAGE_NAME + "."
+ + HsqldbTestServer.getTableName();
+ File ormJarFile = runGenerationTest(argv, className);
+
+ ClassLoader prevClassLoader = ClassLoaderStack.addJarFile(
+ ormJarFile.getCanonicalPath(), className);
+ Class tableClass = Class.forName(className, true,
+ Thread.currentThread().getContextClassLoader());
+ Method cloneImplementation = tableClass.getMethod("clone");
+
+ Object instance = tableClass.newInstance();
+
+ assertTrue(cloneImplementation.invoke(instance).getClass().
+ getCanonicalName().equals(className));
+
+ if (null != prevClassLoader) {
+ ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
+ }
+ }
+
+ /**
+ * Test the generated equals method.
+ * @throws IOException
+ * @throws ClassNotFoundException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ * @throws NoSuchMethodException
+ * @throws SecurityException
+ * @throws InvocationTargetException
+ * @throws IllegalArgumentException
+ */
+ @Test
+ public void testEqualsMethod() throws IOException, ClassNotFoundException,
+ InstantiationException, IllegalAccessException, NoSuchMethodException,
+ InvocationTargetException {
+
+ // Set the option strings in an "argv" to redirect our srcdir and bindir
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ "--class-name",
+ OVERRIDE_CLASS_AND_PACKAGE_NAME,
+ };
+
+ File ormJarFile = runGenerationTest(argv, OVERRIDE_CLASS_AND_PACKAGE_NAME);
+ ClassLoader prevClassLoader = ClassLoaderStack.addJarFile(
+ ormJarFile.getCanonicalPath(),
+ OVERRIDE_CLASS_AND_PACKAGE_NAME);
+ Class tableClass = Class.forName(
+ OVERRIDE_CLASS_AND_PACKAGE_NAME,
+ true,
+ Thread.currentThread().getContextClassLoader());
+ Method setterIntField1 =
+ tableClass.getMethod("set_INTFIELD1", Integer.class);
+ Method setterIntField2 =
+ tableClass.getMethod("set_INTFIELD2", Integer.class);
+ Method equalsImplementation = tableClass.getMethod("equals", Object.class);
+
+ Object instance1 = tableClass.newInstance();
+ Object instance2 = tableClass.newInstance();
+
+ // test reflexivity
+ assertTrue((Boolean) equalsImplementation.invoke(instance1, instance1));
+
+ // test equality for uninitialized fields
+ assertTrue((Boolean) equalsImplementation.invoke(instance1, instance2));
+
+ // test symmetry
+ assertTrue((Boolean) equalsImplementation.invoke(instance2, instance1));
+
+ // test reflexivity with initialized fields
+ setterIntField1.invoke(instance1, new Integer(1));
+ setterIntField2.invoke(instance1, new Integer(2));
+ assertTrue((Boolean) equalsImplementation.invoke(instance1, instance1));
+
+ // test difference in both fields
+ setterIntField1.invoke(instance2, new Integer(3));
+ setterIntField2.invoke(instance2, new Integer(4));
+ assertFalse((Boolean) equalsImplementation.invoke(instance1, instance2));
+
+ // test difference in second field
+ setterIntField1.invoke(instance2, new Integer(1));
+ setterIntField2.invoke(instance2, new Integer(3));
+ assertFalse((Boolean) equalsImplementation.invoke(instance1, instance2));
+
+ // test difference in first field
+ setterIntField1.invoke(instance2, new Integer(3));
+ setterIntField2.invoke(instance2, new Integer(2));
+ assertFalse((Boolean) equalsImplementation.invoke(instance1, instance2));
+
+ // test equality for initialized fields
+ setterIntField1.invoke(instance2, new Integer(1));
+ setterIntField2.invoke(instance2, new Integer(2));
+ assertTrue((Boolean) equalsImplementation.invoke(instance1, instance2));
+
+ if (null != prevClassLoader) {
+ ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
+ }
+ }
+
+ private static final String USERMAPPING_CLASS_AND_PACKAGE_NAME =
+ "usermapping.pkg.prefix.classname";
+
+ @Test
+ public void testUserMapping() throws IOException, ClassNotFoundException,
+ InstantiationException, IllegalAccessException, NoSuchMethodException,
+ InvocationTargetException {
+
+ // Set the option strings in an "argv" to redirect our srcdir and bindir
+ String [] argv = {
+ "--bindir", JAR_GEN_DIR,
+ "--outdir", CODE_GEN_DIR,
+ "--class-name", USERMAPPING_CLASS_AND_PACKAGE_NAME,
+ "--map-column-java", "INTFIELD1=String",
+ };
+
+ File ormJarFile = runGenerationTest(argv,
+ USERMAPPING_CLASS_AND_PACKAGE_NAME);
+ ClassLoader prevClassLoader = ClassLoaderStack.addJarFile(
+ ormJarFile.getCanonicalPath(),
+ USERMAPPING_CLASS_AND_PACKAGE_NAME);
+ Class tableClass = Class.forName(
+ USERMAPPING_CLASS_AND_PACKAGE_NAME,
+ true,
+ Thread.currentThread().getContextClassLoader());
+
+ try {
+ Field intfield = tableClass.getDeclaredField("INTFIELD1");
+
+ assertEquals(String.class, intfield.getType());
+ } catch (NoSuchFieldException ex) {
+ fail("Can't find field for INTFIELD1");
+ } catch (SecurityException ex) {
+ fail("Can't find field for INTFIELD1");
+ }
+
+ if (null != prevClassLoader) {
+ ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
+ }
+ }
+
+ @Test
+ public void testBrokenUserMapping() throws Exception {
+
+ String [] argv = {
+ "--bindir", JAR_GEN_DIR,
+ "--outdir", CODE_GEN_DIR,
+ "--class-name", USERMAPPING_CLASS_AND_PACKAGE_NAME,
+ "--map-column-java", "INTFIELD1=NotARealClass",
+ };
+
+ try {
+ runGenerationTest(
+ argv,
+ USERMAPPING_CLASS_AND_PACKAGE_NAME);
+ } catch(IllegalArgumentException e) {
+ return;
+ }
+ fail("we shouldn't successfully generate code");
+ }
+
+ /**
+ * A dummy manager that declares that it ORM is self managed.
+ */
+ public static class DummyDirectManager extends DummyManager {
+ @Override
+ public boolean isORMFacilitySelfManaged() {
+ return true;
+ }
+ }
+
+ @Test
+ public void testNoClassGeneration() throws Exception {
+ manager = new DummyDirectManager();
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ };
+
+ try {
+ options = new ImportTool().parseArguments(argv,
+ null, options, true);
+ } catch (Exception e) {
+ LOG.error("Could not parse options: " + e.toString());
+ }
+
+ CompilationManager compileMgr = new CompilationManager(options);
+ ClassWriter writer = new ClassWriter(options, manager,
+ HsqldbTestServer.getTableName(), compileMgr);
+
+ writer.generate();
+
+ thrown.expect(Exception.class);
+ compileMgr.compile();
+ }
+
+ @Test(timeout = 25000)
+ public void testWideTableClassGeneration() throws Exception {
+ createWideTable();
+ options = new SqoopOptions(HsqldbTestServer.getDbUrl(), WIDE_TABLE_NAME);
+
+ // Set the option strings in an "argv" to redirect our srcdir and bindir.
+ String [] argv = {
+ "--bindir",
+ JAR_GEN_DIR,
+ "--outdir",
+ CODE_GEN_DIR,
+ };
+
+ File ormJarFile = runGenerationTest(argv, WIDE_TABLE_NAME, WIDE_TABLE_NAME);
+
+ ClassLoader prevClassLoader = ClassLoaderStack.addJarFile(ormJarFile.getCanonicalPath(),
+ WIDE_TABLE_NAME);
+ Class tableClass = Class.forName(WIDE_TABLE_NAME, true,
+ Thread.currentThread().getContextClassLoader());
+
+ Object instance = tableClass.newInstance();
+ Method setterMethod = tableClass.getMethod("setField", String.class, Object.class);
+ Random random = new Random(0);
+ for (int j = 0; j < WIDE_TABLE_ROW_COUNT; ++j) {
+ for (int i = 0; i < WIDE_TABLE_COLUMN_COUNT; ++i) {
+ setterMethod.invoke(instance, "INTFIELD" + i, random.nextInt());
+ }
+ }
+
+ if (null != prevClassLoader) {
+ ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
+ }
+ }
+
+ private void createWideTable() throws Exception {
+ try (Connection conn = testServer.getConnection(); Statement stmt = conn.createStatement();) {
+ stmt.executeUpdate("DROP TABLE \"" + WIDE_TABLE_NAME + "\" IF EXISTS");
+ StringBuilder sb = new StringBuilder("CREATE TABLE \"" + WIDE_TABLE_NAME + "\" (");
+ for (int i = 0; i < WIDE_TABLE_COLUMN_COUNT; ++i) {
+ sb.append("intField" + i + " INT");
+ if (i < WIDE_TABLE_COLUMN_COUNT - 1) {
+ sb.append(",");
+ } else {
+ sb.append(")");
+ }
+ }
+ stmt.executeUpdate(sb.toString());
+ conn.commit();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/orm/TestCompilationManager.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/orm/TestCompilationManager.java b/src/test/org/apache/sqoop/orm/TestCompilationManager.java
index b9e2608..abd72d8 100644
--- a/src/test/org/apache/sqoop/orm/TestCompilationManager.java
+++ b/src/test/org/apache/sqoop/orm/TestCompilationManager.java
@@ -17,7 +17,7 @@
*/
package org.apache.sqoop.orm;
-import com.cloudera.sqoop.SqoopOptions;
+import org.apache.sqoop.SqoopOptions;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/org/apache/sqoop/orm/TestParseMethods.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/orm/TestParseMethods.java b/src/test/org/apache/sqoop/orm/TestParseMethods.java
new file mode 100644
index 0000000..46bb52d
--- /dev/null
+++ b/src/test/org/apache/sqoop/orm/TestParseMethods.java
@@ -0,0 +1,296 @@
+/**
+ * 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.orm;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.commons.cli.ParseException;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.NullWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.FileInputFormat;
+import org.apache.hadoop.mapred.FileOutputFormat;
+import org.apache.hadoop.mapred.JobClient;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.sqoop.testutil.BaseSqoopTestCase;
+import org.apache.sqoop.testutil.CommonArgs;
+import org.apache.sqoop.testutil.ExplicitSetMapper;
+import org.apache.sqoop.testutil.HsqldbTestServer;
+import org.apache.sqoop.testutil.ImportJobTestCase;
+import org.apache.sqoop.testutil.ReparseMapper;
+import org.apache.sqoop.tool.BaseSqoopTool;
+
+import org.apache.sqoop.SqoopOptions;
+import org.apache.sqoop.SqoopOptions.InvalidOptionsException;
+import org.apache.sqoop.config.ConfigurationHelper;
+
+import org.apache.sqoop.tool.ImportTool;
+import org.apache.sqoop.util.ClassLoaderStack;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Test that the parse() methods generated in user SqoopRecord implementations
+ * work.
+ */
+public class TestParseMethods extends ImportJobTestCase {
+
+ /**
+ * Create the argv to pass to Sqoop.
+ * @return the argv as an array of strings.
+ */
+ private String [] getArgv(boolean includeHadoopFlags, String fieldTerminator,
+ String lineTerminator, String encloser, String escape,
+ boolean encloserRequired) {
+
+ ArrayList<String> args = new ArrayList<String>();
+
+ if (includeHadoopFlags) {
+ CommonArgs.addHadoopFlags(args);
+ }
+
+ args.add("--table");
+ args.add(getTableName());
+ args.add("--warehouse-dir");
+ args.add(getWarehouseDir());
+ args.add("--connect");
+ args.add(HsqldbTestServer.getUrl());
+ args.add("--as-textfile");
+ args.add("--split-by");
+ args.add("DATA_COL0"); // always split by first column.
+ args.add("--fields-terminated-by");
+ args.add(fieldTerminator);
+ args.add("--lines-terminated-by");
+ args.add(lineTerminator);
+ args.add("--escaped-by");
+ args.add(escape);
+ if (encloserRequired) {
+ args.add("--enclosed-by");
+ } else {
+ args.add("--optionally-enclosed-by");
+ }
+ args.add(encloser);
+ args.add("--num-mappers");
+ args.add("1");
+
+ return args.toArray(new String[0]);
+ }
+
+ @Test
+ public void testTemporaryRootDirParse() throws Exception {
+ String customRoot = "customroot";
+ String[] args = new String[] {"--"+BaseSqoopTool.TEMP_ROOTDIR_ARG, customRoot};
+
+ SqoopOptions opts = new ImportTool().parseArguments(args, null, null, true);
+
+ assertEquals(customRoot, opts.getTempRootDir());
+ }
+
+ public void runParseTest(String fieldTerminator, String lineTerminator,
+ String encloser, String escape, boolean encloseRequired)
+ throws IOException {
+
+ ClassLoader prevClassLoader = null;
+
+ String [] argv = getArgv(true, fieldTerminator, lineTerminator,
+ encloser, escape, encloseRequired);
+ runImport(argv);
+ try {
+ String tableClassName = getTableName();
+
+ argv = getArgv(false, fieldTerminator, lineTerminator, encloser, escape,
+ encloseRequired);
+ SqoopOptions opts = new ImportTool().parseArguments(argv, null, null,
+ true);
+
+ CompilationManager compileMgr = new CompilationManager(opts);
+ String jarFileName = compileMgr.getJarFilename();
+
+ // Make sure the user's class is loaded into our address space.
+ prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
+ tableClassName);
+
+ JobConf job = new JobConf();
+ job.setJar(jarFileName);
+
+ // Tell the job what class we're testing.
+ job.set(ReparseMapper.USER_TYPE_NAME_KEY, tableClassName);
+
+ // use local mode in the same JVM.
+ ConfigurationHelper.setJobtrackerAddr(job, "local");
+ if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
+ job.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
+ }
+ String warehouseDir = getWarehouseDir();
+ Path warehousePath = new Path(warehouseDir);
+ Path inputPath = new Path(warehousePath, getTableName());
+ Path outputPath = new Path(warehousePath, getTableName() + "-out");
+
+ job.setMapperClass(ReparseMapper.class);
+ job.setNumReduceTasks(0);
+ FileInputFormat.addInputPath(job, inputPath);
+ FileOutputFormat.setOutputPath(job, outputPath);
+
+ job.setOutputKeyClass(Text.class);
+ job.setOutputValueClass(NullWritable.class);
+
+ JobClient.runJob(job);
+ } catch (InvalidOptionsException ioe) {
+ fail(ioe.toString());
+ } catch (ParseException pe) {
+ fail(pe.toString());
+ } finally {
+ if (null != prevClassLoader) {
+ ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
+ }
+ }
+ }
+
+ @Test
+ public void testDefaults() throws IOException {
+ String [] types = { "INTEGER", "VARCHAR(32)", "INTEGER" };
+ String [] vals = { "64", "'foo'", "128" };
+
+ createTableWithColTypes(types, vals);
+ runParseTest(",", "\\n", "\\\"", "\\", false);
+ }
+
+ @Test
+ public void testRequiredEnclose() throws IOException {
+ String [] types = { "INTEGER", "VARCHAR(32)", "INTEGER" };
+ String [] vals = { "64", "'foo'", "128" };
+
+ createTableWithColTypes(types, vals);
+ runParseTest(",", "\\n", "\\\"", "\\", true);
+ }
+
+ @Test
+ public void testStringEscapes() throws IOException {
+ String [] types = {
+ "VARCHAR(32)",
+ "VARCHAR(32)",
+ "VARCHAR(32)",
+ "VARCHAR(32)",
+ "VARCHAR(32)",
+ };
+ String [] vals = {
+ "'foo'",
+ "'foo,bar'",
+ "'foo''bar'",
+ "'foo\\bar'",
+ "'foo,bar''baz'",
+ };
+
+ createTableWithColTypes(types, vals);
+ runParseTest(",", "\\n", "\\\'", "\\", false);
+ }
+
+ @Test
+ public void testNumericTypes() throws IOException {
+ String [] types = {
+ "INTEGER",
+ "REAL",
+ "FLOAT",
+ "DATE",
+ "TIME",
+ "TIMESTAMP",
+ "NUMERIC",
+ "BOOLEAN",
+ };
+ String [] vals = {
+ "42",
+ "36.0",
+ "127.1",
+ "'2009-07-02'",
+ "'11:24:00'",
+ "'2009-08-13 20:32:00.1234567'",
+ "92104916282869291837672829102857271948687.287475322",
+ "true",
+ };
+
+ createTableWithColTypes(types, vals);
+ runParseTest(",", "\\n", "\\\'", "\\", false);
+ }
+
+ @Test
+ public void testFieldSetter() throws IOException {
+ ClassLoader prevClassLoader = null;
+
+ String [] types = { "VARCHAR(32)", "VARCHAR(32)" };
+ String [] vals = { "'meep'", "'foo'" };
+ createTableWithColTypes(types, vals);
+
+ String [] argv = getArgv(true, ",", "\\n", "\\\'", "\\", false);
+ runImport(argv);
+ try {
+ String tableClassName = getTableName();
+
+ argv = getArgv(false, ",", "\\n", "\\\'", "\\", false);
+ SqoopOptions opts = new ImportTool().parseArguments(argv, null, null,
+ true);
+
+ CompilationManager compileMgr = new CompilationManager(opts);
+ String jarFileName = compileMgr.getJarFilename();
+
+ // Make sure the user's class is loaded into our address space.
+ prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
+ tableClassName);
+
+ JobConf job = new JobConf();
+ job.setJar(jarFileName);
+
+ // Tell the job what class we're testing.
+ job.set(ExplicitSetMapper.USER_TYPE_NAME_KEY, tableClassName);
+ job.set(ExplicitSetMapper.SET_COL_KEY, BASE_COL_NAME + "0");
+ job.set(ExplicitSetMapper.SET_VAL_KEY, "this-is-a-test");
+
+ // use local mode in the same JVM.
+ ConfigurationHelper.setJobtrackerAddr(job, "local");
+ if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
+ job.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
+ }
+ String warehouseDir = getWarehouseDir();
+ Path warehousePath = new Path(warehouseDir);
+ Path inputPath = new Path(warehousePath, getTableName());
+ Path outputPath = new Path(warehousePath, getTableName() + "-out");
+
+ job.setMapperClass(ExplicitSetMapper.class);
+ job.setNumReduceTasks(0);
+ FileInputFormat.addInputPath(job, inputPath);
+ FileOutputFormat.setOutputPath(job, outputPath);
+
+ job.setOutputKeyClass(Text.class);
+ job.setOutputValueClass(NullWritable.class);
+
+ JobClient.runJob(job);
+ } catch (InvalidOptionsException ioe) {
+ fail(ioe.toString());
+ } catch (ParseException pe) {
+ fail(pe.toString());
+ } finally {
+ if (null != prevClassLoader) {
+ ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
+ }
+ }
+ }
+}
+