Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give up processing and throw ConfigException when "Auth fail" appears at the first time #33

Merged
merged 4 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/embulk/input/sftp/SftpFileInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public boolean isRetryableException(Exception exception)
{
if (exception.getCause() != null && exception.getCause().getCause() != null) {
Throwable cause = exception.getCause().getCause();
if (cause.getMessage().contains("Auth fail")) {
if (!cause.getMessage().isEmpty() && cause.getMessage().contains("Auth fail")) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for confusion 🙇
What I mean is some exceptions won't have message, for example: java.util.concurrent.TimeoutException. So this line still could raise NPE.

throw new ConfigException(exception);
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/org/embulk/input/sftp/TestSftpFileInputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class TestSftpFileInputPlugin
{
Expand Down Expand Up @@ -248,6 +249,36 @@ public List<TaskReport> run(TaskSource taskSource, int taskCount)
assertEquals(SftpFileInput.getRelativePath(task, Optional.of(expected.get(1).get(0))), configDiff.get(String.class, "last_path"));
}

@Test
public void testListFilesAuthFail() throws Exception
{
uploadFile(Resources.getResource("sample_01.csv").getPath(), REMOTE_DIRECTORY + "sample_01.csv", true);
uploadFile(Resources.getResource("sample_02.csv").getPath(), REMOTE_DIRECTORY + "sample_02.csv", true);

PluginTask task = config.deepCopy().set("user", "wrong_user").loadConfig(PluginTask.class);

plugin.transaction(config, new FileInputPlugin.Control() {
@Override
public List<TaskReport> run(TaskSource taskSource, int taskCount)
{
assertEquals(2, taskCount);
return emptyTaskReports(taskCount);
}
});

Method listFilesByPrefix = SftpFileInput.class.getDeclaredMethod("listFilesByPrefix", PluginTask.class);
listFilesByPrefix.setAccessible(true);
try {
listFilesByPrefix.invoke(plugin, task);
fail();
}
catch (Exception ex) {
Throwable cause = ex.getCause();
assertEquals(cause.getClass(), ConfigException.class);
assertEquals(cause.getCause().getCause().getCause().getMessage(), "Auth fail");
}
}

@Test
public void testListFilesWithPathPrefixPointToFile() throws Exception
{
Expand Down