forked from eclipse-ditto/ditto
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse-ditto#605 extract connection ids retrieval into separate acto…
…r, add necessary config, add actor test, add unit for new retrieve command/response Signed-off-by: Dominik Guggemos <dominik.guggemos@bosch.io>
- Loading branch information
Showing
18 changed files
with
732 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...ain/java/org/eclipse/ditto/services/connectivity/config/ConnectionIdsRetrievalConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.services.connectivity.config; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
import org.eclipse.ditto.services.utils.config.KnownConfigValue; | ||
|
||
/** | ||
* Provides configuration settings for Connectivity service's behaviour for retrieval of connection ids. | ||
*/ | ||
@Immutable | ||
public interface ConnectionIdsRetrievalConfig { | ||
|
||
/** | ||
* Returns the number of events to read from the event journal with one query. | ||
* | ||
* @return the number of events to read with one query. | ||
*/ | ||
int getReadJournalBatchSize(); | ||
|
||
/** | ||
* Returns the number of entries to read from the snapshot collection with one query. | ||
* | ||
* @return the number of entries to read with one query. | ||
*/ | ||
int getReadSnapshotBatchSize(); | ||
|
||
/** | ||
* An enumeration of the known config path expressions and their associated default values for | ||
* {@code ReconnectConfig}. | ||
*/ | ||
enum ConnectionIdsRetrievalConfigValue implements KnownConfigValue { | ||
|
||
/** | ||
* The number of events to read in one query. | ||
*/ | ||
READ_JOURNAL_BATCH_SIZE("read-journal-batch-size", 500), | ||
|
||
/** | ||
* The number of snapshots to read in one query. | ||
*/ | ||
READ_SNAPSHOT_BATCH_SIZE("read-snapshot-batch-size", 50); | ||
|
||
private final String path; | ||
private final Object defaultValue; | ||
|
||
// enum constructors are always private. | ||
ConnectionIdsRetrievalConfigValue(final String thePath, final Object theDefaultValue) { | ||
path = thePath; | ||
defaultValue = theDefaultValue; | ||
} | ||
|
||
@Override | ||
public Object getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
@Override | ||
public String getConfigPath() { | ||
return path; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...a/org/eclipse/ditto/services/connectivity/config/DefaultConnectionIdsRetrievalConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.services.connectivity.config; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
import org.eclipse.ditto.services.utils.config.ConfigWithFallback; | ||
import org.eclipse.ditto.services.utils.config.ScopedConfig; | ||
|
||
import com.typesafe.config.Config; | ||
|
||
/** | ||
* This class is the default implementation of the config for the retrieval of connection ids. | ||
*/ | ||
@Immutable | ||
public final class DefaultConnectionIdsRetrievalConfig implements ConnectionIdsRetrievalConfig { | ||
|
||
private static final String CONFIG_PATH = "connection-ids-retrieval"; | ||
|
||
private final int readJournalBatchSize; | ||
private final int readSnapshotBatchSize; | ||
|
||
private DefaultConnectionIdsRetrievalConfig(final ScopedConfig config) { | ||
readJournalBatchSize = config.getInt(ConnectionIdsRetrievalConfigValue.READ_JOURNAL_BATCH_SIZE.getConfigPath()); | ||
readSnapshotBatchSize = | ||
config.getInt(ConnectionIdsRetrievalConfigValue.READ_SNAPSHOT_BATCH_SIZE.getConfigPath()); | ||
} | ||
|
||
/** | ||
* Returns an instance of {@code DefaultReconnectConfig} based on the settings of the specified Config. | ||
* | ||
* @param config is supposed to provide the settings of the JavaScript mapping config at {@value #CONFIG_PATH}. | ||
* @return the instance. | ||
* @throws org.eclipse.ditto.services.utils.config.DittoConfigError if {@code config} is invalid. | ||
*/ | ||
public static DefaultConnectionIdsRetrievalConfig of(final Config config) { | ||
final ConfigWithFallback reconnectScopedConfig = | ||
ConfigWithFallback.newInstance(config, CONFIG_PATH, ConnectionIdsRetrievalConfigValue.values()); | ||
|
||
return new DefaultConnectionIdsRetrievalConfig(reconnectScopedConfig); | ||
} | ||
|
||
@Override | ||
public int getReadJournalBatchSize() { | ||
return readJournalBatchSize; | ||
} | ||
|
||
@Override | ||
public int getReadSnapshotBatchSize() { | ||
return readSnapshotBatchSize; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
final DefaultConnectionIdsRetrievalConfig that = (DefaultConnectionIdsRetrievalConfig) o; | ||
return readJournalBatchSize == that.readJournalBatchSize && readSnapshotBatchSize == that.readSnapshotBatchSize; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(readJournalBatchSize, readSnapshotBatchSize); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + " [" + | ||
"readJournalBatchSize=" + readJournalBatchSize + | ||
", readSnapshotBatchSize=" + readSnapshotBatchSize + | ||
"]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...g/eclipse/ditto/services/connectivity/config/DefaultConnectionIdsRetrievalConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.services.connectivity.config; | ||
|
||
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; | ||
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; | ||
|
||
import org.assertj.core.api.JUnitSoftAssertions; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigFactory; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
|
||
/** | ||
* Unit test for {@link org.eclipse.ditto.services.connectivity.messaging.config.DefaultConnectionIdsRetrievalConfig}. | ||
*/ | ||
public final class DefaultConnectionIdsRetrievalConfigTest { | ||
|
||
private static Config connectionIdsConf; | ||
|
||
@Rule | ||
public final JUnitSoftAssertions softly = new JUnitSoftAssertions(); | ||
|
||
@BeforeClass | ||
public static void initTestFixture() { | ||
connectionIdsConf = ConfigFactory.load("connections-ids-retrieval-test"); | ||
} | ||
|
||
@Test | ||
public void assertImmutability() { | ||
assertInstancesOf(DefaultConnectionIdsRetrievalConfig.class, | ||
areImmutable()); | ||
} | ||
|
||
@Test | ||
public void testHashCodeAndEquals() { | ||
EqualsVerifier.forClass(DefaultConnectionIdsRetrievalConfig.class) | ||
.usingGetClass() | ||
.verify(); | ||
} | ||
|
||
@Test | ||
public void underTestReturnsDefaultValuesIfBaseConfigWasEmpty() { | ||
final ConnectionIdsRetrievalConfig underTest = DefaultConnectionIdsRetrievalConfig.of(ConfigFactory.empty()); | ||
|
||
softly.assertThat(underTest.getReadJournalBatchSize()) | ||
.as(ConnectionIdsRetrievalConfig.ConnectionIdsRetrievalConfigValue.READ_JOURNAL_BATCH_SIZE.getConfigPath()) | ||
.isEqualTo( | ||
ConnectionIdsRetrievalConfig.ConnectionIdsRetrievalConfigValue.READ_JOURNAL_BATCH_SIZE.getDefaultValue()); | ||
|
||
softly.assertThat(underTest.getReadSnapshotBatchSize()) | ||
.as(ConnectionIdsRetrievalConfig.ConnectionIdsRetrievalConfigValue.READ_SNAPSHOT_BATCH_SIZE.getConfigPath()) | ||
.isEqualTo( | ||
ConnectionIdsRetrievalConfig.ConnectionIdsRetrievalConfigValue.READ_SNAPSHOT_BATCH_SIZE.getDefaultValue()); | ||
} | ||
|
||
@Test | ||
public void underTestReturnsValuesOfConfigFile() { | ||
final ConnectionIdsRetrievalConfig underTest = DefaultConnectionIdsRetrievalConfig.of(connectionIdsConf); | ||
|
||
softly.assertThat(underTest.getReadJournalBatchSize()) | ||
.as(ConnectionIdsRetrievalConfig.ConnectionIdsRetrievalConfigValue.READ_JOURNAL_BATCH_SIZE.getConfigPath()) | ||
.isEqualTo(42); | ||
|
||
softly.assertThat(underTest.getReadSnapshotBatchSize()) | ||
.as(ConnectionIdsRetrievalConfig.ConnectionIdsRetrievalConfigValue.READ_SNAPSHOT_BATCH_SIZE.getConfigPath()) | ||
.isEqualTo(21); | ||
} | ||
} |
Oops, something went wrong.