+ 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() {
+
+ 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() {
+
+ 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() {
+
+ 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() {
+
+ 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);
+ }