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());
}
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);
}
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);
}
Aggregations