forked from eclipse-vertx/vertx-sql-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPgPoolTest.java
More file actions
660 lines (613 loc) · 21.5 KB
/
PgPoolTest.java
File metadata and controls
660 lines (613 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
/*
* Copyright (C) 2017 Julien Viet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.vertx.pgclient;
import io.netty.channel.EventLoop;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.VertxOptions;
import io.vertx.core.impl.ContextInternal;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.Repeat;
import io.vertx.ext.unit.junit.RepeatRule;
import io.vertx.pgclient.impl.PgSocketConnection;
import io.vertx.pgclient.spi.PgDriver;
import io.vertx.sqlclient.*;
import io.vertx.sqlclient.impl.SqlConnectionInternal;
import io.vertx.sqlclient.spi.ConnectionFactory;
import org.junit.Rule;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collector;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class PgPoolTest extends PgPoolTestBase {
@Rule
public RepeatRule rule = new RepeatRule();
private Set<PgPool> pools = new HashSet<>();
@Override
public void tearDown(TestContext ctx) {
int size = pools.size();
if (size > 0) {
Async async = ctx.async(size);
Set<PgPool> pools = this.pools;
this.pools = new HashSet<>();
pools.forEach(pool -> {
pool
.close()
.onComplete(ar -> {
async.countDown();
});
});
async.awaitSuccess(20_000);
}
super.tearDown(ctx);
}
@Override
protected PgPool createPool(PgConnectOptions connectOptions, PoolOptions poolOptions) {
PgPool pool = PgPool.pool(vertx, connectOptions, poolOptions);
pools.add(pool);
return pool;
}
@Test
public void testClosePool(TestContext ctx) {
Async async = ctx.async();
PgPool pool = createPool(options, new PoolOptions().setMaxSize(1).setMaxWaitQueueSize(0));
pool
.getConnection()
.onComplete(ctx.asyncAssertSuccess(conn -> {
conn.close().onComplete(ctx.asyncAssertSuccess(v1 -> {
pool
.close()
.onComplete(v2 -> {
async.complete();
});
}));
}));
async.await(4000000);
}
@Test
public void testReconnectQueued(TestContext ctx) {
Async async = ctx.async();
ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
AtomicReference<ProxyServer.Connection> proxyConn = new AtomicReference<>();
proxy.proxyHandler(conn -> {
proxyConn.set(conn);
conn.connect();
});
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v1 -> {
PgPool pool = createPool(new PgConnectOptions(options).setPort(8080).setHost("localhost"), 1);
pool
.getConnection()
.onComplete(ctx.asyncAssertSuccess(conn -> {
proxyConn.get().close();
}));
pool
.getConnection()
.onComplete(ctx.asyncAssertSuccess(conn -> {
conn
.query("SELECT id, randomnumber from WORLD")
.execute()
.onComplete(ctx.asyncAssertSuccess(v2 -> {
async.complete();
}));
}));
}));
}
@Test
public void testAuthFailure(TestContext ctx) {
Async async = ctx.async();
PgPool pool = createPool(new PgConnectOptions(options).setPassword("wrong"), 1);
pool
.query("SELECT id, randomnumber from WORLD")
.execute()
.onComplete(ctx.asyncAssertFailure(v2 -> {
async.complete();
}));
}
@Test
public void testConnectionFailure(TestContext ctx) {
Async async = ctx.async();
ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
AtomicReference<ProxyServer.Connection> proxyConn = new AtomicReference<>();
proxy.proxyHandler(conn -> {
proxyConn.set(conn);
conn.connect();
});
PgPool pool = createPool(new PgConnectOptions(options).setPort(8080).setHost("localhost"),
new PoolOptions()
.setMaxSize(1)
.setMaxWaitQueueSize(0)
);
pool
.getConnection()
.onComplete(ctx.asyncAssertFailure(err -> {
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v1 -> {
pool
.getConnection()
.onComplete(ctx.asyncAssertSuccess(conn -> {
async.complete();
}));
}));
}));
}
@Test
public void testRunWithExisting(TestContext ctx) {
Async async = ctx.async();
vertx.runOnContext(v -> {
try {
PgPool.pool(new PoolOptions());
ctx.fail();
} catch (IllegalStateException ignore) {
async.complete();
}
});
}
@Test
public void testRunStandalone(TestContext ctx) {
Async async = ctx.async();
PgPool pool = createPool(new PgConnectOptions(options), new PoolOptions());
pool
.query("SELECT id, randomnumber from WORLD")
.execute()
.onComplete(ctx.asyncAssertSuccess(v -> {
async.complete();
}));
async.await(4000);
}
@Test
public void testMaxWaitQueueSize(TestContext ctx) {
Async async = ctx.async();
PgPool pool = createPool(options, new PoolOptions().setMaxSize(1).setMaxWaitQueueSize(0));
pool
.getConnection()
.onComplete(ctx.asyncAssertSuccess(v -> {
pool
.getConnection()
.onComplete(ctx.asyncAssertFailure(err -> {
v.close().onComplete(ctx.asyncAssertSuccess(vv -> {
async.complete();
}));
}));
}));
async.await(4000000);
}
// This test check that when using pooled connections, the preparedQuery pool operation
// will actually use the same connection for the prepare and the query commands
@Test
public void testConcurrentMultipleConnection(TestContext ctx) {
PgPool pool = createPool(new PgConnectOptions(this.options).setCachePreparedStatements(true), 2);
int numRequests = 2;
Async async = ctx.async(numRequests);
for (int i = 0; i < numRequests; i++) {
pool
.preparedQuery("SELECT * FROM Fortune WHERE id=$1")
.execute(Tuple.of(1))
.onComplete(ctx.asyncAssertSuccess(results -> {
ctx.assertEquals(1, results.size());
Tuple row = results.iterator().next();
ctx.assertEquals(1, row.getInteger(0));
ctx.assertEquals("fortune: No such file or directory", row.getString(1));
async.countDown();
}));
}
}
@Test
public void testUseAvailableResources(TestContext ctx) {
int poolSize = 10;
Async async = ctx.async(poolSize + 1);
PgPool pool = PgPool.pool(options, new PoolOptions().setMaxSize(poolSize));
AtomicReference<PgConnection> ctrlConnRef = new AtomicReference<>();
PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(ctrlConn -> {
ctrlConnRef.set(ctrlConn);
for (int i = 0; i < poolSize; i++) {
vertx.setTimer(10 * (i + 1), l -> {
pool
.query("select pg_sleep(5)")
.execute()
.onComplete(ctx.asyncAssertSuccess(res -> async.countDown()));
});
}
vertx.setTimer(10 * poolSize + 50, event -> {
ctrlConn
.query("select count(*) as cnt from pg_stat_activity where application_name like '%vertx%'")
.execute()
.onComplete(ctx.asyncAssertSuccess(rows -> {
Integer count = rows.iterator().next().getInteger("cnt");
ctx.assertEquals(poolSize + 1, count);
async.countDown();
}));
});
}));
try {
async.await();
} finally {
PgConnection ctrlConn = ctrlConnRef.get();
if (ctrlConn != null) {
ctrlConn.close();
}
pool.close();
}
}
@Test
public void testEventLoopSize(TestContext ctx) {
int num = VertxOptions.DEFAULT_EVENT_LOOP_POOL_SIZE;
int size = num * 2;
PgPool pool = PgPool.pool(options, new PoolOptions().setMaxSize(size).setEventLoopSize(2));
Set<EventLoop> eventLoops = Collections.synchronizedSet(new HashSet<>());
Async async = ctx.async(size);
for (int i = 0;i < size;i++) {
pool
.getConnection()
.onComplete(ctx.asyncAssertSuccess(conn -> {
PgSocketConnection c = (PgSocketConnection) ((SqlConnectionInternal) conn).unwrap().unwrap();
EventLoop eventLoop = ((ContextInternal) c.context()).nettyEventLoop();
eventLoops.add(eventLoop);
async.countDown();
}));
}
try {
async.await();
} finally {
pool.close();
}
ctx.assertEquals(2, eventLoops.size());
}
@Test
public void testPipelining(TestContext ctx) {
AtomicLong latency = new AtomicLong(0L);
ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
proxy.proxyHandler(conn -> {
conn.clientHandler(buff -> {
long delay = latency.get();
if (delay == 0L) {
conn.serverSocket().write(buff);
} else {
vertx.setTimer(delay, id -> {
conn.serverSocket().write(buff);
});
}
});
conn.connect();
});
Async latch = ctx.async();
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(res -> latch.complete()));
latch.awaitSuccess(20_000);
options.setPort(8080);
options.setHost("localhost");
int num = 3;
Async async = ctx.async(num);
SqlClient pool = PgPool.client(options, new PoolOptions().setMaxSize(1));
AtomicLong start = new AtomicLong();
// Connect to the database
pool
.query("select 1")
.execute()
.onComplete(ctx.asyncAssertSuccess(res1 -> {
// We have a connection in the pool
start.set(System.currentTimeMillis());
latency.set(1000);
for (int i = 0; i < num; i++) {
pool
.query("select 1")
.execute()
.onComplete(ctx.asyncAssertSuccess(res2 -> async.countDown()));
}
}));
async.awaitSuccess(20_000);
long elapsed = System.currentTimeMillis() - start.get();
ctx.assertTrue(elapsed < 2000, "Was expecting pipelined latency " + elapsed + " < 2000");
}
@Test
public void testCannotAcquireConnectionOnPipelinedPool(TestContext ctx) {
PgPool pool = (PgPool) PgPool.client(options, new PoolOptions().setMaxSize(1));
pool
.getConnection()
.onComplete(ctx.asyncAssertFailure());
}
/* @Test
public void testPipeliningDistribution(TestContext ctx) {
int num = 10;
SqlClient pool = PgPool.client(options.setPipeliningLimit(512), new PoolOptions().setMaxSize(num));
Async async = ctx.async(num);
for (int i = 0;i < num;i++) {
pool.query("select 1").execute(ctx.asyncAssertSuccess(res1 -> {
async.countDown();
}));
}
async.awaitSuccess(20_000);
int s = ((PoolBase)pool).size();
System.out.println("s = " + s);
int count = 1000;
Async async2 = ctx.async(num * count);
for (int i = 0;i < count * num;i++) {
pool.query("select 1").execute(ctx.asyncAssertSuccess(res1 -> {
async2.countDown();
}));
}
async2.awaitSuccess(20_000);
((PoolBase)pool).check(ctx.asyncAssertSuccess(list -> {
System.out.println("list = " + list);
}));
}*/
@Test
public void testPoolIdleTimeout(TestContext ctx) {
ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
AtomicReference<ProxyServer.Connection> proxyConn = new AtomicReference<>();
int poolCleanerPeriod = 100;
int idleTimeout = 3000;
Async latch = ctx.async();
proxy.proxyHandler(conn -> {
proxyConn.set(conn);
long now = System.currentTimeMillis();
conn.clientCloseHandler(v -> {
long lifetime = System.currentTimeMillis() - now;
int delta = 500;
int lowerBound = idleTimeout - poolCleanerPeriod - delta;
int upperBound = idleTimeout + poolCleanerPeriod + delta;
ctx.assertTrue(lifetime >= lowerBound, "Was expecting connection to be closed in more than " + lowerBound + ": " + lifetime);
ctx.assertTrue(lifetime <= upperBound, "Was expecting connection to be closed in less than " + upperBound + ": "+ lifetime);
latch.complete();
});
conn.connect();
});
// Start proxy
Async listenLatch = ctx.async();
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(res -> listenLatch.complete()));
listenLatch.awaitSuccess(20_000);
poolOptions
.setPoolCleanerPeriod(poolCleanerPeriod)
.setMaxLifetime(0)
.setIdleTimeout(idleTimeout)
.setIdleTimeoutUnit(TimeUnit.MILLISECONDS);
options.setPort(8080);
options.setHost("localhost");
PgPool pool = createPool(options, poolOptions);
// Create a connection that remains in the pool
pool
.getConnection()
.flatMap(SqlClient::close)
.onComplete(ctx.asyncAssertSuccess());
}
@Test
public void testPoolMaxLifetime(TestContext ctx) {
ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
AtomicReference<ProxyServer.Connection> proxyConn = new AtomicReference<>();
int poolCleanerPeriod = 100;
int maxLifetime = 3000;
Async latch = ctx.async();
proxy.proxyHandler(conn -> {
proxyConn.set(conn);
long now = System.currentTimeMillis();
conn.clientCloseHandler(v -> {
long lifetime = System.currentTimeMillis() - now;
int delta = 500;
int lowerBound = maxLifetime - poolCleanerPeriod - delta;
int upperBound = maxLifetime + poolCleanerPeriod + delta;
ctx.assertTrue(lifetime >= lowerBound, "Was expecting connection to be closed in more than " + lowerBound + ": " + lifetime);
ctx.assertTrue(lifetime <= upperBound, "Was expecting connection to be closed in less than " + upperBound + ": "+ lifetime);
latch.complete();
});
conn.connect();
});
// Start proxy
Async listenLatch = ctx.async();
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(res -> listenLatch.complete()));
listenLatch.awaitSuccess(20_000);
poolOptions
.setPoolCleanerPeriod(poolCleanerPeriod)
.setIdleTimeout(0)
.setMaxLifetime(maxLifetime)
.setMaxLifetimeUnit(TimeUnit.MILLISECONDS);
options.setPort(8080);
options.setHost("localhost");
PgPool pool = createPool(options, poolOptions);
// Create a connection that remains in the pool
pool
.getConnection()
.flatMap(SqlClient::close)
.onComplete(ctx.asyncAssertSuccess());
}
@Test
public void testPoolConnectTimeout(TestContext ctx) {
Async async = ctx.async(2);
ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
List<ProxyServer.Connection> connections = Collections.synchronizedList(new ArrayList<>());
proxy.proxyHandler(conn -> {
// Ignore connection
connections.add(conn);
async.countDown();
});
// Start proxy
Async listenLatch = ctx.async();
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(res -> listenLatch.complete()));
listenLatch.awaitSuccess(20_000);
poolOptions
.setConnectionTimeout(1)
.setConnectionTimeoutUnit(TimeUnit.SECONDS);
options.setPort(8080);
options.setHost("localhost");
PgPool pool = createPool(options, poolOptions);
// Create a connection that remains in the pool
long now = System.currentTimeMillis();
pool
.getConnection()
.onComplete(ctx.asyncAssertFailure(err -> {
ctx.assertTrue(System.currentTimeMillis() - now > 900);
async.countDown();
}));
async.awaitSuccess(20_000);
connections.forEach(conn -> conn.clientSocket().close());
}
@Test
@Repeat(50)
public void testNoConnectionLeaks(TestContext ctx) {
Async killConnections = ctx.async();
PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
Collector<Row, ?, List<Boolean>> collector = mapping(row -> row.getBoolean(0), toList());
String sql = "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = $1";
PreparedQuery<SqlResult<List<Boolean>>> preparedQuery = conn.preparedQuery(sql).collecting(collector);
Tuple params = Tuple.of(options.getDatabase());
preparedQuery.execute(params).compose(cf -> conn.close()).onComplete(ctx.asyncAssertSuccess(v -> killConnections.complete()));
}));
killConnections.awaitSuccess();
String sql = "SELECT pg_backend_pid() AS pid, (SELECT count(*) FROM pg_stat_activity WHERE application_name LIKE '%vertx%') AS cnt";
int idleTimeout = 50;
poolOptions
.setMaxSize(1)
.setIdleTimeout(idleTimeout)
.setIdleTimeoutUnit(TimeUnit.MILLISECONDS)
.setPoolCleanerPeriod(5);
PgPool pool = createPool(options, poolOptions);
Async async = ctx.async();
AtomicInteger pid = new AtomicInteger();
vertx.getOrCreateContext().runOnContext(v -> {
pool
.query(sql)
.execute()
.onComplete(ctx.asyncAssertSuccess(rs1 -> {
Row row1 = rs1.iterator().next();
pid.set(row1.getInteger("pid"));
ctx.assertEquals(1, row1.getInteger("cnt"));
vertx.setTimer(2 * idleTimeout, l -> {
pool
.query(sql)
.execute()
.onComplete(ctx.asyncAssertSuccess(rs2 -> {
Row row2 = rs2.iterator().next();
ctx.assertEquals(1, row2.getInteger("cnt"));
ctx.assertNotEquals(pid.get(), row2.getInteger("pid"));
async.complete();
}));
});
}));
});
async.awaitSuccess();
}
@Test
public void testConnectionHook1(TestContext ctx) {
Async async = ctx.async(2);
Handler<SqlConnection> hook = f -> {
vertx.setTimer(1000, id -> {
f.close().onComplete(ctx.asyncAssertSuccess(v -> async.countDown()));
});
};
PgPool pool = createPool(options, new PoolOptions().setMaxSize(1)).connectHandler(hook);
pool
.getConnection()
.onComplete(ctx.asyncAssertSuccess(conn -> {
conn
.query("SELECT id, randomnumber from WORLD")
.execute()
.onComplete(ctx.asyncAssertSuccess(v2 -> {
async.countDown();
}));
}));
}
@Test
public void testConnectionHook2(TestContext ctx) {
Async async = ctx.async(2);
Handler<SqlConnection> hook = f -> {
vertx.setTimer(1000, id -> {
f.close().onComplete(ctx.asyncAssertSuccess(v -> async.countDown()));
});
};
PgPool pool = createPool(options, new PoolOptions().setMaxSize(1)).connectHandler(hook);
pool
.query("SELECT id, randomnumber from WORLD")
.execute()
.onComplete(ctx.asyncAssertSuccess(v2 -> {
async.countDown();
}));
}
@Test
public void testConnectionClosedInHook(TestContext ctx) {
Async async = ctx.async(2);
ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
AtomicReference<ProxyServer.Connection> proxyConn = new AtomicReference<>();
proxy.proxyHandler(conn -> {
proxyConn.set(conn);
conn.connect();
});
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v1 -> {
Handler<SqlConnection> hook = f -> {
f.closeHandler(v -> {
async.countDown();
});
proxyConn.get().close();
};
PgPool pool = createPool(new PgConnectOptions(options).setPort(8080).setHost("localhost"), new PoolOptions().setMaxSize(1)).connectHandler(hook);
pool
.getConnection()
.onComplete(ctx.asyncAssertFailure(conn -> {
async.countDown();
}));
}));
}
@Test
public void testConnectionClosedInProvider1(TestContext ctx) {
testConnectionClosedInProvider(ctx, true);
}
@Test
public void testConnectionClosedInProvider2(TestContext ctx) {
testConnectionClosedInProvider(ctx, false);
}
private void testConnectionClosedInProvider(TestContext ctx, boolean immediately) {
Async async = ctx.async(2);
ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
AtomicReference<ProxyServer.Connection> proxyConn = new AtomicReference<>();
proxy.proxyHandler(conn -> {
proxyConn.set(conn);
conn.connect();
});
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v1 -> {
PgConnectOptions options = new PgConnectOptions(this.options).setPort(8080).setHost("localhost");
ConnectionFactory factory = PgDriver.INSTANCE.createConnectionFactory(vertx, options);
PgPool pool = createPool(options, new PoolOptions().setMaxSize(1));
pool.connectionProvider(context -> {
Future<SqlConnection> fut = factory.connect(context);
if (immediately) {
return fut.map(conn -> {
conn.close();
return conn;
});
} else {
return fut.flatMap(conn -> conn.close().map(conn));
}
});
pool
.getConnection()
.onComplete(ctx.asyncAssertFailure(conn -> {
vertx.runOnContext(v -> {
ctx.assertEquals(0, pool.size());
async.complete();
});
}));
}));
}
}