1
1
/*
2
- * Copyright 2020-2021 the original author or authors
2
+ * Copyright 2020-2022 the original author or authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
27
27
import static org .springframework .data .couchbase .config .BeanNames .REACTIVE_COUCHBASE_TEMPLATE ;
28
28
import static org .springframework .data .couchbase .util .Util .waitUntilCondition ;
29
29
30
+ import okhttp3 .Credentials ;
31
+ import okhttp3 .FormBody ;
32
+ import okhttp3 .OkHttpClient ;
33
+ import okhttp3 .Request ;
34
+ import okhttp3 .Response ;
35
+
30
36
import java .io .IOException ;
31
37
import java .time .Duration ;
32
38
import java .util .Collections ;
39
45
import java .util .function .Function ;
40
46
import java .util .function .Predicate ;
41
47
42
- import com .couchbase .client .core .io .CollectionIdentifier ;
43
48
import org .junit .jupiter .api .BeforeAll ;
44
49
import org .junit .jupiter .api .Timeout ;
45
50
import org .springframework .context .ApplicationContext ;
60
65
import com .couchbase .client .core .error .QueryException ;
61
66
import com .couchbase .client .core .error .ScopeNotFoundException ;
62
67
import com .couchbase .client .core .error .UnambiguousTimeoutException ;
68
+ import com .couchbase .client .core .io .CollectionIdentifier ;
63
69
import com .couchbase .client .core .json .Mapper ;
64
70
import com .couchbase .client .core .service .ServiceType ;
65
71
import com .couchbase .client .java .Bucket ;
@@ -200,6 +206,7 @@ protected static void waitForQueryIndexerToHaveBucket(final Cluster cluster, fin
200
206
}
201
207
202
208
if (!ready ) {
209
+ createAndDeleteBucket ();// need to do this because of https://issues.couchbase.com/browse/MB-50132
203
210
try {
204
211
Thread .sleep (50 );
205
212
} catch (InterruptedException e ) {}
@@ -211,6 +218,32 @@ protected static void waitForQueryIndexerToHaveBucket(final Cluster cluster, fin
211
218
}
212
219
}
213
220
221
+ private static void createAndDeleteBucket () {
222
+ final OkHttpClient httpClient = new OkHttpClient .Builder ().connectTimeout (30 , TimeUnit .SECONDS )
223
+ .readTimeout (30 , TimeUnit .SECONDS ).writeTimeout (30 , TimeUnit .SECONDS ).build ();
224
+ String hostPort = connectionString ().replace ("11210" , "8091" );
225
+ String bucketname = UUID .randomUUID ().toString ();
226
+ try {
227
+
228
+ Response postResponse = httpClient .newCall (new Request .Builder ()
229
+ .header ("Authorization" , Credentials .basic (config ().adminUsername (), config ().adminPassword ()))
230
+ .url ("http://" + hostPort + "/pools/default/buckets/" )
231
+ .post (new FormBody .Builder ().add ("name" , bucketname ).add ("bucketType" , "membase" ).add ("ramQuotaMB" , "100" )
232
+ .add ("replicaNumber" , Integer .toString (0 )).add ("flushEnabled" , "1" ).build ())
233
+ .build ()).execute ();
234
+
235
+ if (postResponse .code () != 202 ) {
236
+ throw new IOException ("Could not create bucket: " + postResponse + ", Reason: " + postResponse .body ().string ());
237
+ }
238
+ Response deleteResponse = httpClient .newCall (new Request .Builder ()
239
+ .header ("Authorization" , Credentials .basic (config ().adminUsername (), config ().adminPassword ()))
240
+ .url ("http://" + hostPort + "/pools/default/buckets/" + bucketname ).delete ().build ()).execute ();
241
+ System .out .println ("deleteResponse: " + deleteResponse );
242
+ } catch (IOException ioe ) {
243
+ ioe .printStackTrace ();
244
+ }
245
+ }
246
+
214
247
/**
215
248
* Improve test stability by waiting for a given service to report itself ready.
216
249
*/
0 commit comments