Skip to content

Commit

Permalink
review: made some configs "non 0"-able where reasonable
Browse files Browse the repository at this point in the history
* removed unused MqttConfig.getSourceBufferSize()

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Jul 12, 2021
1 parent 48a1eb4 commit 8d96b7c
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public final class DefaultExponentialBackOffConfig implements ExponentialBackOff
private final Duration corruptedReceiveTimeout;

private DefaultExponentialBackOffConfig(final ScopedConfig config) {
min = config.getNonNegativeAndNonZeroDurationOrThrow(ExponentialBackOffConfigValue.MIN);
min = config.getNonNegativeDurationOrThrow(ExponentialBackOffConfigValue.MIN);
max = config.getNonNegativeDurationOrThrow(ExponentialBackOffConfigValue.MAX);
randomFactor = config.getNonNegativeDoubleOrThrow(ExponentialBackOffConfigValue.RANDOM_FACTOR);
randomFactor = config.getPositiveDoubleOrThrow(ExponentialBackOffConfigValue.RANDOM_FACTOR);
corruptedReceiveTimeout =
config.getNonNegativeDurationOrThrow(ExponentialBackOffConfigValue.CORRUPTED_RECEIVE_TIMEOUT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private DefaultPersistenceCleanupConfig(final ScopedConfig config) {
this.enabled = config.getBoolean(ConfigValue.ENABLED.getConfigPath());
this.quietPeriod = config.getNonNegativeAndNonZeroDurationOrThrow(ConfigValue.QUIET_PERIOD);
this.cleanupTimeout = config.getNonNegativeAndNonZeroDurationOrThrow(ConfigValue.CLEANUP_TIMEOUT);
this.parallelism = config.getNonNegativeIntOrThrow(ConfigValue.PARALLELISM);
this.parallelism = config.getPositiveIntOrThrow(ConfigValue.PARALLELISM);
this.keptCreditDecisions = config.getPositiveIntOrThrow(ConfigValue.KEEP_CREDIT_DECISIONS);
this.keptActions = config.getPositiveIntOrThrow(ConfigValue.KEEP_ACTIONS);
this.keptEvents = config.getPositiveIntOrThrow(ConfigValue.KEEP_EVENTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class DefaultThingsAggregatorConfig implements ThingsAggregatorConf
private DefaultThingsAggregatorConfig(final ScopedConfig config) {
singleRetrieveThingTimeout =
config.getNonNegativeAndNonZeroDurationOrThrow(ThingsAggregatorConfigValue.SINGLE_RETRIEVE_THING_TIMEOUT);
maxParallelism = config.getNonNegativeIntOrThrow(ThingsAggregatorConfigValue.MAX_PARALLELISM);
maxParallelism = config.getPositiveIntOrThrow(ThingsAggregatorConfigValue.MAX_PARALLELISM);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public final class DefaultConnectionIdsRetrievalConfig implements ConnectionIdsR

private DefaultConnectionIdsRetrievalConfig(final ScopedConfig config) {
readJournalBatchSize =
config.getNonNegativeIntOrThrow(ConnectionIdsRetrievalConfigValue.READ_JOURNAL_BATCH_SIZE);
config.getPositiveIntOrThrow(ConnectionIdsRetrievalConfigValue.READ_JOURNAL_BATCH_SIZE);
readSnapshotBatchSize =
config.getNonNegativeIntOrThrow(ConnectionIdsRetrievalConfigValue.READ_SNAPSHOT_BATCH_SIZE);
config.getPositiveIntOrThrow(ConnectionIdsRetrievalConfigValue.READ_SNAPSHOT_BATCH_SIZE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class DefaultHttpPushConfig implements HttpPushConfig, WithStringMapDecodi
private final Map<String, String> hmacAlgorithms;

private DefaultHttpPushConfig(final ScopedConfig config) {
maxQueueSize = config.getNonNegativeIntOrThrow(ConfigValue.MAX_QUEUE_SIZE);
maxQueueSize = config.getPositiveIntOrThrow(ConfigValue.MAX_QUEUE_SIZE);
requestTimeout = config.getNonNegativeAndNonZeroDurationOrThrow(ConfigValue.REQUEST_TIMEOUT);
httpProxyConfig = DefaultHttpProxyConfig.ofProxy(config);
hmacAlgorithms = asStringMap(config, ConfigValue.HMAC_ALGORITHMS.getConfigPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public final class DefaultKafkaProducerConfig implements KafkaProducerConfig {
private final Config alpakkaConfig;

private DefaultKafkaProducerConfig(final ScopedConfig kafkaProducerScopedConfig) {
queueSize = kafkaProducerScopedConfig.getNonNegativeIntOrThrow(ConfigValue.QUEUE_SIZE);
parallelism = kafkaProducerScopedConfig.getNonNegativeIntOrThrow(ConfigValue.PARALLELISM);
queueSize = kafkaProducerScopedConfig.getPositiveIntOrThrow(ConfigValue.QUEUE_SIZE);
parallelism = kafkaProducerScopedConfig.getPositiveIntOrThrow(ConfigValue.PARALLELISM);
minBackoff = kafkaProducerScopedConfig.getNonNegativeDurationOrThrow(ConfigValue.MIN_BACKOFF);
maxBackoff = kafkaProducerScopedConfig.getNonNegativeAndNonZeroDurationOrThrow(ConfigValue.MAX_BACKOFF);
randomFactor = kafkaProducerScopedConfig.getNonNegativeDoubleOrThrow(ConfigValue.RANDOM_FACTOR);
randomFactor = kafkaProducerScopedConfig.getPositiveDoubleOrThrow(ConfigValue.RANDOM_FACTOR);
alpakkaConfig = kafkaProducerScopedConfig.getConfig(ALPAKKA_PATH);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public final class DefaultMqttConfig implements MqttConfig {
private static final String CONFIG_PATH = "mqtt";
private static final String RECONNECT_PATH = "reconnect";

private final int sourceBufferSize;
private final int eventLoopThreads;
private final boolean cleanSession;
private final boolean reconnectForRedelivery;
Expand All @@ -43,7 +42,6 @@ public final class DefaultMqttConfig implements MqttConfig {
private final BackOffConfig reconnectBackOffConfig;

private DefaultMqttConfig(final ScopedConfig config) {
sourceBufferSize = config.getNonNegativeIntOrThrow(MqttConfigValue.SOURCE_BUFFER_SIZE);
eventLoopThreads = config.getNonNegativeIntOrThrow(MqttConfigValue.EVENT_LOOP_THREADS);
cleanSession = config.getBoolean(MqttConfigValue.CLEAN_SESSION.getConfigPath());
reconnectForRedelivery = config.getBoolean(MqttConfigValue.RECONNECT_FOR_REDELIVERY.getConfigPath());
Expand All @@ -68,11 +66,6 @@ public static DefaultMqttConfig of(final Config config) {
return new DefaultMqttConfig(ConfigWithFallback.newInstance(config, CONFIG_PATH, MqttConfigValue.values()));
}

@Override
public int getSourceBufferSize() {
return sourceBufferSize;
}

@Override
public int getEventLoopThreads() {
return eventLoopThreads;
Expand Down Expand Up @@ -117,8 +110,7 @@ public boolean equals(@Nullable final Object o) {
return false;
}
final DefaultMqttConfig that = (DefaultMqttConfig) o;
return Objects.equals(sourceBufferSize, that.sourceBufferSize) &&
Objects.equals(eventLoopThreads, that.eventLoopThreads) &&
return Objects.equals(eventLoopThreads, that.eventLoopThreads) &&
Objects.equals(cleanSession, that.cleanSession) &&
Objects.equals(reconnectForRedelivery, that.reconnectForRedelivery) &&
Objects.equals(reconnectForRedeliveryDelay, that.reconnectForRedeliveryDelay) &&
Expand All @@ -130,16 +122,15 @@ public boolean equals(@Nullable final Object o) {

@Override
public int hashCode() {
return Objects.hash(sourceBufferSize, eventLoopThreads, cleanSession, reconnectForRedelivery,
return Objects.hash(eventLoopThreads, cleanSession, reconnectForRedelivery,
reconnectForRedeliveryDelay, useSeparateClientForPublisher,
reconnectMinTimeoutForMqttBrokerInitiatedDisconnect, reconnectBackOffConfig);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" +
"sourceBufferSize=" + sourceBufferSize +
", eventLoopThreads=" + eventLoopThreads +
"eventLoopThreads=" + eventLoopThreads +
", cleanSession=" + cleanSession +
", reconnectForRedelivery=" + reconnectForRedelivery +
", reconnectForRedeliveryDelay=" + reconnectForRedeliveryDelay +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
@Immutable
public interface MqttConfig {

/**
* Returns the maximum number of buffered messages for each MQTT source.
*
* @return the buffer size.
*/
int getSourceBufferSize();


/**
* Returns the number of threads to use for the underlying event loop of the MQTT client.
* When configured to {@code 0}, the size is determined based on {@code the available processor cores * 2}.
Expand Down Expand Up @@ -96,11 +88,6 @@ public interface MqttConfig {
*/
enum MqttConfigValue implements KnownConfigValue {

/**
* The maximum number of buffered messages for each MQTT source.
*/
SOURCE_BUFFER_SIZE("source-buffer-size", 8),

/**
* The number of threads to use for the underlying event loop of the MQTT client.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private DefaultJavaScriptConfig(final ScopedConfig config) {
maxScriptSizeBytes = config.getPositiveIntOrThrow(JavaScriptConfigValue.MAX_SCRIPT_SIZE_BYTES);
maxScriptExecutionTime =
config.getNonNegativeAndNonZeroDurationOrThrow(JavaScriptConfigValue.MAX_SCRIPT_EXECUTION_TIME);
maxScriptStackDepth = config.getNonNegativeIntOrThrow(JavaScriptConfigValue.MAX_SCRIPT_STACK_DEPTH);
maxScriptStackDepth = config.getPositiveIntOrThrow(JavaScriptConfigValue.MAX_SCRIPT_STACK_DEPTH);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public final class DefaultMappingConfig implements MappingConfig {

private DefaultMappingConfig(final ScopedConfig config) {
bufferSize = config.getNonNegativeIntOrThrow(MappingConfigValue.BUFFER_SIZE);
parallelism = config.getNonNegativeIntOrThrow(MappingConfigValue.PARALLELISM);
maxPoolSize = config.getNonNegativeIntOrThrow(MappingConfigValue.MAX_POOL_SIZE);
parallelism = config.getPositiveIntOrThrow(MappingConfigValue.PARALLELISM);
maxPoolSize = config.getPositiveIntOrThrow(MappingConfigValue.MAX_POOL_SIZE);
mapperLimitsConfig = DefaultMapperLimitsConfig.of(config);
javaScriptConfig = DefaultJavaScriptConfig.of(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ public void underTestReturnsValuesOfConfigFile() {
.as(SnapshotConfig.SnapshotConfigValue.THRESHOLD.getConfigPath())
.isEqualTo(20));

softly.assertThat(underTest.getMqttConfig())
.as("mqttConfig")
.satisfies(mqttConfig -> softly.assertThat(mqttConfig.getSourceBufferSize())
.as(MqttConfig.MqttConfigValue.SOURCE_BUFFER_SIZE.getConfigPath())
.isEqualTo(7));

softly.assertThat(underTest.getHttpPushConfig())
.as("httpPushConfig")
.satisfies(httpPushConfig -> softly.assertThat(httpPushConfig.getMaxQueueSize())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public interface ScopedConfig extends Config, WithConfigPath {
String DITTO_SCOPE = "ditto";

/**
* Same as {@link #getDuration(String)} but with the guarantee that the returned Duration is non-negative.
* Same as {@link #getDuration(String)} but with the guarantee that the returned Duration is positive.
*
* @param withConfigPath provides the config path to get the Duration value for.
* @return the duration.
Expand Down Expand Up @@ -128,7 +128,7 @@ default int getPositiveIntOrThrow(final WithConfigPath withConfigPath) {
* Same as {@link #getLong(String)} but with the guarantee that the returned value is positive.
*
* @param withConfigPath provides the config path to get the long value for.
* @return the int value.
* @return the long value.
* @throws DittoConfigError if the long value at the config path is zero or negative.
*/
default long getPositiveLongOrThrow(final WithConfigPath withConfigPath) {
Expand All @@ -140,6 +140,22 @@ default long getPositiveLongOrThrow(final WithConfigPath withConfigPath) {
return result;
}

/**
* Same as {@link #getDouble(String)} but with the guarantee that the returned value is positive.
*
* @param withConfigPath provides the config path to get the double value for.
* @return the double value.
* @throws DittoConfigError if the long value at the config path is zero or negative.
*/
default double getPositiveDoubleOrThrow(final WithConfigPath withConfigPath) {
final var result = getDouble(withConfigPath.getConfigPath());
if (0.0 >= result) {
final var msgPattern = "The double value at <{0}> must be positive but it was <{1}>!";
throw new DittoConfigError(MessageFormat.format(msgPattern, withConfigPath.getConfigPath(), result));
}
return result;
}

/**
* Same as {@link #getInt(String)} but with the guarantee that the returned int is greater zero.
*
Expand All @@ -160,7 +176,7 @@ default int getNonNegativeIntOrThrow(final WithConfigPath withConfigPath) {
* Same as {@link #getLong(String)} but with the guarantee that the returned long is greater zero.
*
* @param withConfigPath provides the config path to get the long value for.
* @return the int value.
* @return the long value.
* @throws DittoConfigError if the long value at the config path is negative.
*/
default long getNonNegativeLongOrThrow(final WithConfigPath withConfigPath) {
Expand All @@ -176,7 +192,7 @@ default long getNonNegativeLongOrThrow(final WithConfigPath withConfigPath) {
* Same as {@link #getDouble(String)} but with the guarantee that the returned double is not negative.
*
* @param withConfigPath provides the config path to get the double value for.
* @return the int value.
* @return the double value.
* @throws DittoConfigError if the double value at the config path is negative.
*/
default double getNonNegativeDoubleOrThrow(final WithConfigPath withConfigPath) {
Expand All @@ -192,7 +208,7 @@ default double getNonNegativeDoubleOrThrow(final WithConfigPath withConfigPath)
* Same as {@link #getBytes(String)} but with the guarantee that the returned long is greater zero.
*
* @param withConfigPath provides the config path to get the bytes value for.
* @return the int value.
* @return the bytes value.
* @throws DittoConfigError if the bytes value at the config path is negative.
*/
default long getNonNegativeBytesOrThrow(final WithConfigPath withConfigPath) {
Expand Down

0 comments on commit 8d96b7c

Please sign in to comment.