Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure DiskSpaceMonitor is initialised on each Queue instantiation #1474

Open
tgd opened this issue Nov 14, 2023 · 0 comments
Open

Ensure DiskSpaceMonitor is initialised on each Queue instantiation #1474

tgd opened this issue Nov 14, 2023 · 0 comments
Assignees

Comments

@tgd
Copy link
Contributor

tgd commented Nov 14, 2023

Previously, the disk space monitor was only instantiated when acquiring a store file. This meant that disk space monitor only monitored queue paths that had been appended to by the current Queue API instance. After this change the disk space monitor will monitor each queue path even if an appender was never instantiated or used. For test coverage please see:

class DiskSpaceMonitoringIntegrationTest extends QueueTestCommon {
/**
* Stores which paths are being monitored by the {@link net.openhft.chronicle.threads.DiskSpaceMonitor}.
*/
private Map<String, FileStore> monitoredPaths;
@SuppressWarnings("unchecked")
@BeforeEach
public void beforeEach() throws NoSuchFieldException, IllegalAccessException {
Field fileStoreCacheMap = DiskSpaceMonitor.class.getDeclaredField("fileStoreCacheMap");
fileStoreCacheMap.setAccessible(true);
monitoredPaths = (Map<String, FileStore>) fileStoreCacheMap.get(DiskSpaceMonitor.INSTANCE);
}
@Nested
class EnsureThatPollIsCalledInDifferentScenarioTests {
@Test
void newQueueNoWrite() {
File tmpDir = getTmpDir();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder().path(tmpDir).build();
ExcerptAppender appender = queue.createAppender()) {
assertMapped(tmpDir);
} finally {
IOTools.deleteDirWithFiles(tmpDir);
}
}
@Test
void newQueueWithWrite() {
File tmpDir = getTmpDir();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder().path(tmpDir).build();
ExcerptAppender appender = queue.createAppender()) {
appender.writeText("Test");
assertMapped(tmpDir);
} finally {
IOTools.deleteDirWithFiles(tmpDir);
}
}
@Test
void newQueueJustTail() {
File tmpDir = getTmpDir();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder().path(tmpDir).build();
ExcerptTailer tailer = queue.createTailer()) {
assertMapped(tmpDir);
} finally {
IOTools.deleteDirWithFiles(tmpDir);
}
}
@Test
void existingQueueNoWrite() {
File tmpDir = getTmpDir();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder().path(tmpDir).build();
ExcerptAppender appender = queue.createAppender()) {
// Intentional no-op
}
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder().path(tmpDir).build();
ExcerptAppender appender = queue.createAppender()) {
assertMapped(tmpDir);
}
}
@Test
void existingQueueWithWrite() {
File tmpDir = getTmpDir();
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder().path(tmpDir).build();
ExcerptAppender appender = queue.createAppender()) {
// Intentional no-op
}
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder().path(tmpDir).build();
ExcerptAppender appender = queue.createAppender()) {
appender.writeText("Test");
assertMapped(tmpDir);
}
}
}
private void assertMapped(File queuePath) {
String path = queuePath.getAbsolutePath().toString();
assertTrue(monitoredPaths.containsKey(path), () -> "Expected that the following queue path should be monitored by the disk space monitor, but it was not. Path: " + path);
}

@tgd tgd self-assigned this Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant