Search in sources :

Example 36 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfTraceTest method testSeekEventNotOnCacheBoundary.

@Test
public void testSeekEventNotOnCacheBoundary() {
    // Position trace at event rank 9
    ITmfContext tmpContext = fTrace.seekEvent(TmfTimestamp.create(10, SCALE));
    TmfContext context = fTrace.seekEvent(tmpContext.getLocation());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    ITmfEvent event = fTrace.parseEvent(context);
    assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    event = fTrace.getNext(context);
    assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    // Position trace at event rank 999
    tmpContext = fTrace.seekEvent(TmfTimestamp.create(1000, SCALE));
    context = fTrace.seekEvent(tmpContext.getLocation());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    event = fTrace.parseEvent(context);
    assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    event = fTrace.getNext(context);
    assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    // Position trace at event rank 1001
    tmpContext = fTrace.seekEvent(TmfTimestamp.create(1002, SCALE));
    context = fTrace.seekEvent(tmpContext.getLocation());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    event = fTrace.parseEvent(context);
    assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    event = fTrace.getNext(context);
    assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    // Position trace at event rank 4500
    tmpContext = fTrace.seekEvent(TmfTimestamp.create(4501, SCALE));
    context = fTrace.seekEvent(tmpContext.getLocation());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    event = fTrace.parseEvent(context);
    assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
    event = fTrace.getNext(context);
    assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
    assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) TmfContext(org.eclipse.tracecompass.tmf.core.trace.TmfContext) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Example 37 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfTraceTest method testProcessEventRequestForOtherEvents.

@Test
public void testProcessEventRequestForOtherEvents() throws InterruptedException {
    final int startIndex = 99;
    final long startTime = 100;
    final int nbEvents = 1000;
    final Vector<ITmfEvent> requestedEvents = new Vector<>();
    final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.create(startTime, SCALE), TmfTimestamp.BIG_CRUNCH);
    final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, startIndex, nbEvents, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(final ITmfEvent event) {
            super.handleData(event);
            requestedEvents.add(event);
        }
    };
    final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class);
    providers[0].sendRequest(request);
    request.waitForCompletion();
    assertEquals("nbEvents", nbEvents, requestedEvents.size());
    assertTrue("isCompleted", request.isCompleted());
    assertFalse("isCancelled", request.isCancelled());
    // Don't go overboard: we are not validating the stub!
    for (int i = 0; i < nbEvents; i++) {
        assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue());
    }
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) Vector(java.util.Vector) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) Test(org.junit.Test)

Example 38 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfTraceTest method testSeekEventOnTimestampOnCacheBoundary.

@Test
public void testSeekEventOnTimestampOnCacheBoundary() {
    // Position trace at event rank 0
    ITmfContext context = fTrace.seekEvent(TmfTimestamp.create(1, SCALE));
    assertEquals("Event rank", 0, context.getRank());
    ITmfEvent event = fTrace.parseEvent(context);
    assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
    assertEquals("Event rank", 0, context.getRank());
    event = fTrace.getNext(context);
    assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
    assertEquals("Event rank", 1, context.getRank());
    // Position trace at event rank 1000
    context = fTrace.seekEvent(TmfTimestamp.create(1001, SCALE));
    assertEquals("Event rank", 1000, context.getRank());
    event = fTrace.parseEvent(context);
    assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
    assertEquals("Event rank", 1000, context.getRank());
    event = fTrace.getNext(context);
    assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
    assertEquals("Event rank", 1001, context.getRank());
    // Position trace at event rank 4000
    context = fTrace.seekEvent(TmfTimestamp.create(4001, SCALE));
    assertEquals("Event rank", 4000, context.getRank());
    event = fTrace.parseEvent(context);
    assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
    assertEquals("Event rank", 4000, context.getRank());
    event = fTrace.getNext(context);
    assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
    assertEquals("Event rank", 4001, context.getRank());
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Example 39 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfTraceTest method testGetNextAfteSeekingOnTS_1.

// ------------------------------------------------------------------------
// getNext - updates the context
// ------------------------------------------------------------------------
@Test
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 = fTrace.seekEvent(TmfTimestamp.create(INITIAL_TS, SCALE));
    // 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());
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Example 40 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfTraceTest method testCancel.

// ------------------------------------------------------------------------
// cancel
// ------------------------------------------------------------------------
@Test
public void testCancel() throws InterruptedException {
    final int limit = 500;
    final Vector<ITmfEvent> requestedEvents = new Vector<>();
    final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
    final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        int nbRead = 0;

        @Override
        public void handleData(final ITmfEvent event) {
            super.handleData(event);
            requestedEvents.add(event);
            if (++nbRead == limit) {
                cancel();
            }
        }
    };
    final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class);
    providers[0].sendRequest(request);
    request.waitForCompletion();
    assertEquals("nbEvents", limit, requestedEvents.size());
    assertTrue("isCompleted", request.isCompleted());
    assertTrue("isCancelled", request.isCancelled());
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) Vector(java.util.Vector) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) Test(org.junit.Test)

Aggregations

ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)182 Test (org.junit.Test)127 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)112 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)40 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)30 AnalysisManagerTest (org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest)27 ITmfLocation (org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation)25 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)24 NonNull (org.eclipse.jdt.annotation.NonNull)20 TmfEvent (org.eclipse.tracecompass.tmf.core.event.TmfEvent)17 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)16 Vector (java.util.Vector)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 Predicate (java.util.function.Predicate)14 TmfTraceUtils (org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 CtfTestTrace (org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace)13 CtfTmfTestTraceUtils (org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils)13 Assert.assertEquals (org.junit.Assert.assertEquals)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)13