Fix another pile of Javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfLightweightContextTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
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 *
9 * Contributors:
10 * Matthew Khouzam - Initial implementation
11 * Alexandre Montplaisir
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
16 import static org.junit.Assert.assertTrue;
17
18 import java.util.ArrayList;
19
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;
27
28 /**
29 * Tests for the CtfTmfLightweightContext class
30 *
31 * @author Matthew Khouzam
32 * @version 1.1
33 */
34 public class CtfTmfLightweightContextTest {
35
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 */
39
40 private CtfTmfTrace fixture;
41
42 private class SeekerThread extends Thread {
43 long val;
44
45 public void setVal(long val) {
46 this.val = val;
47 }
48 }
49
50 /**
51 * Pre-test initialization
52 *
53 * @throws TmfTraceException
54 * If the trace couldn't be init'ed, which shouldn't happen.
55 */
56 @Before
57 public void setUp() throws TmfTraceException {
58 fixture = new CtfTmfTrace();
59 fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class);
60 }
61
62 /**
63 * Index all the events in the test trace.
64 */
65 @Test
66 public void testIndexing() {
67 CtfTmfLightweightContext context = new CtfTmfLightweightContext(fixture);
68 context.seek(0);
69
70 int count = 0;
71 while (fixture.getNext(context) != null) {
72 count++;
73 }
74 assertTrue(count > 0);
75 }
76
77 /**
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.
80 *
81 * @throws InterruptedException
82 * Would fail the test
83 */
84 @Test
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>();
91
92 for (double i = begin; i < end; i += increment) {
93 SeekerThread thread = new SeekerThread() {
94 @Override
95 public void run() {
96 CtfTmfLightweightContext lwc = new CtfTmfLightweightContext(fixture);
97 lwc.seek(val);
98 fixture.getNext(lwc);
99 synchronized(fixture){
100 vals.add(lwc.getCurrentEvent().getTimestampValue());
101 tooManyContexts.add(lwc);
102 }
103 }
104 };
105 thread.setVal((long)i);
106 threads.add(thread);
107 thread.start();
108 }
109
110 for( Thread t: threads){
111 t.join();
112 }
113
114 for( Long val : vals){
115 assertTrue(val >= begin);
116 assertTrue(val <= end);
117 }
118 }
119 }
This page took 0.035095 seconds and 5 git commands to generate.