-
Notifications
You must be signed in to change notification settings - Fork 521
/
QueueInspectorTest.java
72 lines (63 loc) · 2.78 KB
/
QueueInspectorTest.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
package net.openhft.chronicle.queue.impl.single;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.queue.ExcerptAppender;
import net.openhft.chronicle.wire.DocumentContext;
import net.openhft.chronicle.wire.ValueOut;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.IOException;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
public final class QueueInspectorTest {
private static final String PROPERTY_KEY = "wire.encodePidInHeader";
private static String previousValue = null;
@Rule
public TemporaryFolder tmpDir = new TemporaryFolder();
@BeforeClass
public static void enableFeature() {
previousValue = System.getProperty(PROPERTY_KEY);
System.setProperty(PROPERTY_KEY, Boolean.TRUE.toString());
}
@AfterClass
public static void resetFeature() {
if (previousValue != null) {
System.setProperty(PROPERTY_KEY, previousValue);
}
}
@Test
public void shouldDetermineWritingProcessIdWhenDocumentIsNotComplete() throws IOException {
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir.newFolder()).
testBlockSize().
build()) {
final QueueInspector inspector = new QueueInspector(queue);
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(37L, ValueOut::int64);
try (final DocumentContext ctx = appender.writingDocument()) {
ctx.wire().write("foo").int32(17L);
final int writingProcessId = inspector.getWritingProcessId();
assertThat(writingProcessId, is(OS.getProcessId()));
assertThat(QueueInspector.isValidProcessId(writingProcessId), is(true));
}
}
}
@Test
public void shouldIndicateNoProcessIdWhenDocumentIsComplete() throws IOException {
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir.newFolder()).
testBlockSize().
build()) {
final QueueInspector inspector = new QueueInspector(queue);
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(37L, ValueOut::int64);
try (final DocumentContext ctx = appender.writingDocument()) {
ctx.wire().write("foo").int32(17L);
}
final int writingProcessId = inspector.getWritingProcessId();
assertThat(writingProcessId, is(not(OS.getProcessId())));
assertThat(QueueInspector.isValidProcessId(writingProcessId), is(false));
}
}
}