james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [07/13] james-project git commit: JAMES-2545 Add retry connection parameters in RabbitMQ configuration
Date Fri, 14 Sep 2018 03:19:31 GMT
JAMES-2545 Add retry connection parameters in RabbitMQ configuration


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f2da55f0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f2da55f0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f2da55f0

Branch: refs/heads/master
Commit: f2da55f0b56020b2fbe7dee5cc3f6261ae20d331
Parents: f02def1
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Wed Sep 12 15:05:14 2018 +0200
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Sep 14 10:17:43 2018 +0700

----------------------------------------------------------------------
 .../backend/rabbitmq/RabbitMQConfiguration.java | 43 +++++++++++++++--
 .../rabbitmq/RabbitMQConfigurationTest.java     | 51 ++++++++++++++++++++
 2 files changed, 90 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f2da55f0/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
index 4093431..650d6fc 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
@@ -20,6 +20,7 @@ package org.apache.james.backend.rabbitmq;
 
 import java.net.URI;
 import java.util.Objects;
+import java.util.Optional;
 
 import org.apache.commons.configuration.PropertiesConfiguration;
 
@@ -38,18 +39,38 @@ public class RabbitMQConfiguration {
     }
 
     public static class Builder {
+        public static final int DEFAULT_MAX_RETRIES = 7;
+        public static final int DEFAULT_MIN_DELAY = 3000;
+
         private final URI amqpUri;
         private final URI managementUri;
+        private Optional<Integer> maxRetries;
+        private Optional<Integer> minDelay;
 
         private Builder(URI amqpUri, URI managementUri) {
             this.amqpUri = amqpUri;
             this.managementUri = managementUri;
+            this.maxRetries = Optional.empty();
+            this.minDelay = Optional.empty();
+        }
+
+        public Builder maxRetries(int maxRetries) {
+            this.maxRetries = Optional.of(maxRetries);
+            return this;
+        }
+
+        public Builder minDelay(int minDelay) {
+            this.minDelay = Optional.of(minDelay);
+            return this;
         }
 
         public RabbitMQConfiguration build() {
             Preconditions.checkNotNull(amqpUri, "'amqpUri' should not be null");
             Preconditions.checkNotNull(managementUri, "'managementUri' should not be null");
-            return new RabbitMQConfiguration(amqpUri, managementUri);
+            return new RabbitMQConfiguration(amqpUri, 
+                    managementUri, 
+                    maxRetries.orElse(DEFAULT_MAX_RETRIES),
+                    minDelay.orElse(DEFAULT_MIN_DELAY));
         }
     }
 
@@ -85,10 +106,14 @@ public class RabbitMQConfiguration {
 
     private final URI uri;
     private final URI managementUri;
+    private final int maxRetries;
+    private final int minDelay;
 
-    private RabbitMQConfiguration(URI uri, URI managementUri) {
+    private RabbitMQConfiguration(URI uri, URI managementUri, int maxRetries, int minDelay)
{
         this.uri = uri;
         this.managementUri = managementUri;
+        this.maxRetries = maxRetries;
+        this.minDelay = minDelay;
     }
 
     public URI getUri() {
@@ -99,19 +124,29 @@ public class RabbitMQConfiguration {
         return managementUri;
     }
 
+    public int getMaxRetries() {
+        return maxRetries;
+    }
+
+    public int getMinDelay() {
+        return minDelay;
+    }
+
     @Override
     public final boolean equals(Object o) {
         if (o instanceof RabbitMQConfiguration) {
             RabbitMQConfiguration that = (RabbitMQConfiguration) o;
 
             return Objects.equals(this.uri, that.uri)
-                && Objects.equals(this.managementUri, that.managementUri);
+                && Objects.equals(this.managementUri, that.managementUri)
+                && Objects.equals(this.maxRetries, that.maxRetries)
+                && Objects.equals(this.minDelay, that.minDelay);
         }
         return false;
     }
 
     @Override
     public final int hashCode() {
-        return Objects.hash(uri, managementUri);
+        return Objects.hash(uri, managementUri, maxRetries, minDelay);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f2da55f0/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
index 3066e48..7a1a747 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
@@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.net.URI;
+import java.net.URISyntaxException;
 
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.junit.jupiter.api.Test;
@@ -131,4 +132,54 @@ class RabbitMQConfigurationTest {
                 .managementUri(URI.create(managementUri))
                 .build());
     }
+
+    @Test
+    void maxRetriesShouldEqualsDefaultValueWhenNotGiven() throws URISyntaxException {
+        RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+            .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
+            .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+            .build();
+
+        assertThat(rabbitMQConfiguration.getMaxRetries())
+            .isEqualTo(RabbitMQConfiguration.Builder.DEFAULT_MAX_RETRIES);
+    }
+
+    @Test
+    void maxRetriesShouldEqualsCustomValueWhenGiven() throws URISyntaxException {
+        int maxRetries = 1;
+
+        RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+            .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
+            .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+            .maxRetries(maxRetries)
+            .build();
+
+        assertThat(rabbitMQConfiguration.getMaxRetries())
+            .isEqualTo(maxRetries);
+    }
+
+    @Test
+    void minDelayShouldEqualsDefaultValueWhenNotGiven() throws URISyntaxException {
+        RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+            .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
+            .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+            .build();
+
+        assertThat(rabbitMQConfiguration.getMinDelay())
+            .isEqualTo(RabbitMQConfiguration.Builder.DEFAULT_MIN_DELAY);
+    }
+
+    @Test
+    void minDelayShouldEqualsCustomValueWhenGiven() throws URISyntaxException {
+        int minDelay = 1;
+
+        RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+            .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
+            .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+            .minDelay(minDelay)
+            .build();
+
+        assertThat(rabbitMQConfiguration.getMinDelay())
+            .isEqualTo(minDelay);
+    }
 }


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


Mime
View raw message