Fix seek behaviour in CtfAdaptor
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 9 May 2012 20:15:31 +0000 (16:15 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 9 May 2012 20:16:25 +0000 (16:16 -0400)
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java

index 9619e8b398b540f1a9be024a8576d5761fe40041..6cbc6cb3ea768167010e1141bc0b204759e45393 100644 (file)
@@ -157,13 +157,7 @@ public class CtfIteratorTest {
 
         int result = fixture.compareTo(o);
 
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    java.lang.NullPointerException
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.createStreamInputReaders(CTFTraceReader.java:152)
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.<init>(CTFTraceReader.java:92)
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
-        assertEquals(0, result);
+        assertEquals(1L, result);
     }
 
     /**
@@ -193,13 +187,7 @@ public class CtfIteratorTest {
 
         int result = fixture.compareTo(o);
 
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    java.lang.NullPointerException
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.createStreamInputReaders(CTFTraceReader.java:152)
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.<init>(CTFTraceReader.java:92)
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
-        assertEquals(0, result);
+        assertEquals(1, result);
     }
 
     /**
@@ -220,14 +208,7 @@ public class CtfIteratorTest {
         CtfIterator o = new CtfIterator(createTrace());
 
         int result = fixture.compareTo(o);
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    java.lang.NullPointerException
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.createStreamInputReaders(CTFTraceReader.java:152)
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.<init>(CTFTraceReader.java:92)
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
-        assertEquals(0, result);
+        assertEquals(1, result);
     }
 
     /**
@@ -247,13 +228,6 @@ public class CtfIteratorTest {
         fixture.increaseRank();
 
         fixture.dispose();
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    java.lang.NullPointerException
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.createStreamInputReaders(CTFTraceReader.java:152)
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.<init>(CTFTraceReader.java:92)
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
     }
 
     /**
@@ -458,7 +432,7 @@ public class CtfIteratorTest {
         //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.createStreamInputReaders(CTFTraceReader.java:152)
         //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.<init>(CTFTraceReader.java:92)
         //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
-        assertEquals(0L, result);
+        assertEquals(1L, result);
     }
 
     /**
index 8bc5d884794152a349584758dc081197a5a8db77..ceaca0ded222a56624891da3c1b07f81af0e589e 100644 (file)
@@ -22,7 +22,6 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
 import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -239,7 +238,7 @@ public class CtfTmfTraceTest {
         // An unexpected exception was thrown in user code while executing this test:
         //    org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException: Path must be a valid directory
         //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace.initTrace(CtfTmfTrace.java:98)
-        assertNotNull(result);
+        assertNull(result);
     }
 
     @Test
@@ -477,7 +476,7 @@ public class CtfTmfTraceTest {
     public void testGetNext_1()
         throws Exception {
         CtfTmfTrace fixture = initTrace();
-        ITmfContext context = new TmfContext();
+        ITmfContext context = fixture.seekEvent(0);
 
         CtfTmfEvent result = fixture.getNext(context);
 
@@ -766,7 +765,7 @@ public class CtfTmfTraceTest {
     public void testReadNextEvent_1()
         throws Exception {
         CtfTmfTrace fixture = initTrace();
-        ITmfContext context = new TmfContext();
+        ITmfContext context = fixture.seekEvent(0);
 
         CtfTmfEvent result = fixture.readNextEvent(context);
 
index 506e506e0a4a04f751e64c1436aab3750be8f319..aa259ae7c06eaff98ae0a1e803ebf6f0bcf3b653 100644 (file)
@@ -25,7 +25,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     private final CtfTmfTrace ctfTmfTrace;
 
-    final public static CtfLocation nullLocation = new CtfLocation(
+    final public static CtfLocation NULL_LOCATION = new CtfLocation(
             CtfLocation.INVALID_LOCATION);
     private CtfLocation curLocation;
     private long curRank;
@@ -52,7 +52,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      *
      */
     private void setUnknownLocation() {
-        this.curLocation = nullLocation;
+        this.curLocation = NULL_LOCATION;
         this.curRank = UNKNOWN_RANK;
     }
 
@@ -119,6 +119,8 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
         if (ret) {
             curLocation.setLocation(getCurrentEvent().getTimestampValue());
+        } else {
+            curLocation = NULL_LOCATION;
         }
         return ret;
     }
@@ -134,6 +136,8 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
         if (ret) {
             curLocation.setLocation(getCurrentEvent().getTimestampValue());
+        } else {
+            curLocation = NULL_LOCATION;
         }
         return ret;
     }
