timing.core: add stream unit tests to segment store tests
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 8 Sep 2016 01:00:13 +0000 (21:00 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 15 Sep 2016 15:35:28 +0000 (11:35 -0400)
Now test stream building segment statistics.

Also improve speed of other tests marginally by pre-allocating
arrays to right size.

Change-Id: I6894c8a92b95a6fc4bc4339e4dd33901939963f2
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/80640
Reviewed-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
analysis/org.eclipse.tracecompass.analysis.timing.core.tests/src/org/eclipse/tracecompass/analysis/timing/core/tests/segmentstore/statistics/SegmentStoreStatisticsTest.java

index 3be02e39194671f4390d05a6dd765161f8d3f0a1..640b70ab179747af6fc01bf79372ec6b82d65e95 100644 (file)
@@ -50,7 +50,7 @@ public class SegmentStoreStatisticsTest {
      */
     @Test
     public void climbTest() {
-        List<@NonNull ISegment> fixture = new ArrayList<>();
+        List<@NonNull ISegment> fixture = new ArrayList<>(MEDIUM_AMOUNT_OF_SEGMENTS);
         for (int i = 0; i < MEDIUM_AMOUNT_OF_SEGMENTS; i++) {
             fixture.add(createDummySegment(i, i * 2));
         }
@@ -77,7 +77,7 @@ public class SegmentStoreStatisticsTest {
      */
     @Test
     public void decrementingTest() {
-        List<@NonNull ISegment> fixture = new ArrayList<>();
+        List<@NonNull ISegment> fixture = new ArrayList<>(MEDIUM_AMOUNT_OF_SEGMENTS);
         for (int i = MEDIUM_AMOUNT_OF_SEGMENTS; i >= 0; i--) {
             fixture.add(createDummySegment(i, i * 2));
         }
@@ -108,7 +108,7 @@ public class SegmentStoreStatisticsTest {
      */
     @Test
     public void largeTest() {
-        List<@NonNull ISegment> fixture = new ArrayList<>();
+        List<@NonNull ISegment> fixture = new ArrayList<>(LARGE_AMOUNT_OF_SEGMENTS);
         for (int i = 1; i <= LARGE_AMOUNT_OF_SEGMENTS; i++) {
             fixture.add(createDummySegment(i, i * 2));
         }
@@ -122,7 +122,7 @@ public class SegmentStoreStatisticsTest {
     public void noiseTest() {
         Random rnd = new Random();
         rnd.setSeed(1234);
-        List<@NonNull ISegment> fixture = new ArrayList<>();
+        List<@NonNull ISegment> fixture = new ArrayList<>(LARGE_AMOUNT_OF_SEGMENTS);
         for (int i = 1; i <= LARGE_AMOUNT_OF_SEGMENTS; i++) {
             int start = Math.abs(rnd.nextInt(100000000));
             int end = start + Math.abs(rnd.nextInt(1000000));
@@ -138,7 +138,7 @@ public class SegmentStoreStatisticsTest {
     public void gaussianNoiseTest() {
         Random rnd = new Random();
         rnd.setSeed(1234);
-        List<@NonNull ISegment> fixture = new ArrayList<>();
+        List<@NonNull ISegment> fixture = new ArrayList<>(LARGE_AMOUNT_OF_SEGMENTS);
         for (int i = 1; i <= LARGE_AMOUNT_OF_SEGMENTS; i++) {
             int start = Math.abs(rnd.nextInt(100000000));
             final int delta = Math.abs(rnd.nextInt(1000));
@@ -148,6 +148,38 @@ public class SegmentStoreStatisticsTest {
         testOnlineVsOffline(fixture);
     }
 
+    /**
+     * Test building a statistics store with streams
+     */
+    @Test
+    public void streamBuildingTest() {
+        SegmentStoreStatistics expected = new SegmentStoreStatistics();
+        List<@NonNull ISegment> fixture = new ArrayList<>(LARGE_AMOUNT_OF_SEGMENTS);
+        for (long i = 0; i < LARGE_AMOUNT_OF_SEGMENTS; i++) {
+            fixture.add(new BasicSegment(i, i + 2));
+        }
+        fixture.forEach(e -> expected.update(e));
+        SegmentStoreStatistics actual = fixture.stream()
+                .<@NonNull SegmentStoreStatistics> collect(SegmentStoreStatistics::new, SegmentStoreStatistics::update, SegmentStoreStatistics::merge);
+        validate(expected, actual);
+    }
+
+    /**
+     * Test building a statistics store with parallel streams
+     */
+    @Test
+    public void parallelStreamBuildingTest() {
+        SegmentStoreStatistics expected = new SegmentStoreStatistics();
+        List<@NonNull ISegment> fixture = new ArrayList<>(LARGE_AMOUNT_OF_SEGMENTS);
+        for (long i = 0; i < LARGE_AMOUNT_OF_SEGMENTS; i++) {
+            fixture.add(new BasicSegment(i, i + 2));
+        }
+        fixture.forEach(e -> expected.update(e));
+        SegmentStoreStatistics actual = fixture.parallelStream()
+                .<@NonNull SegmentStoreStatistics> collect(SegmentStoreStatistics::new, SegmentStoreStatistics::update, SegmentStoreStatistics::merge);
+        validate(expected, actual);
+    }
+
     /**
      * Test statistics nodes being merged. Two contiguous blocks.
      */
This page took 0.027311 seconds and 5 git commands to generate.