Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
clock.step(2L, ChronoUnit.HOURS)
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish committed Apr 30, 2019
1 parent b460f19 commit c64c680
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.testutil.TestClock;

import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalLong;
Expand Down Expand Up @@ -434,13 +435,15 @@ public void shouldEvictMultipleOldTransactions() {

@Test
public void shouldEvictSingleOldTransaction() {
final int maxTransactionRetentionHours = 1000;
final int maxTransactionRetentionHours = 1;
final PendingTransactions transactions =
new PendingTransactions(
maxTransactionRetentionHours, MAX_TRANSACTIONS, clock, metricsSystem);
transactions.addRemoteTransaction(transaction1);
assertThat(transactions.size()).isEqualTo(1);
clock.stepMillis(2000);

clock.step(2L, ChronoUnit.HOURS);

transactions.evictOldTransactions();
assertThat(transactions.size()).isEqualTo(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalUnit;

public class TestClock extends Clock {
public static Clock fixed() {
Expand All @@ -42,4 +44,8 @@ public Instant instant() {
public void stepMillis(final long millis) {
now = now.plusMillis(millis);
}

public void step(final long a, final TemporalUnit unit) {
now = now.plus(a, unit);
}
}

0 comments on commit c64c680

Please sign in to comment.