Search in sources :

Example 1 with TmfEventProviderStub

use of org.eclipse.tracecompass.tmf.tests.stubs.component.TmfEventProviderStub in project tracecompass by tracecompass.

the class TmfEventProviderTest method setUp.

/**
 * Initialization
 *
 * @throws IOException
 *             If we can't find the test trace (they are committed in the
 *             tree, so it shouldn't happen).
 */
@Before
public void setUp() throws IOException {
    fEventProvider = new TmfEventProviderStub();
    fSyntheticEventProvider = new TmfSyntheticEventProviderStub();
}
Also used : TmfSyntheticEventProviderStub(org.eclipse.tracecompass.tmf.tests.stubs.component.TmfSyntheticEventProviderStub) TmfEventProviderStub(org.eclipse.tracecompass.tmf.tests.stubs.component.TmfEventProviderStub) Before(org.junit.Before)

Example 2 with TmfEventProviderStub

use of org.eclipse.tracecompass.tmf.tests.stubs.component.TmfEventProviderStub in project tracecompass by tracecompass.

the class TmfEventProviderTest method testCancelRequests.

/**
 * Test canceling requests.
 */
@Test
public void testCancelRequests() {
    final int NB_EVENTS = 1000;
    final int NUMBER_EVENTS_BEFORE_CANCEL_REQ1 = 10;
    final int NUMBER_EVENTS_BEFORE_CANCEL_REQ2 = 800;
    final Vector<ITmfEvent> requestedEventsReq1 = new Vector<>();
    final Vector<ITmfEvent> requestedEventsReq2 = new Vector<>();
    // Get the TmfSyntheticEventStub provider
    ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
    ITmfEventProvider provider = eventProviders[0];
    TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
    // Create first request
    final TmfEventRequest request1 = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            requestedEventsReq1.add(event);
            // cancel sub request
            if (getNbRead() == NUMBER_EVENTS_BEFORE_CANCEL_REQ1) {
                cancel();
            }
        }
    };
    // Synchronize requests
    ((TmfEventProviderStub) provider).startSynch(new TmfStartSynchSignal(0));
    // Additionally, notify provider for up-coming requests
    provider.notifyPendingRequest(true);
    // Call sendRequest, which will create a coalescing request, but it
    // doesn't send request1 yet
    provider.sendRequest(request1);
    // Check if request1 is not running yet.
    assertFalse("isRunning", request1.isRunning());
    // Create second request
    final TmfEventRequest request2 = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            requestedEventsReq2.add(event);
            // cancel sub request which will cancel also main request
            if (getNbRead() == NUMBER_EVENTS_BEFORE_CANCEL_REQ2) {
                cancel();
            }
        }
    };
    // Call sendRequest, which will create a coalescing request, but it
    // doesn't send request2 yet
    provider.sendRequest(request2);
    // Check if request1/2 is not running yet.
    assertFalse("isRunning", request1.isRunning());
    assertFalse("isRunning", request2.isRunning());
    // Send end synch signal, however requests won't be sent
    ((TmfEventProviderStub) provider).endSynch(new TmfEndSynchSignal(0));
    // Check if request1/2 is not running yet.
    assertFalse("isRunning", request1.isRunning());
    assertFalse("isRunning", request2.isRunning());
    // Finally, trigger sending of requests
    provider.notifyPendingRequest(false);
    try {
        // Wait until requests start
        request1.waitForStart();
        request2.waitForStart();
        // // Verify that the requests are running
        // assertTrue("isRunning", request1.isRunning());
        // assertTrue("isRunning", request2.isRunning());
        request1.waitForCompletion();
        // // Check if request2 is still running
        // assertTrue("isRunning",  request2.isRunning());
        // Verify result (request1)
        assertEquals("nbEvents", NUMBER_EVENTS_BEFORE_CANCEL_REQ1, requestedEventsReq1.size());
        assertTrue("isCompleted", request1.isCompleted());
        assertTrue("isCancelled", request1.isCancelled());
        request2.waitForCompletion();
        // Verify result (request2)
        assertEquals("nbEvents", NUMBER_EVENTS_BEFORE_CANCEL_REQ2, requestedEventsReq2.size());
        assertTrue("isCompleted", request2.isCompleted());
        assertTrue("isCancelled", request2.isCancelled());
    } catch (InterruptedException e) {
        fail();
    }
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) TmfEventProviderStub(org.eclipse.tracecompass.tmf.tests.stubs.component.TmfEventProviderStub) TmfStartSynchSignal(org.eclipse.tracecompass.tmf.core.signal.TmfStartSynchSignal) 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) TmfEndSynchSignal(org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal) Test(org.junit.Test)

Aggregations

TmfEventProviderStub (org.eclipse.tracecompass.tmf.tests.stubs.component.TmfEventProviderStub)2 Vector (java.util.Vector)1 ITmfEventProvider (org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider)1 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)1 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)1 TmfEndSynchSignal (org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal)1 TmfStartSynchSignal (org.eclipse.tracecompass.tmf.core.signal.TmfStartSynchSignal)1 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)1 TmfSyntheticEventProviderStub (org.eclipse.tracecompass.tmf.tests.stubs.component.TmfSyntheticEventProviderStub)1 Before (org.junit.Before)1 Test (org.junit.Test)1