23
23
24
24
import java .util .*;
25
25
import java .util .concurrent .*;
26
+ import java .util .function .Function ;
26
27
import java .util .stream .IntStream ;
27
28
28
29
import static com .github .pgasync .DatabaseRule .createPoolBuilder ;
@@ -43,11 +44,9 @@ public static Iterable<Object[]> data() {
43
44
results = new TreeMap <>();
44
45
List <Object []> testData = new ArrayList <>();
45
46
for (int poolSize = 1 ; poolSize <= 4 ; poolSize *= 2 ) {
46
- results .putIfAbsent (key (poolSize ), new TreeMap <>());
47
47
results .putIfAbsent (key (poolSize ), new TreeMap <>());
48
48
for (int threads = 1 ; threads <= 16 ; threads *= 2 ) {
49
49
testData .add (new Object []{poolSize , threads });
50
- testData .add (new Object []{poolSize , threads });
51
50
}
52
51
}
53
52
return testData ;
@@ -89,7 +88,6 @@ public void t1_preAllocatePool() throws Exception {
89
88
}
90
89
91
90
@ Test
92
- // @Ignore
93
91
public void t3_run () throws Exception {
94
92
Collection <Callable <Long >> tasks = new ArrayList <>();
95
93
for (int i = 0 ; i < batchSize ; ++i ) {
@@ -98,7 +96,43 @@ public void t3_run() throws Exception {
98
96
99
97
@ Override
100
98
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")
102
136
.thenAccept(r -> {
103
137
try {
104
138
swap.exchange(currentTimeMillis());
@@ -109,6 +143,7 @@ public Long call() throws Exception {
109
143
.exceptionally(th -> {
110
144
throw new AssertionError(th);
111
145
});
146
+ */
112
147
return swap .exchange (null );
113
148
}
114
149
});
0 commit comments