72 e2.commit(); |
72 e2.commit(); |
73 } |
73 } |
74 } |
74 } |
75 |
75 |
76 private static final int THREAD_COUNT = 4; |
76 private static final int THREAD_COUNT = 4; |
|
77 private static final boolean[] BOOLEAN_STATES = { false, true }; |
77 |
78 |
78 public static void main(String... args) throws Exception { |
79 public static void main(String... args) throws Exception { |
79 Path p = makeUnorderedRecording(); |
80 Path p = makeUnorderedRecording(); |
80 |
81 |
81 testSetOrderedTrue(p); |
82 testSetOrderedTrue(p); |
82 testSetOrderedFalse(p); |
83 testSetOrderedFalse(p); |
83 } |
84 } |
84 |
85 |
85 private static void testSetOrderedTrue(Path p) throws Exception { |
86 private static void testSetOrderedTrue(Path p) throws Exception { |
86 AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN); |
87 for (boolean reuse : BOOLEAN_STATES) { |
87 try (EventStream es = EventStream.openFile(p)) { |
88 AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN); |
88 es.setOrdered(true); |
89 try (EventStream es = EventStream.openFile(p)) { |
89 es.onEvent(e -> { |
90 es.setReuse(reuse); |
90 Instant endTime = e.getEndTime(); |
91 es.setOrdered(true); |
91 if (endTime.isBefore(timestamp.get())) { |
92 es.onEvent(e -> { |
92 throw new Error("Events are not ordered!"); |
93 Instant endTime = e.getEndTime(); |
93 } |
94 if (endTime.isBefore(timestamp.get())) { |
94 timestamp.set(endTime); |
95 throw new Error("Events are not ordered! Reues = " + reuse); |
95 }); |
96 } |
96 es.start(); |
97 timestamp.set(endTime); |
|
98 }); |
|
99 es.start(); |
|
100 } |
97 } |
101 } |
98 } |
102 } |
99 |
103 |
100 private static void testSetOrderedFalse(Path p) throws Exception { |
104 private static void testSetOrderedFalse(Path p) throws Exception { |
101 AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN); |
105 for (boolean reuse : BOOLEAN_STATES) { |
102 AtomicBoolean unoreded = new AtomicBoolean(false); |
106 AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN); |
103 try (EventStream es = EventStream.openFile(p)) { |
107 AtomicBoolean unoreded = new AtomicBoolean(false); |
104 es.setOrdered(false); |
108 try (EventStream es = EventStream.openFile(p)) { |
105 es.onEvent(e -> { |
109 es.setReuse(reuse); |
106 Instant endTime = e.getEndTime(); |
110 es.setOrdered(false); |
107 if (endTime.isBefore(timestamp.get())) { |
111 es.onEvent(e -> { |
108 unoreded.set(true); |
112 Instant endTime = e.getEndTime(); |
109 es.close(); |
113 if (endTime.isBefore(timestamp.get())) { |
|
114 unoreded.set(true); |
|
115 es.close(); |
|
116 } |
|
117 timestamp.set(endTime); |
|
118 }); |
|
119 es.start(); |
|
120 if (!unoreded.get()) { |
|
121 throw new Exception("Expected at least some events to be out of order! Reues = " + reuse); |
110 } |
122 } |
111 timestamp.set(endTime); |
|
112 }); |
|
113 es.start(); |
|
114 if (!unoreded.get()) { |
|
115 throw new Exception("Expected at least some events to be out of order"); |
|
116 } |
123 } |
117 } |
124 } |
118 } |
125 } |
119 |
126 |
120 private static Path makeUnorderedRecording() throws Exception { |
127 private static Path makeUnorderedRecording() throws Exception { |