-
Notifications
You must be signed in to change notification settings - Fork 1.6k
test: add dual DB engine test coverage with RocksDB support #6581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
vividctrlalt
wants to merge
4
commits into
tronprotocol:develop
from
vividctrlalt:test/dual-db-engine-coverage
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dbb4699
test: add dual DB engine test coverage with RocksDB support
vividctrlalt 7d961c9
fix(sonar): remove unused ROCKS_DB_ENGINE constant in Storage
vividctrlalt ccec7da
refactor(test): use Typesafe Config system property for DB engine ove…
vividctrlalt f6f2456
refactor(test): revert TestEnv rename and withDbEngineOverride changes
vividctrlalt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -134,6 +134,18 @@ public static void setParam(final String[] args, final String confFileName) { | |
| initLocalWitnesses(config, cmd); | ||
| } | ||
|
|
||
| /** | ||
| * Validate final configuration after all sources (defaults, config, CLI) are applied. | ||
| */ | ||
| public static void validateConfig() { | ||
| if (Arch.isArm64() && !"ROCKSDB".equals(PARAMETER.storage.getDbEngine())) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change |
||
| throw new TronError( | ||
| "ARM64 architecture only supports RocksDB. Current engine: " | ||
| + PARAMETER.storage.getDbEngine(), | ||
| TronError.ErrCode.PARAMETER_INIT); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Apply parameters from config file. | ||
| */ | ||
|
|
||
This file contains hidden or 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 hidden or 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
98 changes: 98 additions & 0 deletions
98
framework/src/test/java/org/tron/common/BaseMethodTest.java
This file contains hidden or 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,98 @@ | ||
| package org.tron.common; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.rules.TemporaryFolder; | ||
| import org.tron.common.application.Application; | ||
| import org.tron.common.application.ApplicationFactory; | ||
| import org.tron.common.application.TronApplicationContext; | ||
| import org.tron.core.ChainBaseManager; | ||
| import org.tron.core.config.DefaultConfig; | ||
| import org.tron.core.config.args.Args; | ||
| import org.tron.core.db.Manager; | ||
|
|
||
| /** | ||
| * Base class for tests that need a fresh Spring context per test method. | ||
| * | ||
| * Each @Test method gets its own TronApplicationContext, created in @Before | ||
| * and destroyed in @After, ensuring full isolation between tests. | ||
| * | ||
| * Subclasses can customize behavior by overriding hook methods: | ||
| * extraArgs() — additional CLI args (e.g. "--debug") | ||
| * configFile() — config file (default: config-test.conf) | ||
| * beforeContext() — runs after Args.setParam, before Spring context creation | ||
| * afterInit() — runs after Spring context is ready (e.g. get extra beans) | ||
| * beforeDestroy() — runs before context shutdown (e.g. close resources) | ||
| * | ||
| * Use this when: | ||
| * - methods modify database state that would affect other methods | ||
| * - methods need different CommonParameter settings (e.g. setP2pDisable) | ||
| * - methods need beforeContext() to configure state before Spring starts | ||
| * | ||
| * If methods are read-only and don't interfere with each other, use BaseTest instead. | ||
| * Tests that don't need Spring (e.g. pure unit tests) should NOT extend either base class. | ||
| */ | ||
| @Slf4j | ||
| public abstract class BaseMethodTest { | ||
|
|
||
| @Rule | ||
| public final TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
|
||
| protected TronApplicationContext context; | ||
| protected Application appT; | ||
| protected Manager dbManager; | ||
| protected ChainBaseManager chainBaseManager; | ||
|
|
||
| protected String[] extraArgs() { | ||
| return new String[0]; | ||
| } | ||
|
|
||
| protected String configFile() { | ||
| return TestConstants.TEST_CONF; | ||
| } | ||
|
|
||
| @Before | ||
| public final void initContext() throws IOException { | ||
| String[] baseArgs = new String[]{ | ||
| "--output-directory", temporaryFolder.newFolder().toString()}; | ||
| String[] allArgs = mergeArgs(baseArgs, extraArgs()); | ||
| Args.setParam(allArgs, configFile()); | ||
| beforeContext(); | ||
| context = new TronApplicationContext(DefaultConfig.class); | ||
| appT = ApplicationFactory.create(context); | ||
| dbManager = context.getBean(Manager.class); | ||
| chainBaseManager = context.getBean(ChainBaseManager.class); | ||
| afterInit(); | ||
| } | ||
|
|
||
| protected void beforeContext() { | ||
| } | ||
|
|
||
| protected void afterInit() { | ||
| } | ||
|
|
||
| @After | ||
| public final void destroyContext() { | ||
| beforeDestroy(); | ||
| if (appT != null) { | ||
| appT.shutdown(); | ||
| } | ||
| if (context != null) { | ||
| context.close(); | ||
| } | ||
| Args.clearParam(); | ||
| } | ||
|
|
||
| protected void beforeDestroy() { | ||
| } | ||
|
|
||
| private static String[] mergeArgs(String[] base, String[] extra) { | ||
| String[] result = Arrays.copyOf(base, base.length + extra.length); | ||
| System.arraycopy(extra, 0, result, base.length, extra.length); | ||
| return result; | ||
| } | ||
| } |
This file contains hidden or 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
32 changes: 32 additions & 0 deletions
32
framework/src/test/java/org/tron/common/TestConstants.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,7 +1,39 @@ | ||
| package org.tron.common; | ||
|
|
||
| import static org.junit.Assume.assumeFalse; | ||
|
|
||
| import org.tron.common.arch.Arch; | ||
|
|
||
| /** | ||
| * Centralized test environment constants and utilities. | ||
| * | ||
| * <h3>DB engine override for dual-engine testing</h3> | ||
| * Gradle tasks ({@code test} on ARM64, {@code testWithRocksDb}) set the JVM system property | ||
| * {@code -Dstorage.db.engine=ROCKSDB}. Because test config files are loaded from the classpath | ||
| * via {@code ConfigFactory.load(fileName)}, Typesafe Config automatically merges system | ||
| * properties with higher priority than the config file values. This means the config's | ||
| * {@code storage.db.engine = "LEVELDB"} is overridden transparently, without any code changes | ||
| * in individual tests. | ||
| * | ||
| * <p><b>IMPORTANT:</b> Config files MUST be classpath resources (in {@code src/test/resources/}), | ||
| * NOT standalone files in the working directory. If a config file exists on disk, | ||
| * {@code Configuration.getByFileName} falls back to {@code ConfigFactory.parseFile()}, | ||
| * which does NOT merge system properties, and the engine override will silently fail. | ||
| */ | ||
| public class TestConstants { | ||
|
|
||
| public static final String TEST_CONF = "config-test.conf"; | ||
| public static final String NET_CONF = "config.conf"; | ||
| public static final String MAINNET_CONF = "config-test-mainnet.conf"; | ||
| public static final String DBBACKUP_CONF = "config-test-dbbackup.conf"; | ||
| public static final String LOCAL_CONF = "config-localtest.conf"; | ||
| public static final String STORAGE_CONF = "config-test-storagetest.conf"; | ||
| public static final String INDEX_CONF = "config-test-index.conf"; | ||
|
|
||
| /** | ||
| * Skips the current test on ARM64 where LevelDB JNI is unavailable. | ||
| */ | ||
| public static void assumeLevelDbAvailable() { | ||
| assumeFalse("LevelDB JNI unavailable on ARM64", Arch.isArm64()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args.validateConfig()is executed beforeKeystoreFactory.start(). With the defaultconfig.confsettingdb.engine = "LEVELDB", running in--keystore-factorymode (e.g., when only generating or importing a keystore on ARM64) causes the program to exit early due to a database engine validation failure. However, this execution path does not require the database to be opened at all.It would be preferable to defer this validation until the code path that actually initializes the database, or to skip the validation entirely for no-DB modes such as
--keystore-factory.