31
31
import java .util .concurrent .TimeUnit ;
32
32
import java .util .concurrent .TimeoutException ;
33
33
import java .util .stream .Stream ;
34
+ import org .junit .jupiter .api .AfterAll ;
35
+ import org .junit .jupiter .api .BeforeAll ;
34
36
import org .junit .jupiter .api .Test ;
35
37
import org .junit .jupiter .api .extension .RegisterExtension ;
36
38
import org .junit .jupiter .params .ParameterizedTest ;
@@ -47,28 +49,51 @@ public abstract class AbstractCouchbaseAsyncClientTest extends AbstractCouchbase
47
49
48
50
@ RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension .create ();
49
51
52
+ private CouchbaseEnvironment environmentCouchbase ;
53
+ private CouchbaseEnvironment environmentMemcache ;
54
+ private CouchbaseAsyncCluster clusterCouchbase ;
55
+ private CouchbaseAsyncCluster clusterMemcache ;
56
+
50
57
private static Stream <Arguments > bucketSettings () {
51
58
return Stream .of (
52
59
Arguments .of (named (bucketCouchbase .type ().name (), bucketCouchbase )),
53
60
Arguments .of (named (bucketMemcache .type ().name (), bucketMemcache )));
54
61
}
55
62
56
- private CouchbaseAsyncCluster prepareCluster (BucketSettings bucketSettings ) {
57
- CouchbaseEnvironment environment = envBuilder (bucketSettings ).build ();
58
- CouchbaseAsyncCluster cluster =
59
- CouchbaseAsyncCluster .create (environment , Collections .singletonList ("127.0.0.1" ));
60
- cleanup .deferCleanup (
61
- () -> cluster .disconnect ().timeout (10 , TimeUnit .SECONDS ).toBlocking ().single ());
62
- cleanup .deferCleanup (environment ::shutdown );
63
+ @ BeforeAll
64
+ void setUpClusters () {
65
+ environmentCouchbase = envBuilder (bucketCouchbase ).build ();
66
+ clusterCouchbase =
67
+ CouchbaseAsyncCluster .create (environmentCouchbase , Collections .singletonList ("127.0.0.1" ));
68
+
69
+ environmentMemcache = envBuilder (bucketMemcache ).build ();
70
+ clusterMemcache =
71
+ CouchbaseAsyncCluster .create (environmentMemcache , Collections .singletonList ("127.0.0.1" ));
72
+ }
73
+
74
+ @ AfterAll
75
+ void cleanUpClusters () {
76
+ clusterCouchbase .disconnect ().timeout (10 , TimeUnit .SECONDS ).toBlocking ().single ();
77
+ environmentCouchbase .shutdown ();
78
+
79
+ clusterMemcache .disconnect ().timeout (10 , TimeUnit .SECONDS ).toBlocking ().single ();
80
+ environmentMemcache .shutdown ();
81
+ }
63
82
64
- return cluster ;
83
+ private CouchbaseAsyncCluster getCluster (BucketSettings bucketSettings ) {
84
+ if (bucketSettings == bucketCouchbase ) {
85
+ return clusterCouchbase ;
86
+ } else if (bucketSettings == bucketMemcache ) {
87
+ return clusterMemcache ;
88
+ }
89
+ throw new IllegalArgumentException ("unknown setting " + bucketSettings .name ());
65
90
}
66
91
67
92
@ ParameterizedTest
68
93
@ MethodSource ("bucketSettings" )
69
94
void hasBucket (BucketSettings bucketSettings )
70
95
throws ExecutionException , InterruptedException , TimeoutException {
71
- CouchbaseAsyncCluster cluster = prepareCluster (bucketSettings );
96
+ CouchbaseAsyncCluster cluster = getCluster (bucketSettings );
72
97
AsyncClusterManager manager = cluster .clusterManager (USERNAME , PASSWORD ).toBlocking ().single ();
73
98
74
99
testing .waitForTraces (1 );
@@ -103,7 +128,7 @@ void hasBucket(BucketSettings bucketSettings)
103
128
@ MethodSource ("bucketSettings" )
104
129
void upsert (BucketSettings bucketSettings )
105
130
throws ExecutionException , InterruptedException , TimeoutException {
106
- CouchbaseAsyncCluster cluster = prepareCluster (bucketSettings );
131
+ CouchbaseAsyncCluster cluster = getCluster (bucketSettings );
107
132
108
133
JsonObject content = JsonObject .create ().put ("hello" , "world" );
109
134
CompletableFuture <JsonDocument > inserted = new CompletableFuture <>();
@@ -144,7 +169,7 @@ void upsert(BucketSettings bucketSettings)
144
169
@ MethodSource ("bucketSettings" )
145
170
void upsertAndGet (BucketSettings bucketSettings )
146
171
throws ExecutionException , InterruptedException , TimeoutException {
147
- CouchbaseAsyncCluster cluster = prepareCluster (bucketSettings );
172
+ CouchbaseAsyncCluster cluster = getCluster (bucketSettings );
148
173
149
174
JsonObject content = JsonObject .create ().put ("hello" , "world" );
150
175
CompletableFuture <JsonDocument > inserted = new CompletableFuture <>();
@@ -194,7 +219,7 @@ void upsertAndGet(BucketSettings bucketSettings)
194
219
@ Test
195
220
void query () throws ExecutionException , InterruptedException , TimeoutException {
196
221
// Only couchbase buckets support queries.
197
- CouchbaseAsyncCluster cluster = prepareCluster (bucketCouchbase );
222
+ CouchbaseAsyncCluster cluster = getCluster (bucketCouchbase );
198
223
199
224
CompletableFuture <JsonObject > queryResult = new CompletableFuture <>();
200
225
// Mock expects this specific query.
0 commit comments