Search in sources :

Example 1 with QuarkIterator

use of org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkSubrange.

/**
 * Test that getIteratorOverQuark returns the correct intervals for a range
 * included in the state system range
 */
@Test
public void testIteratorOverQuarkSubrange() {
    ITmfStateSystem ss = fStateSystem;
    assertNotNull(ss);
    int quark;
    try {
        quark = ss.getQuarkAbsolute(DUMMY_STRING);
        QuarkIterator iterator = new QuarkIterator(ss, quark, 1800L);
        /* There should be one interval ranging from 1500L to 2000L */
        assertTrue(iterator.hasNext());
        ITmfStateInterval interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1500L, interval.getStartTime());
        assertEquals(2000L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    }
}
Also used : AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 2 with QuarkIterator

use of org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkEndTime.

/**
 * Test that getIteratorOverQuark returns the correct intervals for a range
 * included in the state system range
 */
@Test
public void testIteratorOverQuarkEndTime() {
    ITmfStateSystem ss = fStateSystem;
    assertNotNull(ss);
    int quark;
    try {
        quark = ss.getQuarkAbsolute(DUMMY_STRING);
        QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE, 1199);
        /* There should be one interval ranging from 1000L to 1199L */
        assertTrue(iterator.hasNext());
        ITmfStateInterval interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1000L, interval.getStartTime());
        assertEquals(1199L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE, 1200);
        /* There should be 2 intervals ranging from 1000L to 1199L and 1200L to 1499L */
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1000L, interval.getStartTime());
        assertEquals(1199L, interval.getEndTime());
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1200L, interval.getStartTime());
        assertEquals(1499L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        iterator = new QuarkIterator(ss, quark, 1800, 5000);
        /* There should be one interval ranging from 1500L to 2000L */
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1500L, interval.getStartTime());
        assertEquals(2000L, interval.getEndTime());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    }
}
Also used : AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 3 with QuarkIterator

use of org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkResolution.

/**
 * Test that the QuarkIterator returns the correct intervals for a range
 * included in the state system range and a resolution
 */
@Test
public void testIteratorOverQuarkResolution() {
    IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(DUMMY_STRING, 1L);
    ITmfStateSystemBuilder ss = StateSystemFactory.newStateSystem(backend);
    try {
        // Create a small state system with intervals for a resolution
        int quark = ss.getQuarkAbsoluteAndAdd(DUMMY_STRING);
        /**
         * Here follows the state system, with each dash representing a nanosecond and
         * vertical line a change of state. The time are the times that are expected to
         * be queried
         *
         * <pre>
         *
         * resolution of 4:  2   6      10
         * resolution of 3:  2  5    8   11
         *                  ------|-|-|----
         * </pre>
         */
        ss.modifyAttribute(1L, 1, quark);
        ss.modifyAttribute(7L, 2, quark);
        ss.modifyAttribute(8L, 1, quark);
        ss.modifyAttribute(9L, 2, quark);
        ss.closeHistory(12L);
        // Verify a resolution of 4
        QuarkIterator iterator = new QuarkIterator(ss, quark, 2, 14, 4);
        /*
             * With steps of 4, there should be 2 intervals and they should be the same
             * forward and backward
             */
        assertTrue(iterator.hasNext());
        ITmfStateInterval interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        // Check second interval forward
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(9L, interval.getStartTime());
        assertEquals(12L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        // Check the interval backward
        assertTrue(iterator.hasPrevious());
        interval = iterator.previous();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        assertFalse(iterator.hasPrevious());
        // Verify a resolution of 3
        iterator = new QuarkIterator(ss, quark, 2, 14, 3);
        /*
             * With steps of 3, there should be 3 intervals and they should be the same
             * forward and backward
             */
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        // Check second interval forward
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(8L, interval.getStartTime());
        assertEquals(8L, interval.getEndTime());
        // Check the interval forward
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(9L, interval.getStartTime());
        assertEquals(12L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        // Check the first interval backward
        assertTrue(iterator.hasPrevious());
        interval = iterator.previous();
        assertNotNull(interval);
        assertEquals(8L, interval.getStartTime());
        assertEquals(8L, interval.getEndTime());
        // Check the second interval backward
        assertTrue(iterator.hasPrevious());
        interval = iterator.previous();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        assertFalse(iterator.hasPrevious());
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    } finally {
        ss.dispose();
    }
}
Also used : QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Test(org.junit.Test)

Example 4 with QuarkIterator

use of org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkReversed.

/**
 * Test that the reverse iterator returns the correct intervals:
 * <ul>
 * <li>intervals for the correct quark</li>
 * <li>ordered intervals</li>
 * <li>intervals covering the correct time range</li>
 * </ul>
 */
@Test
public void testIteratorOverQuarkReversed() {
    ITmfStateSystem ss = fStateSystem;
    assertNotNull(ss);
    for (int quark = 0; quark < ss.getNbAttributes(); quark++) {
        QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MAX_VALUE);
        ITmfStateInterval prevInterval = null;
        ITmfStateInterval currInterval = null;
        while (iterator.hasPrevious()) {
            currInterval = iterator.previous();
            assertEquals(quark, currInterval.getAttribute());
            if (prevInterval == null) {
                /* This is the first interval for this attribute */
                assertEquals(currInterval.getEndTime(), ss.getCurrentEndTime());
            } else {
                assertEquals(prevInterval.getStartTime() - 1, currInterval.getEndTime());
            }
            prevInterval = currInterval;
        }
        assertNotNull("Iterator should have returned at least one interval", currInterval);
        assertEquals(ss.getStartTime(), currInterval.getStartTime());
    }
}
Also used : QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 5 with QuarkIterator

use of org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuark.

/**
 * Test that iterator returns the correct intervals:
 * <ul>
 * <li>intervals for the correct quark</li>
 * <li>ordered intervals</li>
 * <li>intervals covering the correct time range</li>
 * </ul>
 */
@Test
public void testIteratorOverQuark() {
    ITmfStateSystem ss = fStateSystem;
    assertNotNull(ss);
    for (int quark = 0; quark < ss.getNbAttributes(); quark++) {
        QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE);
        ITmfStateInterval prevInterval = null;
        ITmfStateInterval currInterval = null;
        while (iterator.hasNext()) {
            currInterval = iterator.next();
            assertEquals(quark, currInterval.getAttribute());
            if (prevInterval == null) {
                /* This is the first interval for this attribute */
                assertEquals(currInterval.getStartTime(), ss.getStartTime());
            } else {
                assertEquals(prevInterval.getEndTime() + 1, currInterval.getStartTime());
            }
            prevInterval = currInterval;
        }
        assertNotNull("Iterator should have returned at least one interval", currInterval);
        assertEquals(ss.getCurrentEndTime(), currInterval.getEndTime());
    }
}
Also used : QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Aggregations

QuarkIterator (org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator)12 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)9 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)8 Test (org.junit.Test)6 Nullable (org.eclipse.jdt.annotation.Nullable)3 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)3 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Iterators (com.google.common.collect.Iterators)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 TreeMultimap (com.google.common.collect.TreeMultimap)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1