1 /*******************************************************************************
2 * Copyright (c) 2012 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
10 * Matthew Khouzam - Initial implementation
11 * Alexandre Montplaisir
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.ctfadaptor
;
16 import static org
.junit
.Assert
.assertTrue
;
18 import java
.util
.ArrayList
;
20 import org
.eclipse
.core
.resources
.IResource
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfLightweightContext
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
25 import org
.junit
.Before
;
26 import org
.junit
.Test
;
29 * Tests for the CtfTmfLightweightContext class
31 * @author Matthew Khouzam
34 public class CtfTmfLightweightContextTest
{
36 private static final String PATH
= TestParams
.getPath();
37 private static final long begin
= 1332170682440133097L; /* Trace start time */
38 private static final long end
= 1332170692664579801L; /* Trace end time */
40 private CtfTmfTrace fixture
;
42 private class SeekerThread
extends Thread
{
45 public void setVal(long val
) {
51 * Pre-test initialization
53 * @throws TmfTraceException
54 * If the trace couldn't be init'ed, which shouldn't happen.
57 public void setUp() throws TmfTraceException
{
58 fixture
= new CtfTmfTrace();
59 fixture
.initTrace((IResource
) null, PATH
, CtfTmfEvent
.class);
63 * Index all the events in the test trace.
66 public void testIndexing() {
67 CtfTmfLightweightContext context
= new CtfTmfLightweightContext(fixture
);
71 while (fixture
.getNext(context
) != null) {
74 assertTrue(count
> 0);
78 * Context fuzzer. Use an amount of contexts greater than the size of the
79 * iterator cache and have them access the trace in parallel.
81 * @throws InterruptedException
85 public void testTooManyContexts() throws InterruptedException
{
86 final int lwcCount
= 101;
87 double increment
= (end
- begin
) / lwcCount
;
88 final ArrayList
<Long
> vals
= new ArrayList
<Long
>();
89 final ArrayList
<Thread
> threads
= new ArrayList
<Thread
>();
90 final ArrayList
<CtfTmfLightweightContext
> tooManyContexts
= new ArrayList
<CtfTmfLightweightContext
>();
92 for (double i
= begin
; i
< end
; i
+= increment
) {
93 SeekerThread thread
= new SeekerThread() {
96 CtfTmfLightweightContext lwc
= new CtfTmfLightweightContext(fixture
);
99 synchronized(fixture
){
100 vals
.add(lwc
.getCurrentEvent().getTimestampValue());
101 tooManyContexts
.add(lwc
);
105 thread
.setVal((long)i
);
110 for( Thread t
: threads
){
114 for( Long val
: vals
){
115 assertTrue(val
>= begin
);
116 assertTrue(val
<= end
);