Skip to content

Commit

Permalink
feat: Config constants created & used (#10117)
Browse files Browse the repository at this point in the history
Signed-off-by: Hendrik Ebbers <hendrik.ebbers@web.de>
  • Loading branch information
hendrikebbers authored Dec 4, 2023
1 parent 7ac0a02 commit 864ea88
Show file tree
Hide file tree
Showing 51 changed files with 190 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ plugins { id("com.hedera.hashgraph.application") }

application.mainClass.set("com.swirlds.demo.consistency.ConsistencyTestingToolMain")

mainModuleInfo { annotationProcessor("com.swirlds.config.processor") }

testModuleInfo {
requires("com.swirlds.platform.core")
requires("org.junit.jupiter.api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
plugins { id("com.hedera.hashgraph.application") }

application.mainClass.set("com.swirlds.demo.iss.ISSTestingToolMain")

mainModuleInfo { annotationProcessor("com.swirlds.config.processor") }
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
plugins { id("com.hedera.hashgraph.application") }

application.mainClass.set("com.swirlds.demo.stress.StressTestingToolMain")

mainModuleInfo { annotationProcessor("com.swirlds.config.processor") }
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testDefaultValuesValid() {
void propertiesHasNoPrefix() {
// given
final Configuration configuration = new TestConfigBuilder()
.withValue("jvmPauseDetectorSleepMs", "42")
.withValue(BasicConfig_.JVM_PAUSE_DETECTOR_SLEEP_MS, "42")
.getOrCreateConfig();
final BasicConfig basicConfig = configuration.getConfigData(BasicConfig.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class TransactionConfigTest {
@Test
void testValidation() {
final TestConfigBuilder builder = new TestConfigBuilder()
.withValue("transaction.maxTransactionBytesPerEvent", "1")
.withValue("transaction.transactionMaxBytes", "12");
.withValue(TransactionConfig_.MAX_TRANSACTION_BYTES_PER_EVENT, "1")
.withValue(TransactionConfig_.TRANSACTION_MAX_BYTES, "12");

Assertions.assertThrows(
ConfigViolationException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

import com.swirlds.base.test.fixtures.time.FakeTime;
import com.swirlds.base.time.Time;
import com.swirlds.common.config.StateConfig_;
import com.swirlds.common.io.config.RecycleBinConfig;
import com.swirlds.common.io.config.RecycleBinConfig_;
import com.swirlds.common.metrics.noop.NoOpMetrics;
import com.swirlds.common.system.NodeId;
import com.swirlds.config.api.Configuration;
Expand Down Expand Up @@ -57,7 +59,7 @@ class RecycleBinTests {
void beforeEach() throws IOException {
FileUtils.deleteDirectory(testDirectory);
configuration = new TestConfigBuilder()
.withValue("state.savedStateDirectory", testDirectory.toString())
.withValue(StateConfig_.SAVED_STATE_DIRECTORY, testDirectory.toString())
.getOrCreateConfig();
}

Expand Down Expand Up @@ -213,8 +215,8 @@ void filesDeletedAfterTimePasses() throws IOException, InterruptedException {
final FakeTime time = new FakeTime(Instant.now(), Duration.ZERO);

final Configuration customConfiguration = new TestConfigBuilder()
.withValue("state.savedStateDirectory", testDirectory.toString())
.withValue("recycleBin.collectionPeriod", "1ns")
.withValue(StateConfig_.SAVED_STATE_DIRECTORY, testDirectory.toString())
.withValue(RecycleBinConfig_.COLLECTION_PERIOD, "1ns")
.getOrCreateConfig();

final Duration maximumFileAge =
Expand Down Expand Up @@ -279,8 +281,8 @@ void clearTest() throws IOException, InterruptedException {
final FakeTime time = new FakeTime(Instant.now(), Duration.ZERO);

final Configuration customConfiguration = new TestConfigBuilder()
.withValue("state.savedStateDirectory", testDirectory.toString())
.withValue("recycleBin.collectionPeriod", "1ns")
.withValue(StateConfig_.SAVED_STATE_DIRECTORY, testDirectory.toString())
.withValue(RecycleBinConfig_.COLLECTION_PERIOD, "1ns")
.getOrCreateConfig();

final RecycleBinImpl recycleBin = new RecycleBinImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.swirlds.common.metrics.MetricConfig;
import com.swirlds.common.metrics.PlatformMetricsFactory;
import com.swirlds.common.metrics.config.MetricsConfig;
import com.swirlds.common.metrics.config.MetricsConfig_;
import com.swirlds.common.system.NodeId;
import com.swirlds.config.api.Configuration;
import com.swirlds.test.framework.config.TestConfigBuilder;
Expand Down Expand Up @@ -100,7 +101,7 @@ class DefaultMetricsTest {
@BeforeEach
void setupService() {
final Configuration configuration = new TestConfigBuilder()
.withValue("metrics.metricsUpdatePeriodMillis", 10L)
.withValue(MetricsConfig_.METRICS_UPDATE_PERIOD_MILLIS, 10L)
.getOrCreateConfig();
metricsConfig = configuration.getConfigData(MetricsConfig.class);

Expand Down Expand Up @@ -577,7 +578,7 @@ void testUpdater(@Mock final Runnable updater) {
void testDisabledUpdater(@Mock final Runnable updater) {
// given
final Configuration configuration = new TestConfigBuilder()
.withValue("metrics.metricsUpdatePeriodMillis", 0L)
.withValue(MetricsConfig_.METRICS_UPDATE_PERIOD_MILLIS, 0L)
.getOrCreateConfig();
metricsConfig = configuration.getConfigData(MetricsConfig.class);
final DefaultMetrics metrics = new DefaultMetrics(NODE_ID, registry, executor, factory, metricsConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.swirlds.common.config.BasicConfig_;
import com.swirlds.common.metrics.Counter;
import com.swirlds.common.metrics.DoubleGauge;
import com.swirlds.common.metrics.FunctionGauge;
Expand All @@ -36,6 +37,7 @@
import com.swirlds.common.metrics.SpeedometerMetric;
import com.swirlds.common.metrics.StatEntry;
import com.swirlds.common.metrics.config.MetricsConfig;
import com.swirlds.common.metrics.config.MetricsConfig_;
import com.swirlds.common.system.NodeId;
import com.swirlds.config.api.Configuration;
import com.swirlds.test.framework.config.TestConfigBuilder;
Expand All @@ -61,10 +63,10 @@ class LegacyCsvWriterTest {
@BeforeEach
void setStandardSettings() {
configuration = new TestConfigBuilder()
.withValue("metrics.csvOutputFolder", tempDir.toString())
.withValue("metrics.csvAppend", "false")
.withValue("showInternalStats", "false")
.withValue("verboseStatistics", "false")
.withValue(MetricsConfig_.CSV_OUTPUT_FOLDER, tempDir.toString())
.withValue(MetricsConfig_.CSV_APPEND, "false")
.withValue(BasicConfig_.SHOW_INTERNAL_STATS, "false")
.withValue(BasicConfig_.VERBOSE_STATISTICS, "false")
.getOrCreateConfig();
metricsConfig = configuration.getConfigData(MetricsConfig.class);

Expand Down Expand Up @@ -251,8 +253,8 @@ void testWriteWithExistingFile() throws IOException {
void testWriteWithAppendedModeAndExistingFile() throws IOException {
// given
final Configuration configuration = new TestConfigBuilder()
.withValue("metrics.csvOutputFolder", tempDir.toString())
.withValue("metrics.csvAppend", "true")
.withValue(MetricsConfig_.CSV_OUTPUT_FOLDER, tempDir.toString())
.withValue(MetricsConfig_.CSV_APPEND, "true")
.getOrCreateConfig();
final LegacyCsvWriter writer = new LegacyCsvWriter(NODE_ID, tempDir, configuration);
final Path csvFilePath = writer.getCsvFilePath();
Expand Down Expand Up @@ -301,8 +303,8 @@ void testWriteWithAppendedModeAndExistingFile() throws IOException {
void testWriteWithAppendedModeAndNonExistingFile() throws IOException {
// given
final Configuration configuration = new TestConfigBuilder()
.withValue("metrics.csvOutputFolder", tempDir.toString())
.withValue("metrics.csvAppend", "true")
.withValue(MetricsConfig_.CSV_OUTPUT_FOLDER, tempDir.toString())
.withValue(MetricsConfig_.CSV_APPEND, "true")
.getOrCreateConfig();
final LegacyCsvWriter writer = new LegacyCsvWriter(NODE_ID, tempDir, configuration);
final Path csvFilePath = writer.getCsvFilePath();
Expand Down Expand Up @@ -379,8 +381,9 @@ void testWriteWithInternalIgnored() throws IOException {

@Test
void testWriteWithInternalNotIgnored() throws IOException {
final Configuration configuration =
new TestConfigBuilder().withValue("showInternalStats", "true").getOrCreateConfig();
final Configuration configuration = new TestConfigBuilder()
.withValue(BasicConfig_.SHOW_INTERNAL_STATS, "true")
.getOrCreateConfig();
// given
final LegacyCsvWriter writer = new LegacyCsvWriter(NODE_ID, tempDir, configuration);
final Path csvFilePath = writer.getCsvFilePath();
Expand Down Expand Up @@ -476,8 +479,9 @@ void testWriteWithSecondaryValuesNotIncluded() throws IOException {
@Test
void testWriteWithSecondaryValuesIncluded() throws IOException {
// given
final Configuration configuration =
new TestConfigBuilder().withValue("verboseStatistics", "true").getOrCreateConfig();
final Configuration configuration = new TestConfigBuilder()
.withValue(BasicConfig_.VERBOSE_STATISTICS, "true")
.getOrCreateConfig();
final LegacyCsvWriter writer = new LegacyCsvWriter(NODE_ID, tempDir, configuration);
final Path csvFilePath = writer.getCsvFilePath();
final List<Metric> metrics = createListWithSecondaryValues();
Expand Down Expand Up @@ -643,8 +647,9 @@ void testChangedEntriesWithComplexMetricsAndNoSecondaryValues() throws IOExcepti
@Test
void testChangedEntriesWithComplexMetricsAndSecondaryValues() throws IOException {
// given
final Configuration configuration =
new TestConfigBuilder().withValue("verboseStatistics", "true").getOrCreateConfig();
final Configuration configuration = new TestConfigBuilder()
.withValue(BasicConfig_.VERBOSE_STATISTICS, "true")
.getOrCreateConfig();
final LegacyCsvWriter writer = new LegacyCsvWriter(NODE_ID, tempDir, configuration);
final Path csvFilePath = writer.getCsvFilePath();
final List<Metric> metrics = createComplexList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.swirlds.common.config.StateConfig_;
import com.swirlds.common.constructable.ConstructableRegistry;
import com.swirlds.common.constructable.ConstructableRegistryException;
import com.swirlds.common.context.PlatformContext;
Expand Down Expand Up @@ -68,7 +69,7 @@ void beforeEach() throws IOException {
Files.createDirectories(testDirectory);
TemporaryFileBuilder.overrideTemporaryFileLocation(testDirectory.resolve("tmp"));
final Configuration configuration = new TestConfigBuilder()
.withValue("state.savedStateDirectory", testDirectory.toString())
.withValue(StateConfig_.SAVED_STATE_DIRECTORY, testDirectory.toString())
.getOrCreateConfig();
platformContext = TestPlatformContextBuilder.create()
.withConfiguration(configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class PlatformStatusStateMachineTests {
void setup() {
time = new FakeTime();
final Configuration configuration = new TestConfigBuilder()
.withValue("platformStatus.observingStatusDelay", "5s")
.withValue("platformStatus.activeStatusDelay", "10s")
.withValue(PlatformStatusConfig_.OBSERVING_STATUS_DELAY, "5s")
.withValue(PlatformStatusConfig_.ACTIVE_STATUS_DELAY, "10s")
.getOrCreateConfig();

stateMachine = new PlatformStatusStateMachine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.swirlds.base.test.fixtures.time.FakeTime;
import com.swirlds.common.system.status.PlatformStatus;
import com.swirlds.common.system.status.PlatformStatusConfig;
import com.swirlds.common.system.status.PlatformStatusConfig_;
import com.swirlds.common.system.status.actions.CatastrophicFailureAction;
import com.swirlds.common.system.status.actions.DoneReplayingEventsAction;
import com.swirlds.common.system.status.actions.EmergencyReconnectStartedAction;
Expand Down Expand Up @@ -51,7 +52,7 @@ class ActiveStatusLogicTests {
void setup() {
time = new FakeTime();
final Configuration configuration = new TestConfigBuilder()
.withValue("platformStatus.activeStatusDelay", "5s")
.withValue(PlatformStatusConfig_.ACTIVE_STATUS_DELAY, "5s")
.getOrCreateConfig();
logic = new ActiveStatusLogic(time.now(), configuration.getConfigData(PlatformStatusConfig.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.swirlds.base.test.fixtures.time.FakeTime;
import com.swirlds.common.system.status.PlatformStatus;
import com.swirlds.common.system.status.PlatformStatusConfig;
import com.swirlds.common.system.status.PlatformStatusConfig_;
import com.swirlds.common.system.status.actions.CatastrophicFailureAction;
import com.swirlds.common.system.status.actions.DoneReplayingEventsAction;
import com.swirlds.common.system.status.actions.EmergencyReconnectStartedAction;
Expand Down Expand Up @@ -51,7 +52,7 @@ class ObservingStatusLogicTests {
void setup() {
time = new FakeTime();
final Configuration configuration = new TestConfigBuilder()
.withValue("platformStatus.observingStatusDelay", "5s")
.withValue(PlatformStatusConfig_.OBSERVING_STATUS_DELAY, "5s")
.getOrCreateConfig();
logic = new ObservingStatusLogic(time.now(), configuration.getConfigData(PlatformStatusConfig.class));
}
Expand Down
2 changes: 1 addition & 1 deletion platform-sdk/swirlds-config-processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ testModuleInfo { requires("org.junit.jupiter.api") }

tasks.register<AntlrTask>("generateParser") {
conventionMapping.map("antlrClasspath") {
configurations.detachedConfiguration(dependencies.create("org.antlr:antlr4:4.13.1"))
configurations.detachedConfiguration(dependencies.create("org.antlr:antlr4:4.11.1"))
}
source(layout.projectDirectory.dir("src/main/antlr"))
outputDirectory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ private FileObject getSource(@NonNull final String fileName, @NonNull final Stri
protected void log(@NonNull final String message) {
Objects.requireNonNull(message, "message must not be null");

processingEnv.getMessager().printMessage(Kind.NOTE, message);
processingEnv
.getMessager()
.printMessage(Kind.OTHER, ConfigDataAnnotationProcessor.class.getSimpleName() + ": " + message);
}
}
2 changes: 2 additions & 0 deletions platform-sdk/swirlds-fchashmap/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ plugins {
id("com.hedera.hashgraph.platform-maven-publish")
}

mainModuleInfo { annotationProcessor("com.swirlds.config.processor") }

testModuleInfo {
requires("com.swirlds.base")
requires("com.swirlds.config.extensions")
Expand Down
2 changes: 2 additions & 0 deletions platform-sdk/swirlds-jasperdb/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ plugins {
id("com.hedera.hashgraph.benchmark-conventions")
}

mainModuleInfo { annotationProcessor("com.swirlds.config.processor") }

jmhModuleInfo { requires("jmh.core") }

testModuleInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.swirlds.common.test.merkle.dummy.DummyMerkleInternal;
import com.swirlds.common.test.merkle.util.MerkleTestUtils;
import com.swirlds.config.api.Configuration;
import com.swirlds.merkledb.config.MerkleDbConfig_;
import com.swirlds.test.framework.config.TestConfigBuilder;
import com.swirlds.virtual.merkle.TestKey;
import com.swirlds.virtual.merkle.TestValue;
Expand Down Expand Up @@ -59,9 +60,9 @@ class VirtualMapReconnectTest extends VirtualMapReconnectTestBase {
@BeforeAll
static void beforeAll() throws Exception {
final Configuration config = new TestConfigBuilder()
.withValue("merkleDb.keySetBloomFilterSizeInBytes", 2 * MEBIBYTES_TO_BYTES * BYTES_TO_BITS)
.withValue("merkleDb.keySetHalfDiskHashMapSize", "10000")
.withValue("merkleDb.keySetHalfDiskHashMapBuffer", "1000")
.withValue(MerkleDbConfig_.KEY_SET_BLOOM_FILTER_SIZE_IN_BYTES, 2 * MEBIBYTES_TO_BYTES * BYTES_TO_BITS)
.withValue(MerkleDbConfig_.KEY_SET_HALF_DISK_HASH_MAP_SIZE, "10000")
.withValue(MerkleDbConfig_.KEY_SET_HALF_DISK_HASH_MAP_BUFFER, "1000")
.getOrCreateConfig();

ConfigurationHolder.getInstance().setConfiguration(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.swirlds.common.merkle.MerkleInternal;
import com.swirlds.common.merkle.MerkleNode;
import com.swirlds.common.merkle.synchronization.config.ReconnectConfig;
import com.swirlds.common.merkle.synchronization.config.ReconnectConfig_;
import com.swirlds.common.merkle.synchronization.internal.Lesson;
import com.swirlds.common.merkle.synchronization.internal.QueryResponse;
import com.swirlds.common.test.merkle.dummy.DummyMerkleInternal;
Expand Down Expand Up @@ -151,10 +152,10 @@ public static void startup() throws ConstructableRegistryException, FileNotFound
registry.registerConstructable(new ClassConstructorPair(TestValue.class, TestValue::new));

new TestConfigBuilder()
.withValue("reconnect.active", "true")
.withValue(ReconnectConfig_.ACTIVE, "true")
// This is lower than the default, helps test that is supposed to fail to finish faster.
.withValue("reconnect.asyncStreamTimeout", "5000ms")
.withValue("reconnect.maxAckDelay", "1000ms")
.withValue(ReconnectConfig_.ASYNC_STREAM_TIMEOUT, "5000ms")
.withValue(ReconnectConfig_.MAX_ACK_DELAY, "1000ms")
.getOrCreateConfig();
}

Expand Down
5 changes: 4 additions & 1 deletion platform-sdk/swirlds-platform-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ plugins {
id("java-test-fixtures")
}

mainModuleInfo { runtimeOnly("com.swirlds.config.impl") }
mainModuleInfo {
annotationProcessor("com.swirlds.config.processor")
runtimeOnly("com.swirlds.config.impl")
}

jmhModuleInfo {
requires("com.swirlds.base")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.swirlds.common.system.address.Address;
import com.swirlds.common.system.address.AddressBook;
import com.swirlds.common.test.fixtures.RandomAddressBookGenerator;
import com.swirlds.platform.config.AddressBookConfig_;
import com.swirlds.platform.state.PlatformData;
import com.swirlds.platform.state.PlatformState;
import com.swirlds.platform.state.State;
Expand Down Expand Up @@ -500,9 +501,9 @@ private void assertAddressBookFileContent(
private PlatformContext getPlatformContext(boolean forceUseOfConfigAddressBook) {
return TestPlatformContextBuilder.create()
.withConfiguration(new TestConfigBuilder()
.withValue("addressBook.forceUseOfConfigAddressBook", forceUseOfConfigAddressBook)
.withValue("addressBook.addressBookDirectory", testDirectory.toString())
.withValue("addressBook.maxRecordedAddressBookFiles", 50)
.withValue(AddressBookConfig_.FORCE_USE_OF_CONFIG_ADDRESS_BOOK, forceUseOfConfigAddressBook)
.withValue(AddressBookConfig_.ADDRESS_BOOK_DIRECTORY, testDirectory.toString())
.withValue(AddressBookConfig_.MAX_RECORDED_ADDRESS_BOOK_FILES, 50)
.getOrCreateConfig())
.build();
}
Expand Down
Loading

0 comments on commit 864ea88

Please sign in to comment.