You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/08/05 07:17:40 UTC

[GitHub] [camel-quarkus] ppalaga commented on a change in pull request #2988: Expand AWS DDB tests #2776

ppalaga commented on a change in pull request #2988:
URL: https://github.com/apache/camel-quarkus/pull/2988#discussion_r683162597



##########
File path: integration-test-groups/aws2/aws2-ddb/src/test/java/org/apache/camel/quarkus/component/aws2/ddb/it/Aws2DdbTest.java
##########
@@ -139,31 +111,183 @@ public void crud() {
                 },
                 Matchers.is(204));
 
-        Awaitility.await().atMost(120, TimeUnit.SECONDS).until(
+    }
+
+    @Test
+    public void operations() {
+
+        final String key1 = "key-1-" + UUID.randomUUID().toString().replace("-", "");
+        final String msg1 = "val-1-" + UUID.randomUUID().toString().replace("-", "");
+        final String key2 = "key-2-" + UUID.randomUUID().toString().replace("-", "");
+        final String msg2 = "val-2-" + UUID.randomUUID().toString().replace("-", "");
+        final String key3 = "key-3-" + UUID.randomUUID().toString().replace("-", "");
+        final String msg3 = "val-3-" + UUID.randomUUID().toString().replace("-", "");
+
+        RestAssured.given()
+                .contentType(ContentType.TEXT)
+                .queryParam("table", Table.operations)
+                .body(msg1)
+                .post("/aws2-ddb/item/" + key1)
+                .then()
+                .statusCode(201);
+
+        RestAssured.given()
+                .contentType(ContentType.TEXT)
+                .body(msg2)
+                .queryParam("table", Table.operations)
+                .post("/aws2-ddb/item/" + key2)
+                .then()
+                .statusCode(201);
+
+        RestAssured.given()
+                .contentType(ContentType.TEXT)
+                .body(msg3)
+                .queryParam("table", Table.operations)
+                .post("/aws2-ddb/item/" + key3)
+                .then()
+                .statusCode(201);
+
+        /* Batch items */
+        Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(120, TimeUnit.SECONDS).until(
+                () -> {
+
+                    ExtractableResponse<Response> result = RestAssured.given()
+                            .contentType(ContentType.JSON)
+                            .body(Stream.of(key1, key2).collect(Collectors.toList()))
+                            .post("/aws2-ddb/batchItems")
+                            .then()
+                            .statusCode(200)
+                            .extract();
+
+                    LOG.info("Expecting 2 items, got " + result.statusCode() + ": " + result.body().asString());
+
+                    return result.jsonPath().getMap("$");
+                },
+                /* Both inserted pairs have to be returned */
+                map -> map.size() == 2
+                        && msg1.equals(map.get(key1))
+                        && msg2.equals(map.get(key2)));
+
+        /* Query */
+        Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(120, TimeUnit.SECONDS).until(
                 () -> {
-                    ExtractableResponse<Response> result = RestAssured.get("/aws2-ddbstream/change")
+                    ExtractableResponse<Response> result = RestAssured.given()
+                            .contentType(ContentType.JSON)
+                            .body(key3)
+                            .post("/aws2-ddb/query")
                             .then()
                             .statusCode(200)
                             .extract();
 
-                    LOG.info("Expecting 3 events got " + result.statusCode() + ": " + result.body().asString());
-                    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());
+                    LOG.info("Expecting 1 item, got " + result.statusCode() + ": " + result.body().asString());
+
+                    return result.jsonPath().getMap("$");
                 },
-                /* The above actions should trigger the following three change events (initEvent is also present) */
-                list -> list.size() == 3
+                map -> map.size() == 1
+                        && msg3.equals(map.get(key3)));
+
+        /* Scan */
+        Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(120, TimeUnit.SECONDS).until(
+                () -> {
+                    ExtractableResponse<Response> result = RestAssured.get("/aws2-ddb/scan")
+                            .then()
+                            .statusCode(200)
+                            .extract();
 
-                        && key.equals(list.get(0).get("key"))
-                        && msg.equals(list.get(0).get("new"))
+                    LOG.info("Expecting 3 items, got " + result.statusCode() + ": " + result.body().asString());
 
-                        && key.equals(list.get(1).get("key"))
-                        && msg.equals(list.get(1).get("old"))
-                        && newMsg.equals(list.get(1).get("new"))
+                    return result.jsonPath().getMap("$");
+                },
+                map -> map.size() == 3
+                        && msg1.equals(map.get(key1))
+                        && msg2.equals(map.get(key2))
+                        && msg3.equals(map.get(key3)));
 
-                        && key.equals(list.get(2).get("key"))
-                        && newMsg.equals(list.get(2).get("old")));
+        /* Describe table */
+        Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(120, TimeUnit.SECONDS).until(
+                () -> {
+                    ExtractableResponse<Response> result = RestAssured.given()
+                            .contentType(ContentType.JSON)
+                            .body(Ddb2Operations.DescribeTable)
+                            .post("/aws2-ddb/operation")
+                            .then()
+                            .statusCode(200)
+                            .extract();
+
+                    LOG.info("Expecting table description, got " + result.statusCode() + ": " + result.body().asString());
+
+                    return result.jsonPath().getMap("$");
+                },
+                map -> map.size() == 8
+                        && map.containsKey(Ddb2Constants.CREATION_DATE)
+                        && map.containsKey(Ddb2Constants.READ_CAPACITY)
+                        && TableStatus.ACTIVE.name().equals(map.get(Ddb2Constants.TABLE_STATUS))
+                        && map.containsKey(Ddb2Constants.WRITE_CAPACITY)
+                        && map.containsKey(Ddb2Constants.TABLE_SIZE)
+                        && map.containsKey(Ddb2Constants.KEY_SCHEMA)
+                        && map.containsKey(Ddb2Constants.ITEM_COUNT)
+                        && Table.operations == Table.valueOf((String) map.get(Ddb2Constants.TABLE_NAME)));

Review comment:
       Does DescribeTable need to be enclosed in await()? Maybe TableStatus is not active initially?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org