List of usage examples for org.apache.hadoop.fs Path toString
@Override
public String toString()
From source file:com.cloudera.sqoop.manager.CubridManagerImportTest.java
License:Apache License
private void doImportAndVerify(String tableName, String[] expectedResults, String... extraArgs) throws IOException { Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, tableName); Path filePath = new Path(tablePath, "part-m-00000"); File tableFile = new File(tablePath.toString()); if (tableFile.exists() && tableFile.isDirectory()) { // remove the directory before running the import. FileListing.recursiveDeleteDir(tableFile); }//from w w w . j a v a 2 s .c o m String[] argv = getArgv(tableName, extraArgs); try { runImport(argv); } catch (IOException ioe) { LOG.error("Got IOException during import: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } File f = new File(filePath.toString()); assertTrue("Could not find imported data file", f.exists()); BufferedReader r = null; try { // Read through the file and make sure it's all there. r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); for (String expectedLine : expectedResults) { assertEquals(expectedLine, r.readLine()); } } catch (IOException ioe) { LOG.error("Got IOException verifying results: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } finally { IOUtils.closeStream(r); } }
From source file:com.cloudera.sqoop.manager.DB2ManagerImportManualTest.java
License:Apache License
private void runDb2Test(String[] expectedResults) throws IOException { Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, getTableName()); Path filePath = new Path(tablePath, "part-m-00000"); File tableFile = new File(tablePath.toString()); if (tableFile.exists() && tableFile.isDirectory()) { // remove the directory before running the import. FileListing.recursiveDeleteDir(tableFile); }//from www . j ava2 s . c o m String[] argv = getArgv(); try { runImport(argv); } catch (IOException ioe) { LOG.error("Got IOException during import: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } File f = new File(filePath.toString()); assertTrue("Could not find imported data file", f.exists()); BufferedReader r = null; try { // Read through the file and make sure it's all there. r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); for (String expectedLine : expectedResults) { assertEquals(expectedLine, r.readLine()); } } catch (IOException ioe) { LOG.error("Got IOException verifying results: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } finally { IOUtils.closeStream(r); } }
From source file:com.cloudera.sqoop.manager.DirectMySQLTest.java
License:Apache License
private void doImport(boolean mysqlOutputDelims, boolean isDirect, String tableName, String[] expectedResults, String[] extraArgs) throws IOException { Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, tableName); Path filePath = new Path(tablePath, "part-m-00000"); File tableFile = new File(tablePath.toString()); if (tableFile.exists() && tableFile.isDirectory()) { // remove the directory before running the import. FileListing.recursiveDeleteDir(tableFile); }// w w w. j a va 2 s . c o m String[] argv = getArgv(mysqlOutputDelims, isDirect, tableName, extraArgs); try { runImport(argv); } catch (IOException ioe) { LOG.error("Got IOException during import: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } File f = new File(filePath.toString()); assertTrue("Could not find imported data file: " + f, f.exists()); BufferedReader r = null; try { // Read through the file and make sure it's all there. r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); for (String expectedLine : expectedResults) { assertEquals(expectedLine, r.readLine()); } } catch (IOException ioe) { LOG.error("Got IOException verifying results: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } finally { IOUtils.closeStream(r); } }
From source file:com.cloudera.sqoop.manager.MySQLAuthTest.java
License:Apache License
/** * Connect to a db and ensure that password-based authentication * succeeds.// www . j a v a2 s . com */ @Test public void testAuthAccess() { String[] argv = getArgv(true, true, AUTH_CONNECT_STRING, AUTH_TABLE_NAME); try { runImport(argv); } catch (IOException ioe) { LOG.error("Got IOException during import: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, AUTH_TABLE_NAME); Path filePath = new Path(tablePath, "part-m-00000"); File f = new File(filePath.toString()); assertTrue("Could not find imported data file", f.exists()); BufferedReader r = null; try { // Read through the file and make sure it's all there. r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); assertEquals("1,'Aaron'", r.readLine()); } catch (IOException ioe) { LOG.error("Got IOException verifying results: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } finally { IOUtils.closeStream(r); } }
From source file:com.cloudera.sqoop.manager.MySQLAuthTest.java
License:Apache License
public void doZeroTimestampTest(int testNum, boolean expectSuccess, String connectString) throws IOException, SQLException { LOG.info("Beginning zero-timestamp test #" + testNum); try {// w ww .j ava2 s . c om final String TABLE_NAME = "mysqlTimestampTable" + Integer.toString(testNum); // Create a table containing a full-zeros timestamp. SqoopOptions options = new SqoopOptions(connectString, TABLE_NAME); options.setUsername(AUTH_TEST_USER); options.setPassword(AUTH_TEST_PASS); manager = new DirectMySQLManager(options); Connection connection = null; Statement st = null; connection = manager.getConnection(); connection.setAutoCommit(false); st = connection.createStatement(); // create the database table and populate it with data. st.executeUpdate("DROP TABLE IF EXISTS " + TABLE_NAME); st.executeUpdate("CREATE TABLE " + TABLE_NAME + " (" + "id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, " + "ts TIMESTAMP NOT NULL)"); st.executeUpdate("INSERT INTO " + TABLE_NAME + " VALUES(" + "NULL,'0000-00-00 00:00:00.0')"); connection.commit(); st.close(); connection.close(); // Run the import. String[] argv = getArgv(true, false, connectString, TABLE_NAME); try { runImport(argv); } catch (Exception e) { if (expectSuccess) { // This is unexpected. rethrow. throw new RuntimeException(e); } else { // We expected an error. LOG.info("Got exception running import (expected). msg: " + e); } } // Make sure the result file is there. Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, TABLE_NAME); Path filePath = new Path(tablePath, "part-m-00000"); File f = new File(filePath.toString()); if (expectSuccess) { assertTrue("Could not find imported data file", f.exists()); BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); assertEquals("1,null", r.readLine()); IOUtils.closeStream(r); } else { assertFalse("Imported data when expected failure", f.exists()); } } finally { LOG.info("Finished zero timestamp test #" + testNum); } }
From source file:com.cloudera.sqoop.manager.NetezzaImportManualTest.java
License:Apache License
private void runNetezzaTest(boolean isDirect, String tableName, String[] expectedResults, String... extraArgs) throws IOException { Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, tableName); Path filePath;// w w w.jav a 2 s.c o m filePath = new Path(tablePath, "part-m-00000"); File tableFile = new File(tablePath.toString()); if (tableFile.exists() && tableFile.isDirectory()) { // remove the directory before running the import. FileListing.recursiveDeleteDir(tableFile); } String[] argv = getArgv(isDirect, tableName, extraArgs); try { runImport(argv); } catch (IOException ioe) { LOG.error("Got IOException during import: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } File f = new File(filePath.toString()); assertTrue("Could not find imported data file : " + f, f.exists()); BufferedReader r = null; try { // Read through the file and make sure it's all there. r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); String[] s = new String[3]; for (int i = 0; i < s.length; ++i) { s[i] = r.readLine(); LOG.info("Line read from file = " + s[i]); } Arrays.sort(s); for (int i = 0; i < expectedResults.length; ++i) { assertEquals(expectedResults[i], s[i]); } } catch (IOException ioe) { LOG.error("Got IOException verifying results: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } finally { IOUtils.closeStream(r); } }
From source file:com.cloudera.sqoop.manager.OracleManagerTest.java
License:Apache License
private void runSecondaryTableTest(String[] expectedResults) throws IOException { Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, QUALIFIED_SECONDARY_TABLE_NAME); Path filePath = new Path(tablePath, "part-m-00000"); File tableFile = new File(tablePath.toString()); if (tableFile.exists() && tableFile.isDirectory()) { // remove the directory before running the import FileListing.recursiveDeleteDir(tableFile); }/*from w w w . ja v a 2s . c o m*/ String[] argv = getArgv(QUALIFIED_SECONDARY_TABLE_NAME); try { runImport(argv); } catch (IOException ioe) { LOG.error("Got IOException during import: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } File f = new File(filePath.toString()); assertTrue("Could not find imported data file", f.exists()); BufferedReader r = null; try { // Read through the file and make sure it's all there. r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); for (String expectedLine : expectedResults) { compareRecords(expectedLine, r.readLine()); } } catch (IOException ioe) { LOG.error("Got IOException verifying results: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } finally { IOUtils.closeStream(r); } }
From source file:com.cloudera.sqoop.manager.OracleManagerTest.java
License:Apache License
private void runOracleTest(String[] expectedResults) throws IOException { Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, TABLE_NAME); Path filePath = new Path(tablePath, "part-m-00000"); File tableFile = new File(tablePath.toString()); if (tableFile.exists() && tableFile.isDirectory()) { // remove the directory before running the import. FileListing.recursiveDeleteDir(tableFile); }/*from w w w . j av a 2 s .co m*/ String[] argv = getArgv(); try { runImport(argv); } catch (IOException ioe) { LOG.error("Got IOException during import: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } File f = new File(filePath.toString()); assertTrue("Could not find imported data file", f.exists()); BufferedReader r = null; try { // Read through the file and make sure it's all there. r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); for (String expectedLine : expectedResults) { compareRecords(expectedLine, r.readLine()); } } catch (IOException ioe) { LOG.error("Got IOException verifying results: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } finally { IOUtils.closeStream(r); } }
From source file:com.cloudera.sqoop.manager.PostgresqlImportTest.java
License:Apache License
private void doImportAndVerify(boolean isDirect, String[] expectedResults, String tableName, String... extraArgs) throws IOException { Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, tableName); Path filePath = new Path(tablePath, "part-m-00000"); File tableFile = new File(tablePath.toString()); if (tableFile.exists() && tableFile.isDirectory()) { // remove the directory before running the import. FileListing.recursiveDeleteDir(tableFile); }/* ww w. j a v a 2 s . c om*/ String[] argv = getArgv(isDirect, tableName, extraArgs); try { runImport(argv); } catch (IOException ioe) { LOG.error("Got IOException during import: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } File f = new File(filePath.toString()); assertTrue("Could not find imported data file, " + f, f.exists()); BufferedReader r = null; try { // Read through the file and make sure it's all there. r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); for (String expectedLine : expectedResults) { assertEquals(expectedLine, r.readLine()); } } catch (IOException ioe) { LOG.error("Got IOException verifying results: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } finally { IOUtils.closeStream(r); } }
From source file:com.cloudera.sqoop.manager.PostgresqlTest.java
License:Apache License
private void doImportAndVerify(boolean isDirect, String[] expectedResults, String tableName, String... extraArgs) throws IOException { Path warehousePath = new Path(this.getWarehouseDir()); Path tablePath = new Path(warehousePath, tableName); Path filePath;// w w w . j a v a 2 s . com if (isDirect) { filePath = new Path(tablePath, "data-00000"); } else { filePath = new Path(tablePath, "part-m-00000"); } File tableFile = new File(tablePath.toString()); if (tableFile.exists() && tableFile.isDirectory()) { // remove the directory before running the import. FileListing.recursiveDeleteDir(tableFile); } String[] argv = getArgv(isDirect, tableName, extraArgs); try { runImport(argv); } catch (IOException ioe) { LOG.error("Got IOException during import: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } File f = new File(filePath.toString()); assertTrue("Could not find imported data file, " + f, f.exists()); BufferedReader r = null; try { // Read through the file and make sure it's all there. r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); for (String expectedLine : expectedResults) { assertEquals(expectedLine, r.readLine()); } } catch (IOException ioe) { LOG.error("Got IOException verifying results: " + ioe.toString()); ioe.printStackTrace(); fail(ioe.toString()); } finally { IOUtils.closeStream(r); } }