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 - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.request
;
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
.eclipse
.linuxtools
.tmf
.request
.ITmfRequestHandler
;
25 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequest
;
26 import org
.junit
.BeforeClass
;
27 import org
.junit
.Test
;
30 * <b><u>TmfDataRequestTest</u></b>
32 * TODO: Implement me. Please.
34 public class TmfDataRequestTest
{
36 private static ITmfRequestHandler
<TmfEvent
> fProcessor
= null;
39 public static void setUpBeforeClass() throws Exception
{
40 fProcessor
= new TmfRequestHandlerStub();
43 // ========================================================================
45 // ========================================================================
48 public void testConstructorForRange() throws Exception
{
49 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
50 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(range
, 0, -1, 1);
52 assertEquals("StartTime", TmfTimestamp
.BigBang
, request
.getRange().getStartTime());
53 assertEquals("EndTime", TmfTimestamp
.BigCrunch
, request
.getRange().getEndTime());
54 assertEquals("Offset", 0, request
.getOffset());
55 assertEquals("NbRequestedEvents", -1, request
.getNbRequestedItems());
59 public void testConstructorForNbEvents() throws Exception
{
60 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
61 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(range
, 0, 10, 1);
63 assertEquals("StartTime", TmfTimestamp
.BigBang
, request
.getRange().getStartTime());
64 assertEquals("EndTime", TmfTimestamp
.BigCrunch
, request
.getRange().getEndTime());
65 assertEquals("Offset", 0, request
.getOffset());
66 assertEquals("NbRequestedEvents", 10, request
.getNbRequestedItems());
70 public void testConstructorWithOffset() throws Exception
{
71 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
72 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(range
, 5, 10, 1);
74 assertEquals("StartTime", TmfTimestamp
.BigBang
, request
.getRange().getStartTime());
75 assertEquals("EndTime", TmfTimestamp
.BigCrunch
, request
.getRange().getEndTime());
76 assertEquals("Offset", 5, request
.getOffset());
77 assertEquals("NbRequestedEvents", 10, request
.getNbRequestedItems());
81 public void testConstructorWithNegativeOffset() throws Exception
{
82 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
83 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(range
, -5, 10, 1);
85 assertEquals("StartTime", TmfTimestamp
.BigBang
, request
.getRange().getStartTime());
86 assertEquals("EndTime", TmfTimestamp
.BigCrunch
, request
.getRange().getEndTime());
87 assertEquals("Offset", -5, request
.getOffset());
88 assertEquals("NbRequestedEvents", 10, request
.getNbRequestedItems());
91 // ========================================================================
93 // ========================================================================
96 public void testProcessRequestForNbEvents() throws Exception
{
98 final int NB_EVENTS
= 10 * 1000;
99 final int BLOCK_SIZE
= 100;
100 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
102 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
103 final TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(range
, 0, NB_EVENTS
, BLOCK_SIZE
) {
105 public void handlePartialResult() {
106 TmfEvent
[] events
= getData();
107 for (TmfEvent e
: events
) {
108 requestedEvents
.add(e
);
112 fProcessor
.processRequest(request
, true);
114 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
115 assertTrue("isCompleted", request
.isCompleted());
116 assertFalse("isCancelled", request
.isCancelled());
118 // Ensure that we have distinct events.
119 // Don't go overboard: we are not validating the stub!
120 for (int i
= 0; i
< NB_EVENTS
; i
++) {
121 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
126 public void testProcessRequestForAllEvents() throws Exception
{
128 final int NB_EVENTS
= -1;
129 final int BLOCK_SIZE
= 1;
130 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
131 int nbExpectedEvents
= TmfRequestHandlerStub
.MAX_GENERATED_EVENTS
;
133 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
134 final TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(range
, 0, NB_EVENTS
, BLOCK_SIZE
) {
136 public void handlePartialResult() {
137 TmfEvent
[] events
= getData();
138 for (TmfEvent e
: events
) {
139 requestedEvents
.add(e
);
143 fProcessor
.processRequest(request
, true);
145 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
146 assertTrue("isCompleted", request
.isCompleted());
147 assertFalse("isCancelled", request
.isCancelled());
149 // Ensure that we have distinct events.
150 // Don't go overboard: we are not validating the stub!
151 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
152 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
157 public void testProcessRequestWithOffset() throws Exception
{
159 final int NB_EVENTS
= -1;
160 final int BLOCK_SIZE
= 1;
161 final int OFFSET
= 5;
162 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
163 int nbExpectedEvents
= TmfRequestHandlerStub
.MAX_GENERATED_EVENTS
;
165 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
166 final TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(range
, OFFSET
, NB_EVENTS
, BLOCK_SIZE
) {
168 public void handlePartialResult() {
169 TmfEvent
[] events
= getData();
170 for (TmfEvent e
: events
) {
171 requestedEvents
.add(e
);
175 fProcessor
.processRequest(request
, true);
177 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
178 assertTrue("isCompleted", request
.isCompleted());
179 assertFalse("isCancelled", request
.isCancelled());
181 // Ensure that we have distinct events.
182 // Don't go overboard: we are not validating the stub!
183 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
184 assertEquals("Distinct events", i
+ OFFSET
, requestedEvents
.get(i
).getTimestamp().getValue());
189 public void testProcessRequestWithNegativeOffset() throws Exception
{
191 final int NB_EVENTS
= -1;
192 final int BLOCK_SIZE
= 1;
193 final int OFFSET
= -5;
194 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
195 int nbExpectedEvents
= TmfRequestHandlerStub
.MAX_GENERATED_EVENTS
;
197 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
198 final TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(range
, OFFSET
, NB_EVENTS
, BLOCK_SIZE
) {
200 public void handlePartialResult() {
201 TmfEvent
[] events
= getData();
202 for (TmfEvent e
: events
) {
203 requestedEvents
.add(e
);
207 fProcessor
.processRequest(request
, true);
209 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
210 assertTrue("isCompleted", request
.isCompleted());
211 assertFalse("isCancelled", request
.isCancelled());
213 // Ensure that we have distinct events.
214 // Don't go overboard: we are not validating the stub!
215 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
216 assertEquals("Distinct events", i
+ OFFSET
, requestedEvents
.get(i
).getTimestamp().getValue());
220 // ========================================================================
222 // ========================================================================
225 public void testCancel() throws Exception
{
227 final int NB_EVENTS
= 10 * 1000;
228 final int BLOCK_SIZE
= 100;
229 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
231 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
232 final TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(range
, 0, NB_EVENTS
, BLOCK_SIZE
) {
234 public void handlePartialResult() {
235 TmfEvent
[] events
= getData();
236 for (TmfEvent e
: events
) {
237 requestedEvents
.add(e
);
239 // Cancel request after the first chunk is received
243 fProcessor
.processRequest(request
, true);
245 assertEquals("nbEvents", BLOCK_SIZE
, requestedEvents
.size());
246 assertTrue("isCompleted", request
.isCompleted());
247 assertTrue("isCancelled", request
.isCancelled());
This page took 0.035584 seconds and 5 git commands to generate.