test: add dual DB engine test coverage with RocksDB support#6581
test: add dual DB engine test coverage with RocksDB support#6581vividctrlalt wants to merge 4 commits intotronprotocol:developfrom
Conversation
- Refactor config validation to support dual-engine (LevelDB/RocksDB) test override - Add BaseMethodTest for per-method Spring context isolation - Unify DB tests with parameterized dual-engine coverage - Migrate 176+ BaseTest subclasses to support dual DB engine override - Fix flaky tests (TrieTest, ConditionallyStopTest, NeedBeanCondition null safety) - Add ARM64 RocksDB engine test support - Add RocksDB engine test step to PR check workflow - Centralize config file constants in TestEnv
| /** | ||
| * Validate final configuration after all sources (defaults, config, CLI) are applied. | ||
| */ | ||
| public static void validateConfig() { |
There was a problem hiding this comment.
Args.validateConfig() is executed before KeystoreFactory.start(). With the default config.conf setting db.engine = "LEVELDB", running in --keystore-factory mode (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.
| * 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.
Change "ROCKSDB".equals(PARAMETER.storage.getDbEngine()) to "ROCKSDB".equals(PARAMETER.storage.getDbEngine()).toUpperCase(), so that values like rocksdb or RocksDB are also supported.
|
The statement “ Although To illustrate this, I added a log in the // added variable
String engineBeforeReset = Args.getInstance().getStorage().getDbEngine();
Args.setParam(new String[]{}, TestEnv.TEST_CONF);
// added log
logger.info("[testWithRocksDb-demo] requested={}, beforeReset={}, afterReset={}",
System.getProperty("tron.test.db.engine"),
engineBeforeReset,
Args.getInstance().getStorage().getDbEngine());Running: produces: This confirms that although RocksDB is requested and initially active, the global engine configuration is subsequently reverted to LevelDB during the test execution. |
…rride Replace withDbEngineOverride() CLI injection with Gradle systemProperty 'storage.db.engine' which ConfigFactory.load() merges automatically. Rename TestEnv back to TestConstants to minimize review diff.
Restore 212 test files to develop state. The DB engine override is now handled by Gradle systemProperty injection via Typesafe Config, so individual test files no longer need withDbEngineOverride() wrapping or TestConstants->TestEnv rename.
Summary
java-tron supports both LevelDB and RocksDB, but the test suite only ran with the default engine (LevelDB). This PR adds dual DB engine test coverage so the same business tests can run under both engines, and fixes several related issues.
What changed
TestEnvclass with config file constants (TEST_CONF,NET_CONF,MAINNET_CONF, etc.) and utility methods, replacing 200+ hardcoded config strings across test fileswithDbEngineOverride()toBaseTestandTestEnv, allowing Gradle to inject--storage-db-engine ROCKSDBvia system propertytron.test.db.engineDbDataSourceImplTestwith@RunWith(Parameterized.class)to run common DB operations (put/get, batch, reset, iterator, etc.) against both LevelDB and RocksDB, eliminating ~400 lines of duplicate test code fromLevelDbDataSourceImplTestandRocksDbDataSourceImplTestBaseMethodTest: New base class for tests requiring per-method Spring context isolation (fresh context per@Testmethod)assumeLevelDbAvailable(); Gradle ARM64 builds auto-inject RocksDB enginetestWithRocksDbtask: New CI task that reruns the full test suite with RocksDB enginetestWithRocksDbstep topr-check.ymlfor x86_64 buildsArm64EngineOverrideTestverifies ARM64 silently forces RocksDB even when config says LevelDBTrieTest(missing test body),ConditionallyStopTest(Spring context leak),NeedBeanCondition(null-safety),NativeMessageQueue(missing shutdown hook)Why
Test plan
./gradlew :framework:test— all existing tests pass./gradlew :framework:testWithRocksDb— business tests pass with RocksDB engine./gradlew :framework:test --tests "org.tron.common.storage.DbDataSourceImplTest"— parameterized tests run both engines./gradlew :framework:test --tests "org.tron.common.storage.Arm64EngineOverrideTest"— ARM64 mock tests pass