File tree Expand file tree Collapse file tree 4 files changed +19
-12
lines changed
src/test/java/com/github/pgasync/impl Expand file tree Collapse file tree 4 files changed +19
-12
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import com .github .pgasync .ConnectionPool ;
4
4
import com .github .pgasync .SqlException ;
5
+ import org .junit .ClassRule ;
5
6
import org .junit .Test ;
6
7
7
8
import static com .github .pgasync .impl .DatabaseRule .createPoolBuilder ;
10
11
11
12
public class AuthenticationTest {
12
13
14
+ @ ClassRule
15
+ public static DatabaseRule dbr = new DatabaseRule (createPoolBuilder (1 ));
16
+
13
17
@ Test
14
18
public void shouldThrowExceptionOnInvalidCredentials () throws Exception {
15
- try (ConnectionPool pool = createPoolBuilder ( 1 ) .password ("_invalid_" ).build ()) {
19
+ try (ConnectionPool pool = dbr . builder .password ("_invalid_" ).build ()) {
16
20
pool .queryRows ("SELECT 1" ).toBlocking ().first ();
17
21
fail ();
18
22
} catch (SqlException sqle ) {
Original file line number Diff line number Diff line change 1
1
package com .github .pgasync .impl ;
2
2
3
3
import static java .lang .System .getenv ;
4
+ import static java .lang .System .out ;
4
5
import static ru .yandex .qatools .embed .postgresql .distribution .Version .V9_5_0 ;
5
6
6
7
import com .github .pgasync .ConnectionPool ;
@@ -51,6 +52,8 @@ class DatabaseRule extends ExternalResource {
51
52
new AbstractPostgresConfig .Credentials ("async-pg" , "async-pg" ));
52
53
PostgresExecutable exec = runtime .prepare (config );
53
54
process = exec .start ();
55
+
56
+ out .printf ("Started postgres to %s:%d%n" , process .getConfig ().net ().host (), process .getConfig ().net ().port ());
54
57
}
55
58
catch (IOException e )
56
59
{
@@ -123,7 +126,6 @@ static class EmbeddedConnectionPoolBuilder extends ConnectionPoolBuilder {
123
126
database ("async-pg" );
124
127
username ("async-pg" );
125
128
password ("async-pg" );
126
- port (2345 );
127
129
}
128
130
}
129
131
Original file line number Diff line number Diff line change 1
1
package com .github .pgasync .impl ;
2
2
3
3
import com .github .pgasync .ConnectionPool ;
4
- import org .junit .AfterClass ;
4
+ import org .junit .ClassRule ;
5
5
import org .junit .Test ;
6
6
import rx .Subscription ;
7
7
16
16
*/
17
17
public class ListenNotifyTest {
18
18
19
- static final ConnectionPool pool = DatabaseRule .createPool (5 );
19
+ @ ClassRule
20
+ public static DatabaseRule dbr = new DatabaseRule (DatabaseRule .createPoolBuilder (5 ));
20
21
21
22
@ Test
22
23
public void shouldReceiveNotificationsOnListenedChannel () throws Exception {
24
+ ConnectionPool pool = dbr .pool ;
23
25
BlockingQueue <String > result = new LinkedBlockingQueue <>(5 );
24
26
25
27
Subscription subscription = pool .listen ("example" ).subscribe (result ::add , Throwable ::printStackTrace );
@@ -39,9 +41,4 @@ public void shouldReceiveNotificationsOnListenedChannel() throws Exception {
39
41
pool .querySet ("notify example, 'msg'" ).toBlocking ().single ();
40
42
assertNull (result .poll (2 , TimeUnit .SECONDS ));
41
43
}
42
-
43
- @ AfterClass
44
- public static void close () throws Exception {
45
- pool .close ();
46
- }
47
44
}
Original file line number Diff line number Diff line change 18
18
import com .github .pgasync .ConnectionPool ;
19
19
import com .github .pgasync .ResultSet ;
20
20
import org .junit .After ;
21
+ import org .junit .ClassRule ;
21
22
import org .junit .Ignore ;
22
23
import org .junit .Test ;
23
24
42
43
* @author Mikko Tiihonen
43
44
*/
44
45
public class PipelineTest {
46
+ @ ClassRule
47
+ public static DatabaseRule dbr = new DatabaseRule ();
48
+
45
49
final Consumer <Throwable > err = t -> { throw new AssertionError ("failed" , t ); };
46
50
47
51
Connection c ;
@@ -59,7 +63,7 @@ public void closeConnection() throws Exception {
59
63
60
64
@ Test
61
65
public void connectionPipelinesQueries () throws InterruptedException {
62
- pool = createPoolBuilder ( 1 ) .pipeline (true ).build ();
66
+ pool = dbr . builder .pipeline (true ).build ();
63
67
64
68
int count = 5 ;
65
69
double sleep = 0.5 ;
@@ -80,7 +84,7 @@ public void connectionPipelinesQueries() throws InterruptedException {
80
84
}
81
85
82
86
private Connection getConnection (boolean pipeline ) throws InterruptedException {
83
- pool = createPoolBuilder ( 1 ) .pipeline (pipeline ).build ();
87
+ pool = dbr . builder .pipeline (pipeline ).build ();
84
88
SynchronousQueue <Connection > connQueue = new SynchronousQueue <>();
85
89
pool .getConnection ().subscribe (connQueue ::add );
86
90
return c = connQueue .take ();
@@ -123,7 +127,7 @@ public void connectionPoolPipelinesQueries() throws InterruptedException {
123
127
124
128
@ Test
125
129
public void connectionPoolPipelinesQueriesWithinTransaction () throws InterruptedException {
126
- pool = createPoolBuilder ( 1 ) .pipeline (true ).build ();
130
+ pool = dbr . builder .pipeline (true ).build ();
127
131
128
132
int count = 5 ;
129
133
double sleep = 0.5 ;
You can’t perform that action at this time.
0 commit comments