Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS2 ddb-streams integration tests failures #2860 #2951

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
*/
package org.apache.camel.quarkus.component.aws2.ddb.it;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
Expand All @@ -40,9 +42,44 @@ class Aws2DdbTest {

@Test
public void crud() {

final String key = "key" + UUID.randomUUID().toString().replace("-", "");
final String msg = "val" + UUID.randomUUID().toString().replace("-", "");
final String initKeyPrefix = "initKey";
final String initMsg = "val";

/* Wait for the consumer to start. Test event has to be created periodically to ensure consumer reception */
RestAssured.given()
.contentType(ContentType.TEXT)
.body("")
.post("/aws2-ddb/item/" + initKeyPrefix + UUID.randomUUID().toString().replace("-", ""))
.then()
.statusCode(201);

/* Periodically check that init event is received and if nothing is received, invoke another one */
Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(120, TimeUnit.SECONDS).until(
() -> {
ExtractableResponse<Response> result = RestAssured.get("/aws2-ddbstream/change")
.then()
.statusCode(200)
.extract();

LOG.info("Expecting at least 1 init event, got " + result.statusCode() + ": " + result.body().asString());

List<Map> res = result.jsonPath().getList("$", Map.class);

/* If there is no received event, consumer is still not running. Repeat insert. */
if (res.isEmpty()) {
RestAssured.given()
.contentType(ContentType.TEXT)
.body(initMsg)
.post("/aws2-ddb/item/initKey" + UUID.randomUUID().toString().replace("-", ""))
.then()
.statusCode(201);
}
return res;
},
/* If at least one of the init events is recceived, consumer is working */
list -> !list.isEmpty());

/* Ensure initially empty */
RestAssured.get("/aws2-ddb/item/" + key)
Expand Down Expand Up @@ -110,9 +147,12 @@ public void crud() {
.extract();

LOG.info("Expecting 3 events got " + result.statusCode() + ": " + result.body().asString());
return result.jsonPath().getList("$", Map.class);
List<Map> retVal = result.jsonPath().getList("$", Map.class);
//remove init events
return retVal.stream().filter(m -> !String.valueOf(m.get("key")).startsWith("initKey"))
.collect(Collectors.toList());
},
/* The above actions should trigger the following three change events */
/* The above actions should trigger the following three change events (initEvent is also present) */
list -> list.size() == 3

&& key.equals(list.get(0).get("key"))
Expand All @@ -124,7 +164,6 @@ public void crud() {

&& key.equals(list.get(2).get("key"))
&& newMsg.equals(list.get(2).get("old")));

}

}