Skip to content

Commit e318d07

Browse files
Performance test fixed
1 parent cef86fa commit e318d07

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ target/
66
*.iml
77
src/test/java/com/github/pgasync/impl/Heroku.java
88
.repository/
9+
.gradle

src/test/java/com/github/pgasync/DatabaseRule.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
package com.github.pgasync;
22

33
import static java.lang.System.getenv;
4+
import static ru.yandex.qatools.embed.postgresql.distribution.Version.V11_1;
45

56
import com.pgasync.ConnectionPool;
67
import com.pgasync.ConnectionPoolBuilder;
78
import com.pgasync.Db;
89
import com.pgasync.ResultSet;
910
import org.junit.rules.ExternalResource;
1011

12+
import java.io.IOException;
1113
import java.util.Collection;
1214
import java.util.List;
1315
import java.util.concurrent.CompletableFuture;
1416
import java.util.concurrent.TimeUnit;
1517

18+
import ru.yandex.qatools.embed.postgresql.PostgresExecutable;
1619
import ru.yandex.qatools.embed.postgresql.PostgresProcess;
20+
import ru.yandex.qatools.embed.postgresql.PostgresStarter;
21+
import ru.yandex.qatools.embed.postgresql.config.AbstractPostgresConfig;
22+
import ru.yandex.qatools.embed.postgresql.config.PostgresConfig;
1723

1824
/**
1925
* @author Antti Laisi
@@ -42,7 +48,7 @@ class DatabaseRule extends ExternalResource {
4248
PostgresExecutable exec = runtime.prepare(config);
4349
process = exec.start();
4450
45-
out.printf("Started postgres to %s:%d%n", process.getConfig().net().host(), process.getConfig().net().port());
51+
System.out.printf("Started postgres to %s:%d%n", process.getConfig().net().host(), process.getConfig().net().port());
4652
} catch (IOException e) {
4753
throw new RuntimeException(e);
4854
}

src/test/java/com/github/pgasync/PerformanceTest.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.util.*;
2525
import java.util.concurrent.*;
26+
import java.util.function.Function;
2627
import java.util.stream.IntStream;
2728

2829
import static com.github.pgasync.DatabaseRule.createPoolBuilder;
@@ -43,11 +44,9 @@ public static Iterable<Object[]> data() {
4344
results = new TreeMap<>();
4445
List<Object[]> testData = new ArrayList<>();
4546
for (int poolSize = 1; poolSize <= 4; poolSize *= 2) {
46-
results.putIfAbsent(key(poolSize), new TreeMap<>());
4747
results.putIfAbsent(key(poolSize), new TreeMap<>());
4848
for (int threads = 1; threads <= 16; threads *= 2) {
4949
testData.add(new Object[]{poolSize, threads});
50-
testData.add(new Object[]{poolSize, threads});
5150
}
5251
}
5352
return testData;
@@ -89,7 +88,6 @@ public void t1_preAllocatePool() throws Exception {
8988
}
9089

9190
@Test
92-
// @Ignore
9391
public void t3_run() throws Exception {
9492
Collection<Callable<Long>> tasks = new ArrayList<>();
9593
for (int i = 0; i < batchSize; ++i) {
@@ -98,7 +96,43 @@ public void t3_run() throws Exception {
9896

9997
@Override
10098
public Long call() throws Exception {
101-
pool.completeQuery("select 42")
99+
100+
pool.getConnection()
101+
.thenApply(connection -> connection.prepareStatement("select 42")
102+
.thenApply(stmt ->
103+
stmt.query()
104+
.thenAccept(res -> {
105+
try {
106+
swap.exchange(currentTimeMillis());
107+
} catch (Exception e) {
108+
throw new AssertionError(e);
109+
}
110+
})
111+
.handle((v, th) ->
112+
stmt.close()
113+
.thenAccept(_v -> {
114+
if (th != null)
115+
throw new RuntimeException(th);
116+
})
117+
)
118+
.thenCompose(Function.identity())
119+
)
120+
.thenCompose(Function.identity())
121+
.handle((v, th) -> connection.close()
122+
.thenAccept(_v -> {
123+
if (th != null) {
124+
throw new RuntimeException(th);
125+
}
126+
}))
127+
.thenCompose(Function.identity())
128+
)
129+
.thenCompose(Function.identity())
130+
.exceptionally(th -> {
131+
throw new AssertionError(th);
132+
});
133+
134+
/*
135+
pool.completeScript("select 42")
102136
.thenAccept(r -> {
103137
try {
104138
swap.exchange(currentTimeMillis());
@@ -109,6 +143,7 @@ public Long call() throws Exception {
109143
.exceptionally(th -> {
110144
throw new AssertionError(th);
111145
});
146+
*/
112147
return swap.exchange(null);
113148
}
114149
});

0 commit comments

Comments
 (0)