Skip to content

Commit d2aee7c

Browse files
authored
Fix failing test due to race condition (#222)
1 parent b6341fc commit d2aee7c

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

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

+23-20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.IOException;
99
import java.net.URI;
1010
import java.net.URISyntaxException;
11+
import java.time.Duration;
1112
import java.util.Arrays;
1213
import java.util.Collections;
1314
import java.util.concurrent.TimeUnit;
@@ -47,6 +48,7 @@
4748

4849
import static io.netty.util.CharsetUtil.UTF_8;
4950
import static org.assertj.core.api.Assertions.assertThat;
51+
import static org.awaitility.Awaitility.await;
5052
import static org.junit.Assert.*;
5153
import static org.junit.Assume.assumeTrue;
5254

@@ -781,28 +783,29 @@ public void testMoveNode() throws IOException, URISyntaxException
781783

782784
NettyHttpClient client = new NettyHttpClient(BASE_URL);
783785

784-
URI uri = new URIBuilder(BASE_PATH + "/ops/node/move")
785-
.addParameter("newToken", "1234")
786-
.build();
787-
Pair<Integer, String> response = client.post(uri.toURL(), null)
788-
.thenApply(this::responseAsCodeAndBody).join();
789-
assertThat(response.getLeft()).isEqualTo(HttpStatus.SC_ACCEPTED);
790-
String jobId = response.getRight();
786+
URI nodeMoveUri = new URIBuilder(BASE_PATH + "/ops/node/move")
787+
.addParameter("newToken", "1234")
788+
.build();
789+
Pair<Integer, String> nodeMoveResponse = client.post(nodeMoveUri.toURL(), null)
790+
.thenApply(this::responseAsCodeAndBody).join();
791+
assertThat(nodeMoveResponse.getLeft()).isEqualTo(HttpStatus.SC_ACCEPTED);
792+
String jobId = nodeMoveResponse.getRight();
791793
assertThat(jobId).isNotEmpty();
792794

793-
uri = new URIBuilder(BASE_PATH + "/ops/executor/job")
794-
.addParameter("job_id", jobId)
795-
.build();
796-
response = client.get(uri.toURL()).thenApply(this::responseAsCodeAndBody).join();
797-
assertThat(response.getLeft()).isEqualTo(HttpStatus.SC_OK);
798-
799-
Map<String, String> jobDetails = new JsonMapper().readValue(response.getRight(), new TypeReference<Map<String, String>>(){});
800-
assertThat(jobDetails)
801-
.hasEntrySatisfying("id", value -> assertThat(value).isEqualTo(jobId))
802-
.hasEntrySatisfying("type", value -> assertThat(value).isEqualTo("move"))
803-
.hasEntrySatisfying("status", value -> assertThat(value).isEqualTo("ERROR"))
804-
.hasEntrySatisfying("error", value -> assertThat(value).contains("This node has more than one token and cannot be moved"))
805-
;
795+
URI getJobDetailsUri = new URIBuilder(BASE_PATH + "/ops/executor/job")
796+
.addParameter("job_id", jobId)
797+
.build();
798+
799+
await().atMost(Duration.ofMinutes(1)).untilAsserted(() -> {
800+
Pair<Integer, String> getJobDetailsResponse = client.get(getJobDetailsUri.toURL()).thenApply(this::responseAsCodeAndBody).join();
801+
assertThat(getJobDetailsResponse.getLeft()).isEqualTo(HttpStatus.SC_OK);
802+
Map<String, String> jobDetails = new JsonMapper().readValue(getJobDetailsResponse.getRight(), new TypeReference<Map<String, String>>(){});
803+
assertThat(jobDetails)
804+
.hasEntrySatisfying("id", value -> assertThat(value).isEqualTo(jobId))
805+
.hasEntrySatisfying("type", value -> assertThat(value).isEqualTo("move"))
806+
.hasEntrySatisfying("status", value -> assertThat(value).isEqualTo("ERROR"))
807+
.hasEntrySatisfying("error", value -> assertThat(value).contains("This node has more than one token and cannot be moved"));
808+
});
806809
}
807810

808811
private void createKeyspace(NettyHttpClient client, String localDc, String keyspaceName) throws IOException, URISyntaxException

0 commit comments

Comments
 (0)