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
;
19 import static org
.junit
.Assume
.assumeTrue
;
21 import java
.util
.ArrayList
;
23 import org
.eclipse
.core
.resources
.IResource
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfContext
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTraces
;
29 import org
.junit
.Before
;
30 import org
.junit
.Test
;
33 * Tests for the CtfTmfLightweightContext class
35 * @author Matthew Khouzam
38 public class CtfTmfContextTest
{
40 private static final int TRACE_INDEX
= 0;
41 private static final long begin
= 1332170682440133097L; /* Trace start time */
42 private static final long end
= 1332170692664579801L; /* Trace end time */
44 private CtfTmfTrace trace
;
46 private class SeekerThread
extends Thread
{
49 public void setVal(long val
) {
55 * Pre-test initialization
57 * @throws TmfTraceException
58 * If the trace couldn't be init'ed, which shouldn't happen.
61 public void setUp() throws TmfTraceException
{
62 assumeTrue(CtfTmfTestTraces
.tracesExist());
63 trace
= new CtfTmfTrace();
64 String path
= CtfTmfTestTraces
.getTestTracePath(TRACE_INDEX
);
65 trace
.initTrace((IResource
) null, path
, CtfTmfEvent
.class);
69 * Index all the events in the test trace.
72 public void testIndexing() {
73 CtfTmfContext context
= new CtfTmfContext(trace
);
77 while (trace
.getNext(context
) != null) {
80 assertTrue(count
> 0);
84 * Context fuzzer. Use an amount of contexts greater than the size of the
85 * iterator cache and have them access the trace in parallel.
87 * @throws InterruptedException
91 public void testTooManyContexts() throws InterruptedException
{
92 final int lwcCount
= 101;
93 double increment
= (end
- begin
) / lwcCount
;
94 final ArrayList
<Long
> vals
= new ArrayList
<Long
>();
95 final ArrayList
<Thread
> threads
= new ArrayList
<Thread
>();
96 final ArrayList
<CtfTmfContext
> tooManyContexts
= new ArrayList
<CtfTmfContext
>();
98 for (double i
= begin
; i
< end
; i
+= increment
) {
99 SeekerThread thread
= new SeekerThread() {
102 CtfTmfContext lwc
= new CtfTmfContext(trace
);
106 if (lwc
.getCurrentEvent() != null) {
107 vals
.add(lwc
.getCurrentEvent().getTimestamp().getValue());
109 tooManyContexts
.add(lwc
);
113 thread
.setVal((long)i
);
118 for( Thread t
: threads
){
122 for( Long val
: vals
){
123 assertTrue(val
>= begin
);
124 assertTrue(val
<= end
);
129 * Test for clone method
132 public void testClone() {
133 CtfTmfContext fixture1
= new CtfTmfContext(trace
);
134 CtfTmfContext fixture2
= fixture1
.clone();
135 //assertTrue(fixture1.equals(fixture2)); FIXME no .equals() override!
136 assertNotSame(fixture1
, fixture2
);
138 /* Make sure clone() did its job */
139 assertSame(fixture1
.getTrace(), fixture2
.getTrace());
140 assertSame(fixture1
.getLocation(), fixture2
.getLocation());
141 assertSame(fixture1
.getRank(), fixture2
.getRank());
This page took 0.032658 seconds and 5 git commands to generate.