Skip to content

Commit

Permalink
fixed net.openhft.chronicle.queue.impl.single.ToEndTest.toEndAfterWri…
Browse files Browse the repository at this point in the history
…teTest
  • Loading branch information
Rob Austin committed Aug 12, 2016
1 parent 997695a commit 008c896
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Expand Up @@ -1157,13 +1157,15 @@ public final ExcerptTailer toStart() {
* @return the last index at the time this method was called.
*/
private long approximateLastIndex() throws EOFException {

RollCycle rollCycle = queue.rollCycle();
final int lastCycle = queue.lastCycle();
try {
RollCycle rollCycle = queue.rollCycle();
final int lastCycle = queue.lastCycle();
if (lastCycle == Integer.MIN_VALUE)
return rollCycle.toIndex(queue.cycle(), 0L);

final WireStore wireStore = queue.storeForCycle(lastCycle, queue.epoch(), false);
this.cycle = lastCycle;
assert wireStore != null;

if (store != null)
Expand All @@ -1172,13 +1174,16 @@ private long approximateLastIndex() throws EOFException {
if (this.store != wireStore) {
this.store = wireStore;
resetWires();
this.cycle = lastCycle;
}
// give the position of the last entry and
// flag we want to count it even though we don't know if it will be meta data or not.

long sequenceNumber = store.sequenceForPosition(this, Long.MAX_VALUE, false);
return rollCycle.toIndex(lastCycle, sequenceNumber);

} catch (EOFException e) {
this.index = queue.rollCycle().toIndex(queue.cycle(), Long.MAX_VALUE);
throw e;
} catch (StreamCorruptedException | UnrecoverableTimeoutException e) {
throw new IllegalStateException(e);
}
Expand Down
Expand Up @@ -248,6 +248,8 @@ public void toEndBeforeWriteTest() {
IOTools.shallowDeleteDirWithFiles(baseDir);
}

long lastCycle;

@Test
public void toEndAfterWriteTest() {
String baseDir = OS.TARGET + "/toEndAfterWriteTest";
Expand All @@ -256,14 +258,19 @@ public void toEndAfterWriteTest() {
final SetTimeProvider stp = new SetTimeProvider();
stp.currentTimeMillis(1470757797000L);

ChronicleQueue wqueue = SingleChronicleQueueBuilder
RollingChronicleQueue wqueue = SingleChronicleQueueBuilder
.binary(baseDir)
.rollCycle(RollCycles.TEST_SECONDLY)
.timeProvider(stp)
.build();
ExcerptAppender appender = wqueue.acquireAppender();

for (int i = 0; i < 10; i++) {
appender.writeText("hi-"+i);
try(DocumentContext dc = appender.writingDocument()){
dc.wire().write().text("hi-"+i);
lastCycle = wqueue.rollCycle().toCycle(dc.index());
}

stp.currentTimeMillis(stp.currentTimeMillis() + 1000);
}

Expand All @@ -282,7 +289,9 @@ public void toEndAfterWriteTest() {
assertNull(tailer.readText());
stp.currentTimeMillis(stp.currentTimeMillis() + 1000);

assertNull(rqueue.createTailer().toEnd().readText());
ExcerptTailer tailer1 = rqueue.createTailer();
ExcerptTailer excerptTailer = tailer1.toEnd();
assertNull(excerptTailer.readText());

IOTools.shallowDeleteDirWithFiles(baseDir);
}
Expand Down

0 comments on commit 008c896

Please sign in to comment.