7dd6efcf962c79749fa99e8f0f68d92b294a150b
[sqoop.git] / src / test / org / apache / sqoop / manager / postgresql / DirectPostgreSQLExportManualTest.java
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.sqoop.manager.postgresql;
20
21 import java.io.IOException;
22 import java.sql.Connection;
23 import java.sql.SQLException;
24 import java.sql.PreparedStatement;
25 import java.util.Arrays;
26 import java.util.ArrayList;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.hadoop.mapred.JobConf;
30 import org.apache.sqoop.TestExport;
31 import org.apache.sqoop.mapreduce.db.DBConfiguration;
32 import org.apache.sqoop.testcategories.sqooptest.ManualTest;
33 import org.apache.sqoop.testcategories.thirdpartytest.PostgresqlTest;
34 import org.junit.Ignore;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37
38
39 /**
40 * Test the DirectPostgresqlManager implementations.
41 * DirectPostgresqlManager uses JDBC driver to facilitate it.
42 *
43 * Since this requires a Postgresql installation on your local machine to use,
44 * this class is named in such a way that Hadoop's default QA process does not
45 * run it.
46 *
47 * You need to run this manually with
48 * -Dtestcase=DirectPostgreSQLExportManualTest.
49 *
50 * You need to put Postgresql's JDBC driver library into lib dir.
51 *
52 * You need to create a sqooptest superuser and database and tablespace,
53 *
54 * $ sudo -u postgres createuser -U postgres -s sqooptest
55 * $ sudo -u postgres createdb -U sqooptest sqooptest
56 * $ psql -U sqooptest sqooptest
57 *
58 */
59 @Category({ManualTest.class, PostgresqlTest.class})
60 public class DirectPostgreSQLExportManualTest extends TestExport {
61
62 public static final Log LOG =
63 LogFactory.getLog(DirectPostgreSQLExportManualTest.class.getName());
64 private DBConfiguration dbConf;
65
66 static final String HOST_URL =
67 System.getProperty("sqoop.test.postgresql.connectstring.host_url",
68 "jdbc:postgresql://localhost/");
69 static final String DATABASE =
70 System.getProperty("sqoop.test.postgresql.database", "sqooptest");
71 static final String USERNAME =
72 System.getProperty("sqoop.test.postgresql.username", "sqooptest");
73 static final String PASSWORD = System.getProperty(
74 "sqoop.test.postgresql.password");
75 static final String CONNECT_STRING = HOST_URL + DATABASE;
76
77 public DirectPostgreSQLExportManualTest() {
78 JobConf conf = new JobConf(getConf());
79 DBConfiguration.configureDB(conf,
80 "org.postgresql.Driver",
81 getConnectString(),
82 getUserName(),
83 PASSWORD, (Integer) null);
84 dbConf = new DBConfiguration(conf);
85 }
86
87 @Override
88 protected boolean useHsqldbTestServer() {
89 return false;
90 }
91
92 @Override
93 protected String getConnectString() {
94 return CONNECT_STRING;
95 }
96
97 protected String getUserName() {
98 return USERNAME;
99 }
100
101 @Override
102 protected String getTablePrefix() {
103 return super.getTablePrefix().toLowerCase();
104 }
105
106 @Override
107 protected String getTableName() {
108 return super.getTableName().toLowerCase();
109 }
110
111 @Override
112 public String getStagingTableName() {
113 return super.getStagingTableName().toLowerCase();
114 }
115
116 @Override
117 protected Connection getConnection() {
118 try {
119 Connection conn = dbConf.getConnection();
120 conn.setAutoCommit(false);
121 PreparedStatement stmt =
122 conn.prepareStatement("SET extra_float_digits TO 0");
123 stmt.executeUpdate();
124 conn.commit();
125 return conn;
126 } catch (SQLException sqlE) {
127 LOG.error("Could not get connection to test server: " + sqlE);
128 return null;
129 } catch (ClassNotFoundException cnfE) {
130 LOG.error("Could not find driver class: " + cnfE);
131 return null;
132 }
133 }
134
135 @Override
136 protected String getDropTableStatement(String tableName) {
137 return "DROP TABLE IF EXISTS " + tableName;
138 }
139
140 @Override
141 protected String[] getArgv(boolean includeHadoopFlags,
142 int rowsPerStatement,
143 int statementsPerTx,
144 String... additionalArgv) {
145 ArrayList<String> args =
146 new ArrayList<String>(Arrays.asList(additionalArgv));
147 args.add("--username");
148 args.add(getUserName());
149 args.add("--password");
150 args.add(PASSWORD);
151 args.add("--direct");
152 return super.getArgv(includeHadoopFlags,
153 rowsPerStatement,
154 statementsPerTx,
155 args.toArray(new String[0]));
156 }
157
158 @Override
159 protected String [] getCodeGenArgv(String... extraArgs) {
160 ArrayList<String> args = new ArrayList<String>(Arrays.asList(extraArgs));
161 args.add("--username");
162 args.add(getUserName());
163 args.add("--password");
164 args.add(PASSWORD);
165 return super.getCodeGenArgv(args.toArray(new String[0]));
166 }
167
168 @Ignore("Ignoring this test case as direct export does not support --columns option.")
169 @Override
170 @Test
171 public void testColumnsExport() throws IOException, SQLException {
172 }
173
174 @Ignore("Ignoring this test case as the scenario is not supported with direct export.")
175 @Override
176 @Test
177 public void testLessColumnsInFileThanInTable() throws IOException, SQLException {
178 }
179
180 @Ignore("Ignoring this test case as the scenario is not supported with direct export.")
181 @Override
182 @Test
183 public void testLessColumnsInFileThanInTableInputNullIntPassed() throws IOException, SQLException {
184 }
185
186 @Ignore("Ignoring this test case as the scenario is not supported with direct export.")
187 @Override
188 @Test
189 public void testLessColumnsInFileThanInTableInputNullStringPassed() throws IOException, SQLException {
190 }
191
192
193 }