embulk-encoder-commons-compress 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23a1109315cf57fbdf2ffde3d4eec038d0dbea18
4
- data.tar.gz: 391ee97d553804487bee7e5421dc1cef952bb99d
3
+ metadata.gz: a0ad3ce0045781de0d2faac7790c076dbc636187
4
+ data.tar.gz: 3d0d8425b24195917ec0dc101c553ceaff8982b6
5
5
  SHA512:
6
- metadata.gz: 789058ac973dfcb777cf0216bacf107dc27a92dcb2016a2fdc190095b5c5295a0e57ba26f6f7f8b83a4e2a96471a2cba479c497830641d91be0a46f2294dcd2c
7
- data.tar.gz: 43e265e8be8e80bccabcf032f964f8cbea0fdeefa1c898730e344ff3e0a9931c57f6310c900bd00e919cc67ce2c8d9089045c40bd91d67351709393666d13c26
6
+ metadata.gz: 497dd5d2c8908446ed70d69e26b407ffe2afa3119916f3419eb1e0fde5e11f10ea7186b30c54898374519580719ca7fbd108f8d2596d8703972ba53cff9a8e1c
7
+ data.tar.gz: c8ca43ee86d84c6841e6eccff86f66de9ea6b77d11d5bdd9de1e8ac61e5bc11410f8e277397adaabef8b34944f231fd88eae3fa97431e8180a760d94b6f97964
@@ -0,0 +1,3 @@
1
+ language: java
2
+ script: ./gradlew -DenableIntegrationTest=true gem
3
+
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Commons Compress Encoder plugin for Embulk
2
+ [![Build Status](https://travis-ci.org/hata/embulk-encoder-commons-compress.svg)](https://travis-ci.org/hata/embulk-encoder-commons-compress)
2
3
 
3
4
  This encoder plugin supports to encode a format like bzip2 and gzip.
4
5
 
@@ -10,7 +11,7 @@ This encoder plugin supports to encode a format like bzip2 and gzip.
10
11
 
11
12
  ## Configuration
12
13
 
13
- - **format**: File format like bzip2, gzip (string, required)
14
+ - **format**: File format like bzip2 and gzip (string, required)
14
15
 
15
16
  ## Example
16
17
 
@@ -18,7 +19,7 @@ This encoder plugin supports to encode a format like bzip2 and gzip.
18
19
  out:
19
20
  type: file
20
21
  path_prefix: any path
21
- file_ext: .csv.bz2
22
+ file_ext: csv.bz2
22
23
  formatter:
23
24
  type: csv
24
25
  encoders:
@@ -31,3 +32,9 @@ out:
31
32
  ```
32
33
  $ ./gradlew gem
33
34
  ```
35
+
36
+ To run integrationTest
37
+ ```
38
+ $ ./gradlew -DenableIntegrationTest=true gem
39
+ ```
40
+
@@ -5,6 +5,8 @@ plugins {
5
5
  }
6
6
  import com.github.jrubygradle.JRubyExec
7
7
 
8
+ apply from: 'https://raw.githubusercontent.com/hata/gradle-plugins/master/embulk-integration-test.gradle'
9
+
8
10
  sourceCompatibility = '1.7'
9
11
  targetCompatibility = '1.7'
10
12
 
@@ -16,12 +18,12 @@ configurations {
16
18
  provided
17
19
  }
18
20
 
19
- version = "0.1.0"
21
+ version = "0.1.1"
20
22
 
21
23
  dependencies {
22
- compile "org.embulk:embulk-core:0.4.6"
23
- compile "org.apache.commons:commons-compress:1.9"
24
- provided "org.embulk:embulk-core:0.4.6"
24
+ compile "org.embulk:embulk-core:0.8.0"
25
+ compile "org.apache.commons:commons-compress:1.13"
26
+ provided "org.embulk:embulk-core:0.8.0"
25
27
  // compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
26
28
  testCompile "org.jmockit:jmockit:1.15"
27
29
  testCompile "junit:junit:4.+"
@@ -61,3 +63,9 @@ Gem::Specification.new do |spec|
61
63
  end
62
64
  /$)
63
65
  }
66
+
67
+ //
68
+ // To enable integrationTest, run like this:
69
+ // ./gradlew -DenableIntegrationTest=true gem
70
+ //
71
+ project.tasks.integrationTest.dependsOn(classpath)
@@ -0,0 +1,80 @@
1
+ package org.embulk.encoder;
2
+
3
+ import static org.junit.Assert.assertEquals;
4
+
5
+ import java.io.BufferedReader;
6
+ import java.io.File;
7
+ import java.io.FileInputStream;
8
+ import java.io.FileReader;
9
+ import java.io.IOException;
10
+ import java.io.InputStreamReader;
11
+ import java.util.zip.CRC32;
12
+ import java.util.zip.Checksum;
13
+
14
+ import org.apache.commons.compress.compressors.CompressorException;
15
+ import org.apache.commons.compress.compressors.CompressorStreamFactory;
16
+ import org.junit.Test;
17
+
18
+ public class TestIntegration {
19
+ static final String TEST_DIR = System.getProperty("embulk.integrationtest.dir");
20
+
21
+ private static String getTestFile(String name) {
22
+ return TEST_DIR + File.separator + name;
23
+ }
24
+
25
+ @Test
26
+ public void testSolidCompressionFormatTarGz() throws Exception {
27
+ assertEquals("Verify input and output contents are identical.",
28
+ getChecksumFromFiles("sample_1.csv"),
29
+ getChecksumFromCompressedFiles("gz", "result_gz_000.00.csv.gz"));
30
+ }
31
+
32
+ @Test
33
+ public void testSolidCompressionFormatTarZ() throws Exception {
34
+ assertEquals("Verify input and output contents are identical.",
35
+ getChecksumFromFiles("sample_1.csv"),
36
+ getChecksumFromCompressedFiles("bzip2", "result_bz2_000.00.csv.bz2"));
37
+
38
+
39
+ }
40
+
41
+ private long getChecksumFromFiles(String ... files) throws IOException {
42
+ Checksum cksum = new CRC32();
43
+
44
+ for (String srcFile : files) {
45
+ try (BufferedReader reader = new BufferedReader(new FileReader(getTestFile(srcFile)))) {
46
+ getChecksum(cksum, reader);
47
+ }
48
+ }
49
+
50
+ return cksum.getValue();
51
+ }
52
+
53
+ private long getChecksumFromCompressedFiles(String compressName, String ... files) throws IOException, CompressorException {
54
+ Checksum cksum = new CRC32();
55
+
56
+ CompressorStreamFactory factory = new CompressorStreamFactory();
57
+
58
+ for (String srcFile : files) {
59
+ try(BufferedReader reader = new BufferedReader(new InputStreamReader(
60
+ factory.createCompressorInputStream(compressName, new FileInputStream(getTestFile(srcFile)))))) {
61
+ getChecksum(cksum, reader);
62
+ }
63
+ }
64
+
65
+ return cksum.getValue();
66
+ }
67
+
68
+ private long getChecksum(Checksum cksum, BufferedReader reader) throws IOException {
69
+ String line = reader.readLine();
70
+ while (line != null) {
71
+ byte[] lineBuf = line.trim().getBytes();
72
+ if (lineBuf.length > 0) {
73
+ // System.out.println("line:" + new String(lineBuf));
74
+ cksum.update(lineBuf, 0, lineBuf.length);
75
+ }
76
+ line = reader.readLine();
77
+ }
78
+ return cksum.getValue();
79
+ }
80
+ }
@@ -0,0 +1,27 @@
1
+ in:
2
+ type: file
3
+ path_prefix: ./sample_1.csv
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: '"'
10
+ trim_if_not_quoted: false
11
+ skip_header_lines: 1
12
+ allow_extra_columns: false
13
+ allow_optional_columns: false
14
+ columns:
15
+ - {name: id, type: long}
16
+ - {name: comment, type: string}
17
+ out:
18
+ type: file
19
+ path_prefix: ./result_bz2_
20
+ file_ext: csv.bz2
21
+ formatter:
22
+ type: csv
23
+ quote_policy: MINIMAL
24
+ newline: LF
25
+ encoders:
26
+ - type: commons-compress
27
+ format: bzip2
@@ -0,0 +1,27 @@
1
+ in:
2
+ type: file
3
+ path_prefix: ./sample_1.csv
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: '"'
10
+ trim_if_not_quoted: false
11
+ skip_header_lines: 1
12
+ allow_extra_columns: false
13
+ allow_optional_columns: false
14
+ columns:
15
+ - {name: id, type: long}
16
+ - {name: comment, type: string}
17
+ out:
18
+ type: file
19
+ path_prefix: ./result_gz_
20
+ file_ext: csv.gz
21
+ formatter:
22
+ type: csv
23
+ quote_policy: MINIMAL
24
+ newline: LF
25
+ encoders:
26
+ - type: commons-compress
27
+ format: gzip
@@ -0,0 +1,3 @@
1
+ id,comment
2
+ 1,foo
3
+ 2,bar
@@ -0,0 +1,189 @@
1
+ /*
2
+ * $Id$
3
+ *
4
+ * Copyright 2015 Hiroki Ata
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ package org.embulk.encoder;
19
+
20
+ import static org.junit.Assert.assertFalse;
21
+ import static org.junit.Assert.assertNotNull;
22
+ import static org.junit.Assert.assertTrue;
23
+
24
+ import java.io.OutputStream;
25
+
26
+ import mockit.Mocked;
27
+ import mockit.NonStrictExpectations;
28
+ import mockit.Verifications;
29
+
30
+ import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
31
+ import org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream;
32
+ import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
33
+ import org.embulk.encoder.CommonsCompressEncoderPlugin.PluginTask;
34
+ import org.embulk.spi.Buffer;
35
+ import org.embulk.spi.BufferAllocator;
36
+ import org.embulk.spi.FileOutput;
37
+ import org.junit.After;
38
+ import org.junit.Before;
39
+ import org.junit.Test;
40
+
41
+ public class TestCommonsCompressCompressorProvider {
42
+ @Mocked
43
+ PluginTask task;
44
+
45
+ @Mocked
46
+ FileOutput fileOutput;
47
+
48
+ CommonsCompressCompressorProvider provider;
49
+
50
+ @Before
51
+ public void setUp() throws Exception {
52
+ }
53
+
54
+ @After
55
+ public void tearDown() throws Exception {
56
+ provider = null;
57
+ }
58
+
59
+ @Test
60
+ public void testIsCompressorFormat() {
61
+ assertTrue(CommonsCompressCompressorProvider.isCompressorFormat("bzip2"));
62
+ assertTrue(CommonsCompressCompressorProvider.isCompressorFormat("gzip"));
63
+ assertTrue(CommonsCompressCompressorProvider.isCompressorFormat("deflate"));
64
+ assertFalse(CommonsCompressCompressorProvider.isCompressorFormat("tar"));
65
+ assertFalse(CommonsCompressCompressorProvider.isCompressorFormat("zip"));
66
+ }
67
+
68
+ @Test
69
+ public void testCommonsCompressCompressorProvider() {
70
+ new NonStrictExpectations() {{
71
+ task.getFormat(); result = "gzip";
72
+ task.getBufferAllocator(); result = new MockBufferAllocator();
73
+ }};
74
+
75
+ assertNotNull("Check constructor.", new CommonsCompressCompressorProvider(task, fileOutput));
76
+ }
77
+
78
+ @Test
79
+ public void testOpenNext() throws Exception {
80
+ new NonStrictExpectations() {{
81
+ task.getFormat(); result = "gzip";
82
+ task.getBufferAllocator(); result = new MockBufferAllocator();
83
+ }};
84
+
85
+ provider = new CommonsCompressCompressorProvider(task, fileOutput);
86
+ OutputStream out = provider.openNext();
87
+ assertTrue("Verify a stream instance.", out instanceof GzipCompressorOutputStream);
88
+ provider.close();
89
+
90
+ new Verifications() {{
91
+ fileOutput.nextFile(); times = 1;
92
+ }};
93
+ }
94
+
95
+ @Test
96
+ public void testFinish() throws Exception {
97
+ new NonStrictExpectations() {{
98
+ task.getFormat(); result = "gzip";
99
+ task.getBufferAllocator(); result = new MockBufferAllocator();
100
+ }};
101
+
102
+ provider = new CommonsCompressCompressorProvider(task, fileOutput);
103
+ provider.finish();
104
+ provider.close();
105
+
106
+ new Verifications() {{
107
+ fileOutput.finish(); times = 1;
108
+ }};
109
+ }
110
+
111
+ @Test
112
+ public void testClose() throws Exception {
113
+ new NonStrictExpectations() {{
114
+ task.getFormat(); result = "gzip";
115
+ task.getBufferAllocator(); result = new MockBufferAllocator();
116
+ }};
117
+
118
+ provider = new CommonsCompressCompressorProvider(task, fileOutput);
119
+ provider.close();
120
+
121
+ new Verifications() {{
122
+ fileOutput.close(); times = 1;
123
+ }};
124
+ }
125
+
126
+ @Test
127
+ public void testCreateCompressorOutputStreamGzip() throws Exception {
128
+ new NonStrictExpectations() {{
129
+ task.getFormat(); result = "gzip";
130
+ task.getBufferAllocator(); result = new MockBufferAllocator();
131
+ }};
132
+
133
+ provider = new CommonsCompressCompressorProvider(task, fileOutput);
134
+ OutputStream out = provider.createCompressorOutputStream();
135
+ assertTrue("Verify a stream instance.", out instanceof GzipCompressorOutputStream);
136
+ provider.close();
137
+
138
+ new Verifications() {{
139
+ fileOutput.close(); times = 1;
140
+ }};
141
+ }
142
+
143
+ @Test
144
+ public void testCreateCompressorOutputStreamBzip2() throws Exception {
145
+ new NonStrictExpectations() {{
146
+ task.getFormat(); result = "bzip2";
147
+ task.getBufferAllocator(); result = new MockBufferAllocator();
148
+ }};
149
+
150
+ provider = new CommonsCompressCompressorProvider(task, fileOutput);
151
+ OutputStream out = provider.createCompressorOutputStream();
152
+ assertTrue("Verify a stream instance.", out instanceof BZip2CompressorOutputStream);
153
+ provider.close();
154
+
155
+ new Verifications() {{
156
+ fileOutput.close(); times = 1;
157
+ }};
158
+ }
159
+
160
+
161
+ @Test
162
+ public void testCreateCompressorOutputStreamDeflate() throws Exception {
163
+ new NonStrictExpectations() {{
164
+ task.getFormat(); result = "deflate";
165
+ task.getBufferAllocator(); result = new MockBufferAllocator();
166
+ }};
167
+
168
+ provider = new CommonsCompressCompressorProvider(task, fileOutput);
169
+ OutputStream out = provider.createCompressorOutputStream();
170
+ assertTrue("Verify a stream instance.", out instanceof DeflateCompressorOutputStream);
171
+ provider.close();
172
+
173
+ new Verifications() {{
174
+ fileOutput.close(); times = 1;
175
+ }};
176
+ }
177
+
178
+ private class MockBufferAllocator implements BufferAllocator {
179
+ @Override
180
+ public Buffer allocate() {
181
+ return allocate(8192);
182
+ }
183
+
184
+ @Override
185
+ public Buffer allocate(int size) {
186
+ return Buffer.allocate(size);
187
+ }
188
+ }
189
+ }
@@ -1,5 +1,81 @@
1
1
  package org.embulk.encoder;
2
2
 
3
+ import static org.junit.Assert.assertNotNull;
4
+ import static org.junit.Assert.assertTrue;
5
+ import mockit.Mocked;
6
+ import mockit.NonStrictExpectations;
7
+ import mockit.Verifications;
8
+
9
+ import org.embulk.config.ConfigSource;
10
+ import org.embulk.config.TaskSource;
11
+ import org.embulk.encoder.CommonsCompressEncoderPlugin.PluginTask;
12
+ import org.embulk.spi.EncoderPlugin;
13
+ import org.embulk.spi.FileOutput;
14
+ import org.embulk.spi.util.OutputStreamFileOutput;
15
+ import org.junit.After;
16
+ import org.junit.Before;
17
+ import org.junit.Test;
18
+
3
19
  public class TestCommonsCompressEncoderPlugin
4
20
  {
21
+ @Mocked
22
+ CommonsCompressEncoderPlugin.PluginTask task;
23
+
24
+ @Mocked
25
+ FileOutput output;
26
+
27
+ @Mocked
28
+ TaskSource taskSource;
29
+
30
+ @Mocked
31
+ ConfigSource config;
32
+
33
+ @Mocked
34
+ EncoderPlugin.Control control;
35
+
36
+ CommonsCompressEncoderPlugin plugin;
37
+
38
+ @Before
39
+ public void setUp() throws Exception {
40
+ plugin = new CommonsCompressEncoderPlugin();
41
+ }
42
+
43
+ @After
44
+ public void tearDown() throws Exception {
45
+ plugin = null;
46
+ }
47
+
48
+ @Test
49
+ public void testTransaction() {
50
+ new NonStrictExpectations() {{
51
+ config.loadConfig(PluginTask.class); result = task;
52
+ task.dump(); result = taskSource;
53
+ }};
54
+
55
+ plugin.transaction(config, control);
56
+
57
+ new Verifications() {{
58
+ control.run(taskSource); times = 1;
59
+ }};
60
+ }
61
+
62
+ @Test
63
+ public void testOpen() {
64
+ new NonStrictExpectations() {{
65
+ task.getFormat(); result = "gzip";
66
+ taskSource.loadTask(PluginTask.class); result = task;
67
+ }};
68
+
69
+ assertNotNull(plugin.open(taskSource, output));
70
+ }
71
+
72
+ @Test
73
+ public void testCreateProvider() {
74
+ new NonStrictExpectations() {{
75
+ task.getFormat(); result = "gzip";
76
+ }};
77
+
78
+ OutputStreamFileOutput.Provider provider = plugin.createProvider(task, output);
79
+ assertTrue("Verify a provider instance.", provider instanceof CommonsCompressCompressorProvider);
80
+ }
5
81
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-encoder-commons-compress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-16 00:00:00.000000000 Z
11
+ date: 2017-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - .gitignore
49
+ - .travis.yml
49
50
  - LICENSE.txt
50
51
  - README.md
51
52
  - build.gradle
@@ -54,12 +55,17 @@ files:
54
55
  - gradlew
55
56
  - gradlew.bat
56
57
  - lib/embulk/encoder/commons-compress.rb
58
+ - src/integration-test/java/org/embulk/encoder/TestIntegration.java
59
+ - src/integration-test/resources/config_bz2.yml
60
+ - src/integration-test/resources/config_gzip.yml
61
+ - src/integration-test/resources/sample_1.csv
57
62
  - src/main/java/org/embulk/encoder/CommonsCompressArchiveProvider.java
58
63
  - src/main/java/org/embulk/encoder/CommonsCompressCompressorProvider.java
59
64
  - src/main/java/org/embulk/encoder/CommonsCompressEncoderPlugin.java
65
+ - src/test/java/org/embulk/encoder/TestCommonsCompressCompressorProvider.java
60
66
  - src/test/java/org/embulk/encoder/TestCommonsCompressEncoderPlugin.java
61
- - classpath/commons-compress-1.9.jar
62
- - classpath/embulk-encoder-commons-compress-0.1.0.jar
67
+ - classpath/commons-compress-1.13.jar
68
+ - classpath/embulk-encoder-commons-compress-0.1.1.jar
63
69
  homepage: https://github.com/hata/embulk-encoder-commons-compress
64
70
  licenses:
65
71
  - MIT