diff --git a/src/main/java/com/exactpro/th2/estore/Configuration.java b/src/main/java/com/exactpro/th2/estore/Configuration.java index 6508097..364db3d 100644 --- a/src/main/java/com/exactpro/th2/estore/Configuration.java +++ b/src/main/java/com/exactpro/th2/estore/Configuration.java @@ -16,6 +16,7 @@ package com.exactpro.th2.estore; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; public class Configuration { private static final int DEFAULT_MAX_TASK_RETRIES = 1000000; @@ -23,54 +24,56 @@ public class Configuration { private static final long DEFAULT_RETRY_DELAY_BASEM_S = 5000; private static final int DEFAULT_PROCESSING_THREADS = Runtime.getRuntime().availableProcessors(); - private Integer maxTaskCount; - private Long maxTaskDataSize; - private Integer maxRetryCount; - private Long retryDelayBase; - private Integer processingThreads; + private final int maxTaskCount; + private final long maxTaskDataSize; + private final int maxRetryCount; + private final long retryDelayBase; + private final int processingThreads; - public Long getMaxTaskDataSize() { - return maxTaskDataSize == null ? defaultMaxDataSize() : maxTaskDataSize; - } - - public Integer getMaxTaskCount() { - return maxTaskCount == null ? DEFAULT_MAX_TASK_COUNT : maxTaskCount; + public Configuration() { + this(DEFAULT_MAX_TASK_COUNT, defaultMaxDataSize(), DEFAULT_MAX_TASK_RETRIES, + DEFAULT_RETRY_DELAY_BASEM_S, DEFAULT_PROCESSING_THREADS); } - public Integer getMaxRetryCount() { - return maxRetryCount == null ? DEFAULT_MAX_TASK_RETRIES : maxRetryCount; + @JsonCreator + public Configuration( + @JsonProperty("maxTaskCount") Integer maxTaskCount, + @JsonProperty("maxTaskDataSize") Long maxTaskDataSize, + @JsonProperty("maxRetryCount") Integer maxRetryCount, + @JsonProperty ("retryDelayBase") Long retryDelayBase, + @JsonProperty("processingThreads") Integer processingThreads + ) { + this.maxTaskCount = maxTaskCount == null ? DEFAULT_MAX_TASK_COUNT : maxTaskCount; + this.maxTaskDataSize = maxTaskDataSize == null ? defaultMaxDataSize() : maxTaskDataSize; + this.maxRetryCount = maxRetryCount == null ? DEFAULT_MAX_TASK_RETRIES : maxRetryCount; + this.retryDelayBase = retryDelayBase == null ? DEFAULT_RETRY_DELAY_BASEM_S : retryDelayBase; + this.processingThreads = processingThreads == null ? DEFAULT_PROCESSING_THREADS : processingThreads; + + if (this.maxTaskCount <= 1) throw new IllegalArgumentException("'maxTaskCount' should be >=1. Actual: " + maxTaskCount); + if (this.maxTaskDataSize <= 1) throw new IllegalArgumentException("'maxTaskDataSize' should be >=1. Actual: " + maxTaskDataSize); + if (this.maxRetryCount <= 0) throw new IllegalArgumentException("'maxRetryCount' should be >=0. Actual: " + maxRetryCount); + if (this.retryDelayBase <= 1) throw new IllegalArgumentException("'retryDelayBase' should be >=1. Actual: " + retryDelayBase); + if (this.processingThreads <= 1) throw new IllegalArgumentException("'processingThreads' should be >=1. Actual: " + processingThreads); } - public Long getRetryDelayBase() { - return retryDelayBase == null ? DEFAULT_RETRY_DELAY_BASEM_S : retryDelayBase; + public int getMaxTaskCount() { + return maxTaskCount; } - public int getProcessingThreads() { - return processingThreads == null ? DEFAULT_PROCESSING_THREADS : processingThreads; + public long getMaxTaskDataSize() { + return maxTaskDataSize; } - public Configuration() { - this(DEFAULT_MAX_TASK_COUNT, DEFAULT_MAX_TASK_RETRIES, DEFAULT_RETRY_DELAY_BASEM_S, - defaultMaxDataSize(), DEFAULT_PROCESSING_THREADS); + public int getMaxRetryCount() { + return maxRetryCount; } - @JsonCreator - public Configuration(Integer maxTaskCount, Integer maxTaskRetries, Long taskRetryDelayBase, - Long maxTaskDataSize, Integer processingThreads) { - this.maxTaskCount = maxTaskCount; - this.maxRetryCount = maxTaskRetries; - this.retryDelayBase = taskRetryDelayBase; - this.maxTaskDataSize = maxTaskDataSize; - this.processingThreads = processingThreads; - validate(); + public long getRetryDelayBase() { + return retryDelayBase; } - public void validate() { - if (maxTaskCount <= 1) throw new IllegalArgumentException("'maxTaskCount' should be >=1. Actual: " + maxTaskCount); - if (maxTaskDataSize <= 1) throw new IllegalArgumentException("'maxTaskDataSize' should be >=1. Actual: " + maxTaskDataSize); - if (maxRetryCount <= 0) throw new IllegalArgumentException("'maxRetryCount' should be >=0. Actual: " + maxRetryCount); - if (retryDelayBase <= 1) throw new IllegalArgumentException("'retryDelayBase' should be >=1. Actual: " + retryDelayBase); - if (processingThreads <= 1) throw new IllegalArgumentException("'processingThreads' should be >=1. Actual: " + processingThreads); + public int getProcessingThreads() { + return processingThreads; } private static long defaultMaxDataSize() { diff --git a/src/main/java/com/exactpro/th2/estore/EventStore.java b/src/main/java/com/exactpro/th2/estore/EventStore.java index d05a4eb..e17cbb7 100644 --- a/src/main/java/com/exactpro/th2/estore/EventStore.java +++ b/src/main/java/com/exactpro/th2/estore/EventStore.java @@ -59,8 +59,6 @@ public static void main(String[] args) { Configuration config = factory.getCustomConfiguration(Configuration.class); if (config == null) { config = new Configuration(); - } else { - config.validate(); } LOGGER.info("Effective configuration:\n{}", config); diff --git a/src/test/java/com/exactpro/th2/estore/TestEventPersistor.java b/src/test/java/com/exactpro/th2/estore/TestEventPersistor.java index de58c2f..670b69a 100644 --- a/src/test/java/com/exactpro/th2/estore/TestEventPersistor.java +++ b/src/test/java/com/exactpro/th2/estore/TestEventPersistor.java @@ -94,7 +94,7 @@ void setUp() throws CradleStorageException, IOException, InterruptedException { cradleEntitiesFactory = spy(new CradleEntitiesFactory(MAX_MESSAGE_BATCH_SIZE, MAX_TEST_EVENT_BATCH_SIZE, STORE_ACTION_REJECTION_THRESHOLD)); doReturn(CompletableFuture.completedFuture(null)).when(storageMock).storeTestEventAsync(any()); - Configuration config = new Configuration(MAX_EVENT_QUEUE_TASK_SIZE, MAX_EVENT_PERSIST_RETRIES, 10L, MAX_EVENT_QUEUE_DATA_SIZE, TASK_PROCESSING_THREADS); + Configuration config = new Configuration(MAX_EVENT_QUEUE_TASK_SIZE, MAX_EVENT_QUEUE_DATA_SIZE, MAX_EVENT_PERSIST_RETRIES, 10L, TASK_PROCESSING_THREADS); persistor = spy(new EventPersistor(errorCollector, config, storageMock)); persistor.start(); }