embulk-input-postgresql 0.7.4 → 0.8.0

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: 0f32e58dff1927d5f0670a8a464f58b610292b10
4
- data.tar.gz: dcbff14e3e9b025849de763833a35980df655a87
3
+ metadata.gz: 2c06aab77369550b3a8fe22a06ed19f08813b552
4
+ data.tar.gz: fe540f426d5a51eab8768330faf2964fa0323410
5
5
  SHA512:
6
- metadata.gz: b5e4ef218b2a91133777dd18dc10073026c6839282fe0fac31f1114d9f1c9b4a9bf240981fc81a0132a45e24e03c824128e830a69f6cc0b29a7c40a7ceeb3f32
7
- data.tar.gz: 2648def1e2996ecb44aae9b9b25b1d7393f37ec11b435b44bef94850cbf1a28865a4344d4afa23c9c3f64be5d2a7c932aafe3a24ee69846c0432727aef0c9094
6
+ metadata.gz: 563d09b98cd013a35089223a1f88dbf413be9dd5d894c3cd567420e0f67bd5d390eab565cdc1ad2b4dcf7c70cde6f8c1461b19a35cfa6562ddadff88a1458fb4
7
+ data.tar.gz: 5166f3f915d6159c7a576fbf0db217ad5ee153b72eaa051feb6f9c2b2c7452f38ef0cce6c1cbb83ec2313716abe0e30eef66f38ac10c91937d9150f7896a0cd8
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # PostgreSQL input plugins for Embulk
1
+ # PostgreSQL input plugin for Embulk
2
2
 
3
- PostgreSQL input plugins for Embulk loads records from PostgreSQL.
3
+ PostgreSQL input plugin for Embulk loads records from PostgreSQL.
4
4
 
5
5
  ## Overview
6
6
 
@@ -1,83 +1,62 @@
1
1
  package org.embulk.input.postgresql;
2
2
 
3
+ import static java.util.Locale.ENGLISH;
3
4
  import static org.junit.Assert.assertEquals;
4
5
 
5
6
  import java.io.BufferedReader;
6
- import java.io.File;
7
7
  import java.io.IOException;
8
8
  import java.io.InputStreamReader;
9
- import java.net.URISyntaxException;
10
- import java.nio.charset.Charset;
11
- import java.nio.file.FileSystem;
12
- import java.nio.file.FileSystems;
13
- import java.nio.file.Files;
14
9
  import java.sql.Connection;
15
10
  import java.sql.DriverManager;
16
- import java.sql.Statement;
11
+ import java.sql.SQLException;
17
12
  import java.util.Arrays;
18
- import java.util.List;
19
13
 
20
- import org.embulk.input.EmbulkPluginTester;
14
+ import org.apache.commons.lang3.StringUtils;
15
+ import org.embulk.input.AbstractJdbcInputPluginTest;
21
16
  import org.embulk.input.PostgreSQLInputPlugin;
22
17
  import org.embulk.spi.InputPlugin;
23
- import org.junit.AfterClass;
24
- import org.junit.BeforeClass;
25
18
  import org.junit.Test;
26
19
 
