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 ro...@apache.org on 2018/12/12 09:52:45 UTC
[06/32] james-project git commit: JAMES-2617 Generalize test
JAMES-2617 Generalize test
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5dc4d64c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5dc4d64c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5dc4d64c
Branch: refs/heads/master
Commit: 5dc4d64c59010326040afec994add5c5c50d4ce4
Parents: 371e5c4
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Wed Dec 5 15:03:32 2018 +0100
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Thu Dec 6 11:24:20 2018 +0100
----------------------------------------------------------------------
.../es/DockerElasticSearch2Extension.java | 2 +-
.../apache/james/metric/es/ES2ReporterTest.java | 26 ++++
.../james/metric/es/ESReporterContract.java | 127 ++++++++++++++++++
.../apache/james/metric/es/ESReporterTest.java | 129 -------------------
4 files changed, 154 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/5dc4d64c/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/DockerElasticSearch2Extension.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/DockerElasticSearch2Extension.java b/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/DockerElasticSearch2Extension.java
index 76e6006..730fde5 100644
--- a/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/DockerElasticSearch2Extension.java
+++ b/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/DockerElasticSearch2Extension.java
@@ -35,7 +35,7 @@ public class DockerElasticSearch2Extension implements ParameterResolver, BeforeE
private DockerElasticSearch2Extension() {
this.elasticSearchContainer = new SwarmGenericContainer(Images.ELASTICSEARCH)
.withAffinityToContainer()
- .withExposedPorts(ESReporterTest.ES_HTTP_PORT)
+ .withExposedPorts(ESReporterContract.ES_HTTP_PORT)
.waitingFor(new HostPortWaitStrategy().withRateLimiter(RateLimiters.TWENTIES_PER_SECOND));
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/5dc4d64c/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ES2ReporterTest.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ES2ReporterTest.java b/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ES2ReporterTest.java
new file mode 100644
index 0000000..891ca45
--- /dev/null
+++ b/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ES2ReporterTest.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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.metric.es;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(DockerElasticSearch2Extension.class)
+class ES2ReporterTest extends ESReporterContract {
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/5dc4d64c/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterContract.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterContract.java b/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterContract.java
new file mode 100644
index 0000000..83ac4ed
--- /dev/null
+++ b/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterContract.java
@@ -0,0 +1,127 @@
+/****************************************************************
+ * 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.metric.es;
+
+import static io.restassured.RestAssured.when;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.Matchers.greaterThan;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.apache.http.HttpStatus;
+import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.TimeMetric;
+import org.apache.james.metrics.dropwizard.DropWizardMetricFactory;
+import org.apache.james.metrics.es.ESMetricReporter;
+import org.apache.james.metrics.es.ESReporterConfiguration;
+import org.apache.james.util.docker.SwarmGenericContainer;
+import org.awaitility.Duration;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.codahale.metrics.MetricRegistry;
+
+import io.restassured.RestAssured;
+
+abstract class ESReporterContract {
+ public static final String INDEX = "index_name";
+ public static final long PERIOD_IN_SECOND = 1L;
+ public static final int DELAY_IN_MS = 100;
+ public static final int PERIOD_IN_MS = 100;
+ public static final int ES_HTTP_PORT = 9200;
+
+ private ESMetricReporter esMetricReporter;
+ private MetricRegistry registry;
+ private Timer timer;
+
+ @BeforeEach
+ void setUp(SwarmGenericContainer esContainer) {
+ RestAssured.baseURI = String.format("http://%s:%d", esContainer.getHostIp(), esContainer.getMappedPort(ES_HTTP_PORT));
+ await().atMost(Duration.ONE_MINUTE)
+ .untilAsserted(() -> elasticSearchStarted());
+
+ registry = new MetricRegistry();
+ timer = new Timer();
+ esMetricReporter = new ESMetricReporter(
+ ESReporterConfiguration.builder()
+ .enabled()
+ .onHost(esContainer.getHostIp(), esContainer.getMappedPort(ES_HTTP_PORT))
+ .onIndex(INDEX)
+ .periodInSecond(PERIOD_IN_SECOND)
+ .build(),
+ registry);
+
+ esMetricReporter.start();
+ }
+
+ @AfterEach
+ void tearDown() {
+ timer.cancel();
+ esMetricReporter.stop();
+ }
+
+ @Test
+ void esMetricReporterShouldProduceDocumentsOnAnElasticsearchContainer(SwarmGenericContainer esContainer) {
+ Metric metric = new DropWizardMetricFactory(registry).generate("probe");
+ TimerTask timerTask = new TimerTask() {
+ @Override
+ public void run() {
+ metric.increment();
+ }
+ };
+ timer.schedule(timerTask, DELAY_IN_MS, PERIOD_IN_MS);
+
+ await().atMost(Duration.TEN_MINUTES)
+ .untilAsserted(() -> done());
+ }
+
+ @Test
+ void esMetricReporterShouldProduceDocumentsOnAnElasticsearchContainerWhenRecordingTimeMetric(SwarmGenericContainer esContainer) {
+ TimeMetric metric = new DropWizardMetricFactory(registry).timer("itstime");
+ TimerTask timerTask = new TimerTask() {
+ @Override
+ public void run() {
+ metric.stopAndPublish();
+ }
+ };
+ timer.schedule(timerTask, DELAY_IN_MS, PERIOD_IN_MS);
+
+ await().atMost(Duration.TEN_MINUTES)
+ .untilAsserted(() -> done());
+ }
+
+ private void elasticSearchStarted() {
+ when()
+ .get("/")
+ .then()
+ .assertThat()
+ .statusCode(HttpStatus.SC_OK);
+ }
+
+ private void done() {
+ when()
+ .get("/_search")
+ .then()
+ .assertThat()
+ .body("hits.total", greaterThan(0));
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/5dc4d64c/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterTest.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterTest.java b/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterTest.java
deleted file mode 100644
index 9ae03bc..0000000
--- a/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/****************************************************************
- * 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.metric.es;
-
-import static io.restassured.RestAssured.when;
-import static org.awaitility.Awaitility.await;
-import static org.hamcrest.Matchers.greaterThan;
-
-import java.util.Timer;
-import java.util.TimerTask;
-
-import org.apache.http.HttpStatus;
-import org.apache.james.metrics.api.Metric;
-import org.apache.james.metrics.api.TimeMetric;
-import org.apache.james.metrics.dropwizard.DropWizardMetricFactory;
-import org.apache.james.metrics.es.ESMetricReporter;
-import org.apache.james.metrics.es.ESReporterConfiguration;
-import org.apache.james.util.docker.SwarmGenericContainer;
-import org.awaitility.Duration;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-import com.codahale.metrics.MetricRegistry;
-
-import io.restassured.RestAssured;
-
-@ExtendWith(DockerElasticSearch2Extension.class)
-class ESReporterTest {
- public static final String INDEX = "index_name";
- public static final long PERIOD_IN_SECOND = 1L;
- public static final int DELAY_IN_MS = 100;
- public static final int PERIOD_IN_MS = 100;
- public static final int ES_HTTP_PORT = 9200;
-
- private ESMetricReporter esMetricReporter;
- private MetricRegistry registry;
- private Timer timer;
-
- @BeforeEach
- void setUp(SwarmGenericContainer esContainer) {
- RestAssured.baseURI = String.format("http://%s:%d", esContainer.getHostIp(), esContainer.getMappedPort(ES_HTTP_PORT));
- await().atMost(Duration.ONE_MINUTE)
- .untilAsserted(() -> elasticSearchStarted());
-
- registry = new MetricRegistry();
- timer = new Timer();
- esMetricReporter = new ESMetricReporter(
- ESReporterConfiguration.builder()
- .enabled()
- .onHost(esContainer.getHostIp(), esContainer.getMappedPort(ES_HTTP_PORT))
- .onIndex(INDEX)
- .periodInSecond(PERIOD_IN_SECOND)
- .build(),
- registry);
-
- esMetricReporter.start();
- }
-
- @AfterEach
- void tearDown() {
- timer.cancel();
- esMetricReporter.stop();
- }
-
- @Test
- void esMetricReporterShouldProduceDocumentsOnAnElasticsearchContainer(SwarmGenericContainer esContainer) {
- Metric metric = new DropWizardMetricFactory(registry).generate("probe");
- TimerTask timerTask = new TimerTask() {
- @Override
- public void run() {
- metric.increment();
- }
- };
- timer.schedule(timerTask, DELAY_IN_MS, PERIOD_IN_MS);
-
- await().atMost(Duration.TEN_MINUTES)
- .untilAsserted(() -> done());
- }
-
- @Test
- void esMetricReporterShouldProduceDocumentsOnAnElasticsearchContainerWhenRecordingTimeMetric(SwarmGenericContainer esContainer) {
- TimeMetric metric = new DropWizardMetricFactory(registry).timer("itstime");
- TimerTask timerTask = new TimerTask() {
- @Override
- public void run() {
- metric.stopAndPublish();
- }
- };
- timer.schedule(timerTask, DELAY_IN_MS, PERIOD_IN_MS);
-
- await().atMost(Duration.TEN_MINUTES)
- .untilAsserted(() -> done());
- }
-
- private void elasticSearchStarted() {
- when()
- .get("/")
- .then()
- .assertThat()
- .statusCode(HttpStatus.SC_OK);
- }
-
- private void done() {
- when()
- .get("/_search")
- .then()
- .assertThat()
- .body("hits.total", greaterThan(0));
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org