27
27
import com .datastax .mgmtapi .resources .models .KeyspaceRequest ;
28
28
import com .datastax .mgmtapi .resources .models .ReplicationSetting ;
29
29
import com .datastax .mgmtapi .resources .models .ScrubRequest ;
30
+ import io .netty .handler .codec .http .FullHttpResponse ;
30
31
import org .apache .http .HttpStatus ;
31
32
import org .apache .http .client .utils .URIBuilder ;
32
33
import org .assertj .core .api .Assertions ;
@@ -101,15 +102,7 @@ public void testSeedReload() throws IOException
101
102
102
103
String requestSuccessful = client .post (URI .create (BASE_PATH + "/ops/seeds/reload" ).toURL (), null )
103
104
.thenApply (r -> {
104
- if (r .status ().code () == HttpStatus .SC_OK )
105
- {
106
- byte [] versionBytes = new byte [r .content ().readableBytes ()];
107
- r .content ().readBytes (versionBytes );
108
-
109
- return new String (versionBytes );
110
- }
111
-
112
- return null ;
105
+ return responseAsString (r );
113
106
}).join ();
114
107
115
108
//Empty because getSeeds removes local node
@@ -275,15 +268,7 @@ public void testGetReleaseVersion() throws IOException, URISyntaxException
275
268
.build ();
276
269
String response = client .get (uri .toURL ())
277
270
.thenApply (r -> {
278
- if (r .status ().code () == HttpStatus .SC_OK )
279
- {
280
- byte [] versionBytes = new byte [r .content ().readableBytes ()];
281
- r .content ().readBytes (versionBytes );
282
-
283
- return new String (versionBytes );
284
- }
285
-
286
- return null ;
271
+ return responseAsString (r );
287
272
}).join ();
288
273
assertNotNull (response );
289
274
assertNotEquals ("" , response );
@@ -301,15 +286,7 @@ public void testGetEndpoints() throws IOException, URISyntaxException
301
286
.build ();
302
287
String response = client .get (uri .toURL ())
303
288
.thenApply (r -> {
304
- if (r .status ().code () == HttpStatus .SC_OK )
305
- {
306
- byte [] versionBytes = new byte [r .content ().readableBytes ()];
307
- r .content ().readBytes (versionBytes );
308
-
309
- return new String (versionBytes );
310
- }
311
-
312
- return null ;
289
+ return responseAsString (r );
313
290
}).join ();
314
291
315
292
System .err .println (response );
@@ -449,17 +426,7 @@ public void testGetStreamInfo() throws IOException, URISyntaxException
449
426
450
427
URI uri = new URIBuilder (BASE_PATH + "/ops/node/streaminfo" ).build ();
451
428
String response = client .get (uri .toURL ())
452
- .thenApply (r -> {
453
- if (r .status ().code () == HttpStatus .SC_OK )
454
- {
455
- byte [] result = new byte [r .content ().readableBytes ()];
456
- r .content ().readBytes (result );
457
-
458
- return new String (result );
459
- }
460
-
461
- return null ;
462
- }).join ();
429
+ .thenApply (this ::responseAsString ).join ();
463
430
assertNotNull (response );
464
431
assertNotEquals ("" , response );
465
432
}
@@ -471,8 +438,11 @@ public void testCreateKeyspace() throws IOException, URISyntaxException
471
438
ensureStarted ();
472
439
473
440
NettyHttpClient client = new NettyHttpClient (BASE_URL );
441
+ String localDc = client .get (new URIBuilder (BASE_PATH + "/metadata/localdc" ).build ().toURL ())
442
+ .thenApply (this ::responseAsString ).join ();
443
+
474
444
475
- CreateKeyspaceRequest request = new CreateKeyspaceRequest ("someTestKeyspace" , Arrays .asList (new ReplicationSetting ("Cassandra" , 1 )));
445
+ CreateKeyspaceRequest request = new CreateKeyspaceRequest ("someTestKeyspace" , Arrays .asList (new ReplicationSetting (localDc , 1 )));
476
446
String requestAsJSON = WriterUtility .asString (request , MediaType .APPLICATION_JSON );
477
447
478
448
URI uri = new URIBuilder (BASE_PATH + "/ops/keyspace/create" )
@@ -481,4 +451,17 @@ public void testCreateKeyspace() throws IOException, URISyntaxException
481
451
.thenApply (r -> r .status ().code () == HttpStatus .SC_OK ).join ();
482
452
assertTrue (requestSuccessful );
483
453
}
454
+
455
+ private String responseAsString (FullHttpResponse r )
456
+ {
457
+ if (r .status ().code () == HttpStatus .SC_OK )
458
+ {
459
+ byte [] result = new byte [r .content ().readableBytes ()];
460
+ r .content ().readBytes (result );
461
+
462
+ return new String (result );
463
+ }
464
+
465
+ return null ;
466
+ }
484
467
}
0 commit comments