27
- public class PostgreSQLInputPluginTest
20
+ public class PostgreSQLInputPluginTest extends AbstractJdbcInputPluginTest
28
21
  {
29
- private static final String DATABASE = "test_db";
30
- private static final String USER = "test_user";
31
- private static final String PASSWORD = "test_pw";
32
- private static final String URL = "jdbc:postgresql://localhost:5432/" + DATABASE;
33
-
34
- private static boolean prepared = false;
35
- private static EmbulkPluginTester tester = new EmbulkPluginTester(InputPlugin.class, "postgresql", PostgreSQLInputPlugin.class);
36
-
37
- @BeforeClass
38
- public static void prepare() throws Exception
22
+ @Override
23
+ protected void prepare() throws SQLException
39
24
  {
25
+ tester.addPlugin(InputPlugin.class, "postgresql", PostgreSQLInputPlugin.class);
26
+
40
27
  try {
41
28
  // Create User and Database
42
- psql(String.format("DROP DATABASE IF EXISTS %s;", DATABASE));
43
- psql(String.format("DROP USER IF EXISTS %s;", USER));
44
- psql(String.format("CREATE USER %s WITH SUPERUSER PASSWORD '%s';", USER, PASSWORD));
45
- psql(String.format("CREATE DATABASE %s WITH OWNER %s;", DATABASE, USER));
29
+ psql(String.format(ENGLISH, "DROP DATABASE IF EXISTS %s;", getDatabase()));
30
+ psql(String.format(ENGLISH, "DROP USER IF EXISTS %s;", getUser()));
31
+ psql(String.format(ENGLISH, "CREATE USER %s WITH SUPERUSER PASSWORD '%s';", getUser(), getPassword()));
32
+ psql(String.format(ENGLISH, "CREATE DATABASE %s WITH OWNER %s;", getDatabase(), getUser()));
46
33
  } catch (IOException e) {
47
34
  System.err.println(e);
48
35
  System.err.println("Warning: cannot prepare a database for testing embulk-input-postgresql.");
49
36
  // 1. install postgresql.
50
37
  // 2. add bin directory to path.
51
- // 3. set environment variable PGPASSWORD
38
+ // 3. set environment variable PGPASSWORD or write pgpassword in tests.yml
52
39
  return;
40
+ } catch (InterruptedException e) {
41
+ throw new RuntimeException(e);
53
42
  }
54
43
 
55
- prepared = true;
44
+ enabled = true;
56
45
 
57
46
  // Insert Data
58
- try(Connection connection = DriverManager.getConnection(URL, USER, PASSWORD)) {
59
- try (Statement statement = connection.createStatement()) {
60
- String sql = "";
61
- sql += "DROP TABLE IF EXISTS input_hstore;";
62
- sql += "CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public;";
63
- sql += "CREATE TABLE input_hstore (c1 hstore);";
64
- sql += "INSERT INTO input_hstore (c1) VALUES('\"a\" => \"b\"');";
65
- statement.execute(sql);
66
- }
67
- }
68
- }
69
-
70
- @AfterClass
71
- public static void dispose()
72
- {
73
- tester.destroy();
47
+ String sql = "";
48
+ sql += "DROP TABLE IF EXISTS input_hstore;";
49
+ sql += "CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public;";
50
+ sql += "CREATE TABLE input_hstore (c1 hstore);";
51
+ sql += "INSERT INTO input_hstore (c1) VALUES('\"a\" => \"b\"');";
52
+ executeSQL(sql);
74
53
  }
75
54
 
76
55
  @Test
77
56
  public void testHstoreAsString() throws Exception
78
57
  {
79
- if (prepared) {
80
- tester.run(convertPath("/yml/input_hstore.yml"));
58
+ if (enabled) {
59
+ test("/yml/input_hstore.yml");
81
60
  assertEquals(Arrays.asList("c1", "\"\"\"a\"\"=>\"\"b\"\"\""),
82
61
  read("postgresql-input000.00.csv"));
83
62
  }
@@ -86,29 +65,19 @@ public class PostgreSQLInputPluginTest
86
65
  @Test
87
66
  public void testHstoreAsJson() throws Exception
88
67
  {
89
- if (prepared) {
90
- tester.run(convertPath("/yml/input_hstore2.yml"));
68
+ if (enabled) {
69
+ test("/yml/input_hstore2.yml");
91
70
  assertEquals(Arrays.asList("c1", "\"{\"\"a\"\":\"\"b\"\"}\""),
92
71
  read("postgresql-input000.00.csv"));
93
72
  }
94
73
  }
95
74
 
96
- private List<String> read(String path) throws IOException
97
- {
98
- FileSystem fs = FileSystems.getDefault();
99
- return Files.readAllLines(fs.getPath(path), Charset.defaultCharset());
100
- }
101
-
102
- private String convertPath(String name) throws URISyntaxException
103
- {
104
- if (getClass().getResource(name) == null) {
105
- return name;
106
- }
107
- return new File(getClass().getResource(name).toURI()).getAbsolutePath();
108
- }
109
-
110
- private static void psql(String sql) throws IOException, InterruptedException {
75
+ private void psql(String sql) throws IOException, InterruptedException {
111
76
  ProcessBuilder pb = new ProcessBuilder("psql", "-w", "-c", sql);
77
+ String pgPassword = (String)getTestConfig("pgpassword", false);
78
+ if (!StringUtils.isEmpty(pgPassword)) {
79
+ pb.environment().put("PGPASSWORD", pgPassword);
80
+ }
112
81
  System.out.println("PSQL: " + pb.command().toString());
113
82
  final Process process = pb.start();
114
83
  final int code = process.waitFor();
@@ -123,4 +92,11 @@ public class PostgreSQLInputPluginTest
123
92
  "Command finished with non-zero exit code. Exit code is %d.", code));
124
93
  }
125
94
  }
95
+
96
+ @Override
97
+ protected Connection connect() throws SQLException
98
+ {
99
+ return DriverManager.getConnection(String.format(ENGLISH, "jdbc:postgresql://%s:%d/%s", getHost(), getPort(), getDatabase()),
100
+ getUser(), getPassword());
101
+ }
126
102
  }
@@ -1,9 +1,9 @@
1
1
  in:
2
2
  type: postgresql
3
- host: localhost
4
- database: test_db
5
- user: test_user
6
- password: test_pw
3
+ host: #host#
4
+ database: #database#
5
+ user: #user#
6
+ password: #password#
7
7
  table: input_hstore
8
8
  select: "*"
9
9
  out:
@@ -1,9 +1,9 @@
1
1
  in:
2
2
  type: postgresql
3
- host: localhost
4
- database: test_db
5
- user: test_user
6
- password: test_pw
3
+ host: #host#
4
+ database: #database#
5
+ user: #user#
6
+ password: #password#
7
7
  table: input_hstore
8
8
  select: "*"
9
9
  column_options:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-postgresql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-28 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Selects records from a table.
14
14
  email:
@@ -19,8 +19,8 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
21
  - build.gradle
22
- - classpath/embulk-input-jdbc-0.7.4.jar
23
- - classpath/embulk-input-postgresql-0.7.4.jar
22
+ - classpath/embulk-input-jdbc-0.8.0.jar
23
+ - classpath/embulk-input-postgresql-0.8.0.jar
24
24
  - classpath/postgresql-9.4-1205-jdbc41.jar
25
25
  - lib/embulk/input/postgresql.rb
26
26
  - src/main/java/org/embulk/input/PostgreSQLInputPlugin.java