1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.segmentstore
.core
.tests
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
17 import java
.util
.Random
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.tracecompass
.segmentstore
.core
.BasicSegment
;
21 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
22 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegmentStore
;
23 import org
.eclipse
.tracecompass
.segmentstore
.core
.SegmentStoreFactory
;
24 import org
.eclipse
.tracecompass
.segmentstore
.core
.SegmentStoreFactory
.SegmentStoreType
;
25 import org
.junit
.Test
;
28 * Segment Store factory test
30 * @author Matthew Khouzam
33 public class SegmentStoreFactoryTest
{
36 * Simplest create function, should always work
39 public void simpleCreate() {
40 assertNotNull(SegmentStoreFactory
.createSegmentStore());
44 * Create a fast segment store. Should always return the fastest
45 * implementation available
48 public void createFast() {
49 assertNotNull(SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Fast
));
53 * Create a stable segment store, should always return a segment store that
54 * does not change much its performance memory or cpu
57 public void createStable() {
58 assertNotNull(SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Stable
));
62 * Create a "set" like segment store
65 public void createDistinct() {
66 ISegmentStore
<@NonNull ISegment
> fixture
= SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Distinct
);
67 assertNotNull(fixture
);
68 testDistinct(fixture
);
72 * Make sure mixing flags works
75 public void createDistinctFast() {
76 ISegmentStore
<@NonNull ISegment
> fixture
= SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Distinct
, SegmentStoreType
.Fast
);
77 testDistinct(fixture
);
81 * Make sure mixing flags works
84 public void createDistinctStable() {
85 ISegmentStore
<@NonNull ISegment
> fixture
= SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Distinct
, SegmentStoreType
.Stable
);
86 testDistinct(fixture
);
90 * Make sure mixing flags works
93 public void createDoubleDistinct() {
94 ISegmentStore
<@NonNull ISegment
> fixture
= SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Distinct
, SegmentStoreType
.Distinct
);
95 assertNotNull(fixture
);
96 testDistinct(fixture
);
100 * Make sure mixing flags works (power set of all types)
103 public void createAllDressed() {
104 testDistinct(SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Distinct
, SegmentStoreType
.Stable
, SegmentStoreType
.Fast
));
105 testDistinct(SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Distinct
, SegmentStoreType
.Fast
, SegmentStoreType
.Stable
));
106 testDistinct(SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Stable
, SegmentStoreType
.Distinct
, SegmentStoreType
.Fast
));
107 testDistinct(SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Stable
, SegmentStoreType
.Fast
, SegmentStoreType
.Distinct
));
108 testDistinct(SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Fast
, SegmentStoreType
.Distinct
, SegmentStoreType
.Stable
));
109 testDistinct(SegmentStoreFactory
.createSegmentStore(SegmentStoreType
.Fast
, SegmentStoreType
.Stable
, SegmentStoreType
.Distinct
));
113 * Torture test, add many redundant flags
115 @SuppressWarnings("null")
117 public void createTortureTest() {
118 Random rnd
= new Random();
119 List
<@NonNull SegmentStoreType
> args
= new ArrayList
<>();
121 int nbValues
= SegmentStoreType
.values().length
;
122 args
.add(SegmentStoreType
.Distinct
);
123 for (int i
= 0; i
< 1000; i
++) {
124 int nextInt
= rnd
.nextInt(nbValues
);
125 args
.add(SegmentStoreType
.values()[nextInt
]);
127 SegmentStoreType
@NonNull [] array
= args
.toArray(new SegmentStoreType
[args
.size()]);
128 assertNotNull(array
);
129 testDistinct(SegmentStoreFactory
.createSegmentStore(array
));
133 * Create a pre-loaded fast segment store
136 public void createPreloaded() {
137 ISegment
[] data
= new ISegment
[1];
138 data
[0] = new BasicSegment(0, 0);
139 ISegmentStore
<@NonNull ISegment
> segmentStore
;
140 segmentStore
= SegmentStoreFactory
.createSegmentStore(data
);
141 assertNotNull(segmentStore
);
142 assertEquals(1, segmentStore
.size());
143 segmentStore
= SegmentStoreFactory
.createSegmentStore(data
, SegmentStoreType
.Fast
);
144 assertNotNull(segmentStore
);
145 assertEquals(1, segmentStore
.size());
146 segmentStore
= SegmentStoreFactory
.createSegmentStore(data
, SegmentStoreType
.Stable
);
147 assertNotNull(segmentStore
);
148 assertEquals(1, segmentStore
.size());
149 segmentStore
= SegmentStoreFactory
.createSegmentStore(data
, SegmentStoreType
.Distinct
);
150 assertNotNull(segmentStore
);
151 assertEquals(1, segmentStore
.size());
154 private static void testDistinct(ISegmentStore
<@NonNull ISegment
> fixture
) {
155 // test adding the same object
156 ISegment seg
= new BasicSegment(0, 0);
159 assertEquals(1, fixture
.size());
161 // test different equal objects
162 fixture
.add(new BasicSegment(0, 0));
163 fixture
.add(new BasicSegment(0, 0));
164 assertEquals(1, fixture
.size());
This page took 0.034802 seconds and 5 git commands to generate.