ctf: Depend on the tracecompass-test-traces project
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / context / CtfTmfContextTest.java
index 28e992314e0ca8a5b68baa0329fe6d07ea179170..eb1ca690549058bb3bd1dab10493f391c354dda1 100644 (file)
 
 package org.eclipse.tracecompass.tmf.ctf.core.tests.context;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
 
 import java.util.ArrayList;
 
-import org.eclipse.core.resources.IResource;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
 import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
-import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -36,8 +36,10 @@ import org.junit.Test;
  */
 public class CtfTmfContextTest {
 
-    private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
-    private static final long begin = 1332170682440133097L; /* Trace start time */
+    private static final @NonNull CtfTestTrace testTrace = CtfTestTrace.KERNEL;
+    private static final long begin = 1332170682440133097L; /*
+                                                             * Trace start time
+                                                             */
     private static final long end = 1332170692664579801L; /* Trace end time */
 
     private CtfTmfTrace trace;
@@ -52,16 +54,20 @@ public class CtfTmfContextTest {
 
     /**
      * Pre-test initialization
-     *
-     * @throws TmfTraceException
-     *             If the trace couldn't be init'ed, which shouldn't happen.
      */
     @Before
-    public void setUp() throws TmfTraceException {
-        assumeTrue(testTrace.exists());
-        trace = new CtfTmfTrace();
-        String path = testTrace.getPath();
-        trace.initTrace((IResource) null, path, CtfTmfEvent.class);
+    public void setUp() {
+        trace = CtfTmfTestTraceUtils.getTrace(testTrace);
+    }
+
+    /**
+     * Post-test clean-up.
+     */
+    @After
+    public void tearDown() {
+        if (trace != null) {
+            trace.dispose();
+        }
     }
 
     /**
@@ -92,35 +98,35 @@ public class CtfTmfContextTest {
         double increment = (end - begin) / lwcCount;
         final ArrayList<Long> vals = new ArrayList<>();
         final ArrayList<Thread> threads = new ArrayList<>();
-        final ArrayList<CtfTmfContext> tooManyContexts = new ArrayList<>();
 
-        for (double i = begin; i < end; i += increment) {
+        double time = begin;
+        for (int i = 0; i < lwcCount; i++) {
             SeekerThread thread = new SeekerThread() {
                 @Override
                 public void run() {
                     CtfTmfContext lwc = new CtfTmfContext(trace);
                     lwc.seek(val);
                     trace.getNext(lwc);
-                    synchronized(trace){
+                    synchronized (trace) {
                         if (lwc.getCurrentEvent() != null) {
                             vals.add(lwc.getCurrentEvent().getTimestamp().getValue());
                         }
-                        tooManyContexts.add(lwc);
                     }
                 }
             };
-            thread.setVal((long)i);
+            thread.setVal((long) time);
             threads.add(thread);
             thread.start();
+            time += increment;
         }
 
-        for (Thread t: threads){
+        for (Thread t : threads) {
             t.join();
         }
-
-        for (long val : vals){
-            assertTrue(val >= begin);
-            assertTrue(val <= end);
+        assertEquals("seeks done ", lwcCount, vals.size());
+        for (long val : vals) {
+            assertTrue("val >= begin, " + val + " " + begin, val >= begin);
+            assertTrue("val >= end, " + val + " " + end, val <= end);
         }
     }
 }
This page took 0.046482 seconds and 5 git commands to generate.