embulk-output-sftp 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ package org.embulk.output.sftp.utils;
2
+
3
+ import org.embulk.EmbulkTestRuntime;
4
+ import org.junit.Rule;
5
+ import org.junit.Test;
6
+
7
+ import java.util.concurrent.TimeUnit;
8
+ import java.util.concurrent.TimeoutException;
9
+
10
+ import static org.hamcrest.CoreMatchers.instanceOf;
11
+ import static org.hamcrest.MatcherAssert.assertThat;
12
+
13
+ public class TestTimedCallable
14
+ {
15
+ @Rule
16
+ public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
17
+
18
+ @Test
19
+ public void testCallTimeout()
20
+ {
21
+ try {
22
+ new TimedCallable<Void>()
23
+ {
24
+ @Override
25
+ public Void call() throws Exception
26
+ {
27
+ Thread.sleep(200);
28
+ return null;
29
+ }
30
+ }.call(100, TimeUnit.MILLISECONDS);
31
+ }
32
+ catch (Exception e) {
33
+ assertThat(e, instanceOf(TimeoutException.class));
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,45 @@
1
+ package org.embulk.output.sftp.utils;
2
+
3
+ import org.embulk.EmbulkTestRuntime;
4
+ import org.junit.Rule;
5
+ import org.junit.Test;
6
+
7
+ import java.io.Closeable;
8
+ import java.util.concurrent.TimeoutException;
9
+
10
+ import static junit.framework.TestCase.fail;
11
+ import static org.hamcrest.CoreMatchers.instanceOf;
12
+ import static org.hamcrest.MatcherAssert.assertThat;
13
+
14
+ public class TestTimeoutCloser
15
+ {
16
+ @Rule
17
+ public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
18
+
19
+ @Test
20
+ public void testTimeoutAndAbort()
21
+ {
22
+ TimeoutCloser closer = new TimeoutCloser(new Closeable()
23
+ {
24
+ @Override
25
+ public void close()
26
+ {
27
+ try {
28
+ Thread.sleep(5000);
29
+ }
30
+ catch (InterruptedException e) {
31
+ fail("Failed to sleep");
32
+ }
33
+ }
34
+ });
35
+ closer.timeout = 1;
36
+ try {
37
+ closer.close();
38
+ fail("Should not finish");
39
+ }
40
+ catch (Exception e) {
41
+ assertThat(e, instanceOf(RuntimeException.class));
42
+ assertThat(e.getCause(), instanceOf(TimeoutException.class));
43
+ }
44
+ }
45
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-sftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Civitaspo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-05-07 00:00:00.000000000 Z
12
+ date: 2018-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
@@ -64,21 +64,27 @@ files:
64
64
  - gradlew.bat
65
65
  - lib/embulk/output/sftp.rb
66
66
  - src/main/java/org/embulk/output/sftp/ProxyTask.java
67
- - src/main/java/org/embulk/output/sftp/SftpFileOutput.java
68
67
  - src/main/java/org/embulk/output/sftp/SftpFileOutputPlugin.java
68
+ - src/main/java/org/embulk/output/sftp/SftpLocalFileOutput.java
69
+ - src/main/java/org/embulk/output/sftp/SftpRemoteFileOutput.java
69
70
  - src/main/java/org/embulk/output/sftp/SftpUtils.java
70
71
  - src/main/java/org/embulk/output/sftp/provider/sftp/SftpFileObject.java
71
72
  - src/main/java/org/embulk/output/sftp/provider/sftp/SftpFileProvider.java
72
73
  - src/main/java/org/embulk/output/sftp/provider/sftp/SftpFileSystem.java
73
74
  - src/main/java/org/embulk/output/sftp/provider/sftp/package.html
75
+ - src/main/java/org/embulk/output/sftp/utils/DefaultRetry.java
76
+ - src/main/java/org/embulk/output/sftp/utils/TimedCallable.java
77
+ - src/main/java/org/embulk/output/sftp/utils/TimeoutCloser.java
74
78
  - src/main/resources/providers.xml
75
79
  - src/test/java/org/embulk/output/sftp/TestSftpFileOutputPlugin.java
80
+ - src/test/java/org/embulk/output/sftp/utils/TestTimedCallable.java
81
+ - src/test/java/org/embulk/output/sftp/utils/TestTimeoutCloser.java
76
82
  - src/test/resources/id_rsa
77
83
  - src/test/resources/id_rsa.pub
78
- - classpath/commons-io-2.6.jar
79
84
  - classpath/commons-logging-1.2.jar
80
85
  - classpath/commons-vfs2-2.2.jar
81
- - classpath/embulk-output-sftp-0.1.10.jar
86
+ - classpath/embulk-output-sftp-0.1.11.jar
87
+ - classpath/commons-io-2.6.jar
82
88
  - classpath/jsch-0.1.54.jar
83
89
  homepage: https://github.com/embulk/embulk-output-sftp
84
90
  licenses:
@@ -1,140 +0,0 @@
1
- package org.embulk.output.sftp;
2
-
3
- import com.google.common.base.Throwables;
4
- import org.embulk.config.TaskReport;
5
- import org.embulk.spi.Buffer;
6
- import org.embulk.spi.Exec;
7
- import org.embulk.spi.FileOutput;
8
- import org.embulk.spi.TransactionalFileOutput;
9
- import org.slf4j.Logger;
10
-
11
- import java.io.BufferedOutputStream;
12
- import java.io.File;
13
- import java.io.FileNotFoundException;
14
- import java.io.FileOutputStream;
15
- import java.io.IOException;
16
- import java.util.ArrayList;
17
- import java.util.HashMap;
18
- import java.util.List;
19
- import java.util.Map;
20
-
21
- import static org.embulk.output.sftp.SftpFileOutputPlugin.PluginTask;
22
-
23
- /**
24
- * Created by takahiro.nakayama on 10/20/15.
25
- */
26
- public class SftpFileOutput
27
- implements FileOutput, TransactionalFileOutput
28
- {
29
- private final Logger logger = Exec.getLogger(SftpFileOutput.class);
30
- private final String pathPrefix;
31
- private final String sequenceFormat;
32
- private final String fileNameExtension;
33
- private final boolean renameFileAfterUpload;
34
-
35
- private final int taskIndex;
36
- private final SftpUtils sftpUtils;
37
- private int fileIndex = 0;
38
- private File tempFile;
39
- private BufferedOutputStream localOutput = null;
40
- private List<Map<String, String>> fileList = new ArrayList<>();
41
-
42
- private final String temporaryFileSuffix = ".tmp";
43
-
44
- SftpFileOutput(PluginTask task, int taskIndex)
45
- {
46
- this.pathPrefix = task.getPathPrefix();
47
- this.sequenceFormat = task.getSequenceFormat();
48
- this.fileNameExtension = task.getFileNameExtension();
49
- this.renameFileAfterUpload = task.getRenameFileAfterUpload();
50
- this.taskIndex = taskIndex;
51
- this.sftpUtils = new SftpUtils(task);
52
- }
53
-
54
- @Override
55
- public void nextFile()
56
- {
57
- closeCurrentFile();
58
-
59
- try {
60
- tempFile = Exec.getTempFileSpace().createTempFile();
61
- localOutput = new BufferedOutputStream(new FileOutputStream(tempFile));
62
- }
63
- catch (FileNotFoundException e) {
64
- logger.error(e.getMessage());
65
- Throwables.propagate(e);
66
- }
67
- }
68
-
69
- @Override
70
- public void add(final Buffer buffer)
71
- {
72
- try {
73
- localOutput.write(buffer.array(), buffer.offset(), buffer.limit());
74
- }
75
- catch (IOException ex) {
76
- throw Throwables.propagate(ex);
77
- }
78
- finally {
79
- buffer.release();
80
- }
81
- }
82
-
83
- @Override
84
- public void finish()
85
- {
86
- closeCurrentFile();
87
- String fileName = getOutputFilePath();
88
- String temporaryFileName = fileName + temporaryFileSuffix;
89
- if (renameFileAfterUpload) {
90
- sftpUtils.uploadFile(tempFile, temporaryFileName);
91
- }
92
- else {
93
- sftpUtils.uploadFile(tempFile, fileName);
94
- }
95
-
96
- Map<String, String> executedFiles = new HashMap<>();
97
- executedFiles.put("temporary_filename", temporaryFileName);
98
- executedFiles.put("real_filename", fileName);
99
- fileList.add(executedFiles);
100
- fileIndex++;
101
- }
102
-
103
- @Override
104
- public void close()
105
- {
106
- closeCurrentFile();
107
- // TODO
108
- sftpUtils.close();
109
- }
110
-
111
- @Override
112
- public void abort()
113
- {
114
- }
115
-
116
- @Override
117
- public TaskReport commit()
118
- {
119
- TaskReport report = Exec.newTaskReport();
120
- report.set("file_list", fileList);
121
- return report;
122
- }
123
-
124
- private void closeCurrentFile()
125
- {
126
- if (localOutput != null) {
127
- try {
128
- localOutput.close();
129
- }
130
- catch (IOException ex) {
131
- throw Throwables.propagate(ex);
132
- }
133
- }
134
- }
135
-
136
- private String getOutputFilePath()
137
- {
138
- return pathPrefix + String.format(sequenceFormat, taskIndex, fileIndex) + fileNameExtension;
139
- }
140
- }