You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/01/07 07:34:08 UTC

[james-project] 14/16: JAMES-3014 FastProjection HealthCheck Integration Test

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 16ade2dc39f2dc4fe63a75e5983ec999925ac32b
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Mon Dec 16 20:28:59 2019 +0700

    JAMES-3014 FastProjection HealthCheck Integration Test
    
    Memory + Contract
---
 ...stViewProjectionHealthCheckIntegrationTest.java |  38 ++++
 ...stViewProjectionHealthCheckIntegrationTest.java | 226 +++++++++++++++++++++
 2 files changed, 264 insertions(+)

diff --git a/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryFastViewProjectionHealthCheckIntegrationTest.java b/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryFastViewProjectionHealthCheckIntegrationTest.java
new file mode 100644
index 0000000..19b5688
--- /dev/null
+++ b/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryFastViewProjectionHealthCheckIntegrationTest.java
@@ -0,0 +1,38 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.integration.memory;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.MemoryJmapTestRule;
+import org.apache.james.webadmin.WebAdminConfiguration;
+import org.apache.james.webadmin.integration.FastViewProjectionHealthCheckIntegrationTest;
+import org.junit.Rule;
+
+public class MemoryFastViewProjectionHealthCheckIntegrationTest extends FastViewProjectionHealthCheckIntegrationTest {
+
+    @Rule
+    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+
+    @Override
+    public GuiceJamesServer createJamesServer() throws Exception {
+        return memoryJmap.jmapServer(
+            binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
+    }
+}
\ No newline at end of file
diff --git a/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/FastViewProjectionHealthCheckIntegrationTest.java b/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/FastViewProjectionHealthCheckIntegrationTest.java
new file mode 100644
index 0000000..da228bf
--- /dev/null
+++ b/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/FastViewProjectionHealthCheckIntegrationTest.java
@@ -0,0 +1,226 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.integration;
+
+import static io.restassured.RestAssured.with;
+import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
+import static org.apache.james.jmap.JMAPTestingConstants.ALICE;
+import static org.apache.james.jmap.JMAPTestingConstants.ALICE_PASSWORD;
+import static org.apache.james.jmap.JMAPTestingConstants.ARGUMENTS;
+import static org.apache.james.jmap.JMAPTestingConstants.BOB;
+import static org.apache.james.jmap.JMAPTestingConstants.BOB_PASSWORD;
+import static org.apache.james.jmap.JMAPTestingConstants.CEDRIC;
+import static org.apache.james.jmap.JMAPTestingConstants.CEDRIC_PASSWORD;
+import static org.apache.james.jmap.JMAPTestingConstants.DOMAIN;
+import static org.apache.james.jmap.JMAPTestingConstants.calmlyAwait;
+import static org.apache.james.jmap.JMAPTestingConstants.jmapRequestSpecBuilder;
+import static org.apache.james.jmap.JmapCommonRequests.bodyOfMessage;
+import static org.apache.james.jmap.JmapCommonRequests.getLastMessageId;
+import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
+import static org.apache.james.jmap.JmapCommonRequests.listMessageIdsForAccount;
+import static org.apache.james.jmap.LocalHostURIBuilder.baseUri;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+import java.util.stream.IntStream;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.core.healthcheck.ResultStatus;
+import org.apache.james.jmap.AccessToken;
+import org.apache.james.jmap.draft.JmapGuiceProbe;
+import org.apache.james.probe.DataProbe;
+import org.apache.james.util.Port;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.WebAdminGuiceProbe;
+import org.apache.james.webadmin.WebAdminUtils;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import io.restassured.RestAssured;
+import io.restassured.specification.RequestSpecification;
+
+public abstract class FastViewProjectionHealthCheckIntegrationTest {
+
+    private static final String MESSAGE_FAST_VIEW_PROJECTION = "MessageFastViewProjection";
+
+    private GuiceJamesServer guiceJamesServer;
+    private RequestSpecification webAdminApi;
+    private AccessToken bobAccessToken;
+    private AccessToken aliceAccessToken;
+
+    @Before
+    public void setUp() throws Exception {
+        guiceJamesServer = createJamesServer();
+        guiceJamesServer.start();
+
+        DataProbe dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class);
+        dataProbe.addDomain(DOMAIN);
+        dataProbe.addUser(BOB.asString(), BOB_PASSWORD);
+        dataProbe.addUser(ALICE.asString(), ALICE_PASSWORD);
+        dataProbe.addUser(CEDRIC.asString(), CEDRIC_PASSWORD);
+
+        Port jmapPort = guiceJamesServer.getProbe(JmapGuiceProbe.class).getJmapPort();
+        RestAssured.requestSpecification = jmapRequestSpecBuilder
+            .setPort(jmapPort.getValue())
+            .build();
+
+        bobAccessToken = authenticateJamesUser(baseUri(jmapPort), BOB, BOB_PASSWORD);
+        aliceAccessToken = authenticateJamesUser(baseUri(jmapPort), ALICE, ALICE_PASSWORD);
+
+        webAdminApi = WebAdminUtils.spec(guiceJamesServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort());
+    }
+
+    @After
+    public void tearDown() {
+        guiceJamesServer.stop();
+    }
+
+    protected abstract GuiceJamesServer createJamesServer() throws Exception;
+
+    @Test
+    public void checkShouldReturnHealthyWhenNoMessage() {
+        webAdminApi.when()
+            .get("/healthcheck/checks/" + MESSAGE_FAST_VIEW_PROJECTION)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("componentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("escapedComponentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("status", equalTo(ResultStatus.HEALTHY.getValue()));
+    }
+
+    @Test
+    public void checkShouldReturnHealthyAfterSendingMessagesWithoutReading() {
+        IntStream.rangeClosed(1, 5)
+            .forEach(counter -> bobSendAMessageToAlice());
+        calmlyAwait.until(() -> listMessageIdsForAccount(aliceAccessToken).size() == 5);
+
+        webAdminApi.when()
+            .get("/healthcheck/checks/" + MESSAGE_FAST_VIEW_PROJECTION)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("componentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("escapedComponentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("status", equalTo(ResultStatus.HEALTHY.getValue()));
+    }
+
+    @Test
+    public void checkShouldReturnHealthyAfterSendingAMessageWithReads() {
+        bobSendAMessageToAlice();
+        calmlyAwait.untilAsserted(() -> assertThat(listMessageIdsForAccount(aliceAccessToken))
+            .hasSize(1));
+
+        IntStream.rangeClosed(1, 5)
+            .forEach(counter -> aliceReadLastMessage());
+
+        webAdminApi.when()
+            .get("/healthcheck/checks/" + MESSAGE_FAST_VIEW_PROJECTION)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("componentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("escapedComponentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("status", equalTo(ResultStatus.HEALTHY.getValue()));
+    }
+
+    @Test
+    public void checkShouldReturnDegradedAfterFewReadsOnAMissedProjection() {
+        bobSendAMessageToAlice();
+        calmlyAwait.untilAsserted(() -> assertThat(listMessageIdsForAccount(aliceAccessToken))
+            .hasSize(1));
+        guiceJamesServer.getProbe(JmapGuiceProbe.class)
+            .clearMessageFastViewProjection();
+
+        IntStream.rangeClosed(1, 3) // Will miss at the first time as we cleared the preview
+            .forEach(counter -> aliceReadLastMessage());
+
+        webAdminApi.when()
+            .get("/healthcheck/checks/" + MESSAGE_FAST_VIEW_PROJECTION)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("componentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("escapedComponentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("status", equalTo(ResultStatus.DEGRADED.getValue()))
+            .body("cause", equalTo("retrieveMissCount percentage 25.0% (1/4) is higher than the threshold 10.0%"));
+    }
+
+    @Test
+    public void checkShouldTurnFromDegradedToHealthyAfterMoreReadsOnAMissedProjection() {
+        bobSendAMessageToAlice();
+        calmlyAwait.untilAsserted(() -> assertThat(listMessageIdsForAccount(aliceAccessToken))
+            .hasSize(1));
+        makeHealthCheckDegraded();
+
+        IntStream.rangeClosed(1, 10)
+            .forEach(counter -> aliceReadLastMessage());
+
+        webAdminApi.when()
+            .get("/healthcheck/checks/" + MESSAGE_FAST_VIEW_PROJECTION)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("componentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("escapedComponentName", equalTo(MESSAGE_FAST_VIEW_PROJECTION))
+            .body("status", equalTo(ResultStatus.HEALTHY.getValue()));
+    }
+
+    private void makeHealthCheckDegraded() {
+        guiceJamesServer.getProbe(JmapGuiceProbe.class)
+            .clearMessageFastViewProjection();
+        aliceReadLastMessage();
+
+        webAdminApi.when()
+            .get("/healthcheck/checks/" + MESSAGE_FAST_VIEW_PROJECTION)
+        .then()
+            .body("status", equalTo(ResultStatus.DEGRADED.getValue()));
+    }
+
+    private void bobSendAMessageToAlice() {
+        String messageCreationId = "creationId";
+        String outboxId = getOutboxId(bobAccessToken);
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\"," +
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Bob\", \"email\": \"" + BOB.asString() + "\"}," +
+            "        \"to\": [{ \"name\": \"Alice\", \"email\": \"" + ALICE.asString() + "\"}]," +
+            "        \"subject\": \"bob to alice\"," +
+            "        \"textBody\": \"body\"," +
+            "        \"htmlBody\": \"Test <b>body</b>, HTML version\"," +
+            "        \"mailboxIds\": [\"" + outboxId + "\"] " +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+        with()
+            .header("Authorization", bobAccessToken.asString())
+            .body(requestBody)
+            .post("/jmap")
+        .then()
+            .extract()
+            .body()
+            .path(ARGUMENTS + ".created." + messageCreationId + ".id");
+    }
+
+    private void aliceReadLastMessage() {
+        bodyOfMessage(aliceAccessToken, getLastMessageId(aliceAccessToken));
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org