@Test void shouldLimitNumberOfCachedStates() throws Exception { chainBuilder.generateBlocksUpToSlot(MAXIMUM_CACHE_SIZE + 1); when(database.getLatestAvailableFinalizedState(any())) .thenReturn(Optional.of(chainBuilder.getGenesis().getState())); allowStreamingBlocks(); for (int i = 1; i <= MAXIMUM_CACHE_SIZE; i++) { cache.getFinalizedState(UInt64.valueOf(i)); } cache.getFinalizedState(UInt64.valueOf(MAXIMUM_CACHE_SIZE + 1)); cache.getFinalizedState(ONE); verify(database, times(2)).streamFinalizedBlocks(ONE, ONE); }
public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } }
FinalizedStateCache { public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } } }
FinalizedStateCache { public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } } FinalizedStateCache(
      final Database database, final int maximumCacheSize, final boolean useSoftReferences); }
FinalizedStateCache { public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } } FinalizedStateCache(
      final Database database, final int maximumCacheSize, final boolean useSoftReferences); Optional<BeaconState> getFinalizedState(final UInt64 slot); }
FinalizedStateCache { public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } } FinalizedStateCache(
      final Database database, final int maximumCacheSize, final boolean useSoftReferences); Optional<BeaconState> getFinalizedState(final UInt64 slot);  }