import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.request.TmfEventRequest;
import org.eclipse.linuxtools.tmf.tests.TmfCoreTestPlugin;
+import org.eclipse.linuxtools.tmf.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.trace.TmfCheckpoint;
import org.eclipse.linuxtools.tmf.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.trace.TmfTrace;
import org.eclipse.linuxtools.tmf.trace.TmfTraceStub;
/**
* <b><u>TmfTraceTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfTrace class.
*/
+@SuppressWarnings("nls")
public class TmfTraceTest extends TestCase {
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
private static final String DIRECTORY = "testfiles";
private static final String TEST_STREAM = "A-Test-10K";
+ private static final int BLOCK_SIZE = 500;
private static final int NB_EVENTS = 10000;
private static TmfTraceStub fTrace = null;
// Housekeeping
// ------------------------------------------------------------------------
- private TmfTraceStub setupTrace(String path) {
- if (fTrace == null) {
- try {
- URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path), null);
- File test = new File(FileLocator.toFileURL(location).toURI());
- TmfTraceStub trace = new TmfTraceStub(test.getPath(), 500, true);
- fTrace = trace;
- } catch (URISyntaxException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return fTrace;
- }
-
public TmfTraceTest(String name) throws Exception {
super(name);
}
@Override
protected void setUp() throws Exception {
- super.setUp();
- setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+ super.setUp();
+ fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+ // Dummy request to force the trace indexing
+ TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class) {
+ @Override
+ public void handleData(TmfEvent event) {
+ super.handleData(event);
+ }
+ };
+ fTrace.sendRequest(request);
+ request.waitForCompletion();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
+ fTrace.dispose();
+ fTrace = null;
}
+ // ------------------------------------------------------------------------
+ // Helper functions
+ // ------------------------------------------------------------------------
+
+ private TmfTraceStub setupTrace(String path) {
+ if (fTrace == null) {
+ try {
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
+ File test = new File(FileLocator.toFileURL(location).toURI());
+ fTrace = new TmfTraceStub(test.getPath(), BLOCK_SIZE, false);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return fTrace;
+ }
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
public void testTmfTraceDefault() throws Exception {
TmfTraceStub trace = null;
+ File testfile = null;
try {
- URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
- File test = new File(FileLocator.toFileURL(location).toURI());
- trace = new TmfTraceStub(test.getPath(), true);
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ testfile = new File(FileLocator.toFileURL(location).toURI());
+ trace = new TmfTraceStub(testfile.getPath());
} catch (URISyntaxException e) {
- e.printStackTrace();
+ fail("URISyntaxException");
} catch (IOException e) {
- e.printStackTrace();
+ fail("IOException");
}
- assertTrue("Open trace", trace != null);
- assertEquals("getCacheSize", TmfTraceStub.DEFAULT_CACHE_SIZE, trace.getCacheSize());
- assertEquals("getTraceSize", NB_EVENTS, trace.getNbEvents());
+ assertTrue ("Open trace", trace != null);
+ assertEquals("getType", TmfEvent.class, trace.getType());
+ assertEquals("getPath", testfile.getPath(), trace.getPath());
+ assertEquals("getName", TEST_STREAM, trace.getName());
+ assertEquals("getCacheSize", TmfTrace.DEFAULT_INDEX_PAGE_SIZE, trace.getCacheSize());
+ }
+
+ public void testTmfTraceDefaultCacheSize() throws Exception {
+ TmfTraceStub trace = null;
+ File testfile = null;
+ try {
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ testfile = new File(FileLocator.toFileURL(location).toURI());
+ trace = new TmfTraceStub(testfile.getPath(), 0);
+ } catch (URISyntaxException e) {
+ fail("URISyntaxException");
+ } catch (IOException e) {
+ fail("IOException");
+ }
+ assertTrue ("Open trace", trace != null);
+ assertEquals("getType", TmfEvent.class, trace.getType());
+ assertEquals("getPath", testfile.getPath(), trace.getPath());
+ assertEquals("getName", TEST_STREAM, trace.getName());
+ assertEquals("getCacheSize", TmfTrace.DEFAULT_INDEX_PAGE_SIZE, trace.getCacheSize());
}
public void testTmfTrace() throws Exception {
- assertEquals("getCacheSize", 500, fTrace.getCacheSize());
- assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
- assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
- assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue());
+ assertEquals("getType", TmfEvent.class, fTrace.getType());
+ assertEquals("getName", TEST_STREAM, fTrace.getName());
+ assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize());
+ }
+
+ public void testClone() throws Exception {
+ TmfTraceStub trace = fTrace.clone();
+ assertEquals("getType", TmfEvent.class, trace.getType());
+ assertEquals("getPath", fTrace.getPath(), trace.getPath());
+ assertEquals("getName", TEST_STREAM, trace.getName());
+ assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize());
+ assertEquals("getTimeRange", fTrace.getTimeRange(), trace.getTimeRange());
+ }
+
+ // ------------------------------------------------------------------------
+ // Get/Set time range
+ // ------------------------------------------------------------------------
+
+ public void testSetTimeRange() throws Exception {
+ TmfTraceStub trace = fTrace.clone();
+
+ assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, trace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue());
+
+ trace.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200)));
+ assertEquals("setTimeRange", 100, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("setTimeRange", 200, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("setTimeRange", 100, trace.getStartTime().getValue());
+ assertEquals("setTimeRange", 200, trace.getEndTime().getValue());
+ }
+
+ public void testSetStartTime() throws Exception {
+ TmfTraceStub trace = fTrace.clone();
+
+ assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, trace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue());
+
+ trace.setStartTime(new TmfTimestamp(100));
+ assertEquals("setStartTime", 100, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("setStartTime", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("setStartTime", 100, trace.getStartTime().getValue());
+ assertEquals("setStartTime", NB_EVENTS, trace.getEndTime().getValue());
+ }
+
+ public void testSetEndTime() throws Exception {
+ TmfTraceStub trace = fTrace.clone();
+
+ assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, trace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue());
+
+ trace.setEndTime(new TmfTimestamp(100));
+ assertEquals("setEndTime", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("setEndTime", 100, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("setEndTime", 1, trace.getStartTime().getValue());
+ assertEquals("setEndTime", 100, trace.getEndTime().getValue());
+ }
+
+ // ------------------------------------------------------------------------
+ // Verify checkpoints
+ // ------------------------------------------------------------------------
+
+ public void testTmfTraceIndexing() throws Exception {
+ assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize());
+ assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
+ assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue());
+
+ Vector<TmfCheckpoint> checkpoints = fTrace.getCheckpoints();
+ int pageSize = fTrace.getCacheSize();
+ assertTrue("Checkpoints exist", checkpoints != null);
+
+ // Validate that each checkpoint points to the right event
+ for (int i = 0; i < checkpoints.size(); i++) {
+ TmfCheckpoint checkpoint = checkpoints.get(i);
+ TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
+ TmfEvent event = fTrace.parseEvent(context);
+ assertTrue(context.getRank() == i * pageSize);
+ assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // parseEvent - make sure parseEvent doesn't update the context
+ // ------------------------------------------------------------------------
+
+ public void testParseEvent() throws Exception {
+
+ int NB_READS = 20;
+
+ // On lower bound, returns the first event (ts = 0)
+ TmfContext context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0));
+ TmfContext svContext = new TmfContext(context);
+
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
+
+ // Position the trace at event NB_READS
+ for (int i = 1; i < NB_READS; i++) {
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", i, event.getTimestamp().getValue());
+ }
+
+ svContext = new TmfContext(context);
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue());
+ assertEquals("Event rank", NB_READS -1 , context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue());
+ assertEquals("Event rank", NB_READS - 1, context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
}
// ------------------------------------------------------------------------
- // seek
+ // getNextEvent - updates the context
// ------------------------------------------------------------------------
- public void testSeekOnCacheBoundary() throws Exception {
+ public void testGetNextEvent() throws Exception {
+
+ int NB_READS = 20;
+
+ // On lower bound, returns the first event (ts = 1)
+ TmfContext context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0));
+
+ // Read NB_EVENTS
+ TmfEvent event;
+ for (int i = 0; i < NB_READS; i++) {
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", i + 1, context.getRank());
+ }
+
+ // Make sure we stay positioned
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", NB_READS, context.getRank());
+ }
+
+ // ------------------------------------------------------------------------
+ // seekLocation
+ // Note: seekLocation() does not reliably set the rank
+ // ------------------------------------------------------------------------
+
+ public void testSeekLocationOnCacheBoundary() throws Exception {
+
+ // Position trace at event rank 0
TmfContext context = fTrace.seekLocation(null);
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+
+ context = fTrace.seekLocation(context.getLocation());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- context = fTrace.seekEvent(new TmfTimestamp(1, SCALE, 0));
- TmfEvent event = fTrace.getNextEvent(context);
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ // Position trace at event rank 1000
+ TmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0));
+ context = fTrace.seekLocation(tmpContext.getLocation());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ // Position trace at event rank 4000
+ tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0));
+ context = fTrace.seekLocation(tmpContext.getLocation());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+ }
+
+ public void testSeekLocationNotOnCacheBoundary() throws Exception {
+
+ // Position trace at event rank 9
+ TmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0));
+ TmfContext context = fTrace.seekLocation(tmpContext.getLocation());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ event = fTrace.getNextEvent(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(new TmfTimestamp(1000, SCALE, 0));
+ context = fTrace.seekLocation(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.getNextEvent(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(new TmfTimestamp(1002, SCALE, 0));
+ context = fTrace.seekLocation(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.getNextEvent(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(new TmfTimestamp(4501, SCALE, 0));
+ context = fTrace.seekLocation(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.getNextEvent(context);
+ assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+ }
+
+ public void testSeekLocationOutOfScope() throws Exception {
+
+ // Position trace at beginning
+ TmfContext tmpContext = fTrace.seekLocation(null);
+ TmfContext context = fTrace.seekLocation(tmpContext.getLocation());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ // Position trace at event passed the end
+ tmpContext = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
+ context = fTrace.seekLocation(tmpContext.getLocation());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", null, event);
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", null, event);
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+ }
+
+ // ------------------------------------------------------------------------
+ // seekEvent on timestamp
+ // ------------------------------------------------------------------------
+
+ public void testSeekEventOnTimestampOnCacheBoundary() throws Exception {
+
+ // Position trace at event rank 0
+ TmfContext context = fTrace.seekEvent(new TmfTimestamp(1, SCALE, 0));
+ assertEquals("Event rank", 0, context.getRank());
+
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+
+ event = fTrace.getNextEvent(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 1, context.getRank());
- context = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0));
+ // Position trace at event rank 1000
+ context = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0));
+ 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.getNextEvent(context);
assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
assertEquals("Event rank", 1001, context.getRank());
- context = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0));
+ // Position trace at event rank 4000
+ context = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0));
+ 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.getNextEvent(context);
assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
assertEquals("Event rank", 4001, context.getRank());
}
- public void testSeekNotOnCacheBoundary() throws Exception {
- TmfContext context = fTrace.seekLocation(null);
+ public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception {
+ // Position trace at event rank 1
+ TmfContext context = fTrace.seekEvent(new TmfTimestamp(2, SCALE, 0));
+ assertEquals("Event rank", 1, context.getRank());
+
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
+ assertEquals("Event rank", 2, context.getRank());
+
+ // Position trace at event rank 9
context = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0));
- TmfEvent event = fTrace.getNextEvent(context);
+ assertEquals("Event rank", 9, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
+ assertEquals("Event rank", 9, context.getRank());
+
+ event = fTrace.getNextEvent(context);
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
assertEquals("Event rank", 10, context.getRank());
- context = fTrace.seekEvent(new TmfTimestamp(999, SCALE, 0));
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 999, event.getTimestamp().getValue());
+ // Position trace at event rank 999
+ context = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0));
assertEquals("Event rank", 999, context.getRank());
-
- context = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0));
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
+ assertEquals("Event rank", 999, context.getRank());
+
event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1000, context.getRank());
- context = fTrace.seekEvent(new TmfTimestamp(4499, SCALE, 0));
+ // Position trace at event rank 1001
+ context = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0));
+ assertEquals("Event rank", 1001, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1001, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1002, context.getRank());
+
+ // Position trace at event rank 4500
+ context = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0));
+ assertEquals("Event rank", 4500, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
+ assertEquals("Event rank", 4500, context.getRank());
+
event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 4499, event.getTimestamp().getValue());
- assertEquals("Event rank", 4499, context.getRank());
+ assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
+ assertEquals("Event rank", 4501, context.getRank());
}
- public void testSeekForEventOutOfBounds() throws Exception {
- TmfContext context = fTrace.seekLocation(null);
+ public void testSeekEventOnTimestampOutOfScope() throws Exception {
- // On lower bound, returns the first event (ts = 1)
- context = fTrace.seekEvent(new TmfTimestamp(-1, SCALE, 0));
- TmfEvent event = fTrace.getNextEvent(context);
+ // Position trace at beginning
+ TmfContext context = fTrace.seekEvent(new TmfTimestamp(-1, SCALE, 0));
+ assertEquals("Event rank", 0, context.getRank());
+
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+
+ event = fTrace.getNextEvent(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1, context.getRank());
- // On higher bound, returns null (no event)
- context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
+ // Position trace at event passed the end
+ context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
+ assertEquals("Event rank", NB_EVENTS, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", null, event);
+ assertEquals("Event rank", NB_EVENTS, context.getRank());
+
event = fTrace.getNextEvent(context);
assertEquals("Event timestamp", null, event);
+ assertEquals("Event rank", NB_EVENTS, context.getRank());
}
- public void testSeekOnIndex() throws Exception {
- TmfContext context = fTrace.seekLocation(null);
+ // ------------------------------------------------------------------------
+ // seekEvent on rank
+ // ------------------------------------------------------------------------
+
+ public void testSeekOnRankOnCacheBoundary() throws Exception {
// On lower bound, returns the first event (ts = 1)
- context = fTrace.seekEvent(0);
- TmfEvent event = fTrace.getNextEvent(context);
+ TmfContext context = fTrace.seekEvent(0);
+ assertEquals("Event rank", 0, context.getRank());
+
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+
+ event = fTrace.getNextEvent(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1, context.getRank());
- // On higher bound
- context = fTrace.seekEvent(NB_EVENTS - 1);
+ // Position trace at event rank 1000
+ context = fTrace.seekEvent(1000);
+ 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.getNextEvent(context);
- assertEquals("Event timestamp", NB_EVENTS, event.getTimestamp().getValue());
+ assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1001, context.getRank());
- // Above high bound
- context = fTrace.seekEvent(NB_EVENTS);
+ // Position trace at event rank 4000
+ context = fTrace.seekEvent(4000);
+ 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.getNextEvent(context);
- assertEquals("Event", null, event);
+ assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
+ assertEquals("Event rank", 4001, context.getRank());
}
- // ------------------------------------------------------------------------
- // getNextEvent
- // ------------------------------------------------------------------------
+ public void testSeekOnRankNotOnCacheBoundary() throws Exception {
- public void testGetNextEvent() throws Exception {
- TmfContext context = fTrace.seekLocation(null);
+ // Position trace at event rank 9
+ TmfContext context = fTrace.seekEvent(9);
+ assertEquals("Event rank", 9, context.getRank());
+
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
+ assertEquals("Event rank", 9, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
+ assertEquals("Event rank", 10, context.getRank());
- // On lower bound, returns the first event (ts = 0)
- context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0));
- TmfEvent event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ // Position trace at event rank 999
+ context = fTrace.seekEvent(999);
+ assertEquals("Event rank", 999, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
+ assertEquals("Event rank", 999, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1000, context.getRank());
- for (int i = 2; i < 20; i++) {
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", i, event.getTimestamp().getValue());
- }
+ // Position trace at event rank 1001
+ context = fTrace.seekEvent(1001);
+ assertEquals("Event rank", 1001, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1001, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1002, context.getRank());
+
+ // Position trace at event rank 4500
+ context = fTrace.seekEvent(4500);
+ assertEquals("Event rank", 4500, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
+ assertEquals("Event rank", 4500, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
+ assertEquals("Event rank", 4501, context.getRank());
}
+ public void testSeekEventOnRankOfScope() throws Exception {
+
+ // Position trace at beginning
+ TmfContext context = fTrace.seekEvent(-1);
+ assertEquals("Event rank", 0, context.getRank());
+
+ TmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 1, context.getRank());
+
+ // Position trace at event passed the end
+ context = fTrace.seekEvent(NB_EVENTS);
+ assertEquals("Event rank", NB_EVENTS, context.getRank());
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", null, event);
+ assertEquals("Event rank", NB_EVENTS, context.getRank());
+
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", null, event);
+ assertEquals("Event rank", NB_EVENTS, context.getRank());
+ }
+
// ------------------------------------------------------------------------
// processRequest
// ------------------------------------------------------------------------
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void handleData() {
- TmfEvent[] events = getData();
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
+ @Override
+ public void handleData(TmfEvent event) {
+ super.handleData(event);
+ requestedEvents.add(event);
+ }
};
ITmfDataProvider<TmfEvent>[] providers = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
providers[0].sendRequest(request);
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) {
- @Override
- public void handleData() {
- TmfEvent[] events = getData();
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- }
+ @Override
+ public void handleData(TmfEvent event) {
+ super.handleData(event);
+ requestedEvents.add(event);
+ }
};
ITmfDataProvider<TmfEvent>[] providers = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
providers[0].sendRequest(request);
final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, NB_EVENTS) {
- @Override
- public void handleData() {
- TmfEvent[] events = getData();
- for (TmfEvent e : events) {
- requestedEvents.add(e);
- }
- // Cancel request after the first chunk is received
- cancel();
- }
+ final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) {
+ int nbRead = 0;
+ @Override
+ public void handleData(TmfEvent event) {
+ super.handleData(event);
+ requestedEvents.add(event);
+ if (++nbRead == BLOCK_SIZE)
+ cancel();
+ }
};
ITmfDataProvider<TmfEvent>[] providers = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
providers[0].sendRequest(request);
request.waitForCompletion();
- assertEquals("nbEvents", NB_EVENTS, requestedEvents.size());
+ assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size());
assertTrue("isCompleted", request.isCompleted());
assertTrue("isCancelled", request.isCancelled());
}