Search in sources :

Example 1 with StoreBuilder

use of tech.pegasys.teku.storage.store.StoreBuilder in project teku by ConsenSys.

the class StorageBackedRecentChainDataTest method storageBackedClient_storeInitializeViaGetStoreRequestAfterTimeout.

@Test
public void storageBackedClient_storeInitializeViaGetStoreRequestAfterTimeout() throws ExecutionException, InterruptedException {
    SafeFuture<Optional<StoreBuilder>> storeRequestFuture = new SafeFuture<>();
    when(storageQueryChannel.onStoreRequest()).thenReturn(SafeFuture.failedFuture(new TimeoutException())).thenReturn(storeRequestFuture);
    final SafeFuture<RecentChainData> client = StorageBackedRecentChainData.create(new StubMetricsSystem(), StoreConfig.createDefault(), asyncRunner, storageQueryChannel, storageUpdateChannel, voteUpdateChannel, finalizedCheckpointChannel, chainHeadChannel, spec);
    // We should have posted a request to get the store from storage
    verify(storageQueryChannel).onStoreRequest();
    // Client shouldn't be initialized yet
    assertThat(client).isNotDone();
    assertThat(asyncRunner.countDelayedActions()).isEqualTo(1);
    asyncRunner.executeQueuedActions();
    // Now set the genesis state
    final StoreBuilder genesisStoreBuilder = StoreBuilder.forkChoiceStoreBuilder(SYNC_RUNNER, new StubMetricsSystem(), spec, BlockProvider.NOOP, StateAndBlockSummaryProvider.NOOP, AnchorPoint.fromGenesisState(spec, INITIAL_STATE), UInt64.ZERO);
    storeRequestFuture.complete(Optional.of(genesisStoreBuilder));
    assertThat(client).isCompleted();
    assertStoreInitialized(client.get());
    assertStoreIsSet(client.get());
    StoreAssertions.assertStoresMatch(client.get().getStore(), genesisStoreBuilder.build());
}
Also used : Optional(java.util.Optional) StoreBuilder(tech.pegasys.teku.storage.store.StoreBuilder) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 2 with StoreBuilder

use of tech.pegasys.teku.storage.store.StoreBuilder in project teku by ConsenSys.

the class AbstractKvStoreDatabaseTest method createMemoryStore_priorToGenesisTime.

@Test
public void createMemoryStore_priorToGenesisTime() {
    database.storeInitialAnchor(genesisAnchor);
    final Optional<StoreBuilder> storeBuilder = ((KvStoreDatabase) database).createMemoryStore(() -> 0L);
    assertThat(storeBuilder).isNotEmpty();
    final UpdatableStore store = storeBuilder.get().asyncRunner(mock(AsyncRunner.class)).blockProvider(mock(BlockProvider.class)).stateProvider(mock(StateAndBlockSummaryProvider.class)).build();
    assertThat(store.getTime()).isEqualTo(genesisTime);
}
Also used : StoreBuilder(tech.pegasys.teku.storage.store.StoreBuilder) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) BlockProvider(tech.pegasys.teku.dataproviders.lookup.BlockProvider) AbstractStorageBackedDatabaseTest(tech.pegasys.teku.storage.server.AbstractStorageBackedDatabaseTest) Test(org.junit.jupiter.api.Test)

Example 3 with StoreBuilder

use of tech.pegasys.teku.storage.store.StoreBuilder in project teku by ConsenSys.

the class StorageBackedRecentChainDataTest method storageBackedClient_storeInitializeViaGetStoreRequest.

@Test
public void storageBackedClient_storeInitializeViaGetStoreRequest() throws ExecutionException, InterruptedException {
    SafeFuture<Optional<StoreBuilder>> storeRequestFuture = new SafeFuture<>();
    when(storageQueryChannel.onStoreRequest()).thenReturn(storeRequestFuture);
    final StoreConfig storeConfig = StoreConfig.builder().hotStatePersistenceFrequencyInEpochs(5).build();
    final SafeFuture<RecentChainData> client = StorageBackedRecentChainData.create(new StubMetricsSystem(), storeConfig, asyncRunner, storageQueryChannel, storageUpdateChannel, voteUpdateChannel, finalizedCheckpointChannel, chainHeadChannel, spec);
    // We should have posted a request to get the store from storage
    verify(storageQueryChannel).onStoreRequest();
    // Client shouldn't be initialized yet
    assertThat(client).isNotDone();
    // Post a store response to complete initialization
    final StoreBuilder genesisStoreBuilder = StoreBuilder.forkChoiceStoreBuilder(SYNC_RUNNER, new StubMetricsSystem(), spec, BlockProvider.NOOP, StateAndBlockSummaryProvider.NOOP, AnchorPoint.fromGenesisState(spec, INITIAL_STATE), UInt64.ZERO);
    storeRequestFuture.complete(Optional.of(genesisStoreBuilder));
    assertThat(client).isCompleted();
    assertStoreInitialized(client.get());
    assertStoreIsSet(client.get());
    final UpdatableStore expectedStore = genesisStoreBuilder.storeConfig(storeConfig).build();
    StoreAssertions.assertStoresMatch(client.get().getStore(), expectedStore);
}
Also used : Optional(java.util.Optional) StoreBuilder(tech.pegasys.teku.storage.store.StoreBuilder) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) StoreConfig(tech.pegasys.teku.storage.store.StoreConfig) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 StoreBuilder (tech.pegasys.teku.storage.store.StoreBuilder)3 Optional (java.util.Optional)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 StubMetricsSystem (tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem)2 UpdatableStore (tech.pegasys.teku.storage.store.UpdatableStore)2 TimeoutException (java.util.concurrent.TimeoutException)1 BlockProvider (tech.pegasys.teku.dataproviders.lookup.BlockProvider)1 AbstractStorageBackedDatabaseTest (tech.pegasys.teku.storage.server.AbstractStorageBackedDatabaseTest)1 StoreConfig (tech.pegasys.teku.storage.store.StoreConfig)1