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
.assertNotSame
;
17 import static org
.junit
.Assert
.assertSame
;
18 import static org
.junit
.Assert
.assertTrue
;
20 import java
.util
.ArrayList
;
22 import org
.eclipse
.core
.resources
.IResource
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfContext
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
27 import org
.junit
.Before
;
28 import org
.junit
.Test
;
31 * Tests for the CtfTmfLightweightContext class
33 * @author Matthew Khouzam
36 public class CtfTmfContextTest
{
38 private static final String PATH
= TestParams
.getPath();
39 private static final long begin
= 1332170682440133097L; /* Trace start time */
40 private static final long end
= 1332170692664579801L; /* Trace end time */
42 private CtfTmfTrace trace
;
44 private class SeekerThread
extends Thread
{
47 public void setVal(long val
) {
53 * Pre-test initialization
55 * @throws TmfTraceException
56 * If the trace couldn't be init'ed, which shouldn't happen.
59 public void setUp() throws TmfTraceException
{
60 trace
= new CtfTmfTrace();
61 trace
.initTrace((IResource
) null, PATH
, CtfTmfEvent
.class);
65 * Index all the events in the test trace.
68 public void testIndexing() {
69 CtfTmfContext context
= new CtfTmfContext(trace
);
73 while (trace
.getNext(context
) != null) {
76 assertTrue(count
> 0);
80 * Context fuzzer. Use an amount of contexts greater than the size of the
81 * iterator cache and have them access the trace in parallel.
83 * @throws InterruptedException
87 public void testTooManyContexts() throws InterruptedException
{
88 final int lwcCount
= 101;
89 double increment
= (end
- begin
) / lwcCount
;
90 final ArrayList
<Long
> vals
= new ArrayList
<Long
>();
91 final ArrayList
<Thread
> threads
= new ArrayList
<Thread
>();
92 final ArrayList
<CtfTmfContext
> tooManyContexts
= new ArrayList
<CtfTmfContext
>();
94 for (double i
= begin
; i
< end
; i
+= increment
) {
95 SeekerThread thread
= new SeekerThread() {
98 CtfTmfContext lwc
= new CtfTmfContext(trace
);
102 if (lwc
.getCurrentEvent() != null) {
103 vals
.add(lwc
.getCurrentEvent().getTimestamp().getValue());
105 tooManyContexts
.add(lwc
);
109 thread
.setVal((long)i
);
114 for( Thread t
: threads
){
118 for( Long val
: vals
){
119 assertTrue(val
>= begin
);
120 assertTrue(val
<= end
);
125 * Test for clone method
128 public void testClone() {
129 CtfTmfContext fixture1
= new CtfTmfContext(trace
);
130 CtfTmfContext fixture2
= fixture1
.clone();
131 //assertTrue(fixture1.equals(fixture2)); FIXME no .equals() override!
132 assertNotSame(fixture1
, fixture2
);
134 /* Make sure clone() did its job */
135 assertSame(fixture1
.getTrace(), fixture2
.getTrace());
136 assertSame(fixture1
.getLocation(), fixture2
.getLocation());
137 assertSame(fixture1
.getRank(), fixture2
.getRank());
This page took 0.036067 seconds and 5 git commands to generate.