Skip to content

Commit 5299258

Browse files
authored
Merge pull request #22 from sakama/fix-timeout-settings
Use second as timetout setting instead of milli second
2 parents 584ae3c + 6c34783 commit 5299258

File tree

2 files changed

+5
-49
lines changed

2 files changed

+5
-49
lines changed

src/main/java/org/embulk/output/sftp/SftpFileOutput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private FileSystemOptions initializeFsOptions(PluginTask task)
8383
try {
8484
SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
8585
builder.setUserDirIsRoot(fsOptions, task.getUserDirIsRoot());
86-
builder.setTimeout(fsOptions, task.getSftpConnectionTimeout());
86+
builder.setTimeout(fsOptions, task.getSftpConnectionTimeout() * 1000);
8787
builder.setStrictHostKeyChecking(fsOptions, "no");
8888
if (task.getSecretKeyFilePath().isPresent()) {
8989
IdentityInfo identityInfo = new IdentityInfo(

src/test/java/org/embulk/output/sftp/TestSftpFileOutputPlugin.java

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.google.common.base.Optional;
55
import com.google.common.collect.Lists;
66
import com.google.common.io.Resources;
7-
import org.apache.commons.vfs2.FileSystemException;
87
import org.apache.sshd.common.NamedFactory;
98
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
109
import org.apache.sshd.server.Command;
@@ -30,7 +29,6 @@
3029
import org.embulk.spi.Schema;
3130
import org.embulk.spi.TransactionalPageOutput;
3231
import org.embulk.spi.time.Timestamp;
33-
import org.hamcrest.CoreMatchers;
3432
import org.junit.After;
3533
import org.junit.Before;
3634
import org.junit.Rule;
@@ -187,7 +185,7 @@ private List<String> lsR(List<String> fileNames, Path dir)
187185
return fileNames;
188186
}
189187

190-
private void run(String configYaml, final Optional<Integer> sleep)
188+
private void run(String configYaml)
191189
{
192190
ConfigSource config = getConfigFromYaml(configYaml);
193191
runner.transaction(config, SCHEMA, 1, new Control()
@@ -206,16 +204,10 @@ public List<TaskReport> run(TaskSource taskSource)
206204
true, 2L, 3.0D, "45", Timestamp.ofEpochMilli(678L), newMap(newString("k"), newString("v")),
207205
true, 2L, 3.0D, "45", Timestamp.ofEpochMilli(678L), newMap(newString("k"), newString("v")))) {
208206
pageOutput.add(page);
209-
if (sleep.isPresent()) {
210-
Thread.sleep(sleep.get() * 1000);
211-
}
212207
}
213208
pageOutput.commit();
214209
committed = true;
215210
}
216-
catch (InterruptedException e) {
217-
logger.debug(e.getMessage(), e);
218-
}
219211
finally {
220212
if (!committed) {
221213
pageOutput.abort();
@@ -374,7 +366,7 @@ public void testUserPasswordAndPutToUserDirectoryRoot()
374366
" default_timezone: 'UTC'";
375367

376368
// runner.transaction -> ...
377-
run(configYaml, Optional.<Integer>absent());
369+
run(configYaml);
378370

379371
List<String> fileList = lsR(Lists.<String>newArrayList(), Paths.get(testFolder.getRoot().getAbsolutePath()));
380372
assertThat(fileList, hasItem(containsString(pathPrefix + "001.00.txt")));
@@ -410,7 +402,7 @@ public void testUserSecretKeyFileAndPutToRootDirectory()
410402
" default_timezone: 'UTC'";
411403

412404
// runner.transaction -> ...
413-
run(configYaml, Optional.<Integer>absent());
405+
run(configYaml);
414406

415407
List<String> fileList = lsR(Lists.<String>newArrayList(), Paths.get(testFolder.getRoot().getAbsolutePath()));
416408
assertThat(fileList, hasItem(containsString(pathPrefix + "001.00.txt")));
@@ -458,7 +450,7 @@ public void testUserSecretKeyFileWithProxy()
458450
" default_timezone: 'UTC'";
459451

460452
// runner.transaction -> ...
461-
run(configYaml, Optional.<Integer>absent());
453+
run(configYaml);
462454

463455
List<String> fileList = lsR(Lists.<String>newArrayList(), Paths.get(testFolder.getRoot().getAbsolutePath()));
464456
assertThat(fileList, hasItem(containsString(pathPrefix + "001.00.txt")));
@@ -474,42 +466,6 @@ public void testUserSecretKeyFileWithProxy()
474466
}
475467
}
476468

477-
@Test
478-
public void testTimeout()
479-
{
480-
// setting embulk config
481-
final String pathPrefix = "/test/testUserPassword";
482-
String configYaml = "" +
483-
"type: sftp\n" +
484-
"host: " + HOST + "\n" +
485-
"port: " + PORT + "\n" +
486-
"user: " + USERNAME + "\n" +
487-
"secret_key_file: " + SECRET_KEY_FILE + "\n" +
488-
"secret_key_passphrase: " + SECRET_KEY_PASSPHRASE + "\n" +
489-
"path_prefix: " + testFolder.getRoot().getAbsolutePath() + pathPrefix + "\n" +
490-
"timeout: 1\n" +
491-
"file_ext: txt\n" +
492-
"formatter:\n" +
493-
" type: csv\n" +
494-
" newline: CRLF\n" +
495-
" newline_in_field: LF\n" +
496-
" header_line: true\n" +
497-
" charset: UTF-8\n" +
498-
" quote_policy: NONE\n" +
499-
" quote: \"\\\"\"\n" +
500-
" escape: \"\\\\\"\n" +
501-
" null_string: \"\"\n" +
502-
" default_timezone: 'UTC'";
503-
504-
// exception
505-
exception.expect(RuntimeException.class);
506-
exception.expectCause(CoreMatchers.<Throwable>instanceOf(FileSystemException.class));
507-
exception.expectMessage("Could not connect to SFTP server");
508-
509-
// runner.transaction -> ...
510-
run(configYaml, Optional.of(60)); // sleep 1 minute while processing
511-
}
512-
513469
@Test
514470
public void testProxyType()
515471
{

0 commit comments

Comments
 (0)