2222import java .util .stream .Collectors ;
2323import java .util .stream .Stream ;
2424
25+ import org .eclipse .core .runtime .IProgressMonitor ;
2526import org .eclipse .core .runtime .NullProgressMonitor ;
2627import org .eclipse .jdt .annotation .NonNull ;
2728import org .eclipse .jdt .annotation .Nullable ;
3738import org .eclipse .tracecompass .tmf .core .model .ITableColumnDescriptor ;
3839import org .eclipse .tracecompass .tmf .core .model .filters .FilterTimeQueryFilter ;
3940import org .eclipse .tracecompass .tmf .core .model .tree .TmfTreeModel ;
41+ import org .eclipse .tracecompass .tmf .core .response .ITmfResponse ;
4042import org .eclipse .tracecompass .tmf .core .response .TmfModelResponse ;
4143import org .eclipse .tracecompass .tmf .core .trace .ITmfTrace ;
4244import org .eclipse .tracecompass .tmf .tests .stubs .trace .xml .TmfXmlTraceStub ;
@@ -74,14 +76,14 @@ public class SegmentStoreStatisticsDataProviderTest extends AbstractSegmentStore
7476
7577 private static final @ NonNull List <@ NonNull StatisticsHolder > EXPECTED_STATS_FULL = Arrays .asList (
7678 new StatisticsHolder ("" , 0 , -1 , 0 , 65534 , 32767.0 , 18918.46 , 65535 , 2147385345.0 , 0 , 0 , 65534 , 131068 ),
77- new StatisticsHolder ("Total" , 3 , 0 , 0 , 65534 , 32767.0 , 18918.46 , 65535 , 2147385345.0 , 0 , 0 , 65534 , 131068 ),
78- new StatisticsHolder ("even" , 4 , 3 , 0 , 65534 , 32767.0 , 18918.90 , 32768 , 1073709056.0 , 0 , 0 , 65534 , 131068 ),
79- new StatisticsHolder ("odd" , 5 , 3 , 1 , 65533 , 32767.0 , 18918.32 , 32767 , 1073676289.0 , 1 , 2 , 65533 , 131066 ));
79+ new StatisticsHolder ("Total" , 4 , 0 , 0 , 65534 , 32767.0 , 18918.46 , 65535 , 2147385345.0 , 0 , 0 , 65534 , 131068 ),
80+ new StatisticsHolder ("even" , 5 , 4 , 0 , 65534 , 32767.0 , 18918.90 , 32768 , 1073709056.0 , 0 , 0 , 65534 , 131068 ),
81+ new StatisticsHolder ("odd" , 6 , 4 , 1 , 65533 , 32767.0 , 18918.32 , 32767 , 1073676289.0 , 1 , 2 , 65533 , 131066 ));
8082
8183 private static final @ NonNull List <@ NonNull StatisticsHolder > EXPECTED_STATS_SELECTION = Arrays .asList (
82- new StatisticsHolder ("Selection" , 6 , 0 , 512 , 4096 , 2304.0 , 1035.04 , 3585 , 8259840.0 , 512 , 1024 , 4096 , 8192 ),
83- new StatisticsHolder ("even" , 7 , 6 , 512 , 4096 , 2304.0 , 1035.48 , 1793 , 4131072.0 , 512 , 1024 , 4096 , 8192 ),
84- new StatisticsHolder ("odd" , 8 , 6 , 513 , 4095 , 2304.0 , 1034.9 , 1792 , 4128768.0 , 513 , 1026 , 4095 , 8190 ));
84+ new StatisticsHolder ("Selection" , 7 , 0 , 512 , 4096 , 2304.0 , 1035.04 , 3585 , 8259840.0 , 512 , 1024 , 4096 , 8192 ),
85+ new StatisticsHolder ("even" , 8 , 7 , 512 , 4096 , 2304.0 , 1035.48 , 1793 , 4131072.0 , 512 , 1024 , 4096 , 8192 ),
86+ new StatisticsHolder ("odd" , 9 , 7 , 513 , 4095 , 2304.0 , 1034.9 , 1792 , 4128768.0 , 513 , 1026 , 4095 , 8190 ));
8587
8688 private static final List <@ NonNull List <@ NonNull String >> LIST_OF_EXPECTED_LABELS_WITH_MAPPER_FULL = Arrays .asList (
8789 Arrays .asList ("My" , "0" , "65534" , "32767.0" , "18918.46928268775" , "65535" , "2.147385345E9" , "[0,0]" , "[65534,131068]" ),
@@ -91,9 +93,9 @@ public class SegmentStoreStatisticsDataProviderTest extends AbstractSegmentStore
9193
9294 private static final @ NonNull List <@ NonNull StatisticsHolder > EXPECTED_STATS_WITH_MAPPER_FULL = Arrays .asList (
9395 new StatisticsHolder ("My" , 1 , -1 , 0 , 65534 , 32767.0 , 18918.46 , 65535 , 2147385345.0 , 0 , 0 , 65534 , 131068 ),
94- new StatisticsHolder ("MyTotal" , 9 , 1 , 0 , 65534 , 32767.0 , 18918.46 , 65535 , 2147385345.0 , 0 , 0 , 65534 , 131068 ),
95- new StatisticsHolder ("Myeven" , 10 , 9 , 0 , 65534 , 32767.0 , 18918.90 , 32768 , 1073709056.0 , 0 , 0 , 65534 , 131068 ),
96- new StatisticsHolder ("Myodd" , 11 , 9 , 1 , 65533 , 32767.0 , 18918.32 , 32767 , 1073676289.0 , 1 , 2 , 65533 , 131066 ));
96+ new StatisticsHolder ("MyTotal" , 10 , 1 , 0 , 65534 , 32767.0 , 18918.46 , 65535 , 2147385345.0 , 0 , 0 , 65534 , 131068 ),
97+ new StatisticsHolder ("Myeven" , 11 , 10 , 0 , 65534 , 32767.0 , 18918.90 , 32768 , 1073709056.0 , 0 , 0 , 65534 , 131068 ),
98+ new StatisticsHolder ("Myodd" , 12 , 10 , 1 , 65533 , 32767.0 , 18918.32 , 32767 , 1073676289.0 , 1 , 2 , 65533 , 131066 ));
9799
98100 private static final String USER_DEFINED_EXTRA_HEADER = "userDefinedHeader" ;
99101 private static final String USER_DEFINED_EXTRA_VALUE = "userDefinedValue" ;
@@ -107,16 +109,17 @@ public class SegmentStoreStatisticsDataProviderTest extends AbstractSegmentStore
107109 .collect (Collectors .toList ());
108110 private static final @ NonNull List <@ NonNull StatisticsHolderUserDefined > EXPECTED_STATS_FULL_USER_DEFINED = Arrays .asList (
109111 new StatisticsHolderUserDefined ("" , 2 , -1 , 0 , 65534 , 32767.0 , 18918.46 , 65535 , 2147385345.0 , 0 , 0 , 65534 , 131068 , USER_DEFINED_EXTRA_VALUE ),
110- new StatisticsHolderUserDefined ("Total" , 12 , 2 , 0 , 65534 , 32767.0 , 18918.46 , 65535 , 2147385345.0 , 0 , 0 , 65534 , 131068 , USER_DEFINED_EXTRA_VALUE ),
111- new StatisticsHolderUserDefined ("even" , 13 , 12 , 0 , 65534 , 32767.0 , 18918.90 , 32768 , 1073709056.0 , 0 , 0 , 65534 , 131068 , USER_DEFINED_EXTRA_VALUE ),
112- new StatisticsHolderUserDefined ("odd" , 14 , 12 , 1 , 65533 , 32767.0 , 18918.32 , 32767 , 1073676289.0 , 1 , 2 , 65533 , 131066 , USER_DEFINED_EXTRA_VALUE ));
112+ new StatisticsHolderUserDefined ("Total" , 13 , 2 , 0 , 65534 , 32767.0 , 18918.46 , 65535 , 2147385345.0 , 0 , 0 , 65534 , 131068 , USER_DEFINED_EXTRA_VALUE ),
113+ new StatisticsHolderUserDefined ("even" , 14 , 13 , 0 , 65534 , 32767.0 , 18918.90 , 32768 , 1073709056.0 , 0 , 0 , 65534 , 131068 , USER_DEFINED_EXTRA_VALUE ),
114+ new StatisticsHolderUserDefined ("odd" , 15 , 13 , 1 , 65533 , 32767.0 , 18918.32 , 32767 , 1073676289.0 , 1 , 2 , 65533 , 131066 , USER_DEFINED_EXTRA_VALUE ));
113115
114116 private static List <ITableColumnDescriptor > fExpectedDescriptors ;
115117 private static List <ITableColumnDescriptor > fExpectedDescriptorsUserDefined ;
116118
117119 private static SegmentStoreStatisticsDataProvider fTestDataProvider ;
118120 private static SegmentStoreStatisticsDataProvider fTestDataProvider2 ;
119121 private static SegmentStoreStatisticsDataProvider fTestDataProviderWithUserDefinedAspect ;
122+ private static SegmentStoreStatisticsDataProvider fTestDataProviderWithModuleError ;
120123
121124 private static TmfXmlTraceStub fTrace ;
122125
@@ -170,6 +173,10 @@ public String getName() {
170173 }
171174 };
172175 fTestDataProviderWithUserDefinedAspect = new SegmentStoreStatisticsDataProvider (trace , fixture , "org.eclipse.tracecompass.analysis.timing.core.tests.segmentstore" , Arrays .asList (userDefinedAspect ));
176+
177+ fixture = getValidSegmentStats (fTrace , true );
178+ fTestDataProviderWithModuleError = new SegmentStoreStatisticsDataProvider (trace , fixture , "org.eclipse.tracecompass.analysis.timing.core.tests.segmentstore" );
179+
173180 }
174181
175182 /**
@@ -189,6 +196,10 @@ public static void cleanup() {
189196 fTestDataProviderWithUserDefinedAspect .dispose ();
190197 }
191198
199+ if (fTestDataProviderWithModuleError != null ) {
200+ fTestDataProviderWithModuleError .dispose ();
201+ }
202+
192203 if (fTrace != null ) {
193204 fTrace .dispose ();
194205 }
@@ -341,11 +352,40 @@ public void testFetchTreeWithUserDefinedAspectsFullRange() {
341352 EXPECTED_STATS_FULL_USER_DEFINED .size ());
342353 }
343354
355+ /**
356+ * Verify that data provider query returns FAILED if analysis failed.
357+ */
358+ @ Test
359+ public void testModuleExecutionError () {
360+ long start = 1024 ;
361+ long end = 4096 ;
362+ FilterTimeQueryFilter filter = new FilterTimeQueryFilter (start , end , 2 , true );
363+ Map <@ NonNull String , @ NonNull Object > fetchParameters = FetchParametersUtils .filteredTimeQueryToMap (filter );
364+ TmfModelResponse <@ NonNull TmfTreeModel <@ NonNull SegmentStoreStatisticsModel >> response = fTestDataProviderWithModuleError .fetchTree (fetchParameters , new NullProgressMonitor ());
365+ assertNotNull (response );
366+ assertEquals (ITmfResponse .Status .FAILED , response .getStatus ());
367+ TmfTreeModel <@ NonNull SegmentStoreStatisticsModel > treeModel = response .getModel ();
368+ assertNull (treeModel );
369+ }
370+
371+
344372 // ------------------------------------------------------------------------
345373 // Helpers
346374 // ------------------------------------------------------------------------
347375 private static @ NonNull StubSegmentStatisticsAnalysis getValidSegmentStats (@ NonNull ITmfTrace trace ) throws TmfAnalysisException {
348- StubSegmentStatisticsAnalysis fixture = new StubSegmentStatisticsAnalysis ();
376+ return getValidSegmentStats (trace , false );
377+ }
378+
379+ private static @ NonNull StubSegmentStatisticsAnalysis getValidSegmentStats (@ NonNull ITmfTrace trace , boolean moduleError ) throws TmfAnalysisException {
380+ StubSegmentStatisticsAnalysis fixture = new StubSegmentStatisticsAnalysis () {
381+ @ Override
382+ public boolean executeAnalysis (@ NonNull IProgressMonitor monitor ) throws TmfAnalysisException {
383+ if (moduleError ) {
384+ throw new TmfAnalysisException ("Failure" );
385+ }
386+ return super .executeAnalysis (monitor );
387+ }
388+ };
349389 fixture .setTrace (trace );
350390 fixture .getDependentAnalyses ();
351391 fixture .schedule ();
0 commit comments