Search in sources :

Example 1 with TmfLongLocation

use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.

the class AbstractCheckpointCollectionTest method testInsert.

/**
 * Test a single insertion
 */
@Test
public void testInsert() {
    TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(12345), new TmfLongLocation(123456L), 0);
    fCheckpointCollection.insert(checkpoint);
    long found = fCheckpointCollection.binarySearch(checkpoint);
    assertEquals(0, found);
    assertEquals(1, fCheckpointCollection.size());
}
Also used : TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) Test(org.junit.Test)

Example 2 with TmfLongLocation

use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.

the class AbstractCheckpointCollectionTest method testGetSize.

/**
 * Test get size
 */
@Test
public void testGetSize() {
    assertEquals(0, fCheckpointCollection.size());
    int expected = CHECKPOINTS_INSERT_NUM;
    for (int i = 0; i < expected; ++i) {
        fCheckpointCollection.insert(new TmfCheckpoint(TmfTimestamp.fromSeconds(i), new TmfLongLocation(i), i));
    }
    assertEquals(expected, fCheckpointCollection.size());
}
Also used : TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) Test(org.junit.Test)

Example 3 with TmfLongLocation

use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.

the class AbstractCheckpointCollectionTest method testInsertSameTimestamp.

/**
 * Test many checkpoint insertions using the same timestamp. Make sure they
 * can be found after re-opening the file
 */
@Test
public void testInsertSameTimestamp() {
    for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
        TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(12345), new TmfLongLocation(123456L + i), i);
        fCheckpointCollection.insert(checkpoint);
    }
    assertEquals(CHECKPOINTS_INSERT_NUM, fCheckpointCollection.size());
    if (isPersistableCollection()) {
        fCheckpointCollection.dispose();
    }
    boolean random = true;
    ArrayList<Integer> list = new ArrayList<>();
    for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
        if (random) {
            Random rand = new Random();
            list.add(rand.nextInt(CHECKPOINTS_INSERT_NUM));
        } else {
            list.add(i);
        }
    }
    if (isPersistableCollection()) {
        fCheckpointCollection = createCollection();
    }
    assertEquals(CHECKPOINTS_INSERT_NUM, fCheckpointCollection.size());
    for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
        Integer randomCheckpoint = list.get(i);
        TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(12345), new TmfLongLocation(123456L + randomCheckpoint), 0);
        long found = fCheckpointCollection.binarySearch(checkpoint);
        assertEquals(randomCheckpoint.intValue(), found);
    }
}
Also used : TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) Random(java.util.Random) ArrayList(java.util.ArrayList) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) Test(org.junit.Test)

Example 4 with TmfLongLocation

use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.

the class AbstractCheckpointCollectionTest method testBinarySearchFindInBetween.

/**
 * Tests that binarySearch find the correct checkpoint when the time stamp
 * is between checkpoints
 */
@Test
public void testBinarySearchFindInBetween() {
    for (long i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
        TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(2 * i), new TmfLongLocation(2 * i), i);
        fCheckpointCollection.insert(checkpoint);
    }
    assertEquals(CHECKPOINTS_INSERT_NUM, fCheckpointCollection.size());
    TmfCheckpoint searchedCheckpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(123), new TmfLongLocation(123L), 123);
    int expectedInsertionPoint = 61;
    int expectedRank = -(expectedInsertionPoint + 2);
    long rank = fCheckpointCollection.binarySearch(searchedCheckpoint);
    assertEquals(expectedRank, rank);
}
Also used : TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) Test(org.junit.Test)

Example 5 with TmfLongLocation

use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.

the class AbstractCheckpointCollectionTest method insertAlot.

/**
 * Generate many checkpoints and insert them in the collection
 *
 * @return the list of generated checkpoints
 */
protected ArrayList<Integer> insertAlot() {
    for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
        TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(12345 + i), new TmfLongLocation(123456L + i), i);
        fCheckpointCollection.insert(checkpoint);
    }
    assertEquals(CHECKPOINTS_INSERT_NUM, fCheckpointCollection.size());
    if (isPersistableCollection()) {
        fCheckpointCollection.dispose();
    }
    boolean random = true;
    ArrayList<Integer> list = new ArrayList<>();
    for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
        if (random) {
            Random rand = new Random();
            list.add(rand.nextInt(CHECKPOINTS_INSERT_NUM));
        } else {
            list.add(i);
        }
    }
    return list;
}
Also used : TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) Random(java.util.Random) ArrayList(java.util.ArrayList) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint)

Aggregations

TmfLongLocation (org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation)57 TmfCheckpoint (org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint)26 Test (org.junit.Test)26 IOException (java.io.IOException)16 ITmfCheckpoint (org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint)13 ITmfLocation (org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation)13 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)12 TmfContext (org.eclipse.tracecompass.tmf.core.trace.TmfContext)8 TmfExperimentLocation (org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentLocation)6 ByteBuffer (java.nio.ByteBuffer)5 TmfTimestampLocation (org.eclipse.tracecompass.tmf.core.trace.location.TmfTimestampLocation)5 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)4 ArrayList (java.util.ArrayList)3 FileNotFoundException (java.io.FileNotFoundException)2 Random (java.util.Random)2 Matcher (java.util.regex.Matcher)2 NonNullUtils.nullToEmptyString (org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString)2 BadPcapFileException (org.eclipse.tracecompass.internal.pcap.core.trace.BadPcapFileException)2 PcapFile (org.eclipse.tracecompass.internal.pcap.core.trace.PcapFile)2 TmfLocationArray (org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfLocationArray)2