Skip to content

Commit

Permalink
Improve StoreTailer test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
yevgenp committed Jun 20, 2024
1 parent bef580a commit db19f1e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ private ExcerptTailer callOriginalToEnd() {
queue.refreshDirectoryListing();
// due to a race condition, where the queue rolls as we are processing toEnd()
// we may get a NotReachedException ( see https://github.com/OpenHFT/Chronicle-Queue/issues/702 )
// hence are are just going to retry.
// hence we are just going to retry.
try {
return originalToEnd();
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,71 @@ public void run() throws InterruptedException {
}
}
}

@Test(expected = IllegalStateException.class)
public void cantMoveToStartDuringDocumentReading() {
File dir = getTmpDir();
try (SingleChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build();
ExcerptTailer tailer = queue.createTailer();
ExcerptAppender appender = queue.createAppender()) {
appender.writeText("Hello World");
try (DocumentContext dc = tailer.readingDocument(true)) {
assertTrue(dc.isPresent());
assertTrue(dc.isMetaData());
assertEquals("header", dc.wire().readEvent(String.class));
assertTrue(tailer.toString().contains("StoreTailer{"));
tailer.toStart();//forbidden
}
}
}

@Test(expected = IllegalStateException.class)
public void cantMoveToEndDuringDocumentReading() {
File dir = getTmpDir();
try (SingleChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build();
ExcerptTailer tailer = queue.createTailer();
ExcerptAppender appender = queue.createAppender()) {
appender.writeText("Hello World");
try (DocumentContext dc = tailer.readingDocument(true)) {
assertTrue(dc.isPresent());
assertTrue(dc.isMetaData());
assertEquals("header", dc.wire().readEvent(String.class));
assertTrue(tailer.toString().contains("StoreTailer{"));
tailer.toEnd();//forbidden
}
}
}

@Test
public void testStriding() {
File dir = getTmpDir();
try (SingleChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build();
ExcerptTailer tailer = queue.createTailer()) {
tailer.striding(true);
assertTrue(tailer.striding());
}
}

@Test
public void testMoveToIndex() {
File dir = getTmpDir();
try (SingleChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build();
ExcerptTailer tailer = queue.createTailer();
ExcerptAppender appender = queue.createAppender()) {
appender.writeText("Hello World");
try (DocumentContext dc = tailer.readingDocument()) {
tailer.moveToIndex(tailer.index() + 1);
}
}
}

@Test
public void testExcerptsInCycle() {
File dir = getTmpDir();
try (SingleChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build();
ExcerptTailer tailer = queue.createTailer()) {
tailer.excerptsInCycle(tailer.cycle());
}
}

}

0 comments on commit db19f1e

Please sign in to comment.