+ Map<String, String> properties = fModule.getProperties();
+ assertEquals(fModule.getBackendName(), properties.get(Messages.TmfStateSystemAnalysisModule_PropertiesBackend));
+ assertEquals(fModule.getId(), properties.get(org.eclipse.tracecompass.tmf.core.analysis.Messages.TmfAbstractAnalysisModule_LabelId));
+ }
+
+ private static final String CRUCIAL_EVENT = "crucialEvent";
+ private static final String CRUCIAL_FIELD = "crucialInfo";
+
+ private static void setupDependentAnalysisHandler(CyclicBarrier barrier) {
+ TestStateSystemProvider.setEventHandler((ss, event) -> {
+ try {
+ /* Wait before processing the current event */
+ barrier.await();
+ if (event.getName().equals(CRUCIAL_EVENT)) {
+ String crucialInfo = (String) event.getContent().getField(CRUCIAL_FIELD).getValue();
+ int quark = ss.getQuarkAbsoluteAndAdd(CRUCIAL_FIELD);
+ try {
+ ss.modifyAttribute(event.getTimestamp().toNanos(), TmfStateValue.newValueString(crucialInfo), quark);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+ /* Wait before processing the next event */
+ barrier.await();
+ return true;
+ } catch (InterruptedException | BrokenBarrierException e1) {
+ return false;
+ }
+
+ });
+ }
+
+ /**
+ * Test the {@link TmfStateSystemAnalysisModule#isQueryable(long)} method
+ */
+ @Test
+ public void testIsQueryable() {
+
+ CyclicBarrier barrier = new CyclicBarrier(2);
+ setupDependentAnalysisHandler(barrier);
+
+ TestStateSystemModule module = fModule;
+ assertNotNull(module);
+
+ /* Module is not started, it should be queriable */
+ assertTrue(module.isQueryable(1));
+ assertTrue(module.isQueryable(4));
+ assertTrue(module.isQueryable(5));
+ assertTrue(module.isQueryable(7));
+ assertTrue(module.isQueryable(10));
+
+ module.schedule();
+
+ assertTrue(module.waitForInitialization());
+
+ assertFalse(module.isQueryable(1));
+
+ try {
+ /* 2 waits for a barrier for one event */
+ // event 1
+ barrier.await();
+ barrier.await();
+ // event 2
+ barrier.await();
+ assertTrue(module.isQueryable(1));
+ assertTrue(module.isQueryable(4));
+ assertFalse(module.isQueryable(5));
+ barrier.await();
+ // event 3
+ barrier.await();
+ assertTrue(module.isQueryable(1));
+ assertTrue(module.isQueryable(4));
+ assertFalse(module.isQueryable(5));
+ barrier.await();
+ // event 4
+ barrier.await();
+ assertTrue(module.isQueryable(1));
+ assertTrue(module.isQueryable(4));
+ assertFalse(module.isQueryable(5));
+ barrier.await();
+ // event 5
+ barrier.await();
+ assertTrue(module.isQueryable(1));
+ assertTrue(module.isQueryable(4));
+ assertTrue(module.isQueryable(5));
+ assertFalse(module.isQueryable(7));
+ barrier.await();
+ // event 6
+ barrier.await();
+ assertTrue(module.isQueryable(1));
+ assertTrue(module.isQueryable(4));
+ assertTrue(module.isQueryable(5));
+ assertFalse(module.isQueryable(7));
+ barrier.await();
+ // event 7
+ barrier.await();
+ assertTrue(module.isQueryable(1));
+ assertTrue(module.isQueryable(4));
+ assertTrue(module.isQueryable(5));
+ assertTrue(module.isQueryable(7));
+ assertFalse(module.isQueryable(10));
+ barrier.await();
+
+ fModule.waitForCompletion();
+ assertTrue(module.isQueryable(1));
+ assertTrue(module.isQueryable(4));
+ assertTrue(module.isQueryable(5));
+ assertTrue(module.isQueryable(7));
+ assertTrue(module.isQueryable(10));
+
+ // Should return true only if later than trace time
+ assertTrue(module.isQueryable(100));
+
+ } catch (InterruptedException | BrokenBarrierException e1) {
+ fail(e1.getMessage());
+ fModule.cancel();
+ } finally {
+ TestStateSystemProvider.setEventHandler(null);
+ }