Skip to content

Commit

Permalink
Guard the check pointer for a 0 ms time threshold
Browse files Browse the repository at this point in the history
And also fix the tests to take the randomised start offset into account.
  • Loading branch information
chrisvest committed Dec 6, 2016
1 parent 66e6a65 commit e8691fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Expand Up @@ -30,13 +30,13 @@ public class TimeCheckPointThreshold extends AbstractCheckPointThreshold
private final long timeMillisThreshold;
private final Clock clock;

public TimeCheckPointThreshold( long timeMillisThreshold, Clock clock )
public TimeCheckPointThreshold( long thresholdMillis, Clock clock )
{
this.timeMillisThreshold = timeMillisThreshold;
this.timeMillisThreshold = thresholdMillis;
this.clock = clock;
// The random start offset means database in a cluster will not all check-point at the same time.
long randomStartOffset = ThreadLocalRandom.current().nextLong( timeMillisThreshold );
this.nextCheckPointTime = clock.millis() + timeMillisThreshold + randomStartOffset;
long randomStartOffset = thresholdMillis > 0? ThreadLocalRandom.current().nextLong( thresholdMillis ) : 0;
this.nextCheckPointTime = clock.millis() + thresholdMillis + randomStartOffset;

}

Expand Down
Expand Up @@ -61,7 +61,7 @@ public void shouldBeTrueIfTimeThresholdIsReachedAndThereAreCommittedTransactions
TimeCheckPointThreshold threshold = new TimeCheckPointThreshold( 100, clock );
threshold.initialize( 2 );

clock.forward( 100, MILLISECONDS );
clock.forward( 199, MILLISECONDS );

// when
boolean checkPointingNeeded = threshold.isCheckPointingNeeded( 42, triggerInfo );
Expand All @@ -78,7 +78,7 @@ public void shouldBeFalseIfTimeThresholdIsReachedButThereAreNoCommittedTransacti
TimeCheckPointThreshold threshold = new TimeCheckPointThreshold( 100, clock );
threshold.initialize( 42 );

clock.forward( 100, MILLISECONDS );
clock.forward( 199, MILLISECONDS );

// when
boolean checkPointingNeeded = threshold.isCheckPointingNeeded( 42, triggerInfo );
Expand All @@ -96,7 +96,7 @@ public void shouldBeFalseIfTimeThresholdIsReachedAfterCheckPointHappenedButThere
TimeCheckPointThreshold threshold = new TimeCheckPointThreshold( 100, clock );
threshold.initialize( 2 );

clock.forward( 100, MILLISECONDS );
clock.forward( 199, MILLISECONDS );

threshold.checkPointHappened( 42 );

Expand All @@ -118,7 +118,7 @@ public void shouldBeTrueIfTimeThresholdIsReachedAfterCheckPointHappenedAndThereA
TimeCheckPointThreshold threshold = new TimeCheckPointThreshold( 100, clock );
threshold.initialize( 2 );

clock.forward( 100, MILLISECONDS );
clock.forward( 199, MILLISECONDS );

threshold.checkPointHappened( 42 );

Expand Down

0 comments on commit e8691fd

Please sign in to comment.