Skip to content

Commit 13d2017

Browse files
committed
Rewrite job status test to use direct HTTP calls and avoid using the client for build reasons.
1 parent b9f5f7f commit 13d2017

File tree

2 files changed

+78
-24
lines changed

2 files changed

+78
-24
lines changed

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

+48-24
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import static org.junit.Assume.assumeFalse;
1919
import static org.junit.Assume.assumeTrue;
2020

21-
import com.datastax.mgmtapi.client.api.DefaultApi;
22-
import com.datastax.mgmtapi.client.invoker.ApiClient;
2321
import com.datastax.mgmtapi.helpers.IntegrationTestUtils;
2422
import com.datastax.mgmtapi.helpers.NettyHttpClient;
2523
import com.datastax.mgmtapi.resources.models.CompactRequest;
@@ -34,6 +32,8 @@
3432
import com.datastax.mgmtapi.resources.models.ScrubRequest;
3533
import com.datastax.mgmtapi.resources.models.Table;
3634
import com.datastax.mgmtapi.resources.models.TakeSnapshotRequest;
35+
import com.datastax.mgmtapi.resources.v2.models.RepairParallelism;
36+
import com.datastax.mgmtapi.resources.v2.models.RepairRequestResponse;
3737
import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder;
3838
import com.fasterxml.jackson.core.JsonProcessingException;
3939
import com.fasterxml.jackson.core.type.TypeReference;
@@ -1036,38 +1036,62 @@ public void testMoveNode() throws IOException, URISyntaxException {
10361036
});
10371037
}
10381038

1039-
public void ensureStatusChanges() throws Exception {
1039+
@Test
1040+
public void testEnsureStatusChanges() throws Exception {
10401041
assumeTrue(IntegrationTestUtils.shouldRun());
10411042
ensureStarted();
10421043
NettyHttpClient client = new NettyHttpClient(BASE_URL);
1043-
DefaultApi apiClient = new DefaultApi(new ApiClient().setBasePath(BASE_HOST));
1044-
com.datastax.mgmtapi.client.model.RepairRequest req =
1045-
new com.datastax.mgmtapi.client.model.RepairRequest()
1046-
.keyspace("system_distributed")
1047-
.fullRepair(true)
1048-
.notifications(true)
1049-
.repairParallelism(
1050-
com.datastax.mgmtapi.client.model.RepairRequest.RepairParallelismEnum.SEQUENTIAL)
1051-
.associatedTokens(
1052-
Collections.singletonList(
1053-
new com.datastax.mgmtapi.client.model.RingRange()
1054-
.start(Long.valueOf(-1))
1055-
.end(Long.valueOf(100))));
1044+
1045+
com.datastax.mgmtapi.resources.v2.models.RepairRequest req =
1046+
new com.datastax.mgmtapi.resources.v2.models.RepairRequest(
1047+
"system_distributed",
1048+
null,
1049+
true,
1050+
true,
1051+
Collections.singletonList(
1052+
new com.datastax.mgmtapi.resources.v2.models.RingRange(-1L, 100L)),
1053+
RepairParallelism.SEQUENTIAL,
1054+
null,
1055+
null);
1056+
10561057
logger.info("Sending repair request: {}", req);
1057-
String jobID = apiClient.putRepairV2(req).getRepairId();
1058-
Integer repairID = Integer.parseInt(jobID.substring(7)); // Trimming off "repair-" prefix.
1058+
URI repairUri = new URIBuilder(BASE_PATH_V2 + "/repairs").build();
1059+
Pair<Integer, String> repairResp =
1060+
client
1061+
.put(repairUri.toURL(), new ObjectMapper().writeValueAsString(req))
1062+
.thenApply(this::responseAsCodeAndBody)
1063+
.join();
1064+
logger.info("Repair response: {}", repairResp);
1065+
String jobID =
1066+
new ObjectMapper().readValue(repairResp.getRight(), RepairRequestResponse.class).repairID;
1067+
Integer repairID =
1068+
Integer.parseInt(
1069+
jobID.substring(7) // Trimming off "repair-" prefix.
1070+
);
10591071
logger.info("Repair ID: {}", repairID);
10601072
assertThat(repairID).isNotNull();
10611073
assertThat(repairID).isGreaterThan(0);
10621074

1063-
com.datastax.mgmtapi.client.model.Job status = apiClient.getJobStatus(jobID);
1064-
logger.info("Repair job status: {}", status);
1065-
assertThat(status.getStatus()).isNotNull();
1066-
assertThat(status.getStatusChanges()).isNotNull();
1067-
await().atMost(5, SECONDS).until(() -> status.getStatusChanges().size() > 0);
1075+
URI statusUri =
1076+
new URIBuilder(BASE_PATH_V2 + "/ops/executor/job").addParameter("job_id", jobID).build();
1077+
Pair<Integer, String> statusResp =
1078+
client.get(statusUri.toURL()).thenApply(this::responseAsCodeAndBody).join();
1079+
logger.info("Repair job status: {}", statusResp);
1080+
Job jobStatus = new ObjectMapper().readValue(statusResp.getRight(), Job.class);
1081+
1082+
assertThat(jobStatus.getStatus()).isNotNull();
1083+
assertThat(jobStatus.getStatusChanges()).isNotNull();
10681084
await()
10691085
.atMost(5, SECONDS)
10701086
.until(
1071-
() -> status.getStatus() == com.datastax.mgmtapi.client.model.Job.StatusEnum.COMPLETED);
1087+
() -> {
1088+
Pair<Integer, String> statusResp2 =
1089+
client.get(statusUri.toURL()).thenApply(this::responseAsCodeAndBody).join();
1090+
logger.info("Repair job status: {}", statusResp);
1091+
Job jobStatus2 = new ObjectMapper().readValue(statusResp.getRight(), Job.class);
1092+
return jobStatus2.getStatusChanges().size() > 0
1093+
&& jobStatus2.getStatus()
1094+
== com.datastax.mgmtapi.resources.models.Job.JobStatus.COMPLETED;
1095+
});
10721096
}
10731097
}

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

+30
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,36 @@ public CompletableFuture<FullHttpResponse> post(
157157
return result;
158158
}
159159

160+
public CompletableFuture<FullHttpResponse> put(
161+
URL url, final CharSequence body, String contentType) throws UnsupportedEncodingException {
162+
CompletableFuture<FullHttpResponse> result = new CompletableFuture<>();
163+
164+
if (!activeRequestFuture.compareAndSet(null, result))
165+
throw new RuntimeException("outstanding request");
166+
167+
DefaultFullHttpRequest request =
168+
new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, url.getFile());
169+
request.headers().set(HttpHeaders.Names.CONTENT_TYPE, contentType);
170+
request.headers().set(HttpHeaderNames.HOST, url.getHost());
171+
172+
if (body != null) {
173+
request.content().writeBytes(body.toString().getBytes(CharsetUtil.UTF_8.name()));
174+
request.headers().set(HttpHeaders.Names.CONTENT_LENGTH, request.content().readableBytes());
175+
} else {
176+
request.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0);
177+
}
178+
179+
// Send the HTTP request.
180+
client.writeAndFlush(request);
181+
182+
return result;
183+
}
184+
185+
public CompletableFuture<FullHttpResponse> put(URL url, final CharSequence body)
186+
throws UnsupportedEncodingException {
187+
return post(url, body, "application/json");
188+
}
189+
160190
public CompletableFuture<FullHttpResponse> delete(URL url) {
161191
return buildAndSendRequest(HttpMethod.DELETE, url);
162192
}

0 commit comments

Comments
 (0)