diff options
author | Francois Chouinard | 2012-06-14 20:13:02 +0000 |
---|---|---|
committer | Francois Chouinard | 2012-07-03 20:36:12 +0000 |
commit | 6f9a845fcc569065f109004d4fb151dbd726b3c7 (patch) | |
tree | 65a2786177ea04c559fc7e877693076493d979d1 /lttng/org.eclipse.linuxtools.tmf.core.tests | |
parent | ffacfdf76f11eadd8f4380abbcec2eb9ec93086d (diff) | |
download | org.eclipse.linuxtools-6f9a845fcc569065f109004d4fb151dbd726b3c7.tar.gz org.eclipse.linuxtools-6f9a845fcc569065f109004d4fb151dbd726b3c7.tar.xz org.eclipse.linuxtools-6f9a845fcc569065f109004d4fb151dbd726b3c7.zip |
Fix seekEvent() problem and augment TmfExperimentTest
Diffstat (limited to 'lttng/org.eclipse.linuxtools.tmf.core.tests')
3 files changed, 759 insertions, 39 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java index 30f1277572..9968c89651 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java +++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java @@ -24,6 +24,7 @@ import junit.framework.TestCase; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; +import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEvent; @@ -160,12 +161,14 @@ public class TmfExperimentTest extends TestCase { // ------------------------------------------------------------------------ public void testGetTimestamp() throws Exception { - assertTrue("getTimestamp", fExperiment.getTimestamp( 0).equals(new TmfTimestamp( 1, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp( 10).equals(new TmfTimestamp( 11, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp( 100).equals(new TmfTimestamp( 101, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp( 1000).equals(new TmfTimestamp(1001, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp( 2000).equals(new TmfTimestamp(2001, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp( 2500).equals(new TmfTimestamp(2501, (byte) -3))); + assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment.getTimestamp( 0)); + assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment.getTimestamp( 1)); + assertEquals("getTimestamp", new TmfTimestamp( 11, (byte) -3), fExperiment.getTimestamp( 10)); + assertEquals("getTimestamp", new TmfTimestamp( 101, (byte) -3), fExperiment.getTimestamp( 100)); + assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment.getTimestamp(1000)); + assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment.getTimestamp(2000)); + assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment.getTimestamp(2500)); + assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment.getTimestamp(9999)); assertNull("getTimestamp", fExperiment.getTimestamp(10000)); } @@ -264,7 +267,7 @@ public class TmfExperimentTest extends TestCase { assertEquals("getLocationRatio", ratio, ratio2); } -// @SuppressWarnings({ "unchecked", "rawtypes" }) +// @SuppressWarnings("rawtypes") // public void testGetCurrentLocation() throws Exception { // ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); // ITmfLocation location = fExperiment.getCurrentLocation(); @@ -538,22 +541,280 @@ public class TmfExperimentTest extends TestCase { } // ------------------------------------------------------------------------ - // readtNextEvent - updates the context + // getNext - updates the context // ------------------------------------------------------------------------ - public void testReadNextEvent() throws Exception { + private void validateContextRanks(ITmfContext context) { + assertTrue("Experiment context type", context instanceof TmfExperimentContext); + TmfExperimentContext ctx = (TmfExperimentContext) context; - // On lower bound, returns the first event (ts = 0) - final ITmfContext context = fExperiment.seekEvent(0); - ITmfEvent event = fExperiment.getNext(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + int nbTraces = ctx.getContexts().length; + + // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE) + long expRank = -nbTraces + ((ctx.getLastTrace() != TmfExperimentContext.NO_TRACE) ? 1 : 0); + for (int i = 0; i < nbTraces; i++) { + long rank = ctx.getContexts()[i].getRank(); + if (rank == -1) { + expRank = -1; + break; + } + expRank += rank; + } + assertEquals("Experiment context rank", expRank, ctx.getRank()); + } + + public void testGetNextAfteSeekingOnTS_1() throws Exception { - for (int i = 2; i < 20; i++) { + final long INITIAL_TS = 1; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 1) + final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { event = fExperiment.getNext(context); - assertEquals("Event timestamp", i, event.getTimestamp().getValue()); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + + validateContextRanks(context); } + public void testGetNextAfteSeekingOnTS_2() throws Exception { + + final long INITIAL_TS = 2; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 2) + final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfteSeekingOnTS_3() throws Exception { + + final long INITIAL_TS = 500; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 500) + final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnRank_1() throws Exception { + + final long INITIAL_RANK = 0L; + final int NB_READS = 20; + + // On lower bound, returns the first event (rank = 0) + final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnRank_2() throws Exception { + + final long INITIAL_RANK = 1L; + final int NB_READS = 20; + + // On lower bound, returns the first event (rank = 0) + final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnRank_3() throws Exception { + + final long INITIAL_RANK = 500L; + final int NB_READS = 20; + + // On lower bound, returns the first event (rank = 0) + final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnLocation_1() throws Exception { + + final ITmfLocation<?> INITIAL_LOC = null; + final long INITIAL_TS = 1; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 1) + final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnLocation_2() throws Exception { + + final ITmfLocation<?> INITIAL_LOC = fExperiment.seekEvent(1L).getLocation(); + final long INITIAL_TS = 2; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 2) + final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnLocation_3() throws Exception { + + final ITmfLocation<?> INITIAL_LOC = fExperiment.seekEvent(500L).getLocation(); + final long INITIAL_TS = 501; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 501) + final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + + validateContextRanks(context); + } + + public void testGetNextLocation() throws Exception { + ITmfContext context1 = fExperiment.seekEvent(0); + fExperiment.getNext(context1); + ITmfLocation<?> location = context1.getLocation().clone(); + ITmfEvent event1 = fExperiment.getNext(context1); + ITmfContext context2 = fExperiment.seekEvent(location); + ITmfEvent event2 = fExperiment.getNext(context2); + assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); + } + + public void testGetNextEndLocation() throws Exception { + ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1); + fExperiment.getNext(context1); + ITmfLocation<?> location = context1.getLocation().clone(); + ITmfContext context2 = fExperiment.seekEvent(location); + ITmfEvent event = fExperiment.getNext(context2); + assertNull("Event", event); + } + // ------------------------------------------------------------------------ // processRequest // ------------------------------------------------------------------------ @@ -679,4 +940,4 @@ public class TmfExperimentTest extends TestCase { assertTrue("isCancelled", request.isCancelled()); } -}
\ No newline at end of file +} diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java index 9c1d646a8b..6b4c46e24a 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java +++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java @@ -23,6 +23,7 @@ import junit.framework.TestCase; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; +import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; @@ -387,20 +388,278 @@ public class TmfMultiTraceExperimentTest extends TestCase { } // ------------------------------------------------------------------------ - // readtNextEvent - updates the context + // getNext - updates the context // ------------------------------------------------------------------------ - public void testReadNextEvent() throws Exception { + private void validateContextRanks(ITmfContext context) { + assertTrue("Experiment context type", context instanceof TmfExperimentContext); + TmfExperimentContext ctx = (TmfExperimentContext) context; - // On lower bound, returns the first event (ts = 0) - final ITmfContext context = fExperiment.seekEvent(0); - ITmfEvent event = fExperiment.getNext(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + int nbTraces = ctx.getContexts().length; + + // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE) + long expRank = -nbTraces + ((ctx.getLastTrace() != TmfExperimentContext.NO_TRACE) ? 1 : 0); + for (int i = 0; i < nbTraces; i++) { + long rank = ctx.getContexts()[i].getRank(); + if (rank == -1) { + expRank = -1; + break; + } + expRank += rank; + } + assertEquals("Experiment context rank", expRank, ctx.getRank()); + } + + public void testGetNextAfteSeekingOnTS_1() throws Exception { + + final long INITIAL_TS = 1; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 1) + final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfteSeekingOnTS_2() throws Exception { + + final long INITIAL_TS = 2; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 2) + final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfteSeekingOnTS_3() throws Exception { + + final long INITIAL_TS = 500; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 500) + final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnRank_1() throws Exception { + + final long INITIAL_RANK = 0L; + final int NB_READS = 20; + + // On lower bound, returns the first event (rank = 0) + final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnRank_2() throws Exception { + + final long INITIAL_RANK = 1L; + final int NB_READS = 20; + + // On lower bound, returns the first event (rank = 0) + final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); - for (int i = 2; i < 20; i++) { + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { event = fExperiment.getNext(context); - assertEquals("Event timestamp", i, event.getTimestamp().getValue()); + assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnRank_3() throws Exception { + + final long INITIAL_RANK = 500L; + final int NB_READS = 20; + + // On lower bound, returns the first event (rank = 0) + final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnLocation_1() throws Exception { + + final ITmfLocation<?> INITIAL_LOC = null; + final long INITIAL_TS = 1; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 1) + final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnLocation_2() throws Exception { + + final ITmfLocation<?> INITIAL_LOC = fExperiment.seekEvent(1L).getLocation(); + final long INITIAL_TS = 2; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 2) + final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + + validateContextRanks(context); + } + + public void testGetNextAfterSeekingOnLocation_3() throws Exception { + + final ITmfLocation<?> INITIAL_LOC = fExperiment.seekEvent(500L).getLocation(); + final long INITIAL_TS = 501; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 501) + final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); + + validateContextRanks(context); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fExperiment.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + } + + // Make sure we stay positioned + event = fExperiment.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + + validateContextRanks(context); + } + + public void testGetNextLocation() throws Exception { + ITmfContext context1 = fExperiment.seekEvent(0); + fExperiment.getNext(context1); + ITmfLocation<?> location = context1.getLocation().clone(); + ITmfEvent event1 = fExperiment.getNext(context1); + ITmfContext context2 = fExperiment.seekEvent(location); + ITmfEvent event2 = fExperiment.getNext(context2); + assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); + } + + public void testGetNextEndLocation() throws Exception { + ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1); + fExperiment.getNext(context1); + ITmfLocation<?> location = context1.getLocation().clone(); + ITmfContext context2 = fExperiment.seekEvent(location); + ITmfEvent event = fExperiment.getNext(context2); + assertNull("Event", event); } // ------------------------------------------------------------------------ @@ -533,13 +792,16 @@ public class TmfMultiTraceExperimentTest extends TestCase { // ------------------------------------------------------------------------ public void testGetTimestamp() throws Exception { - - assertTrue("getTimestamp", fExperiment.getTimestamp( 0).equals(new TmfTimestamp( 1, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp( 10).equals(new TmfTimestamp( 11, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp( 100).equals(new TmfTimestamp( 101, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp(1000).equals(new TmfTimestamp(1001, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp(2000).equals(new TmfTimestamp(2001, (byte) -3))); - assertTrue("getTimestamp", fExperiment.getTimestamp(2500).equals(new TmfTimestamp(2501, (byte) -3))); + assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment.getTimestamp( 0)); + assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment.getTimestamp( 1)); + assertEquals("getTimestamp", new TmfTimestamp( 11, (byte) -3), fExperiment.getTimestamp( 10)); + assertEquals("getTimestamp", new TmfTimestamp( 101, (byte) -3), fExperiment.getTimestamp( 100)); + assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment.getTimestamp( 1000)); + assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment.getTimestamp( 2000)); + assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment.getTimestamp( 2500)); + assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment.getTimestamp( 9999)); + assertEquals("getTimestamp", new TmfTimestamp(20000, (byte) -3), fExperiment.getTimestamp(19999)); + assertNull("getTimestamp", fExperiment.getTimestamp(20000)); } -}
\ No newline at end of file +} diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java index 70c039dd93..a0bab9788d 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java +++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java @@ -35,6 +35,7 @@ import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; +import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; @@ -246,6 +247,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); } + @SuppressWarnings({ "unchecked", "rawtypes" }) public void testCopyConstructor() throws Exception { TmfTraceStub original = null; TmfTraceStub trace = null; @@ -963,28 +965,223 @@ public class TmfTraceTest extends TestCase { } // ------------------------------------------------------------------------ - // readNextEvent - updates the context + // getNext - updates the context // ------------------------------------------------------------------------ - public void testReadNextEvent() throws Exception { + public void testGetNextAfteSeekingOnTS_1() throws Exception { + final long INITIAL_TS = 1; final int NB_READS = 20; // On lower bound, returns the first event (ts = 1) - final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0)); + final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); // Read NB_EVENTS ITmfEvent event; for (int i = 0; i < NB_READS; i++) { event = fTrace.getNext(context); - assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue()); - assertEquals("Event rank", i + 1, context.getRank()); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); } // Make sure we stay positioned event = fTrace.parseEvent(context); - assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue()); - assertEquals("Event rank", NB_READS, context.getRank()); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + } + + public void testGetNextAfteSeekingOnTS_2() throws Exception { + + final long INITIAL_TS = 2; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 500) + final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fTrace.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + } + + public void testGetNextAfteSeekingOnTS_3() throws Exception { + + final long INITIAL_TS = 500; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 500) + final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fTrace.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + } + + public void testGetNextAfterSeekingOnRank_1() throws Exception { + + final long INITIAL_RANK = 0L; + final int NB_READS = 20; + + // On lower bound, returns the first event (rank = 0) + final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fTrace.getNext(context); + assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); + } + + // Make sure we stay positioned + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); + } + + public void testGetNextAfterSeekingOnRank_2() throws Exception { + + final long INITIAL_RANK = 1L; + final int NB_READS = 20; + + // On lower bound, returns the first event (rank = 0) + final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fTrace.getNext(context); + assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); + } + + // Make sure we stay positioned + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); + } + + public void testGetNextAfterSeekingOnRank_3() throws Exception { + + final long INITIAL_RANK = 500L; + final int NB_READS = 20; + + // On lower bound, returns the first event (rank = 0) + final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fTrace.getNext(context); + assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); + } + + // Make sure we stay positioned + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); + } + + public void testGetNextAfterSeekingOnLocation_1() throws Exception { + + final ITmfLocation<?> INITIAL_LOC = null; + final long INITIAL_TS = 1; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 1) + final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fTrace.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + i, context.getRank()); + } + + // Make sure we stay positioned + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); + } + + public void testGetNextAfterSeekingOnLocation_2() throws Exception { + + final ITmfLocation<?> INITIAL_LOC = fTrace.seekEvent(1L).getLocation(); + final long INITIAL_TS = 2; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 501) + final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fTrace.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + } + + // Make sure we stay positioned + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + } + + public void testGetNextAfterSeekingOnLocation_3() throws Exception { + + final ITmfLocation<?> INITIAL_LOC = fTrace.seekEvent(500L).getLocation(); + final long INITIAL_TS = 501; + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 501) + final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fTrace.getNext(context); + assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); + } + + // Make sure we stay positioned + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); + } + + public void testGetNextLocation() throws Exception { + ITmfContext context1 = fTrace.seekEvent(0); + fTrace.getNext(context1); + ITmfLocation<?> location = context1.getLocation().clone(); + ITmfEvent event1 = fTrace.getNext(context1); + ITmfContext context2 = fTrace.seekEvent(location); + ITmfEvent event2 = fTrace.getNext(context2); + assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); + } + + public void testGetNextEndLocation() throws Exception { + ITmfContext context1 = fTrace.seekEvent(fTrace.getNbEvents() - 1); + fTrace.getNext(context1); + ITmfLocation<?> location = context1.getLocation().clone(); + ITmfContext context2 = fTrace.seekEvent(location); + ITmfEvent event = fTrace.getNext(context2); + assertNull("Event", event); } // ------------------------------------------------------------------------ |