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 21, 2024
1 parent bef580a commit 11237af
Show file tree
Hide file tree
Showing 2 changed files with 74 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,77 @@ public void run() throws InterruptedException {
}
}
}

@Test(expected = IllegalStateException.class)
public void cantMoveToStartDuringDocumentReading() {
File dir = getTmpDir();
try (SingleChronicleQueue queue = ChronicleQueue.singleBuilder(dir)
.testBlockSize().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)
.testBlockSize().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)
.testBlockSize().build();
ExcerptTailer tailer = queue.createTailer()) {
tailer.striding(true);
assertTrue(tailer.striding());
}
}

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

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

}

0 comments on commit 11237af

Please sign in to comment.