summaryrefslogtreecommitdiffstats
path: root/rest-services/dmaap-client
diff options
context:
space:
mode:
authorPawel <pawel.kasperkiewicz@nokia.com>2021-02-03 16:04:14 +0100
committerPawel <pawel.kasperkiewicz@nokia.com>2021-02-05 11:34:12 +0100
commit159f1c86e508bf67ee08a7d42105afa2c2e1bf3a (patch)
treee473ece2626be1ccc605a4db9ca0b156611cc639 /rest-services/dmaap-client
parent29f596f81542b03449c4f780a4c3430718f87b96 (diff)
Add possibility to modify the configuration for persistent connection
Issue-ID: DCAEGEN2-1483 Signed-off-by: Pawel <pawel.kasperkiewicz@nokia.com> Change-Id: Ia5c0699359fe2317bea6177fe6dfce5c68579ba9
Diffstat (limited to 'rest-services/dmaap-client')
-rw-r--r--rest-services/dmaap-client/pom.xml2
-rw-r--r--rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/DmaapClientFactory.java13
-rw-r--r--rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapClientConfiguration.java4
-rw-r--r--rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapConnectionPoolConfig.java39
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java94
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterSubscriberIT.java40
6 files changed, 189 insertions, 3 deletions
diff --git a/rest-services/dmaap-client/pom.xml b/rest-services/dmaap-client/pom.xml
index b8620311..54b9a37e 100644
--- a/rest-services/dmaap-client/pom.xml
+++ b/rest-services/dmaap-client/pom.xml
@@ -7,7 +7,7 @@
<parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>dcaegen2-services-sdk-rest-services</artifactId>
- <version>1.6.0-SNAPSHOT</version>
+ <version>1.7.0-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/DmaapClientFactory.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/DmaapClientFactory.java
index 95850078..ee4f6d38 100644
--- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/DmaapClientFactory.java
+++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/DmaapClientFactory.java
@@ -23,6 +23,8 @@ import io.vavr.control.Option;
import org.jetbrains.annotations.NotNull;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClientFactory;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.config.ConnectionPoolConfig;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.config.ImmutableConnectionPoolConfig;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.config.ImmutableRetryConfig;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.config.ImmutableRxHttpClientConfig;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.config.RetryConfig;
@@ -68,6 +70,7 @@ public final class DmaapClientFactory {
private static @NotNull RxHttpClient createHttpClient(DmaapClientConfiguration config) {
RxHttpClientConfig clientConfig = ImmutableRxHttpClientConfig.builder()
+ .connectionPool(createConnectionPool(config))
.retryConfig(createRetry(config))
.build();
return config.securityKeys() == null
@@ -85,5 +88,15 @@ public final class DmaapClientFactory {
.build())
.getOrNull();
}
+
+ private static ConnectionPoolConfig createConnectionPool(DmaapClientConfiguration config){
+ return Option.of(config.connectionPoolConfig())
+ .map(cp -> ImmutableConnectionPoolConfig.builder()
+ .connectionPool(cp.connectionPool())
+ .maxIdleTime(Duration.ofSeconds(cp.maxIdleTime()))
+ .maxLifeTime(Duration.ofSeconds(cp.maxLifeTime()))
+ .build())
+ .getOrNull();
+ }
}
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapClientConfiguration.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapClientConfiguration.java
index 3e283511..6dcdf988 100644
--- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapClientConfiguration.java
+++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapClientConfiguration.java
@@ -36,4 +36,8 @@ public interface DmaapClientConfiguration {
default @Nullable DmaapRetryConfig retryConfig(){
return null;
}
+ @Value.Default
+ default @Nullable DmaapConnectionPoolConfig connectionPoolConfig (){
+ return null;
+ }
}
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapConnectionPoolConfig.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapConnectionPoolConfig.java
new file mode 100644
index 00000000..38166e4e
--- /dev/null
+++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapConnectionPoolConfig.java
@@ -0,0 +1,39 @@
+/*
+ * ============LICENSE_START====================================
+ * DCAEGEN2-SERVICES-SDK
+ * =========================================================
+ * Copyright (C) 2021 Nokia. All rights reserved.
+ * =========================================================
+ * Licensed 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.
+ * ============LICENSE_END=====================================
+ */
+package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config;
+
+import org.immutables.value.Value;
+
+@Value.Immutable
+public interface DmaapConnectionPoolConfig {
+
+ @Value.Default
+ default int connectionPool(){
+ return 16;
+ }
+ @Value.Default
+ default int maxLifeTime(){
+ return Integer.MAX_VALUE;
+ }
+ @Value.Default
+ default int maxIdleTime(){
+ return Integer.MAX_VALUE;
+ }
+} \ No newline at end of file
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java
index 825ea395..ffd301c3 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java
@@ -34,6 +34,7 @@ import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRo
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.ImmutableDmaapConnectionPoolConfig;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.ImmutableDmaapRetryConfig;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.ImmutableMessageRouterPublisherConfig;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.MessageRouterPublisherConfig;
@@ -337,6 +338,7 @@ class MessageRouterPublisherIT {
@Test
void publisher_shouldRetryWhenRetryableHttpCodeAndSuccessfullyPublish() {
+ //given
final String topic = "TOPIC11";
final String topicUrl = String.format("%s/%s", PROXY_MOCK_EVENTS_PATH, topic);
@@ -369,6 +371,7 @@ class MessageRouterPublisherIT {
@Test
void publisher_shouldRetryWhenClientTimeoutAndSuccessfullyPublish() {
+ //given
final String topic = "TOPIC12";
final String topicUrl = String.format("%s/%s", PROXY_MOCK_EVENTS_PATH, topic);
@@ -400,6 +403,7 @@ class MessageRouterPublisherIT {
@Test
void publisher_shouldRetryManyTimesAndSuccessfullyPublish() {
+ //given
final String topic = "TOPIC13";
final String topicUrl = String.format("%s/%s", PROXY_MOCK_EVENTS_PATH, topic);
@@ -440,6 +444,7 @@ class MessageRouterPublisherIT {
@Test
void publisher_shouldHandleLastRetryError500() {
+ //given
final String topic = "TOPIC14";
final String topicUrl = String.format("%s/%s", PROXY_MOCK_EVENTS_PATH, topic);
@@ -472,6 +477,70 @@ class MessageRouterPublisherIT {
MOCK_SERVER_CLIENT.verify(request().withPath(path), VerificationTimes.exactly(2));
}
+ @Test
+ void publisher_shouldSuccessfullyPublishWhenConnectionPoolConfigurationIsSet() {
+ //given
+ final String topic = "TOPIC15";
+ final String topicUrl = String.format("%s/%s", PROXY_MOCK_EVENTS_PATH, topic);
+
+ final List<String> singleJsonMessage = List.of("{\"message\":\"message1\"}");
+ final List<JsonElement> expectedItems = getAsJsonElements(singleJsonMessage);
+ final Flux<JsonElement> plainBatch = plainBatch(singleJsonMessage);
+
+ final MessageRouterPublishRequest publishRequest = createPublishRequest(topicUrl, Duration.ofSeconds(1));
+ final MessageRouterPublishResponse expectedResponse = successPublishResponse(expectedItems);
+
+ final String path = String.format("/events/%s", topic);
+ MOCK_SERVER_CLIENT
+ .when(request().withPath(path), Times.once())
+ .respond(response().withStatusCode(200));
+
+ final MessageRouterPublisher publisher = DmaapClientFactory.createMessageRouterPublisher(connectionPoolConfiguration());
+
+ //when
+ final Flux<MessageRouterPublishResponse> result = publisher.put(publishRequest, plainBatch);
+
+ //then
+ StepVerifier.create(result)
+ .expectNext(expectedResponse)
+ .expectComplete()
+ .verify();
+
+ MOCK_SERVER_CLIENT.verify(request().withPath(path).withKeepAlive(true), VerificationTimes.exactly(1));
+ }
+
+ @Test
+ void publisher_shouldRetryWhenClientTimeoutAndSuccessfullyPublishWithConnectionPoolConfiguration() {
+ //given
+ final String topic = "TOPIC16";
+ final String topicUrl = String.format("%s/%s", PROXY_MOCK_EVENTS_PATH, topic);
+
+ final List<String> singleJsonMessage = List.of("{\"message\":\"message1\"}");
+ final List<JsonElement> expectedItems = getAsJsonElements(singleJsonMessage);
+ final Flux<JsonElement> plainBatch = plainBatch(singleJsonMessage);
+
+ final MessageRouterPublishRequest publishRequest = createPublishRequest(topicUrl, Duration.ofSeconds(1));
+ final MessageRouterPublishResponse expectedResponse = successPublishResponse(expectedItems);
+
+ final String path = String.format("/events/%s", topic);
+ MOCK_SERVER_CLIENT
+ .when(request().withPath(path), Times.once())
+ .respond(response().withDelay(TimeUnit.SECONDS, 10));
+
+ final MessageRouterPublisher publisher = DmaapClientFactory.createMessageRouterPublisher(connectionPoolAndRetryConfiguration());
+
+ //when
+ final Flux<MessageRouterPublishResponse> result = publisher.put(publishRequest, plainBatch);
+
+ //then
+ StepVerifier.create(result)
+ .expectNext(expectedResponse)
+ .expectComplete()
+ .verify();
+
+ MOCK_SERVER_CLIENT.verify(request().withPath(path).withKeepAlive(true), VerificationTimes.exactly(2));
+ }
+
private MessageRouterPublisherConfig retryConfig(int retryInterval, int retryCount) {
return ImmutableMessageRouterPublisherConfig.builder()
@@ -481,4 +550,27 @@ class MessageRouterPublisherIT {
.build())
.build();
}
-}
+ private MessageRouterPublisherConfig connectionPoolConfiguration() {
+ return ImmutableMessageRouterPublisherConfig.builder()
+ .connectionPoolConfig(ImmutableDmaapConnectionPoolConfig.builder()
+ .connectionPool(10)
+ .maxIdleTime(10)
+ .maxLifeTime(20)
+ .build())
+ .build();
+ }
+
+ private MessageRouterPublisherConfig connectionPoolAndRetryConfiguration() {
+ return ImmutableMessageRouterPublisherConfig.builder()
+ .connectionPoolConfig(ImmutableDmaapConnectionPoolConfig.builder()
+ .connectionPool(10)
+ .maxIdleTime(10)
+ .maxLifeTime(20)
+ .build())
+ .retryConfig(ImmutableDmaapRetryConfig.builder()
+ .retryIntervalInSeconds(1)
+ .retryCount(1)
+ .build())
+ .build();
+ }
+} \ No newline at end of file
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterSubscriberIT.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterSubscriberIT.java
index 2cc6d339..8f4edab0 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterSubscriberIT.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterSubscriberIT.java
@@ -23,7 +23,6 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.vavr.collection.List;
-import io.vavr.control.Try;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -33,6 +32,7 @@ import org.mockserver.verify.VerificationTimes;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.ImmutableDmaapConnectionPoolConfig;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.ImmutableDmaapRetryConfig;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.ImmutableMessageRouterSubscriberConfig;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.MessageRouterPublisherConfig;
@@ -415,6 +415,34 @@ class MessageRouterSubscriberIT {
MOCK_SERVER_CLIENT.verify(request().withPath(path), VerificationTimes.exactly(2));
}
+ @Test
+ void subscriber_shouldSubscribeToTopicWithConnectionPoolConfiguration() {
+ //given
+ final String topic = "TOPIC4";
+ final String topicUrl = String.format("%s/%s", EVENTS_PATH, topic);
+ final MessageRouterPublishRequest publishRequest = createPublishRequest(topicUrl);
+ final MessageRouterSubscribeRequest subscribeRequest = createMRSubscribeRequest(topicUrl,
+ CONSUMER_GROUP, CONSUMER_ID);
+
+ final List<String> twoJsonMessages = List.of("{\"message\":\"message1\"}",
+ "{\"differentMessage\":\"message2\"}");
+ final List<JsonElement> messages = getAsJsonElements(twoJsonMessages);
+ final Flux<JsonObject> jsonMessageBatch = jsonBatch(twoJsonMessages);
+
+ final MessageRouterSubscriber subscriber = DmaapClientFactory.createMessageRouterSubscriber(connectionPoolConfiguration());
+
+ //when
+ registerTopic(publisher, publishRequest, subscriber, subscribeRequest);
+ final Flux<JsonElement> result = publisher.put(publishRequest, jsonMessageBatch)
+ .thenMany(subscriber.subscribeForElements(subscribeRequest, Duration.ofSeconds(1)));
+
+ //then
+ StepVerifier.create(result.take(2))
+ .expectNext(messages.get(0))
+ .expectNext(messages.get(1))
+ .expectComplete()
+ .verify(TIMEOUT);
+ }
private MessageRouterSubscriberConfig retryConfig(int retryInterval, int retryCount) {
return ImmutableMessageRouterSubscriberConfig.builder()
@@ -424,4 +452,14 @@ class MessageRouterSubscriberIT {
.build())
.build();
}
+
+ private MessageRouterSubscriberConfig connectionPoolConfiguration() {
+ return ImmutableMessageRouterSubscriberConfig.builder()
+ .connectionPoolConfig(ImmutableDmaapConnectionPoolConfig.builder()
+ .connectionPool(10)
+ .maxIdleTime(10)
+ .maxLifeTime(20)
+ .build())
+ .build();
+ }
}