|
Added
Link Here
|
| 1 |
package org.eclipse.linuxtools.lttng.ui.tests.distribution; |
| 2 |
|
| 3 |
import junit.framework.TestCase; |
| 4 |
|
| 5 |
import org.eclipse.linuxtools.lttng.ui.views.latency.model.Config; |
| 6 |
import org.eclipse.linuxtools.lttng.ui.views.latency.model.GraphScaledData; |
| 7 |
import org.eclipse.linuxtools.lttng.ui.views.latency.model.IGraphModelListener; |
| 8 |
import org.eclipse.linuxtools.lttng.ui.views.latency.model.LatencyGraphModel; |
| 9 |
|
| 10 |
@SuppressWarnings("nls") |
| 11 |
public class LatencyGraphModelTest extends TestCase { |
| 12 |
|
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
// Test data |
| 15 |
// ------------------------------------------------------------------------ |
| 16 |
|
| 17 |
// ------------------------------------------------------------------------ |
| 18 |
// Housekeeping |
| 19 |
// ------------------------------------------------------------------------ |
| 20 |
|
| 21 |
@Override |
| 22 |
public void setUp() throws Exception { |
| 23 |
} |
| 24 |
|
| 25 |
@Override |
| 26 |
public void tearDown() throws Exception { |
| 27 |
} |
| 28 |
|
| 29 |
// ------------------------------------------------------------------------ |
| 30 |
// Tests |
| 31 |
// ------------------------------------------------------------------------ |
| 32 |
|
| 33 |
public void testLatencyGraphModel() { |
| 34 |
LatencyGraphModel model = new LatencyGraphModel(); |
| 35 |
assertEquals("nbBuckets", Config.DEFAULT_NUMBER_OF_BUCKETS, model.getNbBuckets()); |
| 36 |
assertEquals("currentTime", Config.INVALID_EVENT_TIME, model.getCurrentEventTime()); |
| 37 |
} |
| 38 |
|
| 39 |
public void testLatencyGraphModelInt() { |
| 40 |
LatencyGraphModel model = new LatencyGraphModel(100); |
| 41 |
assertEquals("nbBuckets", 100, model.getNbBuckets()); |
| 42 |
assertEquals("currentTime", Config.INVALID_EVENT_TIME, model.getCurrentEventTime()); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
public void testGraphModelListener() { |
| 47 |
final int nbBuckets = 2000; |
| 48 |
final int nbEvents = 10 * nbBuckets + 256; |
| 49 |
final int[] count = new int[2]; |
| 50 |
count [0] = 0; |
| 51 |
count [1] = 0; |
| 52 |
|
| 53 |
// Test add listener and call of listener |
| 54 |
IGraphModelListener listener = new IGraphModelListener() { |
| 55 |
|
| 56 |
@Override |
| 57 |
public void graphModelUpdated() { |
| 58 |
count[0]++; |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public void currentEventUpdated(long currentEventTime) { |
| 64 |
count[1]++; |
| 65 |
} |
| 66 |
}; |
| 67 |
|
| 68 |
// Test that the listener interface is called every 10000 events. |
| 69 |
LatencyGraphModel model = new LatencyGraphModel(nbBuckets); |
| 70 |
model.addGraphModelListener(listener); |
| 71 |
for (int i = 0; i < nbEvents; i++) { |
| 72 |
model.countEvent(i+1, i, i); |
| 73 |
} |
| 74 |
|
| 75 |
assertEquals("listener", 2, count[0]); |
| 76 |
|
| 77 |
// Test that the listener interface is called when complete is called. |
| 78 |
model.complete(); |
| 79 |
assertEquals("listener", 3, count[0]); |
| 80 |
|
| 81 |
// Test that clear triggers call of listener interface |
| 82 |
model.clear(); |
| 83 |
assertEquals("listener", 4, count[0]); |
| 84 |
|
| 85 |
// Test that clear triggers call of listener interface |
| 86 |
model.setCurrentEventNotifyListeners(100); |
| 87 |
assertEquals("listener", 1, count[1]); |
| 88 |
|
| 89 |
// Test remove listener |
| 90 |
count[0] = 0; |
| 91 |
count[1] = 0; |
| 92 |
model.removeGraphModelListener(listener); |
| 93 |
|
| 94 |
for (int i = 0; i < nbEvents; i++) { |
| 95 |
model.countEvent(i, i, i); |
| 96 |
} |
| 97 |
model.complete(); |
| 98 |
assertEquals("listener", 0, count[1]); |
| 99 |
|
| 100 |
// Test that clear triggers call of listener interface |
| 101 |
model.setCurrentEventNotifyListeners(100); |
| 102 |
assertEquals("listener", 0, count[1]); |
| 103 |
} |
| 104 |
|
| 105 |
public void testConstructor() { |
| 106 |
final int nbBuckets = 2000; |
| 107 |
|
| 108 |
LatencyGraphModel model = new LatencyGraphModel(nbBuckets); |
| 109 |
GraphScaledData scaledData = model.scaleTo(100, 100, 1); |
| 110 |
|
| 111 |
// Verify model parameters |
| 112 |
assertEquals("Horizontal bucket duration", 1, model.getHorBucketDuration()); |
| 113 |
assertEquals("Vertical bucket duration", 1, model.getVerBucketDuration()); |
| 114 |
|
| 115 |
assertEquals("Horizontal first bucket time", 0, model.getHorFirstBucketTime()); |
| 116 |
assertEquals("Vertical first bucket time", 0, model.getVerFirstBucketTime()); |
| 117 |
|
| 118 |
assertEquals("Horizontal last bucket ", 0, model.getHorLastBucket()); |
| 119 |
assertEquals("Vertical last bucket ", 0, model.getVerLastBucket()); |
| 120 |
|
| 121 |
assertEquals("Horizontal first time", 0, model.getHorFirstEventTime()); |
| 122 |
assertEquals("Vertical first time", 0, model.getVerFirstEventTime()); |
| 123 |
|
| 124 |
assertEquals("Horizontal last time", 0, model.getHorLastEventTime()); |
| 125 |
assertEquals("Vertical last time", 0, model.getVerLastEventTime()); |
| 126 |
|
| 127 |
assertEquals("Horizontal time limit", 2000, model.getHorTimeLimit()); |
| 128 |
assertEquals("Vertical time limit", 2000, model.getVerTimeLimit()); |
| 129 |
|
| 130 |
// Verify scaled data parameters |
| 131 |
scaledData = model.scaleTo(101, 100, 1); |
| 132 |
|
| 133 |
assertEquals("barWidth", 1, scaledData.getBarWidth()); |
| 134 |
assertEquals("height", 100, scaledData.getHeight()); |
| 135 |
assertEquals("width", 101, scaledData.getWidth()); |
| 136 |
|
| 137 |
assertEquals(Config.INVALID_EVENT_TIME, scaledData.getCurrentEventTime()); |
| 138 |
|
| 139 |
assertEquals("Horizontal bucket duration", 1, scaledData.getHorBucketDuration()); |
| 140 |
assertEquals("Vertical bucket duration", 1, scaledData.getVerBucketDuration()); |
| 141 |
|
| 142 |
assertEquals("Horizontal bucket end time", 1, scaledData.getHorBucketEndTime(0)); |
| 143 |
assertEquals("Vertical bucket end time", 1, scaledData.getVerBucketEndTime(0)); |
| 144 |
|
| 145 |
assertEquals("Horizontal bucket start time", 0, scaledData.getHorBucketStartTime(0)); |
| 146 |
assertEquals("Vertical bucket start time", 0, scaledData.getVerBucketStartTime(0)); |
| 147 |
|
| 148 |
assertEquals("Horizontal first time", 0, scaledData.getHorFirstEventTime()); |
| 149 |
assertEquals("Vertical first time", 0, scaledData.getVerFirstEventTime()); |
| 150 |
|
| 151 |
assertEquals("Horizontal first bucket time", 0, scaledData.getHorFirstBucketTime()); |
| 152 |
assertEquals("Vertical first bucket time", 0, scaledData.getVerFirstBucketTime()); |
| 153 |
|
| 154 |
assertEquals("Horizontal last bucket time", 0, scaledData.getHorLastBucketTime()); |
| 155 |
assertEquals("Vertical last bucket time", 0, scaledData.getVerLastBucketTime()); |
| 156 |
|
| 157 |
assertEquals("Horizontal number of buckets", 101, scaledData.getHorNbBuckets()); |
| 158 |
assertEquals("Vertical nubmer of buckets", 100, scaledData.getVerNbBuckets()); |
| 159 |
|
| 160 |
assertEquals("Horizontal getIndex", 100, scaledData.getHorBucketIndex(100)); |
| 161 |
assertEquals("Vertical getIndex", 124, scaledData.getVerBucketIndex(124)); |
| 162 |
|
| 163 |
assertEquals("Horizontal last bucket", 0, scaledData.getHorLastBucket()); |
| 164 |
assertEquals("Vertical last bucket", 0, scaledData.getVerLastBucket()); |
| 165 |
|
| 166 |
assertEquals("Horizontal last event time", 0, scaledData.getHorLastEventTime()); |
| 167 |
assertEquals("Vertical last event time", 0, scaledData.getVerLastEventTime()); |
| 168 |
} |
| 169 |
|
| 170 |
public void testClear() { |
| 171 |
final int nbBuckets = 2000; |
| 172 |
final int nbEvents = 10 * nbBuckets + 256; |
| 173 |
|
| 174 |
LatencyGraphModel model = new LatencyGraphModel(nbBuckets); |
| 175 |
for (int i = 0; i < nbEvents; i++) { |
| 176 |
model.countEvent(i+1, i, i); |
| 177 |
} |
| 178 |
// make sure that we actually counted something. |
| 179 |
GraphScaledData scaledData = model.scaleTo(100, 100, 1); |
| 180 |
|
| 181 |
assertTrue(scaledData.getHorLastBucket() > 0); |
| 182 |
|
| 183 |
model.clear(); |
| 184 |
|
| 185 |
// Verify model parameters |
| 186 |
assertEquals("Horizontal bucket duration", 1, model.getHorBucketDuration()); |
| 187 |
assertEquals("Vertical bucket duration", 1, model.getVerBucketDuration()); |
| 188 |
|
| 189 |
assertEquals("Horizontal first bucket time", 0, model.getHorFirstBucketTime()); |
| 190 |
assertEquals("Vertical first bucket time", 0, model.getVerFirstBucketTime()); |
| 191 |
|
| 192 |
assertEquals("Horizontal last bucket ", 0, model.getHorLastBucket()); |
| 193 |
assertEquals("Vertical last bucket ", 0, model.getVerLastBucket()); |
| 194 |
|
| 195 |
assertEquals("Horizontal first time", 0, model.getHorFirstEventTime()); |
| 196 |
assertEquals("Vertical first time", 0, model.getVerFirstEventTime()); |
| 197 |
|
| 198 |
assertEquals("Horizontal last time", 0, model.getHorLastEventTime()); |
| 199 |
assertEquals("Vertical last time", 0, model.getVerLastEventTime()); |
| 200 |
|
| 201 |
assertEquals("Horizontal time limit", 2000, model.getHorTimeLimit()); |
| 202 |
assertEquals("Vertical time limit", 2000, model.getVerTimeLimit()); |
| 203 |
|
| 204 |
// Verify scaled data parameters |
| 205 |
scaledData = model.scaleTo(101, 100, 1); |
| 206 |
|
| 207 |
assertEquals("barWidth", 1, scaledData.getBarWidth()); |
| 208 |
assertEquals("height", 100, scaledData.getHeight()); |
| 209 |
assertEquals("width", 101, scaledData.getWidth()); |
| 210 |
|
| 211 |
assertEquals(Config.INVALID_EVENT_TIME, scaledData.getCurrentEventTime()); |
| 212 |
|
| 213 |
assertEquals("Horizontal bucket duration", 1, scaledData.getHorBucketDuration()); |
| 214 |
assertEquals("Vertical bucket duration", 1, scaledData.getVerBucketDuration()); |
| 215 |
|
| 216 |
assertEquals("Horizontal bucket end time", 1, scaledData.getHorBucketEndTime(0)); |
| 217 |
assertEquals("Vertical bucket end time", 1, scaledData.getVerBucketEndTime(0)); |
| 218 |
|
| 219 |
assertEquals("Horizontal bucket start time", 0, scaledData.getHorBucketStartTime(0)); |
| 220 |
assertEquals("Vertical bucket start time", 0, scaledData.getVerBucketStartTime(0)); |
| 221 |
|
| 222 |
assertEquals("Horizontal first time", 0, scaledData.getHorFirstEventTime()); |
| 223 |
assertEquals("Vertical first time", 0, scaledData.getVerFirstEventTime()); |
| 224 |
|
| 225 |
assertEquals("Horizontal first bucket time", 0, scaledData.getHorFirstBucketTime()); |
| 226 |
assertEquals("Vertical first bucket time", 0, scaledData.getVerFirstBucketTime()); |
| 227 |
|
| 228 |
assertEquals("Horizontal last bucket time", 0, scaledData.getHorLastBucketTime()); |
| 229 |
assertEquals("Vertical last bucket time", 0, scaledData.getVerLastBucketTime()); |
| 230 |
|
| 231 |
assertEquals("Horizontal getIndex", 100, scaledData.getHorBucketIndex(100)); |
| 232 |
assertEquals("Vertical getIndex", 124, scaledData.getVerBucketIndex(124)); |
| 233 |
|
| 234 |
assertEquals("Horizontal number of buckets", 101, scaledData.getHorNbBuckets()); |
| 235 |
assertEquals("Vertical nubmer of buckets", 100, scaledData.getVerNbBuckets()); |
| 236 |
|
| 237 |
assertEquals("Horizontal last bucket", 0, scaledData.getHorLastBucket()); |
| 238 |
assertEquals("Vertical last bucket", 0, scaledData.getVerLastBucket()); |
| 239 |
|
| 240 |
assertEquals("Horizontal last event time", 0, scaledData.getHorLastEventTime()); |
| 241 |
assertEquals("Vertical last event time", 0, scaledData.getVerLastEventTime()); |
| 242 |
} |
| 243 |
|
| 244 |
public void testCountEvent() { |
| 245 |
final int nbBuckets = 2000; |
| 246 |
final int nbEvents = 10 * nbBuckets + 256; |
| 247 |
final long hOffset = 100; |
| 248 |
final long vOffset = 55; |
| 249 |
|
| 250 |
LatencyGraphModel model = new LatencyGraphModel(nbBuckets); |
| 251 |
|
| 252 |
for (int i = 0; i < nbEvents; i++) { |
| 253 |
model.countEvent(i + 1, hOffset + i, vOffset + i); |
| 254 |
} |
| 255 |
|
| 256 |
// Verify model parameters |
| 257 |
assertEquals("Horizontal bucket duration", 16, model.getHorBucketDuration()); |
| 258 |
assertEquals("Vertical bucket duration", 16, model.getVerBucketDuration()); |
| 259 |
|
| 260 |
assertEquals("Horizontal first bucket time", hOffset, model.getHorFirstBucketTime()); |
| 261 |
assertEquals("Vertical first bucket time", vOffset, model.getVerFirstBucketTime()); |
| 262 |
|
| 263 |
assertEquals("Horizontal last bucket ", (nbEvents - 1)/16, model.getHorLastBucket()); |
| 264 |
assertEquals("Vertical last bucket ", (nbEvents - 1)/16, model.getVerLastBucket()); |
| 265 |
|
| 266 |
assertEquals("Horizontal first time", hOffset, model.getHorFirstEventTime()); |
| 267 |
assertEquals("Vertical first time", vOffset, model.getVerFirstEventTime()); |
| 268 |
|
| 269 |
assertEquals("Horizontal last time", nbEvents + hOffset - 1, model.getHorLastEventTime()); |
| 270 |
assertEquals("Vertical last time", nbEvents + vOffset - 1, model.getVerLastEventTime()); |
| 271 |
|
| 272 |
assertEquals("Horizontal time limit", 16 * nbBuckets + hOffset, model.getHorTimeLimit()); |
| 273 |
assertEquals("Vertical time limit", 16 * nbBuckets + vOffset, model.getVerTimeLimit()); |
| 274 |
|
| 275 |
// Verify scaled data parameters |
| 276 |
GraphScaledData scaledData = model.scaleTo(50, 100, 1); |
| 277 |
|
| 278 |
assertEquals("barWidth", 1, scaledData.getBarWidth()); |
| 279 |
assertEquals("height", 100, scaledData.getHeight()); |
| 280 |
assertEquals("width", 50, scaledData.getWidth()); |
| 281 |
|
| 282 |
assertEquals(Config.INVALID_EVENT_TIME, scaledData.getCurrentEventTime()); |
| 283 |
|
| 284 |
// nbBars = width / barWidth |
| 285 |
// bucketsPerBar = lastBucket/nbBars + 1 |
| 286 |
// scaled bucket duration = bucketsPerBar * model.bucketDuration |
| 287 |
// for nbBuckets=2000 and nbEvents=20256 (means 20256 ns + offset) -> model.bucketDuration = 16 |
| 288 |
assertEquals("Horizontal bucket duration", 416, scaledData.getHorBucketDuration()); |
| 289 |
assertEquals("Vertical bucket duration", 208, scaledData.getVerBucketDuration()); |
| 290 |
|
| 291 |
// startTime + scaledData.bucketDuration |
| 292 |
assertEquals("Horizontal bucket end time", hOffset + 416, scaledData.getHorBucketEndTime(0)); |
| 293 |
assertEquals("Vertical bucket end time", 55 + 208, scaledData.getVerBucketEndTime(0)); |
| 294 |
|
| 295 |
assertEquals("Horizontal bucket start time", 100, scaledData.getHorBucketStartTime(0)); |
| 296 |
assertEquals("Vertical bucket start time", 55, scaledData.getVerBucketStartTime(0)); |
| 297 |
|
| 298 |
assertEquals("Horizontal first time", 100, scaledData.getHorFirstEventTime()); |
| 299 |
assertEquals("Vertical first time", 55, scaledData.getVerFirstEventTime()); |
| 300 |
|
| 301 |
assertEquals("Horizontal first bucket time", hOffset, scaledData.getHorFirstBucketTime()); |
| 302 |
assertEquals("Vertical first bucket time", 55, scaledData.getVerFirstBucketTime()); |
| 303 |
|
| 304 |
assertEquals("Horizontal last bucket time", hOffset + 48 * 416, scaledData.getHorLastBucketTime()); |
| 305 |
assertEquals("Vertical last bucket time", vOffset + 97 * 208, scaledData.getVerLastBucketTime()); |
| 306 |
|
| 307 |
assertEquals("Horizontal getIndex", 47, scaledData.getHorBucketIndex(20000)); |
| 308 |
assertEquals("Vertical getIndex", 47, scaledData.getVerBucketIndex(10000)); |
| 309 |
|
| 310 |
// nb Buckets = nbBars |
| 311 |
assertEquals("Horizontal number of buckets", 50, scaledData.getHorNbBuckets()); |
| 312 |
assertEquals("Vertical nubmer of buckets", 100, scaledData.getVerNbBuckets()); |
| 313 |
|
| 314 |
assertEquals("Horizontal last bucket", 48, scaledData.getHorLastBucket()); |
| 315 |
assertEquals("Vertical last bucket", 97, scaledData.getVerLastBucket()); |
| 316 |
|
| 317 |
// start time of last bucket |
| 318 |
assertEquals("Horizontal last event time", hOffset + nbEvents - 1, scaledData.getHorLastEventTime()); |
| 319 |
assertEquals("Vertical last event time", vOffset + nbEvents - 1 , scaledData.getVerLastEventTime()); |
| 320 |
} |
| 321 |
|
| 322 |
public void testCountEvent2() { |
| 323 |
|
| 324 |
final int nbBuckets = 2000; |
| 325 |
final int nbEvents = 10 * nbBuckets + 256; |
| 326 |
final long offset = 100; |
| 327 |
final int height = 100; |
| 328 |
final int width = 100; |
| 329 |
final int barWidth = 1; |
| 330 |
|
| 331 |
int[][] expectedResults = new int[width/barWidth][height/barWidth]; |
| 332 |
|
| 333 |
int total = 0; |
| 334 |
|
| 335 |
// Horizontally and vertically the same data is used |
| 336 |
|
| 337 |
// for nbBuckets=2000 and nbEvents=20256 (means 20256 ns + offset) -> model.bucketDuration = 16 |
| 338 |
// nbBars = width / barWidth = 100 |
| 339 |
// bucketsPerBar = lastBucket/nbBars + 1 = 13 |
| 340 |
// scaled bucket duration = bucketsPerBar * model.bucketDuration = 13 * 16 |
| 341 |
boolean isFinished = false; |
| 342 |
for (int i = 0; i < width/barWidth; i++) { |
| 343 |
if (isFinished) { |
| 344 |
break; |
| 345 |
} |
| 346 |
for (int j = 0; j < height/barWidth; j++) { |
| 347 |
if (i == j) { |
| 348 |
int value = 13 * 16; |
| 349 |
if (total + value > nbEvents) { |
| 350 |
expectedResults[i][j] = nbEvents - total; |
| 351 |
isFinished = true; |
| 352 |
break; |
| 353 |
} |
| 354 |
else { |
| 355 |
expectedResults[i][j] = value; |
| 356 |
total += value; |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
LatencyGraphModel model = new LatencyGraphModel(nbBuckets); |
| 363 |
|
| 364 |
for (int i = 0; i < nbEvents; i++) { |
| 365 |
model.countEvent(i+1, offset + i, offset + i); |
| 366 |
} |
| 367 |
|
| 368 |
GraphScaledData scaledData = model.scaleTo(height, width, barWidth); |
| 369 |
|
| 370 |
for (int i = 0; i < scaledData.getHorLastBucket(); i++) { |
| 371 |
for (int j = 0; j < scaledData.getVerLastBucket(); j++) { |
| 372 |
assertEquals(expectedResults[i][j], scaledData.getEventCount(i, j)); |
| 373 |
} |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
public void testCountEvent3() { |
| 378 |
// Test with barWidth > 1 |
| 379 |
final int nbBuckets = 2000; |
| 380 |
final int nbEvents = 10 * nbBuckets + 256; |
| 381 |
final long offset = 100; |
| 382 |
final int height = 100; |
| 383 |
final int width = 100; |
| 384 |
final int barWidth = 4; |
| 385 |
|
| 386 |
int[][] expectedResults = new int[width/barWidth][height/barWidth]; |
| 387 |
|
| 388 |
int total = 0; |
| 389 |
|
| 390 |
// Horizontally and vertically the same data is used |
| 391 |
|
| 392 |
// for nbBuckets=2000 and nbEvents=20256 (means 20256 ns + offset) -> model.bucketDuration = 16 |
| 393 |
// nbBars = width / barWidth = 25 |
| 394 |
// bucketsPerBar = lastBucket/nbBars + 1 = 51 |
| 395 |
// scaled bucket duration = bucketsPerBar * model.bucketDuration = 51 * 16 |
| 396 |
boolean isFinished = false; |
| 397 |
for (int i = 0; i < width/barWidth; i++) { |
| 398 |
if (isFinished) { |
| 399 |
break; |
| 400 |
} |
| 401 |
for (int j = 0; j < height/barWidth; j++) { |
| 402 |
if (i == j) { |
| 403 |
int value = 51 * 16; |
| 404 |
if (total + value > nbEvents) { |
| 405 |
expectedResults[i][j] = nbEvents - total; |
| 406 |
isFinished = true; |
| 407 |
break; |
| 408 |
} |
| 409 |
else { |
| 410 |
expectedResults[i][j] = value; |
| 411 |
total += value; |
| 412 |
} |
| 413 |
} |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
LatencyGraphModel model = new LatencyGraphModel(nbBuckets); |
| 418 |
|
| 419 |
for (int i = 0; i < nbEvents; i++) { |
| 420 |
model.countEvent(i+1, offset + i, offset + i); |
| 421 |
} |
| 422 |
|
| 423 |
GraphScaledData scaledData = model.scaleTo(height, width, barWidth); |
| 424 |
|
| 425 |
for (int i = 0; i < scaledData.getHorLastBucket(); i++) { |
| 426 |
for (int j = 0; j < scaledData.getVerLastBucket(); j++) { |
| 427 |
assertEquals(expectedResults[i][j], scaledData.getEventCount(i, j)); |
| 428 |
} |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
public void testCountEventReverse1() { |
| 433 |
// Depending on the number of buckets and events the start buckets can be different |
| 434 |
// between forward and reserve times. However, the content is correct. |
| 435 |
final int nbBuckets = 100; |
| 436 |
final int nbEvents = 256; |
| 437 |
final long hOffset = 100; |
| 438 |
final long vOffset = 55; |
| 439 |
final int height = 100; |
| 440 |
final int width = 50; |
| 441 |
final int barWidth = 1; |
| 442 |
|
| 443 |
LatencyGraphModel model = new LatencyGraphModel(nbBuckets); |
| 444 |
|
| 445 |
for (int i = 0; i < nbEvents; i++) { |
| 446 |
model.countEvent(i + 1, hOffset + i, vOffset + i); |
| 447 |
} |
| 448 |
|
| 449 |
GraphScaledData scaledData = model.scaleTo(width, height, barWidth); |
| 450 |
|
| 451 |
model.clear(); |
| 452 |
|
| 453 |
for (int i = nbEvents - 1; i >= 0; i--) { |
| 454 |
model.countEvent(nbEvents - i, hOffset + i, vOffset + i); |
| 455 |
} |
| 456 |
|
| 457 |
GraphScaledData scaledDataReverse = model.scaleTo(50, 100, 1); |
| 458 |
|
| 459 |
long count = 0; |
| 460 |
for (int i = 0; i <= scaledData.getHorLastBucket(); i++) { |
| 461 |
for (int j = 0; j <= scaledData.getVerLastBucket(); j++) { |
| 462 |
count += scaledData.getEventCount(i, j); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
long revCount = 0; |
| 467 |
for (int i = 0; i <= scaledDataReverse.getHorLastBucket(); i++) { |
| 468 |
for (int j = 0; j <= scaledDataReverse.getVerLastBucket(); j++) { |
| 469 |
revCount += scaledDataReverse.getEventCount(i, j); |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
assertEquals(count, revCount); |
| 474 |
|
| 475 |
// Make sure that both scaledData have the same content |
| 476 |
assertTrue("barWidth", scaledData.getBarWidth() == scaledDataReverse.getBarWidth()); |
| 477 |
assertTrue("height", scaledData.getHeight() == scaledDataReverse.getHeight()); |
| 478 |
assertTrue("width", scaledData.getWidth() == scaledDataReverse.getWidth()); |
| 479 |
|
| 480 |
assertTrue(scaledData.getCurrentEventTime() == scaledDataReverse.getCurrentEventTime()); |
| 481 |
|
| 482 |
assertTrue("Horizontal bucket duration", scaledData.getHorBucketDuration() == scaledDataReverse.getHorBucketDuration()); |
| 483 |
assertTrue("Vertical bucket duration", scaledData.getVerBucketDuration() == scaledDataReverse.getVerBucketDuration()); |
| 484 |
|
| 485 |
// startTime + scaledData.bucketDuration |
| 486 |
assertTrue("Horizontal bucket end time", scaledData.getHorBucketEndTime(0) == scaledDataReverse.getHorBucketEndTime(0)); |
| 487 |
assertTrue("Vertical bucket end time", scaledData.getVerBucketEndTime(0) == scaledDataReverse.getVerBucketEndTime(0)); |
| 488 |
|
| 489 |
assertTrue("Horizontal bucket start time", scaledData.getHorBucketStartTime(0) == scaledDataReverse.getHorBucketStartTime(0)); |
| 490 |
assertTrue("Vertical bucket start time", scaledData.getVerBucketStartTime(0) == scaledDataReverse.getVerBucketStartTime(0)); |
| 491 |
|
| 492 |
assertTrue("Horizontal first time", scaledData.getHorFirstEventTime() == scaledDataReverse.getHorFirstEventTime()); |
| 493 |
assertTrue("Vertical first time", scaledData.getVerFirstEventTime() == scaledDataReverse.getVerFirstEventTime()); |
| 494 |
|
| 495 |
assertTrue("Horizontal getIndex", scaledData.getHorBucketIndex(200) == scaledDataReverse.getHorBucketIndex(200)); |
| 496 |
assertTrue("Vertical getIndex", scaledData.getVerBucketIndex(100) == scaledDataReverse.getVerBucketIndex(100)); |
| 497 |
|
| 498 |
assertTrue("Horizontal last bucket", scaledData.getHorNbBuckets() == scaledDataReverse.getHorNbBuckets()); |
| 499 |
assertTrue("Vertical last bucket", scaledData.getVerNbBuckets() == scaledDataReverse.getVerNbBuckets()); |
| 500 |
|
| 501 |
assertTrue("Horizontal nubmer of buckets", scaledData.getHorLastBucket() == scaledDataReverse.getHorLastBucket()); |
| 502 |
assertTrue("Vertical nubmer of buckets", scaledData.getVerLastBucket() == scaledDataReverse.getVerLastBucket()); |
| 503 |
|
| 504 |
// start time of last bucket |
| 505 |
assertTrue("Horizontal last event time", scaledData.getHorLastEventTime() == scaledDataReverse.getHorLastEventTime()); |
| 506 |
assertTrue("Vertical last event time", scaledData.getVerLastEventTime() == scaledDataReverse.getVerLastEventTime()); |
| 507 |
} |
| 508 |
|
| 509 |
public void testCountEventReverse2() { |
| 510 |
// Depending on the number of buckets and events the start buckets can be different |
| 511 |
// between forward and reserve times. However, the content is correct. |
| 512 |
final int nbBuckets = 100; |
| 513 |
final int nbEvents = 256; |
| 514 |
final long hOffset = 100; |
| 515 |
final long vOffset = 55; |
| 516 |
final int height = 100; |
| 517 |
final int width = 50; |
| 518 |
final int barWidth = 1; |
| 519 |
|
| 520 |
LatencyGraphModel model = new LatencyGraphModel(nbBuckets); |
| 521 |
|
| 522 |
for (int i = nbEvents - 1; i >= 0; i--) { |
| 523 |
model.countEvent(nbEvents - i, hOffset + i, vOffset + i); |
| 524 |
} |
| 525 |
|
| 526 |
// Verify model parameters |
| 527 |
int expectedBucketDuration = 4; |
| 528 |
assertEquals("Horizontal bucket duration", expectedBucketDuration, model.getHorBucketDuration()); |
| 529 |
assertEquals("Vertical bucket duration", expectedBucketDuration, model.getVerBucketDuration()); |
| 530 |
|
| 531 |
assertEquals("Horizontal first bucket time", hOffset, model.getHorFirstBucketTime()); |
| 532 |
assertEquals("Vertical first bucket time", vOffset, model.getVerFirstBucketTime()); |
| 533 |
|
| 534 |
assertEquals("Horizontal last bucket", (nbEvents -1)/expectedBucketDuration, model.getHorLastBucket()); |
| 535 |
assertEquals("Vertical last bucket", (nbEvents -1)/expectedBucketDuration, model.getVerLastBucket()); |
| 536 |
|
| 537 |
assertEquals("Horizontal first time", hOffset, model.getHorFirstEventTime()); |
| 538 |
assertEquals("Vertical first time", vOffset, model.getVerFirstEventTime()); |
| 539 |
|
| 540 |
assertEquals("Horizontal last time", nbEvents + hOffset - 1, model.getHorLastEventTime()); |
| 541 |
assertEquals("Vertical last time", nbEvents + vOffset - 1, model.getVerLastEventTime()); |
| 542 |
|
| 543 |
assertEquals("Horizontal time limit", expectedBucketDuration * nbBuckets + hOffset, model.getHorTimeLimit()); |
| 544 |
assertEquals("Vertical time limit", expectedBucketDuration * nbBuckets + vOffset, model.getVerTimeLimit()); |
| 545 |
|
| 546 |
GraphScaledData scaledData = model.scaleTo(50, 100, 1); |
| 547 |
|
| 548 |
// Make sure that both scaledData have the same content |
| 549 |
assertEquals("barWidth", barWidth, scaledData.getBarWidth()); |
| 550 |
assertEquals("height", height, scaledData.getHeight()); |
| 551 |
assertEquals("width", width, scaledData.getWidth()); |
| 552 |
|
| 553 |
assertEquals(-1, scaledData.getCurrentEventTime()); |
| 554 |
|
| 555 |
assertEquals("Horizontal bucket duration", 8, scaledData.getHorBucketDuration()); |
| 556 |
assertEquals("Vertical bucket duration", 4, scaledData.getVerBucketDuration()); |
| 557 |
|
| 558 |
// startTime + scaledData.bucketDuration |
| 559 |
assertEquals("Horizontal bucket end time", hOffset + 8, scaledData.getHorBucketEndTime(0)); |
| 560 |
assertEquals("Vertical bucket end time", vOffset + 4, scaledData.getVerBucketEndTime(0)); |
| 561 |
|
| 562 |
assertEquals("Horizontal bucket start time", hOffset, scaledData.getHorBucketStartTime(0)); |
| 563 |
assertEquals("Vertical bucket start time", vOffset, scaledData.getVerBucketStartTime(0)); |
| 564 |
|
| 565 |
assertEquals("Horizontal first time", hOffset, scaledData.getHorFirstEventTime()); |
| 566 |
assertEquals("Vertical first time", vOffset, scaledData.getVerFirstEventTime()); |
| 567 |
|
| 568 |
assertEquals("Horizontal getIndex", 12, scaledData.getHorBucketIndex(200)); |
| 569 |
assertEquals("Vertical getIndex", 11, scaledData.getVerBucketIndex(100)); |
| 570 |
|
| 571 |
// nb Buckets = nbBars |
| 572 |
assertEquals("Horizontal number of buckets", 50, scaledData.getHorNbBuckets()); |
| 573 |
assertEquals("Vertical number of buckets", 100, scaledData.getVerNbBuckets()); |
| 574 |
|
| 575 |
assertEquals("Horizontal last bucket", 31, scaledData.getHorLastBucket()); |
| 576 |
assertEquals("Vertical last bucket", 63, scaledData.getVerLastBucket()); |
| 577 |
|
| 578 |
// start time of last bucket |
| 579 |
assertEquals("Horizontal last event time", 355, scaledData.getHorLastEventTime()); |
| 580 |
assertEquals("Vertical last event time", 310, scaledData.getVerLastEventTime()); |
| 581 |
} |
| 582 |
} |