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:04:00 UTC
[14/32] sqoop git commit: SQOOP-3273: Removing com.cloudera.sqoop
packages
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/com/cloudera/sqoop/testutil/ImportJobTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/testutil/ImportJobTestCase.java b/src/test/com/cloudera/sqoop/testutil/ImportJobTestCase.java
deleted file mode 100644
index 6368980..0000000
--- a/src/test/com/cloudera/sqoop/testutil/ImportJobTestCase.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/**
- * 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 com.cloudera.sqoop.testutil;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileStatus;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import com.cloudera.sqoop.SqoopOptions;
-import com.cloudera.sqoop.Sqoop;
-import com.cloudera.sqoop.orm.CompilationManager;
-import com.cloudera.sqoop.tool.SqoopTool;
-import com.cloudera.sqoop.tool.ImportTool;
-import com.cloudera.sqoop.util.ClassLoaderStack;
-import org.junit.Before;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Class that implements common methods required for tests which import data
- * from SQL into HDFS and verify correct import.
- */
-public abstract class ImportJobTestCase extends BaseSqoopTestCase {
-
- public static final Log LOG = LogFactory.getLog(
- ImportJobTestCase.class.getName());
-
- @Before
- public void setUp() {
- super.setUp();
- removeTableDir();
- }
-
- protected String getTablePrefix() {
- return "IMPORT_TABLE_";
- }
-
- /**
- * @return a list of additional args to pass to the sqoop command line.
- */
- protected List<String> getExtraArgs(Configuration conf) {
- return new ArrayList<String>();
- }
-
- /**
- * Create the argv to pass to Sqoop.
- * @param includeHadoopFlags if true, then include -D various.settings=values
- * @param colNames the columns to import. If null, all columns are used.
- * @param conf a Configuration specifying additional properties to use when
- * determining the arguments.
- * @return the argv as an array of strings.
- */
- protected String [] getArgv(boolean includeHadoopFlags, String [] colNames,
- Configuration conf) {
- if (null == colNames) {
- colNames = getColNames();
- }
-
- String splitByCol = colNames[0];
- String columnsString = "";
- for (String col : colNames) {
- columnsString += col + ",";
- }
-
- ArrayList<String> args = new ArrayList<String>();
-
- if (includeHadoopFlags) {
- CommonArgs.addHadoopFlags(args);
- }
-
- args.add("--table");
- args.add(getTableName());
- args.add("--columns");
- args.add(columnsString);
- args.add("--split-by");
- args.add(splitByCol);
- args.add("--warehouse-dir");
- args.add(getWarehouseDir());
- args.add("--connect");
- args.add(getConnectString());
- args.add("--as-sequencefile");
- args.add("--num-mappers");
- args.add("1");
-
- args.addAll(getExtraArgs(conf));
-
- return args.toArray(new String[0]);
- }
-
- /**
- * Do a MapReduce-based import of the table and verify that the results
- * were imported as expected. (tests readFields(ResultSet) and toString())
- * @param expectedVal the value we injected into the table.
- * @param importCols the columns to import. If null, all columns are used.
- */
- protected void verifyImport(String expectedVal, String [] importCols) {
-
- // paths to where our output file will wind up.
- Path tableDirPath = getTablePath();
-
- removeTableDir();
-
- Configuration conf = getConf();
- //Need to disable OraOop for existing tests
- conf.set("oraoop.disabled", "true");
- SqoopOptions opts = getSqoopOptions(conf);
-
- // run the tool through the normal entry-point.
- int ret;
- try {
- Sqoop importer = new Sqoop(new ImportTool(), conf, opts);
- ret = Sqoop.runSqoop(importer, getArgv(true, importCols, conf));
- } catch (Exception e) {
- LOG.error("Got exception running Sqoop: " + e.toString());
- throw new RuntimeException(e);
- }
-
- // expect a successful return.
- assertEquals("Failure during job", 0, ret);
-
- opts = getSqoopOptions(conf);
- try {
- ImportTool importTool = new ImportTool();
- opts = importTool.parseArguments(getArgv(false, importCols, conf), conf,
- opts, true);
- } catch (Exception e) {
- fail(e.toString());
- }
-
- CompilationManager compileMgr = new CompilationManager(opts);
- String jarFileName = compileMgr.getJarFilename();
- ClassLoader prevClassLoader = null;
- try {
- prevClassLoader = ClassLoaderStack.addJarFile(jarFileName,
- getTableName());
-
- // Now open and check all part-files in the table path until we find
- // a non-empty one that we can verify contains the value.
- if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
- conf.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
- }
- FileSystem fs = FileSystem.get(conf);
- FileStatus [] stats = fs.listStatus(tableDirPath);
-
- if (stats == null || stats.length == 0) {
- fail("Error: no files in " + tableDirPath);
- }
-
- boolean foundRecord = false;
- for (FileStatus stat : stats) {
- if (!stat.getPath().getName().startsWith("part-")
- && !stat.getPath().getName().startsWith("data-")) {
- // This isn't a data file. Ignore it.
- continue;
- }
-
- try {
- Object readValue = SeqFileReader.getFirstValue(
- stat.getPath().toString());
- LOG.info("Read back from sequencefile: " + readValue);
- foundRecord = true;
- // Add trailing '\n' to expected value since SqoopRecord.toString()
- // encodes the record delim.
- if (null == expectedVal) {
- assertEquals("Error validating result from SeqFile", "null\n",
- readValue.toString());
- } else {
- assertEquals("Error validating result from SeqFile",
- expectedVal + "\n", readValue.toString());
- }
- } catch (EOFException eoe) {
- // EOF in a file isn't necessarily a problem. We may have some
- // empty sequence files, which will throw this. Just continue
- // in the loop.
- }
- }
-
- if (!foundRecord) {
- fail("Couldn't read any records from SequenceFiles");
- }
- } catch (IOException ioe) {
- fail("IOException: " + ioe.toString());
- } finally {
- if (null != prevClassLoader) {
- ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
- }
- }
- }
-
- /**
- * Run a MapReduce-based import (using the argv provided to control
- * execution).
- */
- protected void runImport(SqoopTool tool, String [] argv) throws IOException {
- // run the tool through the normal entry-point.
- int ret;
- try {
- Configuration conf = getConf();
- //Need to disable OraOop for existing tests
- conf.set("oraoop.disabled", "true");
- SqoopOptions opts = getSqoopOptions(conf);
- Sqoop sqoop = new Sqoop(tool, conf, opts);
- ret = Sqoop.runSqoop(sqoop, argv);
- } catch (Exception e) {
- LOG.error("Got exception running Sqoop: " + e.toString());
- e.printStackTrace();
- ret = 1;
- }
-
- // expect a successful return.
- if (0 != ret) {
- throw new IOException("Failure during job; return status " + ret);
- }
- }
-
- /** run an import using the default ImportTool. */
- protected void runImport(String [] argv) throws IOException {
- runImport(new ImportTool(), argv);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/com/cloudera/sqoop/testutil/InjectableConnManager.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/testutil/InjectableConnManager.java b/src/test/com/cloudera/sqoop/testutil/InjectableConnManager.java
deleted file mode 100644
index 3b01d28..0000000
--- a/src/test/com/cloudera/sqoop/testutil/InjectableConnManager.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * 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 com.cloudera.sqoop.testutil;
-
-import java.io.IOException;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.mapreduce.InputFormat;
-import org.apache.hadoop.mapreduce.Mapper;
-import org.apache.hadoop.mapreduce.OutputFormat;
-import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
-import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
-import com.cloudera.sqoop.SqoopOptions;
-import com.cloudera.sqoop.manager.HsqldbManager;
-import com.cloudera.sqoop.manager.ImportJobContext;
-import com.cloudera.sqoop.mapreduce.ImportJobBase;
-import com.cloudera.sqoop.util.ImportException;
-import org.apache.hadoop.util.ReflectionUtils;
-
-/**
- * A ConnManager that uses dependency injection to control "import jobs"
- * that are mocked for testing.
- */
-public class InjectableConnManager extends HsqldbManager {
-
- // The Configuration is used to control the injected classes.
- public static final String MAPPER_KEY = "sqoop.inject.mapper.class";
- public static final String INPUT_FORMAT_KEY =
- "sqoop.inject.input.format.class";
- public static final String OUTPUT_FORMAT_KEY =
- "sqoop.inject.output.format.class";
- public static final String IMPORT_JOB_KEY =
- "sqoop.inject.import.job.class";
-
- public InjectableConnManager(final SqoopOptions options) {
- super(options);
- }
-
- /**
- * Allow the user to inject custom mapper, input, and output formats
- * into the importTable() process.
- */
- @Override
- @SuppressWarnings("unchecked")
- public void importTable(ImportJobContext context)
- throws IOException, ImportException {
-
- SqoopOptions options = context.getOptions();
- Configuration conf = options.getConf();
-
- Class<? extends Mapper> mapperClass = (Class<? extends Mapper>)
- conf.getClass(MAPPER_KEY, Mapper.class);
- Class<? extends InputFormat> ifClass = (Class<? extends InputFormat>)
- conf.getClass(INPUT_FORMAT_KEY, TextInputFormat.class);
- Class<? extends OutputFormat> ofClass = (Class<? extends OutputFormat>)
- conf.getClass(OUTPUT_FORMAT_KEY, TextOutputFormat.class);
-
- Class<? extends ImportJobBase> jobClass = (Class<? extends ImportJobBase>)
- conf.getClass(IMPORT_JOB_KEY, ImportJobBase.class);
-
- String tableName = context.getTableName();
-
- // Instantiate the user's chosen ImportJobBase instance.
- ImportJobBase importJob = ReflectionUtils.newInstance(jobClass, conf);
-
- // And configure the dependencies to inject
- importJob.setOptions(options);
- importJob.setMapperClass(mapperClass);
- importJob.setInputFormatClass(ifClass);
- importJob.setOutputFormatClass(ofClass);
-
- importJob.runImport(tableName, context.getJarFile(),
- getSplitColumn(options, tableName), conf);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/com/cloudera/sqoop/testutil/InjectableManagerFactory.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/testutil/InjectableManagerFactory.java b/src/test/com/cloudera/sqoop/testutil/InjectableManagerFactory.java
deleted file mode 100644
index 24d8493..0000000
--- a/src/test/com/cloudera/sqoop/testutil/InjectableManagerFactory.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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 com.cloudera.sqoop.testutil;
-
-import com.cloudera.sqoop.manager.ConnManager;
-import com.cloudera.sqoop.manager.ManagerFactory;
-import com.cloudera.sqoop.metastore.JobData;
-
-/**
- * ManagerFactory that is used for testing; this accepts any
- * connection string.
- */
-public class InjectableManagerFactory extends ManagerFactory {
-
- public ConnManager accept(JobData data) {
- // Always accept and use the injectable manager.
- return new InjectableConnManager(data.getSqoopOptions());
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/com/cloudera/sqoop/testutil/LobAvroImportTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/testutil/LobAvroImportTestCase.java b/src/test/com/cloudera/sqoop/testutil/LobAvroImportTestCase.java
deleted file mode 100644
index 7469799..0000000
--- a/src/test/com/cloudera/sqoop/testutil/LobAvroImportTestCase.java
+++ /dev/null
@@ -1,397 +0,0 @@
-/**
- * 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 com.cloudera.sqoop.testutil;
-
-import org.junit.After;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.sql.SQLException;
-import java.util.ArrayList;
-
-import org.apache.avro.file.DataFileConstants;
-import org.apache.avro.file.DataFileReader;
-import org.apache.avro.generic.GenericDatumReader;
-import org.apache.avro.generic.GenericRecord;
-import org.apache.avro.io.DatumReader;
-import org.apache.avro.mapred.FsInput;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.Path;
-import org.apache.sqoop.io.CodecMap;
-import org.apache.sqoop.lib.BlobRef;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests BLOB/CLOB import for Avro.
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public abstract class LobAvroImportTestCase extends ImportJobTestCase {
-
- private Log log;
-
- public LobAvroImportTestCase() {
- this.log = LogFactory.getLog(LobAvroImportTestCase.class.getName());
- }
-
- /**
- * @return the Log object to use for reporting during this test
- */
- protected abstract Log getLogger();
-
- /**
- * @return a "friendly" name for the database. e.g "mysql" or "oracle".
- */
- protected abstract String getDbFriendlyName();
-
- @Override
- protected String getTablePrefix() {
- return "LOB_" + getDbFriendlyName().toUpperCase() + "_";
- }
-
- @Override
- protected boolean useHsqldbTestServer() {
- // Hsqldb does not support BLOB/CLOB
- return false;
- }
-
- @After
- public void tearDown() {
- try {
- // Clean up the database on our way out.
- dropTableIfExists(getTableName());
- } catch (SQLException e) {
- log.warn("Error trying to drop table '" + getTableName()
- + "' on tearDown: " + e);
- }
- super.tearDown();
- }
-
- protected String [] getArgv(String ... additionalArgs) {
- // Import every column of the table
- String [] colNames = getColNames();
- String splitByCol = colNames[0];
- String columnsString = "";
- for (String col : colNames) {
- columnsString += col + ",";
- }
-
- ArrayList<String> args = new ArrayList<String>();
-
- CommonArgs.addHadoopFlags(args);
-
- args.add("--table");
- args.add(getTableName());
- args.add("--columns");
- args.add(columnsString);
- args.add("--split-by");
- args.add(splitByCol);
- args.add("--warehouse-dir");
- args.add(getWarehouseDir());
- args.add("--connect");
- args.add(getConnectString());
- args.add("--as-avrodatafile");
- args.add("--num-mappers");
- args.add("1");
-
- for (String arg : additionalArgs) {
- args.add(arg);
- }
-
- return args.toArray(new String[0]);
- }
-
- protected String getBlobType() {
- return "BLOB";
- }
-
- protected String getBlobInsertStr(String blobData) {
- return "'" + blobData + "'";
- }
-
- /**
- * Return the current table number as a string. In test, table number is used
- * to name .lob files.
- * @return current table number.
- */
- private String getTableNum() {
- return getTableName().substring(getTablePrefix().length());
- }
-
- /**
- * Return an instance of DataFileReader for the given filename.
- * @param filename path that we're opening a reader for.
- * @return instance of DataFileReader.
- * @throws IOException
- */
- private DataFileReader<GenericRecord> read(Path filename)
- throws IOException {
- Configuration conf = getConf();
- if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
- conf.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
- }
- FsInput fsInput = new FsInput(filename, conf);
- DatumReader<GenericRecord> datumReader =
- new GenericDatumReader<GenericRecord>();
- return new DataFileReader<GenericRecord>(fsInput, datumReader);
- }
-
- /** Import blob data that is smaller than inline lob limit. Blob data
- * should be saved as Avro bytes.
- * @throws IOException
- * @throws SQLException
- */
- @Test
- public void testBlobAvroImportInline() throws IOException, SQLException {
- String [] types = { getBlobType() };
- String expectedVal = "This is short BLOB data";
- String [] vals = { getBlobInsertStr(expectedVal) };
-
- createTableWithColTypes(types, vals);
-
- runImport(getArgv());
-
- Path outputFile = new Path(getTablePath(), "part-m-00000.avro");
- DataFileReader<GenericRecord> reader = read(outputFile);
- GenericRecord record = reader.next();
-
- // Verify that blob data is imported as Avro bytes.
- ByteBuffer buf = (ByteBuffer) record.get(getColName(0));
- String returnVal = new String(buf.array());
-
- assertEquals(getColName(0), expectedVal, returnVal);
- }
-
- /**
- * Import blob data that is larger than inline lob limit. The reference file
- * should be saved as Avro bytes. Blob data should be saved in LOB file
- * format.
- * @throws IOException
- * @throws SQLException
- */
- @Test
- public void testBlobAvroImportExternal() throws IOException, SQLException {
- String [] types = { getBlobType() };
- String data = "This is short BLOB data";
- String [] vals = { getBlobInsertStr(data) };
-
- createTableWithColTypes(types, vals);
-
- // Set inline lob limit to a small value so that blob data will be
- // written to an external file.
- runImport(getArgv("--inline-lob-limit", "1"));
-
- Path outputFile = new Path(getTablePath(), "part-m-00000.avro");
- DataFileReader<GenericRecord> reader = read(outputFile);
- GenericRecord record = reader.next();
-
- // Verify that the reference file is written in Avro bytes.
- ByteBuffer buf = (ByteBuffer) record.get(getColName(0));
- String returnVal = new String(buf.array());
- String expectedStart = "externalLob(lf,_lob/large_obj";
- String expectedEnd = getTableNum() + "_m_0000000.lob,68,"
- + data.length() + ")";
-
- assertNotNull(returnVal);
- assertTrue("ExpectedStart: " + expectedStart + ", value: " + returnVal, returnVal.startsWith(expectedStart));
- assertTrue("ExpectedEnd: " + expectedEnd + ", value: " + returnVal, returnVal.endsWith(expectedEnd));
-
- // Verify that blob data stored in the external lob file is correct.
- BlobRef br = BlobRef.parse(returnVal);
- Path lobFileDir = new Path(getWarehouseDir(), getTableName());
- InputStream in = br.getDataStream(getConf(), lobFileDir);
-
- byte [] bufArray = new byte[data.length()];
- int chars = in.read(bufArray);
- in.close();
-
- assertEquals(chars, data.length());
-
- returnVal = new String(bufArray);
- String expectedVal = data;
-
- assertEquals(getColName(0), returnVal, expectedVal);
- }
-
- /**
- * Import blob data that is smaller than inline lob limit and compress with
- * deflate codec. Blob data should be encoded and saved as Avro bytes.
- * @throws IOException
- * @throws SQLException
- */
- @Test
- public void testBlobCompressedAvroImportInline()
- throws IOException, SQLException {
- String [] types = { getBlobType() };
- String expectedVal = "This is short BLOB data";
- String [] vals = { getBlobInsertStr(expectedVal) };
-
- createTableWithColTypes(types, vals);
-
- runImport(getArgv("--compression-codec", CodecMap.DEFLATE));
-
- Path outputFile = new Path(getTablePath(), "part-m-00000.avro");
- DataFileReader<GenericRecord> reader = read(outputFile);
- GenericRecord record = reader.next();
-
- // Verify that the data block of the Avro file is compressed with deflate
- // codec.
- assertEquals(CodecMap.DEFLATE,
- reader.getMetaString(DataFileConstants.CODEC));
-
- // Verify that all columns are imported correctly.
- ByteBuffer buf = (ByteBuffer) record.get(getColName(0));
- String returnVal = new String(buf.array());
-
- assertEquals(getColName(0), expectedVal, returnVal);
- }
-
- /**
- * Import blob data that is larger than inline lob limit and compress with
- * deflate codec. The reference file should be encoded and saved as Avro
- * bytes. Blob data should be saved in LOB file format without compression.
- * @throws IOException
- * @throws SQLException
- */
- @Test
- public void testBlobCompressedAvroImportExternal()
- throws IOException, SQLException {
- String [] types = { getBlobType() };
- String data = "This is short BLOB data";
- String [] vals = { getBlobInsertStr(data) };
-
- createTableWithColTypes(types, vals);
-
- // Set inline lob limit to a small value so that blob data will be
- // written to an external file.
- runImport(getArgv(
- "--inline-lob-limit", "1", "--compression-codec", CodecMap.DEFLATE));
-
- Path outputFile = new Path(getTablePath(), "part-m-00000.avro");
- DataFileReader<GenericRecord> reader = read(outputFile);
- GenericRecord record = reader.next();
-
- // Verify that the data block of the Avro file is compressed with deflate
- // codec.
- assertEquals(CodecMap.DEFLATE,
- reader.getMetaString(DataFileConstants.CODEC));
-
- // Verify that the reference file is written in Avro bytes.
- ByteBuffer buf = (ByteBuffer) record.get(getColName(0));
- String returnVal = new String(buf.array());
- String expectedStart = "externalLob(lf,_lob/large_obj";
- String expectedEnd = getTableNum() + "_m_0000000.lob,68,"
- + data.length() + ")";
-
- assertNotNull(returnVal);
- assertTrue("ExpectedStart: " + expectedStart + ", value: " + returnVal, returnVal.startsWith(expectedStart));
- assertTrue("ExpectedEnd: " + expectedEnd + ", value: " + returnVal, returnVal.endsWith(expectedEnd));
-
- // Verify that blob data stored in the external lob file is correct.
- BlobRef br = BlobRef.parse(returnVal);
- Path lobFileDir = new Path(getWarehouseDir(), getTableName());
- InputStream in = br.getDataStream(getConf(), lobFileDir);
-
- byte [] bufArray = new byte[data.length()];
- int chars = in.read(bufArray);
- in.close();
-
- assertEquals(chars, data.length());
-
- returnVal = new String(bufArray);
- String expectedVal = data;
-
- assertEquals(getColName(0), returnVal, expectedVal);
- }
-
- /**
- * Import multiple columns of blob data. Blob data should be saved as Avro
- * bytes.
- * @throws IOException
- * @throws SQLException
- */
- @Test
- public void testBlobAvroImportMultiCols() throws IOException, SQLException {
- String [] types = { getBlobType(), getBlobType(), getBlobType(), };
- String expectedVal1 = "This is short BLOB data1";
- String expectedVal2 = "This is short BLOB data2";
- String expectedVal3 = "This is short BLOB data3";
- String [] vals = { getBlobInsertStr(expectedVal1),
- getBlobInsertStr(expectedVal2),
- getBlobInsertStr(expectedVal3), };
-
- createTableWithColTypes(types, vals);
-
- runImport(getArgv());
-
- Path outputFile = new Path(getTablePath(), "part-m-00000.avro");
- DataFileReader<GenericRecord> reader = read(outputFile);
- GenericRecord record = reader.next();
-
- // Verify that all columns are imported correctly.
- ByteBuffer buf = (ByteBuffer) record.get(getColName(0));
- String returnVal = new String(buf.array());
-
- assertEquals(getColName(0), expectedVal1, returnVal);
-
- buf = (ByteBuffer) record.get(getColName(1));
- returnVal = new String(buf.array());
-
- assertEquals(getColName(1), expectedVal2, returnVal);
-
- buf = (ByteBuffer) record.get(getColName(2));
- returnVal = new String(buf.array());
-
- assertEquals(getColName(2), expectedVal3, returnVal);
- }
-
- @Test
- public void testClobAvroImportInline() throws IOException, SQLException {
- // TODO: add tests for CLOB support for Avro import
- }
-
- @Test
- public void testClobAvroImportExternal() throws IOException, SQLException {
- // TODO: add tests for CLOB support for Avro import
- }
-
- @Test
- public void testClobCompressedAvroImportInline()
- throws IOException, SQLException {
- // TODO: add tests for CLOB support for Avro import
- }
-
- @Test
- public void testClobCompressedAvroImportExternal()
- throws IOException, SQLException {
- // TODO: add tests for CLOB support for Avro import
- }
-
- @Test
- public void testClobAvroImportMultiCols() throws IOException, SQLException {
- // TODO: add tests for CLOB support for Avro import
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/com/cloudera/sqoop/testutil/ManagerCompatTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/testutil/ManagerCompatTestCase.java b/src/test/com/cloudera/sqoop/testutil/ManagerCompatTestCase.java
deleted file mode 100644
index 7db044c..0000000
--- a/src/test/com/cloudera/sqoop/testutil/ManagerCompatTestCase.java
+++ /dev/null
@@ -1,919 +0,0 @@
-/**
- * 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 com.cloudera.sqoop.testutil;
-
-import java.io.UnsupportedEncodingException;
-import java.sql.Blob;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.io.BytesWritable;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Class that implements common tests that should be applied to all jdbc
- * drivers that we want to interop with.
- *
- * The purpose of these tests is to ensure that if a database supports a
- * given data type, we can import this data type into Sqoop. The test is
- * not intended to check whether all data types are supported by all
- * databases, nor that the representation of a given data type has a canonical
- * representation after being imported. Some databases may not support certain
- * data types, and the format of the imported data may vary from database to
- * database. It is not Sqoop's goal to resolve inter-database differences.
- * However, if a database provides a particular type, we should verify that
- * we can import this data in some form into HDFS.
- *
- * This test battery subjects a database to a variety of import tasks. Many
- * adapter methods are provided to allow subclasses to modify the exact type
- * names injected, expected output values, etc., to account for inter-database
- * discrepencies.
- *
- * Each subclass of this class should test a single ConnManager implementation.
- * Subclasses must implement all abstract methods of this class. They may
- * also wish to override several members of the class hierarchy above this.
- * In particular:
- *
- * String getConnectString() -- Return the connect string to use to get the db.
- * void dropTableIfExists(tableName) -- how to drop a table that may not exist.
- * void createTableWithColTypes() -- how to create a table with a set of cols.
- * Configuration getConf() -- specifies config properties specific to a test.
- * SqoopOptions getSqoopOptions(conf) -- Instantiates the SqoopOptions to use.
- * List<String> getExtraArgs() -- specifies extra argv elements.
- */
-public abstract class ManagerCompatTestCase extends ImportJobTestCase {
-
- private Log log;
-
- public ManagerCompatTestCase() {
- this.log = LogFactory.getLog(ManagerCompatTestCase.class.getName());
- }
-
- /**
- * @return the Log object to use for reporting during this test
- */
- protected abstract Log getLogger();
-
- /**
- * @return a "friendly" name for the database. e.g "mysql" or "oracle".
- */
- protected abstract String getDbFriendlyName();
-
- /** Set to true during tearDown() if a test is skipped. */
- protected boolean skipped;
-
- @Override
- protected String getTablePrefix() {
- return "MGR_" + getDbFriendlyName().toUpperCase() + "_";
- }
-
- @Override
- protected boolean useHsqldbTestServer() {
- // Compat tests, by default, do not use hsqldb.
- return false;
- }
-
- @Override
- public void setUp() {
- log = getLogger();
- skipped = false;
- super.setUp();
- }
-
- @Override
- public void tearDown() {
- try {
- // Clean up the database on our way out.
- dropTableIfExists(getTableName());
- } catch (SQLException e) {
- log.warn("Error trying to drop table '" + getTableName()
- + "' on tearDown: " + e);
- }
- super.tearDown();
- }
-
- //////// These methods indicate whether certain datatypes are supported
- //////// by the underlying database.
-
- /** @return true if the database under test has a BOOLEAN type */
- protected boolean supportsBoolean() {
- return true;
- }
-
- /** @return true if the database under test has a BIGINT type */
- protected boolean supportsBigInt() {
- return true;
- }
-
- /** @return true if the database under test has a TINYINT type */
- protected boolean supportsTinyInt() {
- return true;
- }
-
- /** @return true if the database under test has a LONGVARCHAR type */
- protected boolean supportsLongVarChar() {
- return true;
- }
-
- /** @return true if the database under test has a VARBINARY type */
- protected boolean supportsVarBinary() {
- return true;
- }
-
- /** @return true if the database under test has a TIME type */
- protected boolean supportsTime() {
- return true;
- }
-
- /** @return true if the database under test supports CLOB types */
- protected boolean supportsClob() {
- return true;
- }
-
- /** @return true if the database under test supports BLOB types */
- protected boolean supportsBlob() {
- return true;
- }
-
- //////// These methods indicate how to define various datatypes.
-
- /**
- * Define a NUMERIC type that can handle 30 digits total, and 5
- * digits to the right of the decimal point.
- */
- protected String getNumericType() {
- return "NUMERIC(" + getNumericScale() + ", "
- + getNumericDecPartDigits() + ")";
- }
-
- protected String getDecimalType() {
- return "DECIMAL(" + getDecimalScale() + ", "
- + getDecimalDecPartDigits() + ")";
- }
-
- /**
- * Return the number of digits to use in the integral part of a
- * NUMERIC type.
- */
- protected int getNumericScale() {
- return 30;
- }
-
- /**
- * Return the number of digits to use in the decimal part of a
- * NUMERIC type.
- */
- protected int getNumericDecPartDigits() {
- return 5;
- }
-
- /**
- * Return the number of digits to use in the integral part of a
- * DECIMAL type.
- */
- protected int getDecimalScale() {
- return 30;
- }
-
- /**
- * Return the number of digits to use in the decimal part of a
- * DECIMAL type.
- */
- protected int getDecimalDecPartDigits() {
- return 5;
- }
-
- /**
- * Define a DOUBLE column.
- */
- protected String getDoubleType() {
- return "DOUBLE";
- }
-
- /**
- * Define a LONGVARCHAR type that can handle at least 24 characters.
- */
- protected String getLongVarCharType() {
- return "LONGVARCHAR";
- }
-
- /**
- * Define a TIMESTAMP type that can handle null values.
- */
- protected String getTimestampType() {
- return "TIMESTAMP";
- }
-
- /**
- * Define a CLOB column that can contain up to 16 MB of data.
- */
- protected String getClobType() {
- return "CLOB";
- }
-
- /**
- * Define a BLOB column that can contain up to 16 MB of data.
- */
- protected String getBlobType() {
- return "BLOB";
- }
-
- /**
- * Define a VARBINARY column that can contain up to 12 bytes of data.
- */
- protected String getVarBinaryType() {
- return "VARBINARY(12)";
- }
-
- /**
- * Define a TINYINT column that can contain 8-bit signed integers.
- */
- protected String getTinyIntType() {
- return "TINYINT";
- }
-
- //////// These methods indicate how databases respond to various datatypes.
- //////// Since our comparisons are all string-based, these return strings.
-
- /** @return How we insert the value TRUE represented as an int. */
- protected String getTrueBoolNumericSqlInput() {
- return "1";
- }
-
- /** @return How we insert the value FALSE represented as an int. */
- protected String getFalseBoolNumericSqlInput() {
- return "0";
- }
-
- /** @return How we insert the value TRUE represented as a boolean literal. */
- protected String getTrueBoolLiteralSqlInput() {
- return "true";
- }
-
- /** @return How we insert the value FALSE represented as a boolean literal. */
- protected String getFalseBoolLiteralSqlInput() {
- return "false";
- }
-
- /** @return How a BOOLEAN column with value TRUE is represented in a seq-file
- * import. */
- protected String getTrueBoolSeqOutput() {
- return "true";
- }
-
- /** @return How a BOOLEAN column with value FALSE is represented in a seq-file
- * import. */
- protected String getFalseBoolSeqOutput() {
- return "false";
- }
-
- protected String padString(int width, String str) {
- int extra = width - str.length();
- for (int i = 0; i < extra; i++) {
- str = str + " ";
- }
-
- return str;
- }
-
- /**
- * helper method: return a floating-point string in the same way
- * it was entered, but integers get a trailing '.0' attached.
- */
- protected String withDecimalZero(String floatingPointStr) {
- if (floatingPointStr.indexOf(".") == -1) {
- return floatingPointStr + ".0";
- } else {
- return floatingPointStr;
- }
- }
-
- /**
- * @return how a given real value is represented in an imported sequence
- * file
- */
- protected String getRealSeqOutput(String realAsInserted) {
- return withDecimalZero(realAsInserted);
- }
-
- /**
- * @return how a given float value is represented in an imported sequence
- * file
- */
- protected String getFloatSeqOutput(String floatAsInserted) {
- return withDecimalZero(floatAsInserted);
- }
-
- /**
- * @return how a given double value is represented in an imported sequence
- * file
- */
- protected String getDoubleSeqOutput(String doubleAsInserted) {
- return withDecimalZero(doubleAsInserted);
- }
-
- /**
- * Some databases require that we insert dates using a special format.
- * This takes the canonical string used to insert a DATE into a table,
- * and specializes it to the SQL dialect used by the database under
- * test.
- */
- protected String getDateInsertStr(String insertStr) {
- return insertStr;
- }
-
- /**
- * Some databases require that we insert times using a special format.
- * This takes the canonical string used to insert a TIME into a table,
- * and specializes it to the SQL dialect used by the database under
- * test.
- */
- protected String getTimeInsertStr(String insertStr) {
- return insertStr;
- }
-
- /**
- * Some databases require that we insert timestamps using a special format.
- * This takes the canonical string used to insert a TIMESTAMP into a table,
- * and specializes it to the SQL dialect used by the database under
- * test.
- */
- protected String getTimestampInsertStr(String insertStr) {
- return insertStr;
- }
-
- protected String getDateSeqOutput(String dateAsInserted) {
- return dateAsInserted;
- }
-
- /**
- * Convert an input timestamp to the string representation of the timestamp
- * returned by a sequencefile-based import.
- *
- * @param tsAsInserted the input timestamp
- * @return the string version of this as returned by the database is
- * represented.
- */
- protected String getTimestampSeqOutput(String tsAsInserted) {
- if ("null".equals(tsAsInserted)) {
- return tsAsInserted;
- }
-
- int dotPos = tsAsInserted.indexOf(".");
- if (-1 == dotPos) {
- // No dot in the original string; expand to add a single item after the
- // dot.
- return tsAsInserted + ".0";
- } else {
- // all other strings return as-is.
- return tsAsInserted;
- }
- }
-
- protected String getNumericSeqOutput(String numAsInserted) {
- return numAsInserted;
- }
-
- protected String getDecimalSeqOutput(String numAsInserted) {
- return numAsInserted;
- }
-
- /**
- * @return how a CHAR(fieldWidth) field is represented in an imported
- * sequence file
- */
- protected String getFixedCharSeqOut(int fieldWidth, String asInserted) {
- return asInserted;
- }
-
- /**
- * Encode a string to be inserted in a BLOB field.
- * @param blobData the raw text (Without quote marks) to insert for a BLOB.
- * @return 'blobData' in a String form ready for insertion
- */
- protected String getBlobInsertStr(String blobData) {
- return "'" + blobData + "'";
- }
-
- /**
- * @return A byte array declaring how an inserted BLOB will be returned to
- * us via the database.
- */
- protected byte [] getBlobDbOutput(String asInserted) {
- // The database will give us back a byte array; we need to create
- // an identical byte array.
- try {
- return asInserted.getBytes("UTF-8");
- } catch (UnsupportedEncodingException uee) {
- fail("Could not get utf8 bytes"); // Java should always support UTF-8.
- return null;
- }
- }
-
- /**
- * @return A String declaring how an inserted BLOB will be returned to
- * us via the sequencefile.
- */
- protected String getBlobSeqOutput(String asInserted) {
- return new BytesWritable(getBlobDbOutput(asInserted)).toString();
- }
-
- /**
- * @return A String declaring how an inserted VARBINARY will be
- * returned to us via the sequencefile.
- */
- protected String getVarBinarySeqOutput(String asInserted) {
- return new BytesWritable(getBlobDbOutput(asInserted)).toString();
- }
-
- /**
- * Given a string of characters which represent hex values
- * (e.g., 'ABF00F1238'), return the string as a set of separated
- * octets, in lower case (e.g., 'ab f0 0f 12 38').
- *
- * @param str the input string of hex digits
- * @return the input string as space-separated lower-case octets.
- */
- protected String toLowerHexString(String str) {
- // The inserted text is a hex string of the form 'ABABABAB'.
- // We return it in the form 'ab ab ab ab'.
- StringBuilder sb = new StringBuilder();
- boolean isOdd = false;
- boolean first = true;
- for (char c : str.toCharArray()) {
- if (!isOdd && !first) {
- sb.append(' ');
- }
-
- sb.append(Character.toLowerCase(c));
- isOdd = !isOdd;
- first = false;
- }
-
- return sb.toString();
- }
-
- //////// The actual tests occur below here. ////////
-
- /**
- * Do a full verification test on the singleton value of a given type.
- * @param colType The SQL type to instantiate the column.
- * @param insertVal The SQL text to insert a value into the database.
- * @param seqFileVal The string representation of the value as extracted
- * through the DBInputFormat, serialized, and injected into a
- * SequenceFile and put through toString(). This may be slightly
- * different than what ResultSet.getString() returns, which is used
- * by returnVal.
- */
- protected void verifyType(String colType, String insertVal,
- String seqFileVal) {
- verifyType(colType, insertVal, seqFileVal, false);
- }
-
- protected void verifyType(String colType, String insertVal, String seqFileVal,
- boolean useIntPrimaryKey) {
-
- String readbackPrepend = "";
-
- if (useIntPrimaryKey) {
- String [] types = { "INTEGER", colType };
- String [] vals = { "0", insertVal };
- createTableWithColTypes(types, vals);
- readbackPrepend = "0,"; // verifyImport will verify the entire row.
- } else {
- createTableForColType(colType, insertVal);
- }
-
- verifyImport(readbackPrepend + seqFileVal, null);
- }
-
- static final String STRING_VAL_IN = "'this is a short string'";
- static final String STRING_VAL_OUT = "this is a short string";
-
- @Test
- public void testStringCol1() {
- verifyType("VARCHAR(32)", STRING_VAL_IN, STRING_VAL_OUT);
- }
-
- @Test
- public void testStringCol2() {
- verifyType("CHAR(32)", STRING_VAL_IN,
- getFixedCharSeqOut(32, STRING_VAL_OUT));
- }
-
- @Test
- public void testEmptyStringCol() {
- verifyType("VARCHAR(32)", "''", "");
- }
-
- @Test
- public void testNullStringCol() {
- verifyType("VARCHAR(32)", "NULL", null);
- }
-
- @Test
- public void testInt() {
- verifyType("INTEGER", "42", "42");
- }
-
- @Test
- public void testNullInt() {
- verifyType("INTEGER", "NULL", null);
- }
-
- @Test
- public void testBoolean() {
- if (!supportsBoolean()) {
- log.info("Skipping boolean test (unsupported)");
- skipped = true;
- return;
- }
- verifyType("BOOLEAN", getTrueBoolNumericSqlInput(),
- getTrueBoolSeqOutput());
- }
-
- @Test
- public void testBoolean2() {
- if (!supportsBoolean()) {
- log.info("Skipping boolean test (unsupported)");
- skipped = true;
- return;
- }
- verifyType("BOOLEAN", getFalseBoolNumericSqlInput(),
- getFalseBoolSeqOutput());
- }
-
- @Test
- public void testBoolean3() {
- if (!supportsBoolean()) {
- log.info("Skipping boolean test (unsupported)");
- skipped = true;
- return;
- }
- verifyType("BOOLEAN", getFalseBoolLiteralSqlInput(),
- getFalseBoolSeqOutput());
- }
-
- @Test
- public void testTinyInt1() {
- if (!supportsTinyInt()) {
- log.info("Skipping tinyint test (unsupported)");
- skipped = true;
- return;
- }
- verifyType(getTinyIntType(), "0", "0");
- }
-
- @Test
- public void testTinyInt2() {
- if (!supportsTinyInt()) {
- log.info("Skipping tinyint test (unsupported)");
- skipped = true;
- return;
- }
- verifyType(getTinyIntType(), "42", "42");
- }
-
- @Test
- public void testSmallInt1() {
- verifyType("SMALLINT", "-1024", "-1024");
- }
-
- @Test
- public void testSmallInt2() {
- verifyType("SMALLINT", "2048", "2048");
- }
-
- @Test
- public void testBigInt1() {
- if (!supportsBigInt()) {
- log.info("Skipping bigint test (unsupported)");
- skipped = true;
- return;
- }
- verifyType("BIGINT", "10000000000", "10000000000");
- }
-
-
- @Test
- public void testReal1() {
- verifyType("REAL", "256", getRealSeqOutput("256"));
- }
-
- @Test
- public void testReal2() {
- verifyType("REAL", "256.45", getRealSeqOutput("256.45"));
- }
-
- @Test
- public void testFloat1() {
- verifyType("FLOAT", "256", getFloatSeqOutput("256"));
- }
-
- @Test
- public void testFloat2() {
- verifyType("FLOAT", "256.5", getFloatSeqOutput("256.5"));
- }
-
- @Test
- public void testDouble1() {
- verifyType(getDoubleType(), "-256", getDoubleSeqOutput("-256"));
- }
-
- @Test
- public void testDouble2() {
- verifyType(getDoubleType(), "256.45", getDoubleSeqOutput("256.45"));
- }
-
- @Test
- public void testDate1() {
- verifyType("DATE", getDateInsertStr("'2009-01-12'"),
- getDateSeqOutput("2009-01-12"));
- }
-
- @Test
- public void testDate2() {
- verifyType("DATE", getDateInsertStr("'2009-04-24'"),
- getDateSeqOutput("2009-04-24"));
- }
-
- @Test
- public void testTime1() {
- if (!supportsTime()) {
- log.info("Skipping time test (unsupported)");
- skipped = true;
- return;
- }
- verifyType("TIME", getTimeInsertStr("'12:24:00'"), "12:24:00");
- }
-
- @Test
- public void testTime2() {
- if (!supportsTime()) {
- log.info("Skipping time test (unsupported)");
- skipped = true;
- return;
- }
- verifyType("TIME", getTimeInsertStr("'06:24:00'"), "06:24:00");
- }
-
- @Test
- public void testTime3() {
- if (!supportsTime()) {
- log.info("Skipping time test (unsupported)");
- skipped = true;
- return;
- }
- verifyType("TIME", getTimeInsertStr("'6:24:00'"), "06:24:00");
- }
-
- @Test
- public void testTime4() {
- if (!supportsTime()) {
- log.info("Skipping time test (unsupported)");
- skipped = true;
- return;
- }
- verifyType("TIME", getTimeInsertStr("'18:24:00'"), "18:24:00");
- }
-
- @Test
- public void testTimestamp1() {
- verifyType(getTimestampType(),
- getTimestampInsertStr("'2009-04-24 18:24:00'"),
- getTimestampSeqOutput("2009-04-24 18:24:00"));
- }
-
- @Test
- public void testTimestamp2() {
- try {
- log.debug("Beginning testTimestamp2");
- verifyType(getTimestampType(),
- getTimestampInsertStr("'2009-04-24 18:24:00.0002'"),
- getTimestampSeqOutput("2009-04-24 18:24:00.0002"));
- } finally {
- log.debug("End testTimestamp2");
- }
- }
-
- @Test
- public void testTimestamp3() {
- try {
- log.debug("Beginning testTimestamp3");
- verifyType(getTimestampType(), "null", null);
- } finally {
- log.debug("End testTimestamp3");
- }
- }
-
- @Test
- public void testNumeric1() {
- verifyType(getNumericType(), "1",
- getNumericSeqOutput("1"));
- }
-
- @Test
- public void testNumeric2() {
- verifyType(getNumericType(), "-10",
- getNumericSeqOutput("-10"));
- }
-
- @Test
- public void testNumeric3() {
- verifyType(getNumericType(), "3.14159",
- getNumericSeqOutput("3.14159"));
- }
-
- @Test
- public void testNumeric4() {
- verifyType(getNumericType(),
- "3000000000000000000.14159",
- getNumericSeqOutput("3000000000000000000.14159"));
- }
-
- @Test
- public void testNumeric5() {
- verifyType(getNumericType(),
- "99999999999999999999.14159",
- getNumericSeqOutput("99999999999999999999.14159"));
-
- }
-
- @Test
- public void testNumeric6() {
- verifyType(getNumericType(),
- "-99999999999999999999.14159",
- getNumericSeqOutput("-99999999999999999999.14159"));
- }
-
- @Test
- public void testDecimal1() {
- verifyType(getDecimalType(), "1",
- getDecimalSeqOutput("1"));
- }
-
- @Test
- public void testDecimal2() {
- verifyType(getDecimalType(), "-10",
- getDecimalSeqOutput("-10"));
- }
-
- @Test
- public void testDecimal3() {
- verifyType(getDecimalType(), "3.14159",
- getDecimalSeqOutput("3.14159"));
- }
-
- @Test
- public void testDecimal4() {
- verifyType(getDecimalType(),
- "3000000000000000000.14159",
- getDecimalSeqOutput("3000000000000000000.14159"));
- }
-
- @Test
- public void testDecimal5() {
- verifyType(getDecimalType(),
- "99999999999999999999.14159",
- getDecimalSeqOutput("99999999999999999999.14159"));
- }
-
- @Test
- public void testDecimal6() {
- verifyType(getDecimalType(),
- "-99999999999999999999.14159",
- getDecimalSeqOutput("-99999999999999999999.14159"));
- }
-
- @Test
- public void testLongVarChar() {
- if (!supportsLongVarChar()) {
- log.info("Skipping long varchar test (unsupported)");
- skipped = true;
- return;
- }
- verifyType(getLongVarCharType(),
- "'this is a long varchar'",
- "this is a long varchar");
- }
-
-
- protected void verifyClob(String insertVal, String returnVal,
- String seqFileVal) {
- String [] types = { "INTEGER NOT NULL", getClobType() };
- String [] vals = { "1", insertVal };
- String [] checkCol = { "DATA_COL0", "DATA_COL1" };
-
- createTableWithColTypes(types, vals);
- verifyImport("1," + seqFileVal, checkCol);
- }
-
- protected void verifyBlob(String insertVal, byte [] returnVal,
- String seqFileVal) {
- String [] types = { "INTEGER NOT NULL", getBlobType() };
- String [] vals = { "1", insertVal };
- String [] checkCols = { "DATA_COL0", "DATA_COL1" };
-
- createTableWithColTypes(types, vals);
-
- // Verify readback of the data.
- ResultSet results = null;
- try {
- results = getManager().readTable(getTableName(), getColNames());
- assertNotNull("Null results from readTable()!", results);
- assertTrue("Expected at least one row returned", results.next());
- Blob blob = results.getBlob(2);
- byte [] databaseBytes = blob.getBytes(1, (int) blob.length());
- log.info("Verifying readback of bytes from " + getTableName());
-
- assertEquals("byte arrays differ in size", returnVal.length,
- databaseBytes.length);
- for (int i = 0; i < returnVal.length; i++) {
- assertEquals("bytes differ at position " + i + ". Expected "
- + returnVal[i] + "; got " + databaseBytes[i],
- returnVal[i],
- databaseBytes[i]);
- }
-
- assertFalse("Expected at most one row returned", results.next());
- } catch (SQLException sqlE) {
- fail("Got SQLException: " + sqlE.toString());
- } finally {
- if (null != results) {
- try {
- results.close();
- } catch (SQLException sqlE) {
- fail("Got SQLException in resultset.close(): " + sqlE.toString());
- }
- }
-
- // Free internal resources after the readTable.
- getManager().release();
- }
-
- // Now verify that we can use the Sqoop import mechanism on this data.
- verifyImport("1," + seqFileVal, checkCols);
- }
-
-
- @Test
- public void testClob1() {
- if (!supportsClob()) {
- log.info("Skipping CLOB test; database does not support CLOB");
- return;
- }
-
- verifyClob("'This is short CLOB data'",
- "This is short CLOB data",
- "This is short CLOB data");
- }
-
- @Test
- public void testBlob1() {
- if (!supportsBlob()) {
- log.info("Skipping BLOB test; database does not support BLOB");
- return;
- }
-
- verifyBlob(getBlobInsertStr("This is short BLOB data"),
- getBlobDbOutput("This is short BLOB data"),
- getBlobSeqOutput("This is short BLOB data"));
- }
-
- @Test
- public void testVarBinary() {
- if (!supportsVarBinary()) {
- log.info("Skipping VARBINARY test; database does not support VARBINARY");
- return;
- }
-
- verifyType(getVarBinaryType(), "'F00FABCD'",
- getVarBinarySeqOutput("F00FABCD"), true);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/com/cloudera/sqoop/testutil/MockResultSet.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/testutil/MockResultSet.java b/src/test/com/cloudera/sqoop/testutil/MockResultSet.java
deleted file mode 100644
index de7d3cb..0000000
--- a/src/test/com/cloudera/sqoop/testutil/MockResultSet.java
+++ /dev/null
@@ -1,1038 +0,0 @@
-/**
- * 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 com.cloudera.sqoop.testutil;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.StringReader;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.math.BigDecimal;
-import java.net.URL;
-import java.sql.Array;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.Date;
-import java.sql.NClob;
-import java.sql.Ref;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.RowId;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-import java.sql.SQLXML;
-import java.sql.Statement;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.Map;
-
-/**
- * Mock ResultSet instance that mocks Clob/Blob behavior.
- */
-public class MockResultSet implements ResultSet {
-
- public static final byte [] blobData() {
- return new byte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9,
- 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, };
- }
-
- public static final String CLOB_DATA = "This is the mock clob data!";
-
- /**
- * Read-only Blob class that returns 16 bytes 0x0 .. 0xf
- */
- public static class MockBlob implements Blob {
- public InputStream getBinaryStream() {
- return new ByteArrayInputStream(blobData());
- }
-
- public InputStream getBinaryStream(long pos, long len) {
- return new ByteArrayInputStream(getBytes(pos, (int) len));
- }
-
- public byte [] getBytes(long pos, int length) {
- byte [] bytes = new byte[length];
-
- int start = (int) pos - 1; // SQL uses 1-based arrays!!
- byte [] blobData = blobData();
- for (int i = 0; i < length; i++) {
- bytes[i] = blobData[i + start];
- }
- return bytes;
- }
-
- public long length() {
- return blobData().length;
- }
-
-
- public long position(Blob pattern, long start) { return 0; }
- public long position(byte[] pattern, long start) { return 0; }
- public OutputStream setBinaryStream(long pos) { return null; }
- public int setBytes(long pos, byte[] bytes) { return 0; }
- public int setBytes(long pos, byte[] bytes, int offset, int len) {
- return 0;
- }
- public void truncate(long len) { }
- public void free() { }
- }
-
- /**
- * Read-only Clob class that returns the CLOB_DATA string only.
- */
- public static class MockClob implements Clob {
- @Override
- public InputStream getAsciiStream() {
- try {
- return new ByteArrayInputStream(CLOB_DATA.getBytes("UTF-8"));
- } catch (UnsupportedEncodingException uee) {
- return null;
- }
- }
-
- @Override
- public Reader getCharacterStream() {
- return new StringReader(CLOB_DATA);
- }
-
- public Reader getCharacterStream(long pos, long len) {
- return new StringReader(getSubString(pos, (int) len));
- }
-
- @Override
- public String getSubString(long pos, int length) {
- long start = pos - 1; // 1-based offsets in SQL
- return CLOB_DATA.substring((int) start, (int) (start + length));
- }
-
- @Override
- public long length() {
- return CLOB_DATA.length();
- }
-
- public long position(Clob searchstr, long start) { return 0; }
- public long position(String searchstr, long start) { return 0; }
- public OutputStream setAsciiStream(long pos) { return null; }
- public Writer setCharacterStream(long pos) { return null; }
- public int setString(long pos, String str) { return 0; }
- public int setString(long pos, String str, int offset, int len) {
- return 0;
- }
- public void truncate(long len) { }
- public void free() { }
- }
-
-
- // Methods that return mock Blob or Clob instances.
-
- public InputStream getAsciiStream(int columnIndex) {
- return new MockClob().getAsciiStream();
- }
- public InputStream getAsciiStream(String columnName) {
- return new MockClob().getAsciiStream();
- }
- public InputStream getBinaryStream(int columnIndex) {
- return new MockBlob().getBinaryStream();
- }
- public InputStream getBinaryStream(String columnName) {
- return new MockBlob().getBinaryStream();
- }
- public Blob getBlob(int i) {
- return new MockBlob();
- }
- public Blob getBlob(String colName) {
- return new MockBlob();
- }
- public Reader getCharacterStream(int columnIndex) {
- return new MockClob().getCharacterStream();
- }
- public Reader getCharacterStream(String columnName) {
- return new MockClob().getCharacterStream();
- }
- public Clob getClob(int i) {
- return new MockClob();
- }
- public Clob getClob(String colName) {
- return new MockClob();
- }
-
- // Methods down here just return the default value for whatever
- // type they're using (usually null, 0, or false).
- // These stubs were all auto-generated by Eclipse.
- @Override
- public boolean absolute(int row) throws SQLException {
- return false;
- }
-
- @Override
- public void afterLast() throws SQLException { }
-
- @Override
- public void beforeFirst() throws SQLException { }
-
- @Override
- public void cancelRowUpdates() throws SQLException { }
-
- @Override
- public void clearWarnings() throws SQLException { }
-
- @Override
- public void close() throws SQLException { }
-
- @Override
- public void deleteRow() throws SQLException { }
-
- @Override
- public int findColumn(String columnLabel) throws SQLException {
- return 0;
- }
-
- @Override
- public boolean first() throws SQLException {
- return false;
- }
-
- @Override
- public Array getArray(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Array getArray(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public BigDecimal getBigDecimal(int columnIndex, int scale)
- throws SQLException {
- return null;
- }
-
- @Override
- public BigDecimal getBigDecimal(String columnLabel, int scale)
- throws SQLException {
- return null;
- }
- @Override
- public boolean getBoolean(int columnIndex) throws SQLException {
- return false;
- }
-
- @Override
- public boolean getBoolean(String columnLabel) throws SQLException {
- return false;
- }
-
- @Override
- public byte getByte(int columnIndex) throws SQLException {
- return 0;
- }
-
- @Override
- public byte getByte(String columnLabel) throws SQLException {
- return 0;
- }
-
- @Override
- public int getConcurrency() throws SQLException {
- return 0;
- }
-
- @Override
- public String getCursorName() throws SQLException {
- return null;
- }
-
- @Override
- public Date getDate(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Date getDate(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Date getDate(int columnIndex, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public Date getDate(String columnLabel, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public double getDouble(int columnIndex) throws SQLException {
- return 0;
- }
-
- @Override
- public double getDouble(String columnLabel) throws SQLException {
- return 0;
- }
-
- @Override
- public int getFetchDirection() throws SQLException {
- return 0;
- }
-
- @Override
- public int getFetchSize() throws SQLException {
- return 0;
- }
-
- @Override
- public float getFloat(int columnIndex) throws SQLException {
- return 0;
- }
-
- @Override
- public float getFloat(String columnLabel) throws SQLException {
- return 0;
- }
-
- @Override
- public int getHoldability() throws SQLException {
- return 0;
- }
-
- @Override
- public int getInt(int columnIndex) throws SQLException {
- return 0;
- }
-
- @Override
- public int getInt(String columnLabel) throws SQLException {
- return 0;
- }
-
- @Override
- public long getLong(int columnIndex) throws SQLException {
- return 0;
- }
-
- @Override
- public long getLong(String columnLabel) throws SQLException {
- return 0;
- }
-
- @Override
- public ResultSetMetaData getMetaData() throws SQLException {
- return null;
- }
-
- @Override
- public Reader getNCharacterStream(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Reader getNCharacterStream(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public NClob getNClob(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public NClob getNClob(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public String getNString(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public String getNString(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Object getObject(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Object getObject(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Object getObject(int columnIndex, Map<String, Class<?>> map)
- throws SQLException {
- return null;
- }
-
- @Override
- public Object getObject(String columnLabel, Map<String, Class<?>> map)
- throws SQLException {
- return null;
- }
-
- @Override
- public Ref getRef(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Ref getRef(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public int getRow() throws SQLException {
- return 0;
- }
-
- @Override
- public RowId getRowId(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public RowId getRowId(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public SQLXML getSQLXML(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public SQLXML getSQLXML(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public short getShort(int columnIndex) throws SQLException {
- return 0;
- }
-
- @Override
- public short getShort(String columnLabel) throws SQLException {
- return 0;
- }
-
- @Override
- public Statement getStatement() throws SQLException {
- return null;
- }
-
- @Override
- public String getString(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public String getString(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Time getTime(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Time getTime(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Time getTime(int columnIndex, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public Time getTime(String columnLabel, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public Timestamp getTimestamp(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Timestamp getTimestamp(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Timestamp getTimestamp(int columnIndex, Calendar cal)
- throws SQLException {
- return null;
- }
-
- @Override
- public Timestamp getTimestamp(String columnLabel, Calendar cal)
- throws SQLException {
- return null;
- }
-
- @Override
- public int getType() throws SQLException {
- return 0;
- }
-
- @Override
- public URL getURL(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public URL getURL(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public InputStream getUnicodeStream(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public InputStream getUnicodeStream(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public SQLWarning getWarnings() throws SQLException {
- return null;
- }
-
- @Override
- public void insertRow() throws SQLException {
- }
-
- @Override
- public boolean isAfterLast() throws SQLException {
- return false;
- }
-
- @Override
- public boolean isBeforeFirst() throws SQLException {
- return false;
- }
-
- @Override
- public boolean isClosed() throws SQLException {
- return false;
- }
-
- @Override
- public boolean isFirst() throws SQLException {
- return false;
- }
-
- @Override
- public boolean isLast() throws SQLException {
- return false;
- }
-
- @Override
- public boolean last() throws SQLException {
- return false;
- }
-
- @Override
- public void moveToCurrentRow() throws SQLException {
- }
-
- @Override
- public void moveToInsertRow() throws SQLException {
- }
-
- @Override
- public boolean next() throws SQLException {
- return false;
- }
-
- @Override
- public boolean previous() throws SQLException {
- return false;
- }
-
- @Override
- public void refreshRow() throws SQLException {
- }
-
- @Override
- public boolean relative(int rows) throws SQLException {
- return false;
- }
-
- @Override
- public boolean rowDeleted() throws SQLException {
- return false;
- }
-
- @Override
- public boolean rowInserted() throws SQLException {
- return false;
- }
-
- @Override
- public boolean rowUpdated() throws SQLException {
- return false;
- }
-
- @Override
- public void setFetchDirection(int direction) throws SQLException {
- }
-
- @Override
- public void setFetchSize(int rows) throws SQLException {
- }
-
- @Override
- public void updateArray(int columnIndex, Array x) throws SQLException {
- }
-
- @Override
- public void updateArray(String columnLabel, Array x) throws SQLException {
- }
-
- @Override
- public void updateAsciiStream(int columnIndex, InputStream x)
- throws SQLException {
- }
-
- @Override
- public void updateAsciiStream(String columnLabel, InputStream x)
- throws SQLException {
- }
-
- @Override
- public void updateAsciiStream(int columnIndex, InputStream x, int length)
- throws SQLException {
- }
-
- @Override
- public void updateAsciiStream(String columnLabel, InputStream x, int length)
- throws SQLException {
- }
-
- @Override
- public void updateAsciiStream(int columnIndex, InputStream x, long length)
- throws SQLException {
- }
-
- @Override
- public void updateAsciiStream(String columnLabel, InputStream x, long length)
- throws SQLException {
- }
-
- @Override
- public void updateBigDecimal(int columnIndex, BigDecimal x)
- throws SQLException {
- }
-
- @Override
- public void updateBigDecimal(String columnLabel, BigDecimal x)
- throws SQLException {
- }
-
- @Override
- public void updateBinaryStream(int columnIndex, InputStream x)
- throws SQLException {
- }
-
- @Override
- public void updateBinaryStream(String columnLabel, InputStream x)
- throws SQLException {
- }
-
- @Override
- public void updateBinaryStream(int columnIndex, InputStream x, int length)
- throws SQLException {
- }
-
- @Override
- public void updateBinaryStream(String columnLabel, InputStream x, int length)
- throws SQLException {
- }
-
- @Override
- public void updateBinaryStream(int columnIndex, InputStream x, long length)
- throws SQLException {
- }
-
- @Override
- public void updateBinaryStream(String columnLabel, InputStream x, long length)
- throws SQLException {
- }
-
- @Override
- public void updateBlob(int columnIndex, Blob x) throws SQLException {
- }
-
- @Override
- public void updateBlob(String columnLabel, Blob x) throws SQLException {
- }
-
- @Override
- public void updateBlob(int columnIndex, InputStream inputStream)
- throws SQLException {
- }
-
- @Override
- public void updateBlob(String columnLabel, InputStream inputStream)
- throws SQLException {
- }
-
- @Override
- public void updateBlob(int columnIndex, InputStream inputStream, long length)
- throws SQLException {
- }
-
- @Override
- public void updateBlob(String columnLabel, InputStream inputStream,
- long length) throws SQLException {
- }
-
- @Override
- public void updateBoolean(int columnIndex, boolean x) throws SQLException {
- }
-
- @Override
- public void updateBoolean(String columnLabel, boolean x) throws SQLException {
- }
-
- @Override
- public void updateByte(int columnIndex, byte x) throws SQLException {
- }
-
- @Override
- public void updateByte(String columnLabel, byte x) throws SQLException {
- }
-
- @Override
- public void updateBytes(int columnIndex, byte[] x) throws SQLException {
- }
-
- @Override
- public void updateBytes(String columnLabel, byte[] x) throws SQLException {
- }
-
- @Override
- public void updateCharacterStream(int columnIndex, Reader x)
- throws SQLException {
- }
-
- @Override
- public void updateCharacterStream(String columnLabel, Reader reader)
- throws SQLException {
- }
-
- @Override
- public void updateCharacterStream(int columnIndex, Reader x, int length)
- throws SQLException {
- }
-
- @Override
- public void updateCharacterStream(String columnLabel, Reader reader,
- int length) throws SQLException {
- }
-
- @Override
- public void updateCharacterStream(int columnIndex, Reader x, long length)
- throws SQLException {
- }
-
- @Override
- public void updateCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException {
- }
-
- @Override
- public void updateClob(int columnIndex, Clob x) throws SQLException {
- }
-
- @Override
- public void updateClob(String columnLabel, Clob x) throws SQLException {
- }
-
- @Override
- public void updateClob(int columnIndex, Reader reader) throws SQLException {
- }
-
- @Override
- public void updateClob(String columnLabel, Reader reader)
- throws SQLException {
- }
-
- @Override
- public void updateClob(int columnIndex, Reader reader, long length)
- throws SQLException {
- }
-
- @Override
- public void updateClob(String columnLabel, Reader reader, long length)
- throws SQLException {
- }
-
- @Override
- public void updateDate(int columnIndex, Date x) throws SQLException {
- }
-
- @Override
- public void updateDate(String columnLabel, Date x) throws SQLException {
- }
-
- @Override
- public void updateDouble(int columnIndex, double x) throws SQLException {
- }
-
- @Override
- public void updateDouble(String columnLabel, double x) throws SQLException {
- }
-
- @Override
- public void updateFloat(int columnIndex, float x) throws SQLException {
- }
-
- @Override
- public void updateFloat(String columnLabel, float x) throws SQLException {
- }
-
- @Override
- public void updateInt(int columnIndex, int x) throws SQLException {
- }
-
- @Override
- public void updateInt(String columnLabel, int x) throws SQLException {
- }
-
- @Override
- public void updateLong(int columnIndex, long x) throws SQLException {
- }
-
- @Override
- public void updateLong(String columnLabel, long x) throws SQLException {
- }
-
- @Override
- public void updateNCharacterStream(int columnIndex, Reader x)
- throws SQLException {
- }
-
- @Override
- public void updateNCharacterStream(String columnLabel, Reader reader)
- throws SQLException {
- }
-
- @Override
- public void updateNCharacterStream(int columnIndex, Reader x, long length)
- throws SQLException {
- }
-
- @Override
- public void updateNCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException {
- }
-
- @Override
- public void updateNClob(int columnIndex, NClob clob) throws SQLException {
- }
-
- @Override
- public void updateNClob(String columnLabel, NClob clob) throws SQLException {
- }
-
- @Override
- public void updateNClob(int columnIndex, Reader reader) throws SQLException {
- }
-
- @Override
- public void updateNClob(String columnLabel, Reader reader)
- throws SQLException {
- }
-
- /* Commenting @override as this is addition in java 7 that is not available
- * in Java 6
- @Override
- */
- public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
- return null;
- }
-
- /* Commenting @override as this is addition in java 7 that is not available
- * in Java 6
- @Override
- */
- public <T> T getObject(String columnLabel, Class<T> type) throws SQLException{
- return null;
- }
-
- @Override
- public void updateNClob(int columnIndex, Reader reader, long length)
- throws SQLException {
- }
-
- @Override
- public void updateNClob(String columnLabel, Reader reader, long length)
- throws SQLException {
- }
-
- @Override
- public void updateNString(int columnIndex, String string)
- throws SQLException {
- }
-
- @Override
- public void updateNString(String columnLabel, String string)
- throws SQLException {
- }
-
- @Override
- public void updateNull(int columnIndex) throws SQLException {
- }
-
- @Override
- public void updateNull(String columnLabel) throws SQLException {
- }
-
- @Override
- public void updateObject(int columnIndex, Object x) throws SQLException {
- }
-
- @Override
- public void updateObject(String columnLabel, Object x) throws SQLException {
- }
-
- @Override
- public void updateObject(int columnIndex, Object x, int scaleOrLength)
- throws SQLException {
- }
-
- @Override
- public void updateObject(String columnLabel, Object x, int scaleOrLength)
- throws SQLException {
- }
-
- @Override
- public void updateRef(int columnIndex, Ref x) throws SQLException {
- }
-
- @Override
- public void updateRef(String columnLabel, Ref x) throws SQLException {
- }
-
- @Override
- public void updateRow() throws SQLException {
- }
-
- @Override
- public void updateRowId(int columnIndex, RowId x) throws SQLException {
- }
-
- @Override
- public void updateRowId(String columnLabel, RowId x) throws SQLException {
- }
-
- @Override
- public void updateSQLXML(int columnIndex, SQLXML xmlObject)
- throws SQLException {
- }
-
- @Override
- public void updateSQLXML(String columnLabel, SQLXML xmlObject)
- throws SQLException {
- }
-
- @Override
- public void updateShort(int columnIndex, short x) throws SQLException {
- }
-
- @Override
- public void updateShort(String columnLabel, short x) throws SQLException {
- }
-
- @Override
- public void updateString(int columnIndex, String x) throws SQLException {
- }
-
- @Override
- public void updateString(String columnLabel, String x) throws SQLException {
- }
-
- @Override
- public void updateTime(int columnIndex, Time x) throws SQLException {
- }
-
- @Override
- public void updateTime(String columnLabel, Time x) throws SQLException {
- }
-
- @Override
- public void updateTimestamp(int columnIndex, Timestamp x)
- throws SQLException {
- }
-
- @Override
- public void updateTimestamp(String columnLabel, Timestamp x)
- throws SQLException {
- }
-
- @Override
- public boolean wasNull() throws SQLException {
- return false;
- }
-
- @Override
- public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return false;
- }
-
- @Override
- public <T> T unwrap(Class<T> iface) throws SQLException {
- return null;
- }
-
- @Override
- public byte[] getBytes(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public byte[] getBytes(String columnLabel) throws SQLException {
- return null;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/com/cloudera/sqoop/testutil/ReparseMapper.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/testutil/ReparseMapper.java b/src/test/com/cloudera/sqoop/testutil/ReparseMapper.java
deleted file mode 100644
index 7e47df6..0000000
--- a/src/test/com/cloudera/sqoop/testutil/ReparseMapper.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- * 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 com.cloudera.sqoop.testutil;
-
-import java.io.IOException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.io.LongWritable;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.io.NullWritable;
-import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.mapred.MapReduceBase;
-import org.apache.hadoop.mapred.Mapper;
-import org.apache.hadoop.mapred.OutputCollector;
-import org.apache.hadoop.mapred.Reporter;
-import com.cloudera.sqoop.lib.RecordParser;
-import com.cloudera.sqoop.lib.SqoopRecord;
-import org.apache.hadoop.util.ReflectionUtils;
-
-
-/**
- * Test harness mapper. Instantiate the user's specific type, parse() the input
- * line of text, and throw an IOException if the output toString() line of text
- * differs.
- */
-public class ReparseMapper extends MapReduceBase
- implements Mapper<LongWritable, Text, Text, NullWritable> {
-
- public static final Log LOG = LogFactory.getLog(
- ReparseMapper.class.getName());
-
- public static final String USER_TYPE_NAME_KEY = "sqoop.user.class";
-
- private SqoopRecord userRecord;
-
- public void configure(JobConf job) {
- String userTypeName = job.get(USER_TYPE_NAME_KEY);
- if (null == userTypeName) {
- throw new RuntimeException("Unconfigured parameter: "
- + USER_TYPE_NAME_KEY);
- }
-
- LOG.info("User type name set to " + userTypeName);
-
- this.userRecord = null;
-
- try {
- Configuration conf = new Configuration();
- Class userClass = Class.forName(userTypeName, true,
- Thread.currentThread().getContextClassLoader());
- this.userRecord =
- (SqoopRecord) ReflectionUtils.newInstance(userClass, conf);
- } catch (ClassNotFoundException cnfe) {
- // handled by the next block.
- LOG.error("ClassNotFound exception: " + cnfe.toString());
- } catch (Exception e) {
- LOG.error("Got an exception reflecting user class: " + e.toString());
- }
-
- if (null == this.userRecord) {
- LOG.error("Could not instantiate user record of type " + userTypeName);
- throw new RuntimeException("Could not instantiate user record of type "
- + userTypeName);
- }
- }
-
- public void map(LongWritable key, Text val,
- OutputCollector<Text, NullWritable> out, Reporter r) throws IOException {
-
- LOG.info("Mapper input line: " + val.toString());
-
- try {
- // Use the user's record class to parse the line back in.
- userRecord.parse(val);
- } catch (RecordParser.ParseError pe) {
- LOG.error("Got parse error: " + pe.toString());
- throw new IOException(pe);
- }
-
- LOG.info("Mapper output line: " + userRecord.toString());
-
- out.collect(new Text(userRecord.toString()), NullWritable.get());
-
- if (!userRecord.toString(false).equals(val.toString())) {
- // Could not format record w/o end-of-record delimiter.
- throw new IOException("Returned string w/o EOR has value ["
- + userRecord.toString(false) + "] when ["
- + val.toString() + "] was expected.");
- }
-
- if (!userRecord.toString().equals(val.toString() + "\n")) {
- // misparsed.
- throw new IOException("Returned string has value ["
- + userRecord.toString() + "] when ["
- + val.toString() + "\n] was expected.");
- }
- }
-}
-
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6984a36c/src/test/com/cloudera/sqoop/testutil/SeqFileReader.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/testutil/SeqFileReader.java b/src/test/com/cloudera/sqoop/testutil/SeqFileReader.java
deleted file mode 100644
index 68c1ec5..0000000
--- a/src/test/com/cloudera/sqoop/testutil/SeqFileReader.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * 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 com.cloudera.sqoop.testutil;
-
-import java.io.IOException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.io.SequenceFile;
-import org.apache.hadoop.io.SequenceFile.Reader;
-import org.apache.hadoop.util.ReflectionUtils;
-
-/**
- * Utility class to help with test cases. Just reads the first (k, v) pair
- * from a SequenceFile and returns the value part.
- *
- *
- */
-public final class SeqFileReader {
-
- private SeqFileReader() {
- }
-
- public static final Log LOG = LogFactory.getLog(
- SeqFileReader.class.getName());
-
- public static Reader getSeqFileReader(String filename) throws IOException {
- // read from local filesystem
- Configuration conf = new Configuration();
- if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
- conf.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
- }
- FileSystem fs = FileSystem.get(conf);
- LOG.info("Opening SequenceFile " + filename);
- return new SequenceFile.Reader(fs, new Path(filename), conf);
- }
-
- public static Object getFirstValue(String filename) throws IOException {
- Reader r = null;
- try {
- // read from local filesystem
- Configuration conf = new Configuration();
- if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
- conf.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
- }
- FileSystem fs = FileSystem.get(conf);
- r = new SequenceFile.Reader(fs, new Path(filename), conf);
- Object key = ReflectionUtils.newInstance(r.getKeyClass(), conf);
- Object val = ReflectionUtils.newInstance(r.getValueClass(), conf);
- LOG.info("Reading value of type " + r.getValueClassName()
- + " from SequenceFile " + filename);
- r.next(key);
- r.getCurrentValue(val);
- LOG.info("Value as string: " + val.toString());
- return val;
- } finally {
- if (null != r) {
- try {
- r.close();
- } catch (IOException ioe) {
- LOG.warn("IOException during close: " + ioe.toString());
- }
- }
- }
- }
-}
-