5db9fe34efbf2c0cb742a0ad690cc9753d0cca27
[sqoop.git] / src / test / org / apache / sqoop / manager / oracle / ImportTest.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.oracle;
20
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.sqoop.manager.oracle.OraOopConstants.
23 OraOopOracleDataChunkMethod;
24 import org.junit.Test;
25
26 import static org.junit.Assert.assertEquals;
27
28 /**
29 * Test import data from Oracle.
30 */
31 public class ImportTest extends OraOopTestCase {
32
33 private static final boolean DISABLE_ORACLE_ESCAPING_FLAG = false;
34
35 @Test
36 public void testProductImport() throws Exception {
37 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product");
38 createTable("table_tst_product.xml");
39
40 try {
41 int retCode = runImport("TST_PRODUCT", getSqoopConf(), false, DISABLE_ORACLE_ESCAPING_FLAG);
42 assertEquals("Return code should be 0", 0, retCode);
43
44 } finally {
45 cleanupFolders();
46 closeTestEnvConnection();
47 }
48 }
49
50
51 @Test
52 public void testProductWithWhiteSpaceImport() throws Exception {
53 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product");
54 createTable("table_tst_product_with_white_space.xml");
55
56 try {
57 int retCode = runImport("TST_Pr OdUCT", getSqoopConf(), false, DISABLE_ORACLE_ESCAPING_FLAG);
58 assertEquals("Return code should be 0", 0, retCode);
59
60 } finally {
61 cleanupFolders();
62 closeTestEnvConnection();
63 }
64 }
65
66 @Test
67 public void testProductPartImport() throws Exception {
68 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product_part");
69 createTable("table_tst_product_part.xml");
70
71 try {
72 int retCode = runImport("TST_PRODUCT_PART", getSqoopConf(), false, DISABLE_ORACLE_ESCAPING_FLAG);
73 assertEquals("Return code should be 0", 0, retCode);
74
75 } finally {
76 cleanupFolders();
77 closeTestEnvConnection();
78 }
79 }
80
81 @Test
82 public void testProductPartImportPartitionChunk() throws Exception {
83 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product_part");
84 createTable("table_tst_product_part.xml");
85
86 Configuration sqoopConf = getSqoopConf();
87 sqoopConf.set(OraOopConstants.ORAOOP_ORACLE_DATA_CHUNK_METHOD,
88 OraOopConstants.OraOopOracleDataChunkMethod.PARTITION.toString());
89
90 try {
91 int retCode = runImport("TST_PRODUCT_PART", sqoopConf, false, DISABLE_ORACLE_ESCAPING_FLAG);
92 assertEquals("Return code should be 0", 0, retCode);
93
94 } finally {
95 cleanupFolders();
96 closeTestEnvConnection();
97 }
98 }
99
100 @Test
101 public void testProductPartImportSubset() throws Exception {
102 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product_part");
103 createTable("table_tst_product_part.xml");
104
105 Configuration sqoopConf = getSqoopConf();
106 sqoopConf.set(OraOopConstants.ORAOOP_ORACLE_DATA_CHUNK_METHOD,
107 OraOopOracleDataChunkMethod.ROWID.toString());
108 sqoopConf.set(OraOopConstants.ORAOOP_IMPORT_PARTITION_LIST,
109 "tst_product_part_1,tst_product_part_2,\"tst_product_pa#rt_6\"");
110
111 try {
112 int retCode = runImport("TST_PRODUCT_PART", sqoopConf, false, DISABLE_ORACLE_ESCAPING_FLAG);
113 assertEquals("Return code should be 0", 0, retCode);
114
115 } finally {
116 cleanupFolders();
117 closeTestEnvConnection();
118 }
119 }
120
121 @Test
122 public void testProductPartImportSubsetPartitionChunk() throws Exception {
123 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product_part");
124 createTable("table_tst_product_part.xml");
125
126 Configuration sqoopConf = getSqoopConf();
127 sqoopConf.set(OraOopConstants.ORAOOP_ORACLE_DATA_CHUNK_METHOD,
128 OraOopOracleDataChunkMethod.PARTITION.toString());
129 sqoopConf
130 .set(
131 OraOopConstants.ORAOOP_IMPORT_PARTITION_LIST,
132 "tst_product_part_1,tst_product_part_2,"
133 +"tst_product_part_3,\"tst_product_pa#rt_6\"");
134
135 try {
136 int retCode = runImport("TST_PRODUCT_PART", sqoopConf, false, DISABLE_ORACLE_ESCAPING_FLAG);
137 assertEquals("Return code should be 0", 0, retCode);
138
139 } finally {
140 cleanupFolders();
141 closeTestEnvConnection();
142 }
143 }
144
145 @Test
146 public void testProductSubPartImport() throws Exception {
147 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product_subpart");
148 createTable("table_tst_product_subpart.xml");
149
150 try {
151 int retCode = runImport("TST_PRODUCT_SUBPART", getSqoopConf(), false, DISABLE_ORACLE_ESCAPING_FLAG);
152 assertEquals("Return code should be 0", 0, retCode);
153
154 } finally {
155 cleanupFolders();
156 closeTestEnvConnection();
157 }
158 }
159
160 @Test
161 public void testProductSubPartImportPartitionChunk() throws Exception {
162 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product_subpart");
163 createTable("table_tst_product_subpart.xml");
164
165 Configuration sqoopConf = getSqoopConf();
166 sqoopConf.set(OraOopConstants.ORAOOP_ORACLE_DATA_CHUNK_METHOD,
167 OraOopConstants.OraOopOracleDataChunkMethod.PARTITION.toString());
168
169 try {
170 int retCode = runImport("TST_PRODUCT_SUBPART", sqoopConf, false, DISABLE_ORACLE_ESCAPING_FLAG);
171 assertEquals("Return code should be 0", 0, retCode);
172
173 } finally {
174 cleanupFolders();
175 closeTestEnvConnection();
176 }
177 }
178
179 @Test
180 public void testProductSubPartImportSubset() throws Exception {
181 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product_subpart");
182 createTable("table_tst_product_subpart.xml");
183
184 Configuration sqoopConf = getSqoopConf();
185 sqoopConf.set(OraOopConstants.ORAOOP_ORACLE_DATA_CHUNK_METHOD,
186 OraOopOracleDataChunkMethod.ROWID.toString());
187 sqoopConf
188 .set(OraOopConstants.ORAOOP_IMPORT_PARTITION_LIST,
189 "TST_PRODUCT_PART_1,TST_PRODUCT_PART_2,"
190 +"TST_PRODUCT_PART_3,TST_PRODUCT_PART_4");
191
192 try {
193 int retCode = runImport("TST_PRODUCT_SUBPART", sqoopConf, false, DISABLE_ORACLE_ESCAPING_FLAG);
194 assertEquals("Return code should be 0", 0, retCode);
195
196 } finally {
197 cleanupFolders();
198 closeTestEnvConnection();
199 }
200 }
201
202 @Test
203 public void testProductSubPartImportSubsetPartitionChunk() throws Exception {
204 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product_subpart");
205 createTable("table_tst_product_subpart.xml");
206
207 Configuration sqoopConf = getSqoopConf();
208 sqoopConf.set(OraOopConstants.ORAOOP_ORACLE_DATA_CHUNK_METHOD,
209 OraOopConstants.OraOopOracleDataChunkMethod.PARTITION.toString());
210 sqoopConf.set(OraOopConstants.ORAOOP_IMPORT_PARTITION_LIST,
211 "TST_PRODUCT_PART_1,TST_PRODUCT_PART_2,TST_PRODUCT_PART_3");
212
213 try {
214 int retCode = runImport("TST_PRODUCT_SUBPART", sqoopConf, false, DISABLE_ORACLE_ESCAPING_FLAG);
215 assertEquals("Return code should be 0", 0, retCode);
216
217 } finally {
218 cleanupFolders();
219 closeTestEnvConnection();
220 }
221 }
222
223 @Test
224 public void testProductImportConsistentRead() throws Exception {
225 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product");
226 createTable("table_tst_product.xml");
227
228 // Make sure Oracle SCN has updated since creating table
229 Thread.sleep(10000);
230
231 Configuration sqoopConf = getSqoopConf();
232 sqoopConf.setBoolean(OraOopConstants.ORAOOP_IMPORT_CONSISTENT_READ, true);
233
234 try {
235 int retCode = runImport("TST_PRODUCT", sqoopConf, false, DISABLE_ORACLE_ESCAPING_FLAG);
236 assertEquals("Return code should be 0", 0, retCode);
237
238 } finally {
239 cleanupFolders();
240 closeTestEnvConnection();
241 }
242 }
243
244 @Test
245 public void testProductImportMixedCaseTableName() throws Exception {
246 setSqoopTargetDirectory(getSqoopTargetDirectory() + "T5+_Pr#duct");
247 createTable("table_tst_product_special_chars.xml");
248
249 try {
250 int retCode = runImport("\"\"T5+_Pr#duct\"\"", getSqoopConf(), false, DISABLE_ORACLE_ESCAPING_FLAG);
251 assertEquals("Return code should be 0", 0, retCode);
252
253 } finally {
254 cleanupFolders();
255 closeTestEnvConnection();
256 }
257 }
258
259 @Test
260 public void testProductPartIotImport() throws Exception {
261 setSqoopTargetDirectory(getSqoopTargetDirectory() + "tst_product_part");
262 createTable("table_tst_product_part_iot.xml");
263
264 Configuration sqoopConf = getSqoopConf();
265 sqoopConf.set(OraOopConstants.ORAOOP_ORACLE_DATA_CHUNK_METHOD,
266 OraOopConstants.OraOopOracleDataChunkMethod.PARTITION.toString());
267
268 try {
269 int retCode = runImport("TST_PRODUCT_PART_IOT", sqoopConf, false, DISABLE_ORACLE_ESCAPING_FLAG);
270 assertEquals("Return code should be 0", 0, retCode);
271
272 } finally {
273 cleanupFolders();
274 closeTestEnvConnection();
275 }
276 }
277
278 }