Skip to content

Commit 64d8cc8

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

File tree

2 files changed

+84
-26
lines changed

2 files changed

+84
-26
lines changed

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

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@
3434
import com.datastax.mgmtapi.resources.models.ScrubRequest;
3535
import com.datastax.mgmtapi.resources.models.Table;
3636
import com.datastax.mgmtapi.resources.models.TakeSnapshotRequest;
37+
import com.datastax.mgmtapi.resources.v2.models.RepairParallelism;
38+
import com.datastax.mgmtapi.resources.v2.models.RepairRequestResponse;
3739
import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder;
3840
import com.fasterxml.jackson.core.JsonProcessingException;
3941
import com.fasterxml.jackson.core.type.TypeReference;
4042
import com.fasterxml.jackson.databind.ObjectMapper;
4143
import com.fasterxml.jackson.databind.json.JsonMapper;
44+
import com.google.common.base.Function;
4245
import com.google.common.base.Splitter;
4346
import com.google.common.collect.ImmutableList;
4447
import com.google.common.collect.ImmutableMap;
4548
import com.google.common.util.concurrent.Uninterruptibles;
49+
import io.netty.handler.codec.http.FullHttpResponse;
4650
import io.netty.util.IllegalReferenceCountException;
4751
import java.io.IOException;
4852
import java.net.URI;
@@ -1040,34 +1044,58 @@ public void ensureStatusChanges() throws Exception {
10401044
assumeTrue(IntegrationTestUtils.shouldRun());
10411045
ensureStarted();
10421046
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))));
1047+
1048+
1049+
com.datastax.mgmtapi.resources.v2.models.RepairRequest req
1050+
= new com.datastax.mgmtapi.resources.v2.models.RepairRequest(
1051+
"system_distributed",
1052+
null,
1053+
true,
1054+
true,
1055+
Collections.singletonList(
1056+
new com.datastax.mgmtapi.resources.v2.models.RingRange(-1L, 100L)
1057+
),
1058+
RepairParallelism.SEQUENTIAL,
1059+
null,
1060+
null
1061+
);
1062+
10561063
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.
1064+
URI repairUri =
1065+
new URIBuilder(BASE_PATH_V2 + "repairs").build();
1066+
Pair<Integer, String> repairResp = client
1067+
.put(
1068+
repairUri.toURL(),
1069+
new ObjectMapper().writeValueAsString(req))
1070+
.thenApply(this::responseAsCodeAndBody).join();
1071+
String jobID = new ObjectMapper()
1072+
.readValue(repairResp.getRight(), RepairRequestResponse.class)
1073+
.repairID;
1074+
Integer repairID = Integer.parseInt(
1075+
jobID.substring(7) // Trimming off "repair-" prefix.
1076+
);
10591077
logger.info("Repair ID: {}", repairID);
10601078
assertThat(repairID).isNotNull();
10611079
assertThat(repairID).isGreaterThan(0);
10621080

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);
1068-
await()
1069-
.atMost(5, SECONDS)
1070-
.until(
1071-
() -> status.getStatus() == com.datastax.mgmtapi.client.model.Job.StatusEnum.COMPLETED);
1081+
URI statusUri =
1082+
new URIBuilder(BASE_PATH_V2 + "/ops/executor/job").addParameter("job_id", jobID).build();
1083+
Pair<Integer, String> statusResp = client
1084+
.get(statusUri.toURL())
1085+
.thenApply(this::responseAsCodeAndBody).join();
1086+
logger.info("Repair job status: {}", statusResp);
1087+
Job jobStatus = new ObjectMapper().readValue(statusResp.getRight(), Job.class);
1088+
1089+
assertThat(jobStatus.getStatus()).isNotNull();
1090+
assertThat(jobStatus.getStatusChanges()).isNotNull();
1091+
await().atMost(5, SECONDS).until(() -> {
1092+
Pair<Integer, String> statusResp2 = client
1093+
.get(statusUri.toURL())
1094+
.thenApply(this::responseAsCodeAndBody).join();
1095+
logger.info("Repair job status: {}", statusResp);
1096+
Job jobStatus2 = new ObjectMapper().readValue(statusResp.getRight(), Job.class);
1097+
return jobStatus2.getStatusChanges().size() > 0 &&
1098+
jobStatus2.getStatus() == com.datastax.mgmtapi.resources.models.Job.JobStatus.COMPLETED;
1099+
});
10721100
}
1073-
}
1101+
}

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

Lines changed: 31 additions & 1 deletion
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
}
@@ -182,4 +212,4 @@ private CompletableFuture<FullHttpResponse> buildAndSendRequest(HttpMethod metho
182212

183213
return result;
184214
}
185-
}
215+
}

0 commit comments

Comments
 (0)