@@ -145,7 +149,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      */
     @Override
     public long getRank() {
-        return super.getIndex();
+        return curRank;
     }
 
     /**
@@ -155,9 +159,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      */
     @Override
     public void setRank(final long rank) {
-        if(!this.curLocation.equals(nullLocation)) {
-            seekRank(rank);
-        }
+        curRank = rank;
     }
 
     /*
@@ -230,7 +232,13 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      */
     @Override
     public boolean advance() {
-        return super.advance();
+        boolean ret = super.advance();
+        if (ret) {
+            curLocation.setLocation(getCurrentEvent().getTimestampValue());
+        } else {
+            curLocation = NULL_LOCATION;
+        }
+        return ret;
     }
 
     /**
index 991520b29b837f39298a51799c46cf8e294304fe..389170423e4a2d191d6abce96d6b535d3ad1da95 100644 (file)
@@ -59,13 +59,6 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
     // The trace resource
     private IResource fResource;
 
-    /*
-     * Since in TMF, "traces" can read events, this trace here will have its own
-     * iterator. The user can instantiate extra iterator if they want to seek at
-     * many places at the same time.
-     */
-    protected CtfIterator iterator;
-
     /* Reference to the state system assigned to this trace */
     protected IStateSystemQuerier ss = null;
 
@@ -85,7 +78,6 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      * @throws TmfTraceException
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(IResource, String, Class<CtfTmfEvent>)
      */
-    @SuppressWarnings("unused")
     @Override
     public void initTrace(final IResource resource, final String path, final Class<CtfTmfEvent> eventType)
             throws TmfTraceException {
@@ -105,9 +97,9 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
              */
             throw new TmfTraceException(e.getMessage());
         }
-        this.iterator = new CtfIterator(this, 0, 0);
+        CtfIterator iterator = new CtfIterator(this, 0, 0);
         setStartTime(TmfTimestamp.BIG_BANG);
-        if( !this.iterator.getLocation().equals(CtfIterator.nullLocation)) {
+        if( !iterator.getLocation().equals(CtfIterator.NULL_LOCATION)) {
             setStartTime(iterator.getCurrentEvent().getTimestamp());
         }
         TmfSignalManager.register(this);
@@ -156,7 +148,6 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      * @return boolean
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(IProject, String)
      */
-    @SuppressWarnings("unused")
     @Override
     public boolean validate(final IProject project, final String path) {
         try {
@@ -287,13 +278,13 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
     }
 
     /**
-     * Method getCurrentLocation.
-     * @return ITmfLocation<?>
+     * Method getCurrentLocation. This is not applicable in CTF
+     * @return null, since the trace has no knowledge of the current location
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation()
      */
     @Override
     public ITmfLocation<?> getCurrentLocation() {
-        return iterator.getLocation();
+        return null;
     }
 
     // ------------------------------------------------------------------------
@@ -383,10 +374,10 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
         if (currentLocation == null) {
             currentLocation = new CtfLocation(0L);
         }
-        if( !iterator.getLocation().equals(CtfIterator.nullLocation)) {
-            iterator.setLocation(currentLocation);
-        }
-        return iterator;
+        CtfIterator context = new CtfIterator(this);
+        context.setLocation(currentLocation);
+        context.setRank(ITmfContext.UNKNOWN_RANK);
+        return context;
     }
 
     /**
@@ -398,6 +389,7 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
     @Override
     public double getLocationRatio(final ITmfLocation<?> location) {
         final CtfLocation curLocation = (CtfLocation) location;
+        CtfIterator iterator = new CtfIterator(this);
         iterator.seek(curLocation.getLocation());
         return ((double) iterator.getCurrentEvent().getTimestampValue() - iterator
                 .getStartTime())
@@ -422,8 +414,10 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      */
     @Override
     public ITmfContext seekEvent(final ITmfTimestamp timestamp) {
-        iterator.seek(timestamp.getValue());
-        return iterator;
+        CtfIterator context = new CtfIterator(this);
+        context.seek(timestamp.getValue());
+        context.setRank(ITmfContext.UNKNOWN_RANK);
+        return context;
     }
 
     /**
@@ -434,8 +428,10 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      */
     @Override
     public ITmfContext seekEvent(final long rank) {
-        iterator.setRank(rank);
-        return iterator;
+        CtfIterator context = new CtfIterator(this);
+        context.seekRank(rank);
+        context.setRank(rank);
+        return context;
     }
 
     /**
@@ -446,8 +442,10 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      */
     @Override
     public ITmfContext seekEvent(final double ratio) {
-        iterator.seek((long) (this.fNbEvents * ratio));
-        return iterator;
+        CtfIterator context = new CtfIterator(this);
+        context.seek((long) (this.fNbEvents * ratio));
+        context.setRank(ITmfContext.UNKNOWN_RANK);
+        return context;
     }
 
     /**
@@ -456,11 +454,14 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      * @return CtfTmfEvent
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(ITmfContext)
      */
-    @SuppressWarnings("unused")
     @Override
     public CtfTmfEvent readNextEvent(final ITmfContext context) {
-        CtfTmfEvent event = iterator.getCurrentEvent();
-        iterator.advance();
+        CtfTmfEvent event = null;
+        if (context instanceof CtfIterator) {
+            CtfIterator ctfIterator = (CtfIterator) context;
+            event = ctfIterator.getCurrentEvent();
+            ctfIterator.advance();
+        }
         return event;
     }
 
@@ -496,7 +497,6 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      * sub-classes.
      * @throws TmfTraceException
      */
-    @SuppressWarnings({ "unused", "static-method" })
     protected void buildStateSystem() throws TmfTraceException {
         /*
          * Nothing is done in the basic implementation, please specify
This page took 0.029752 seconds and 5 git commands to generate.