Skip to content

Commit 68c5e96

Browse files
author
Eduard Tudenhoefner
committed
Retrieve local datacenter when creating a keyspace
1 parent b82d6e0 commit 68c5e96

File tree

1 file changed

+22
-39
lines changed

1 file changed

+22
-39
lines changed

management-api-server/src/test/java/com/datastax/mgmtapi/NonDestructiveOpsIntegrationTest.java

+22-39
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.datastax.mgmtapi.resources.models.KeyspaceRequest;
2828
import com.datastax.mgmtapi.resources.models.ReplicationSetting;
2929
import com.datastax.mgmtapi.resources.models.ScrubRequest;
30+
import io.netty.handler.codec.http.FullHttpResponse;
3031
import org.apache.http.HttpStatus;
3132
import org.apache.http.client.utils.URIBuilder;
3233
import org.assertj.core.api.Assertions;
@@ -101,15 +102,7 @@ public void testSeedReload() throws IOException
101102

102103
String requestSuccessful = client.post(URI.create(BASE_PATH + "/ops/seeds/reload").toURL(), null)
103104
.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);
113106
}).join();
114107

115108
//Empty because getSeeds removes local node
@@ -275,15 +268,7 @@ public void testGetReleaseVersion() throws IOException, URISyntaxException
275268
.build();
276269
String response = client.get(uri.toURL())
277270
.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);
287272
}).join();
288273
assertNotNull(response);
289274
assertNotEquals("", response);
@@ -301,15 +286,7 @@ public void testGetEndpoints() throws IOException, URISyntaxException
301286
.build();
302287
String response = client.get(uri.toURL())
303288
.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);
313290
}).join();
314291

315292
System.err.println(response);
@@ -449,17 +426,7 @@ public void testGetStreamInfo() throws IOException, URISyntaxException
449426

450427
URI uri = new URIBuilder(BASE_PATH + "/ops/node/streaminfo").build();
451428
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();
463430
assertNotNull(response);
464431
assertNotEquals("", response);
465432
}
@@ -471,8 +438,11 @@ public void testCreateKeyspace() throws IOException, URISyntaxException
471438
ensureStarted();
472439

473440
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+
474444

475-
CreateKeyspaceRequest request = new CreateKeyspaceRequest("someTestKeyspace", Arrays.asList(new ReplicationSetting("Cassandra", 1)));
445+
CreateKeyspaceRequest request = new CreateKeyspaceRequest("someTestKeyspace", Arrays.asList(new ReplicationSetting(localDc, 1)));
476446
String requestAsJSON = WriterUtility.asString(request, MediaType.APPLICATION_JSON);
477447

478448
URI uri = new URIBuilder(BASE_PATH + "/ops/keyspace/create")
@@ -481,4 +451,17 @@ public void testCreateKeyspace() throws IOException, URISyntaxException
481451
.thenApply(r -> r.status().code() == HttpStatus.SC_OK).join();
482452
assertTrue(requestSuccessful);
483453
}
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+
}
484467
}

0 commit comments

Comments
 (0)