9b99e820c3bf8d79e95ea980c65dedf049ca4a42
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.eventlog
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertFalse
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import java
.util
.Vector
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
23 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
24 import org
.junit
.BeforeClass
;
25 import org
.junit
.Test
;
28 * <b><u>TmfEventLogTest</u></b>
30 * TODO: Implement me. Please.
32 public class TmfEventLogTest
{
34 private static String filename
= "Test-10K";
35 private static int fTotalNbEvents
= 10000;
36 private static ITmfEventParser fParser
;
37 private static TmfEventStream fStream
;
40 public static void setUpBeforeClass() throws Exception
{
41 fParser
= new TmfEventParserStub();
42 fStream
= new TmfEventStreamStub(filename
, fParser
);
45 // ========================================================================
47 // ========================================================================
50 public void testBasicTmfEventLog() {
51 TmfTrace eventLog
= new TmfTrace("MyEventLog", fStream
);
53 assertEquals("GetId", "MyEventLog", eventLog
.getId());
54 assertEquals("GetEpoch", TmfTimestamp
.BigBang
, eventLog
.getEpoch());
55 assertEquals("GetNbEvents", fTotalNbEvents
, eventLog
.getNbEvents());
57 TmfTimeRange timeRange
= eventLog
.getTimeRange();
58 assertEquals("GetTimeRange", 0, timeRange
.getStartTime().getValue());
59 assertEquals("GetTimeRange", fTotalNbEvents
- 1, timeRange
.getEndTime().getValue());
63 public void testTmfEventLogWithEpoch() {
64 TmfTimestamp epoch
= new TmfTimestamp(100, (byte) 0, 0);
65 TmfTrace eventLog
= new TmfTrace("MyEventLog", fStream
, epoch
);
67 assertEquals("GetId", "MyEventLog", eventLog
.getId());
68 assertEquals("GetEpoch", epoch
, eventLog
.getEpoch());
69 assertEquals("GetNbEvents", fTotalNbEvents
, eventLog
.getNbEvents());
71 TmfTimeRange timeRange
= eventLog
.getTimeRange();
72 assertEquals("GetTimeRange", 0, timeRange
.getStartTime().getValue());
73 assertEquals("GetTimeRange", fTotalNbEvents
- 1, timeRange
.getEndTime().getValue());
76 // ========================================================================
78 // ========================================================================
81 public void testProcessRequestForNbEvents() throws Exception
{
83 TmfTrace eventLog
= new TmfTrace("MyEventLog", fStream
);
85 final int NB_EVENTS
= 10 * 1000;
86 final int BLOCK_SIZE
= 100;
87 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
89 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
90 final TmfEventRequest request
= new TmfEventRequest(range
, 0, NB_EVENTS
, BLOCK_SIZE
) {
92 public void newEvents(Vector
<TmfEvent
> events
) {
93 for (TmfEvent e
: events
) {
94 requestedEvents
.add(e
);
98 eventLog
.process(request
, true);
100 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
101 assertTrue("isCompleted", request
.isCompleted());
102 assertFalse("isCancelled", request
.isCancelled());
104 // Ensure that we have distinct events.
105 // Don't go overboard: we are not validating the stub!
106 for (int i
= 0; i
< NB_EVENTS
; i
++) {
107 assertEquals("Distinct events", i
, requestedEvents
.get(i
).getTimestamp().getValue());
112 public void testProcessRequestForAllEvents() throws Exception
{
114 TmfTrace eventLog
= new TmfTrace("MyEventLog", fStream
);
116 final int NB_EVENTS
= -1;
117 final int BLOCK_SIZE
= 1;
118 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
119 int nbExpectedEvents
= eventLog
.getNbEvents();
121 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
122 final TmfEventRequest request
= new TmfEventRequest(range
, 0, NB_EVENTS
, BLOCK_SIZE
) {
124 public void newEvents(Vector
<TmfEvent
> events
) {
125 for (TmfEvent e
: events
) {
126 requestedEvents
.add(e
);
130 eventLog
.process(request
, true);
132 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
133 assertTrue("isCompleted", request
.isCompleted());
134 assertFalse("isCancelled", request
.isCancelled());
136 // Ensure that we have distinct events.
137 // Don't go overboard: we are not validating the stub!
138 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
139 assertEquals("Distinct events", i
, requestedEvents
.get(i
).getTimestamp().getValue());
144 public void testProcessRequestWithOffset() throws Exception
{
146 TmfTrace eventLog
= new TmfTrace("MyEventLog", fStream
);
148 final int NB_EVENTS
= -1;
149 final int BLOCK_SIZE
= 1;
150 final int OFFSET
= 5;
151 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
152 int nbExpectedEvents
= TmfRequestHandlerStub
.MAX_GENERATED_EVENTS
;
154 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
155 final TmfEventRequest request
= new TmfEventRequest(range
, OFFSET
, NB_EVENTS
, BLOCK_SIZE
) {
157 public void newEvents(Vector
<TmfEvent
> events
) {
158 for (TmfEvent e
: events
) {
159 requestedEvents
.add(e
);
163 eventLog
.process(request
, true);
165 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
166 assertTrue("isCompleted", request
.isCompleted());
167 assertFalse("isCancelled", request
.isCancelled());
169 // Ensure that we have distinct events.
170 // Don't go overboard: we are not validating the stub!
171 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
172 assertEquals("Distinct events", i
+ OFFSET
, requestedEvents
.get(i
).getTimestamp().getValue());
177 public void testProcessRequestWithNegativeOffset() throws Exception
{
179 TmfTrace eventLog
= new TmfTrace("MyEventLog", fStream
);
181 final int NB_EVENTS
= -1;
182 final int BLOCK_SIZE
= 1;
183 final int OFFSET
= -5;
184 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
185 int nbExpectedEvents
= TmfRequestHandlerStub
.MAX_GENERATED_EVENTS
;
187 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
188 final TmfEventRequest request
= new TmfEventRequest(range
, OFFSET
, NB_EVENTS
, BLOCK_SIZE
) {
190 public void newEvents(Vector
<TmfEvent
> events
) {
191 for (TmfEvent e
: events
) {
192 requestedEvents
.add(e
);
196 eventLog
.process(request
, true);
198 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
199 assertTrue("isCompleted", request
.isCompleted());
200 assertFalse("isCancelled", request
.isCancelled());
202 // Ensure that we have distinct events.
203 // Don't go overboard: we are not validating the stub!
204 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
205 assertEquals("Distinct events", i
+ OFFSET
, requestedEvents
.get(i
).getTimestamp().getValue());
209 // ========================================================================
211 // ========================================================================
214 public void testCancel() throws Exception
{
216 TmfTrace eventLog
= new TmfTrace("MyEventLog", fStream
);
218 final int NB_EVENTS
= 10 * 1000;
219 final int BLOCK_SIZE
= 100;
220 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
222 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
223 final TmfEventRequest request
= new TmfEventRequest(range
, 0, NB_EVENTS
, BLOCK_SIZE
) {
225 public void newEvents(Vector
<TmfEvent
> events
) {
226 for (TmfEvent e
: events
) {
227 requestedEvents
.add(e
);
229 // Cancel request after the first chunk is received
233 eventLog
.process(request
, true);
235 assertEquals("nbEvents", BLOCK_SIZE
, requestedEvents
.size());
236 assertTrue("isCompleted", request
.isCompleted());
237 assertTrue("isCancelled", request
.isCancelled());
This page took 0.03691 seconds and 4 git commands to generate.