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 2019/12/19 05:40:36 UTC
[james-project] 02/08: JAMES-3007 MetricFactory test contract
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 f15ddd75a7d2d033bf1bd59ccc38af40bab52c9f
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Thu Dec 12 14:32:39 2019 +0700
JAMES-3007 MetricFactory test contract
---
.../james/metrics/api/MetricFactoryContract.java | 58 ++++++++++++++++++++++
.../dropwizard/DropWizardMetricFactoryTest.java | 41 +++++++++++++++
.../metrics/logger/DefaultMetricFactoryTest.java | 45 +++++++++++++++++
.../metrics/tests/RecordingMetricFactoryTest.java | 15 +++++-
4 files changed, 158 insertions(+), 1 deletion(-)
diff --git a/metrics/metrics-api/src/test/java/org/apache/james/metrics/api/MetricFactoryContract.java b/metrics/metrics-api/src/test/java/org/apache/james/metrics/api/MetricFactoryContract.java
new file mode 100644
index 0000000..5db31fa
--- /dev/null
+++ b/metrics/metrics-api/src/test/java/org/apache/james/metrics/api/MetricFactoryContract.java
@@ -0,0 +1,58 @@
+/****************************************************************
+ * 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.metrics.api;
+
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.Test;
+
+public interface MetricFactoryContract {
+
+ String NAME_1 = "name 1";
+ String NAME_2 = "name 2";
+
+ MetricFactory testee();
+
+ @Test
+ default void generateWithSameNameShouldReturnMetricsWithCorrelatedCounter() {
+ Metric metric1 = testee().generate(NAME_1);
+ Metric anotherMetric1 = testee().generate(NAME_1);
+
+ metric1.add(47);
+
+ SoftAssertions.assertSoftly(softly -> {
+ softly.assertThat(metric1.getCount()).isEqualTo(47);
+ softly.assertThat(anotherMetric1.getCount()).isEqualTo(47);
+ });
+ }
+
+ @Test
+ default void generateWithDifferentNamesShouldReturnIndependentMetrics() {
+ Metric metric1 = testee().generate(NAME_1);
+ Metric metric2 = testee().generate(NAME_2);
+
+ metric1.increment();
+ metric2.decrement();
+
+ SoftAssertions.assertSoftly(softly -> {
+ softly.assertThat(metric1.getCount()).isEqualTo(1);
+ softly.assertThat(metric2.getCount()).isEqualTo(-1);
+ });
+ }
+}
\ No newline at end of file
diff --git a/metrics/metrics-dropwizard/src/test/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactoryTest.java b/metrics/metrics-dropwizard/src/test/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactoryTest.java
new file mode 100644
index 0000000..75aada0
--- /dev/null
+++ b/metrics/metrics-dropwizard/src/test/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactoryTest.java
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.metrics.dropwizard;
+
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.api.MetricFactoryContract;
+import org.junit.jupiter.api.BeforeEach;
+
+import com.codahale.metrics.MetricRegistry;
+
+class DropWizardMetricFactoryTest implements MetricFactoryContract {
+
+ private DropWizardMetricFactory testee;
+
+ @BeforeEach
+ void setUp() {
+ testee = new DropWizardMetricFactory(new MetricRegistry());
+ }
+
+ @Override
+ public MetricFactory testee() {
+ return testee;
+ }
+}
\ No newline at end of file
diff --git a/metrics/metrics-logger/src/test/java/org/apache/james/metrics/logger/DefaultMetricFactoryTest.java b/metrics/metrics-logger/src/test/java/org/apache/james/metrics/logger/DefaultMetricFactoryTest.java
new file mode 100644
index 0000000..25359b6
--- /dev/null
+++ b/metrics/metrics-logger/src/test/java/org/apache/james/metrics/logger/DefaultMetricFactoryTest.java
@@ -0,0 +1,45 @@
+/****************************************************************
+ * 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.metrics.logger;
+
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.api.MetricFactoryContract;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+
+class DefaultMetricFactoryTest implements MetricFactoryContract {
+
+ private DefaultMetricFactory testee;
+
+ @Disabled("JAMES-3007 Current DefaultMetricFactory doesn't support this")
+ @Override
+ public void generateWithSameNameShouldReturnMetricsWithCorrelatedCounter() {
+ }
+
+ @BeforeEach
+ void setUp() {
+ testee = new DefaultMetricFactory();
+ }
+
+ @Override
+ public MetricFactory testee() {
+ return testee;
+ }
+}
\ No newline at end of file
diff --git a/metrics/metrics-tests/src/test/java/org/apache/james/metrics/tests/RecordingMetricFactoryTest.java b/metrics/metrics-tests/src/test/java/org/apache/james/metrics/tests/RecordingMetricFactoryTest.java
index 9365774..066d33b 100644
--- a/metrics/metrics-tests/src/test/java/org/apache/james/metrics/tests/RecordingMetricFactoryTest.java
+++ b/metrics/metrics-tests/src/test/java/org/apache/james/metrics/tests/RecordingMetricFactoryTest.java
@@ -25,12 +25,15 @@ import java.time.Duration;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.james.metrics.api.Metric;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.api.MetricFactoryContract;
import org.apache.james.metrics.api.TimeMetric;
import org.apache.james.util.concurrency.ConcurrentTestRunner;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-class RecordingMetricFactoryTest {
+class RecordingMetricFactoryTest implements MetricFactoryContract {
private static final String TIME_METRIC_NAME = "timerMetric";
private static final String METRIC_NAME = "metric";
@@ -44,6 +47,16 @@ class RecordingMetricFactoryTest {
testee = new RecordingMetricFactory();
}
+ @Override
+ public MetricFactory testee() {
+ return testee;
+ }
+
+ @Disabled("Current RecordingMetricFactory doesn't support this")
+ @Override
+ public void generateWithSameNameShouldReturnMetricsWithCorrelatedCounter() {
+ }
+
@Test
void executionTimesForATimeMetricShouldBeStoreMultipleTime() throws InterruptedException {
TimeMetric timeMetric1 = testee.timer(TIME_METRIC_NAME);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org