Search in sources :

Example 1 with TestKvStoreDatabase

use of tech.pegasys.teku.storage.server.kvstore.TestKvStoreDatabase in project teku by ConsenSys.

the class DatabaseMigraterTest method shouldCopyVariablesFromHotDb.

@Test
void shouldCopyVariablesFromHotDb(@TempDir Path tmpDir) throws Exception {
    final DataDirLayout dataDirLayout = prepareTempDir(tmpDir, "5");
    DatabaseMigrater migrater = getDatabaseMigrater(dataDirLayout);
    final UInt64 genesis = dataStructureUtil.randomUInt64();
    final Checkpoint finalizedCheckpoint = dataStructureUtil.randomCheckpoint();
    migrater.openDatabases(DatabaseVersion.V5, DatabaseVersion.LEVELDB2);
    TestKvStoreDatabase originalDb = new TestKvStoreDatabase(migrater.getOriginalDatabase());
    try (KvStoreHotDao.HotUpdater updater = originalDb.getHotDao().hotUpdater()) {
        updater.setGenesisTime(genesis);
        updater.setFinalizedCheckpoint(finalizedCheckpoint);
        updater.commit();
    }
    migrater.migrateData();
    TestKvStoreDatabase newDb = new TestKvStoreDatabase(migrater.getNewDatabase());
    assertThat(newDb.getHotDao().getGenesisTime()).isEqualTo(originalDb.getHotDao().getGenesisTime());
    assertThat(newDb.getHotDao().getGenesisTime()).contains(genesis);
    assertThat(newDb.getHotDao().getFinalizedCheckpoint()).isEqualTo(originalDb.getHotDao().getFinalizedCheckpoint());
    assertThat(newDb.getHotDao().getFinalizedCheckpoint()).contains(finalizedCheckpoint);
    migrater.closeDatabases();
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) KvStoreHotDao(tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao) TestKvStoreDatabase(tech.pegasys.teku.storage.server.kvstore.TestKvStoreDatabase) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 2 with TestKvStoreDatabase

use of tech.pegasys.teku.storage.server.kvstore.TestKvStoreDatabase in project teku by ConsenSys.

the class DatabaseMigraterTest method shouldCopyColumnData.

@Test
void shouldCopyColumnData(@TempDir Path tmpDir) throws IOException, DatabaseMigraterError {
    final DataDirLayout dataDirLayout = prepareTempDir(tmpDir, "5");
    DatabaseMigrater migrater = getDatabaseMigrater(dataDirLayout);
    final BeaconBlockAndState blockAndState = dataStructureUtil.randomBlockAndState(1_000_000);
    migrater.openDatabases(DatabaseVersion.V5, DatabaseVersion.LEVELDB2);
    TestKvStoreDatabase originalDb = new TestKvStoreDatabase(migrater.getOriginalDatabase());
    try (KvStoreHotDao.HotUpdater updater = originalDb.getHotDao().hotUpdater()) {
        updater.addHotState(blockAndState.getBlock().getRoot(), blockAndState.getState());
        updater.commit();
    }
    migrater.migrateData();
    TestKvStoreDatabase newDb = new TestKvStoreDatabase(migrater.getNewDatabase());
    assertThat(newDb.getHotDao().getHotState(blockAndState.getRoot())).contains(blockAndState.getState());
    migrater.closeDatabases();
}
Also used : KvStoreHotDao(tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao) TestKvStoreDatabase(tech.pegasys.teku.storage.server.kvstore.TestKvStoreDatabase) BeaconBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)2 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)2 TestKvStoreDatabase (tech.pegasys.teku.storage.server.kvstore.TestKvStoreDatabase)2 KvStoreHotDao (tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 BeaconBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState)1 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)1