|
50 | 50 |
|
51 | 51 | import static org.hamcrest.Matchers.either;
|
52 | 52 | import static org.hamcrest.Matchers.equalTo;
|
| 53 | +import static org.hamcrest.Matchers.not; |
| 54 | +import static org.hamcrest.Matchers.sameInstance; |
53 | 55 |
|
54 | 56 | public class DriverTests extends ESTestCase {
|
55 | 57 | /**
|
@@ -253,6 +255,59 @@ public void testProfileAndStatusInterval() {
|
253 | 255 | assertThat(driver.profile().iterations(), equalTo((long) inPages.size()));
|
254 | 256 | }
|
255 | 257 |
|
| 258 | + public void testUnchangedStatus() { |
| 259 | + DriverContext driverContext = driverContext(); |
| 260 | + List<Page> inPages = randomList(2, 100, DriverTests::randomPage); |
| 261 | + List<Page> outPages = new ArrayList<>(); |
| 262 | + |
| 263 | + long startEpoch = randomNonNegativeLong(); |
| 264 | + long startNanos = randomLong(); |
| 265 | + long waitTime = randomLongBetween(10000, 100000); |
| 266 | + long tickTime = randomLongBetween(10000, 100000); |
| 267 | + long statusInterval = randomLongBetween(1, 10); |
| 268 | + |
| 269 | + Driver driver = new Driver( |
| 270 | + "unset", |
| 271 | + "test", |
| 272 | + startEpoch, |
| 273 | + startNanos, |
| 274 | + driverContext, |
| 275 | + () -> "unset", |
| 276 | + new CannedSourceOperator(inPages.iterator()), |
| 277 | + List.of(), |
| 278 | + new TestResultPageSinkOperator(outPages::add), |
| 279 | + TimeValue.timeValueNanos(statusInterval), |
| 280 | + () -> {} |
| 281 | + ); |
| 282 | + |
| 283 | + NowSupplier nowSupplier = new NowSupplier(startNanos, waitTime, tickTime); |
| 284 | + |
| 285 | + int iterationsPerTick = randomIntBetween(1, 10); |
| 286 | + |
| 287 | + for (int i = 0; i < inPages.size(); i += iterationsPerTick) { |
| 288 | + DriverStatus initialStatus = driver.status(); |
| 289 | + long completedOperatorsHash = initialStatus.completedOperators().hashCode(); |
| 290 | + long activeOperatorsHash = initialStatus.activeOperators().hashCode(); |
| 291 | + long sleepsHash = initialStatus.sleeps().hashCode(); |
| 292 | + |
| 293 | + driver.run(TimeValue.timeValueDays(10), iterationsPerTick, nowSupplier); |
| 294 | + |
| 295 | + DriverStatus newStatus = driver.status(); |
| 296 | + assertThat(newStatus, not(sameInstance(initialStatus))); |
| 297 | + assertThat( |
| 298 | + newStatus.completedOperators() != initialStatus.completedOperators() |
| 299 | + || newStatus.completedOperators().hashCode() == completedOperatorsHash, |
| 300 | + equalTo(true) |
| 301 | + ); |
| 302 | + assertThat( |
| 303 | + newStatus.activeOperators() != initialStatus.activeOperators() |
| 304 | + || newStatus.activeOperators().hashCode() == activeOperatorsHash, |
| 305 | + equalTo(true) |
| 306 | + ); |
| 307 | + assertThat(newStatus.sleeps() != initialStatus.sleeps() || newStatus.sleeps().hashCode() == sleepsHash, equalTo(true)); |
| 308 | + } |
| 309 | + } |
| 310 | + |
256 | 311 | class NowSupplier implements LongSupplier {
|
257 | 312 | private final long startNanos;
|
258 | 313 | private final long waitTime;
|
|
0 commit comments