From b3dd2736620a2cff625e0c7b9afc89825b8e5195 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Wed, 15 Jan 2014 10:02:39 -0500 Subject: [PATCH] TMF: Add default constructor to experiment and method to initialize it MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The experiment behavior is thus equivalent to that of the trace and we can eventually instantiate an experiment in the UI, just as we can a trace, using an experiment constructor from a configuration element. Change-Id: Ib7957a3b6458e424bd34d82d4757174233edec04 Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/20666 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann --- .../core/tests/trace/TmfExperimentTest.java | 29 ++++++++ .../tests/stubs/trace/TmfExperimentStub.java | 10 +++ .../tmf/core/trace/TmfExperiment.java | 66 ++++++++++++++----- 3 files changed, 88 insertions(+), 17 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java index 0a589ea475..041790b87f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java @@ -139,6 +139,35 @@ public class TmfExperimentTest { assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue()); } + // ------------------------------------------------------------------------ + // Experiment setup + // ------------------------------------------------------------------------ + + @Test + public void testExperimentInitialization() { + /* + * Calling default constructor, then init should be equivalent to + * calling the full constructor + */ + + TmfExperimentStub experiment = new TmfExperimentStub(); + experiment.initExperiment(ITmfEvent.class, EXPERIMENT, fTestTraces, 5000, null); + experiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); + + assertEquals("GetId", EXPERIMENT, fExperiment.getName()); + assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents()); + + final long nbExperimentEvents = fExperiment.getNbEvents(); + assertEquals("GetNbEvents", NB_EVENTS, nbExperimentEvents); + + final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents(); + assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents); + + final TmfTimeRange timeRange = fExperiment.getTimeRange(); + assertEquals("getStartTime", 1, timeRange.getStartTime().getValue()); + assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue()); + } + // ------------------------------------------------------------------------ // getTimestamp // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfExperimentStub.java b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfExperimentStub.java index 6ca0eddbe1..c2b88bf013 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfExperimentStub.java +++ b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfExperimentStub.java @@ -12,6 +12,7 @@ package org.eclipse.linuxtools.tmf.tests.stubs.trace; +import org.eclipse.core.resources.IResource; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; @@ -26,6 +27,10 @@ import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer; @SuppressWarnings("javadoc") public class TmfExperimentStub extends TmfExperiment { + public TmfExperimentStub() { + super(); + } + public TmfExperimentStub(String name, ITmfTrace[] traces, int blockSize) { super(ITmfEvent.class, name, traces, blockSize); } @@ -39,4 +44,9 @@ public class TmfExperimentStub extends TmfExperiment { public TmfIndexerStub getIndexer() { return (TmfIndexerStub) super.getIndexer(); } + + @Override + public void initExperiment(final Class type, final String path, final ITmfTrace[] traces, final int indexPageSize, IResource resource) { + super.initExperiment(type, path, traces, indexPageSize, resource); + } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java index 48f749992b..f299e8213c 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java @@ -12,6 +12,7 @@ * Patrick Tasse - Updated for removal of context clone * Patrick Tasse - Updated for ranks in experiment location * Geneviève Bastien - Added support of experiment synchronization + * Added the initExperiment method and default constructor *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -96,6 +97,16 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers // ------------------------------------------------------------------------ /** + * Default constructor + * @since 3.0 + */ + public TmfExperiment() { + super(); + } + + /** + * Constructor with parameters + * * @param type * the event type * @param id @@ -153,23 +164,7 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers * the resource associated to the experiment */ public TmfExperiment(final Class type, final String path, final ITmfTrace[] traces, final int indexPageSize, IResource resource) { - setCacheSize(indexPageSize); - setStreamingInterval(0); - setParser(this); - fTraces = traces; - try { - super.initialize(resource, path, type); - } catch (TmfTraceException e) { - e.printStackTrace(); - } - - if (resource != null) { - try { - this.synchronizeTraces(); - } catch (TmfTraceException e) { - Activator.logError("Error synchronizing experiment", e); //$NON-NLS-1$ - } - } + initExperiment(type, path, traces, indexPageSize, resource); } @Override @@ -208,6 +203,43 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers public void initTrace(final IResource resource, final String path, final Class type) { } + /** + * Initialization of an experiment, taking the type, path, traces, + * indexPageSize and resource + * + * @param type + * the event type + * @param path + * the experiment path + * @param traces + * the experiment set of traces + * @param indexPageSize + * the experiment index page size + * @param resource + * the resource associated to the experiment + * @since 3.0 + */ + public void initExperiment(final Class type, final String path, final ITmfTrace[] traces, final int indexPageSize, IResource resource) { + setCacheSize(indexPageSize); + setStreamingInterval(0); + setParser(this); + try { + super.initialize(resource, path, type); + } catch (TmfTraceException e) { + Activator.logError("Error initializing experiment", e); //$NON-NLS-1$ + } + + fTraces = traces; + + if (resource != null) { + try { + this.synchronizeTraces(); + } catch (TmfTraceException e) { + Activator.logError("Error synchronizing experiment", e); //$NON-NLS-1$ + } + } + } + /** * @since 2.0 */ -- 2.34.1