Skip to content

Commit

Permalink
fixed test case net.openhft.chronicle.queue.impl.single.RollCycleEnco…
Browse files Browse the repository at this point in the history
…deSequenceTest
  • Loading branch information
Rob Austin committed Nov 22, 2017
1 parent 4674fe1 commit 4dfe875
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Expand Up @@ -17,7 +17,6 @@ class RollCycleEncodeSequence implements Sequence {
this.sequenceMask = (1L << cycleShift) - 1;
this.writePositionAndSequence = writePositionAndSequence instanceof TwoLongValue ?
(TwoLongValue) writePositionAndSequence : null;

}

@Override
Expand Down Expand Up @@ -58,8 +57,8 @@ public long getSequence(long forWritePosition) {

// the below cast is safe as cycleMask always returns a number guaranteed within int range
int writePositionCycle = (int) cycleMask(forWritePosition);
final int lowerBitsOfWp = toLowerBitsWritePosition(toLongValue(writePositionCycle, 0));
final int toLowerBitsWritePosition = toLowerBitsWritePosition(cycleMask(sequenceValue));
final long lowerBitsOfWp = toLowerBitsWritePosition(toLongValue(writePositionCycle, 0));
final long toLowerBitsWritePosition = toLowerBitsWritePosition(cycleMask(sequenceValue));

if (lowerBitsOfWp == toLowerBitsWritePosition)
return toSequenceNumber(sequenceValue);
Expand All @@ -71,16 +70,16 @@ private long cycleMask(long number) {
return number & THIRTY_ONE_BITS;
}

private long toLongValue(int cycle, long sequenceNumber) {
return ((long) cycle << cycleShift) + (sequenceNumber & sequenceMask);
private long toLongValue(long cycle, long sequenceNumber) {
return (cycle << cycleShift) + (sequenceNumber & sequenceMask);
}

public long toSequenceNumber(long index) {
return index & sequenceMask;
}

private int toLowerBitsWritePosition(long index) {
return toCycle(index);
private long toLowerBitsWritePosition(long index) {
return index >> cycleShift;
}

private int toCycle(long number) {
Expand Down
Expand Up @@ -27,7 +27,7 @@ public static Collection<Object[]> data() {
{RollCycles.DAILY},
{RollCycles.HOURLY},
{RollCycles.MINUTELY},
//{RollCycles.HUGE_DAILY} java.lang.IllegalArgumentException: Unsigned Int 31-bit -13228 out of range
{RollCycles.HUGE_DAILY}
});
}

Expand Down

0 comments on commit 4dfe875

Please sign in to comment.