-
Notifications
You must be signed in to change notification settings - Fork 522
/
DiskSpaceMonitoringIntegrationTest.java
110 lines (94 loc) · 4.15 KB
/
DiskSpaceMonitoringIntegrationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package net.openhft.chronicle.queue;
import net.openhft.chronicle.core.io.IOTools;
import net.openhft.chronicle.queue.impl.single.SingleChronicleQueue;
import net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder;
import net.openhft.chronicle.threads.DiskSpaceMonitor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.lang.reflect.Field;
import java.nio.file.FileStore;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Whilst {@link DiskSpaceMonitor} is defined in the Threads module Queue is heavily dependent on it. Of particular
* importance is ensuring that queue paths are added to the monitor appropriately by calling the
* {@link DiskSpaceMonitor#pollDiskSpace(File)} method.
*/
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);
}
}