mirror of
https://github.com/apache/sqoop.git
synced 2025-05-06 17:01:59 +08:00
SQOOP-2528: Sqoop2: findbugs: Fix warning in test module
(Colin Ma via Jarek Jarcec Cecho)
This commit is contained in:
parent
afa865e3b8
commit
3864ccf036
@ -28,6 +28,7 @@
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -57,15 +58,14 @@ public static void assertMapreduceOutput(FileSystem fs, String directory, String
|
|||||||
|
|
||||||
Path[] files = HdfsUtils.getOutputMapreduceFiles(fs, directory);
|
Path[] files = HdfsUtils.getOutputMapreduceFiles(fs, directory);
|
||||||
for(Path file : files) {
|
for(Path file : files) {
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(file)));
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(file), Charset.forName("UTF-8")))) {
|
||||||
|
String line;
|
||||||
String line;
|
while ((line = br.readLine()) != null) {
|
||||||
while ((line = br.readLine()) != null) {
|
if (!setLines.remove(line)) {
|
||||||
if (!setLines.remove(line)) {
|
notFound.add(line);
|
||||||
notFound.add(line);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
br.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!setLines.isEmpty() || !notFound.isEmpty()) {
|
if(!setLines.isEmpty() || !notFound.isEmpty()) {
|
||||||
|
@ -50,12 +50,7 @@ public Configuration prepareConfiguration(Configuration config)
|
|||||||
LOG.debug("Config path is: " + configPath);
|
LOG.debug("Config path is: " + configPath);
|
||||||
|
|
||||||
File dir = new File(configPath);
|
File dir = new File(configPath);
|
||||||
String [] files = dir.list(new FilenameFilter() {
|
String [] files = dir.list(new HRCRRilenameFilter());
|
||||||
@Override
|
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith("-site.xml");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(files == null) {
|
if(files == null) {
|
||||||
throw new FileNotFoundException("Hadoop config files not found: " + configPath);
|
throw new FileNotFoundException("Hadoop config files not found: " + configPath);
|
||||||
@ -81,4 +76,10 @@ public void stop() throws Exception {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class HRCRRilenameFilter implements FilenameFilter {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
return name.endsWith("-site.xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
import org.apache.sqoop.common.test.utils.NetworkUtils;
|
import org.apache.sqoop.common.test.utils.NetworkUtils;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hive server runner for testing purpose.
|
* Hive server runner for testing purpose.
|
||||||
@ -129,7 +131,11 @@ public int getPort() {
|
|||||||
|
|
||||||
private void printConfig() {
|
private void printConfig() {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
config.logVars(new PrintStream(baos));
|
try {
|
||||||
LOG.debug("Hive server runner configuration:\n" + baos.toString());
|
config.logVars(new PrintStream(baos.toString("UTF-8"), "UTF-8"));
|
||||||
|
LOG.debug("Hive server runner configuration:\n" + baos.toString("UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException|FileNotFoundException e) {
|
||||||
|
LOG.warn("Error to print the Hive server runner configuration.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
import org.apache.sqoop.common.test.utils.NetworkUtils;
|
import org.apache.sqoop.common.test.utils.NetworkUtils;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,7 +133,11 @@ public int getPort() {
|
|||||||
|
|
||||||
private void printConfig() {
|
private void printConfig() {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
config.logVars(new PrintStream(baos));
|
try {
|
||||||
LOG.debug("Hive server runner configuration:\n" + baos.toString());
|
config.logVars(new PrintStream(baos.toString("UTF-8"), "UTF-8"));
|
||||||
|
LOG.debug("Hive server runner configuration:\n" + baos.toString("UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException |FileNotFoundException e) {
|
||||||
|
LOG.warn("Error to print the Hive server runner configuration.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ public class SqoopTestCase implements ITest {
|
|||||||
/**
|
/**
|
||||||
* Default submission callbacks that are printing various status about the submission.
|
* Default submission callbacks that are printing various status about the submission.
|
||||||
*/
|
*/
|
||||||
protected static SubmissionCallback DEFAULT_SUBMISSION_CALLBACKS = new SubmissionCallback() {
|
protected static final SubmissionCallback DEFAULT_SUBMISSION_CALLBACKS = new SubmissionCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void submitted(MSubmission submission) {
|
public void submitted(MSubmission submission) {
|
||||||
LOG.info("Submission submitted: " + submission);
|
LOG.info("Submission submitted: " + submission);
|
||||||
|
@ -55,7 +55,7 @@ abstract public class ConnectorTestCase extends TomcatTestCase {
|
|||||||
/**
|
/**
|
||||||
* Default submission callbacks that are printing various status about the submission.
|
* Default submission callbacks that are printing various status about the submission.
|
||||||
*/
|
*/
|
||||||
protected static SubmissionCallback DEFAULT_SUBMISSION_CALLBACKS = new SubmissionCallback() {
|
protected static final SubmissionCallback DEFAULT_SUBMISSION_CALLBACKS = new SubmissionCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void submitted(MSubmission submission) {
|
public void submitted(MSubmission submission) {
|
||||||
LOG.info("Submission submitted: " + submission);
|
LOG.info("Submission submitted: " + submission);
|
||||||
|
@ -18,12 +18,14 @@
|
|||||||
package org.apache.sqoop.test.testng;
|
package org.apache.sqoop.test.testng;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.testng.ITestResult;
|
import org.testng.ITestResult;
|
||||||
import org.testng.TestListenerAdapter;
|
import org.testng.TestListenerAdapter;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sqoop specific listener that will print name of each particular test that being run.
|
* Sqoop specific listener that will print name of each particular test that being run.
|
||||||
@ -31,14 +33,22 @@
|
|||||||
* Particularly suitable for integration tests that generally takes long time to finish.
|
* Particularly suitable for integration tests that generally takes long time to finish.
|
||||||
*/
|
*/
|
||||||
public class SqoopTestListener extends TestListenerAdapter {
|
public class SqoopTestListener extends TestListenerAdapter {
|
||||||
|
private static final Logger LOG = Logger.getLogger(SqoopTestListener.class);
|
||||||
/**
|
/**
|
||||||
* Sqoop tests are generally running with redirectTestOutputToFile=true which means
|
* Sqoop tests are generally running with redirectTestOutputToFile=true which means
|
||||||
* that System.out is redirected to file. That is unpleasant as output user is suppose
|
* that System.out is redirected to file. That is unpleasant as output user is suppose
|
||||||
* to see is not available on the console. Hence instead of System.out we're using
|
* to see is not available on the console. Hence instead of System.out we're using
|
||||||
* directly the STDOUT file descriptor.
|
* directly the STDOUT file descriptor.
|
||||||
*/
|
*/
|
||||||
static PrintStream ps = new PrintStream(new FileOutputStream(FileDescriptor.out));
|
static PrintStream ps;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
ps = new PrintStream(new FileOutputStream(FileDescriptor.out), false, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
LOG.warn("Error when initialize the SqoopTestListener.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,17 +59,20 @@ public static void untarStreamToDirectory(InputStream inputStream, String target
|
|||||||
LOG.info("Untaring file: " + entry.getName());
|
LOG.info("Untaring file: " + entry.getName());
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
(new File( HdfsUtils.joinPathFragments(targetDirectory, entry.getName()))).mkdirs();
|
File targetFile = new File( HdfsUtils.joinPathFragments(targetDirectory, entry.getName()));
|
||||||
|
if (!targetFile.mkdirs()) {
|
||||||
|
LOG.warn("Failed to create folder:" + targetFile.getAbsolutePath());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
int count;
|
int count;
|
||||||
byte data[] = new byte[BUFFER_SIZE];
|
byte data[] = new byte[BUFFER_SIZE];
|
||||||
|
|
||||||
FileOutputStream fos = new FileOutputStream(HdfsUtils.joinPathFragments(targetDirectory, entry.getName()));
|
FileOutputStream fos = new FileOutputStream(HdfsUtils.joinPathFragments(targetDirectory, entry.getName()));
|
||||||
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE);
|
try (BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
|
||||||
while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
|
while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
|
||||||
dest.write(data, 0, count);
|
dest.write(data, 0, count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dest.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +44,7 @@ public class HdfsUtils {
|
|||||||
|
|
||||||
private static final char PATH_SEPARATOR = '/';
|
private static final char PATH_SEPARATOR = '/';
|
||||||
|
|
||||||
public static PathFilter filterHiddenFiles = new PathFilter() {
|
public static final PathFilter filterHiddenFiles = new PathFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Path path) {
|
public boolean accept(Path path) {
|
||||||
String fileName = path.getName();
|
String fileName = path.getName();
|
||||||
@ -77,12 +78,13 @@ public boolean accept(Path path) {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static void createFile(FileSystem fs, String path, String ...lines) throws IOException {
|
public static void createFile(FileSystem fs, String path, String ...lines) throws IOException {
|
||||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fs.create(new Path(path), true)));
|
try (BufferedWriter writer = new BufferedWriter(
|
||||||
for (String line : lines) {
|
new OutputStreamWriter(fs.create(new Path(path), true), Charset.forName("UTF-8")))) {
|
||||||
writer.write(line);
|
for (String line : lines) {
|
||||||
writer.newLine();
|
writer.write(line);
|
||||||
|
writer.newLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
writer.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user