|
50 | 50 | import static org.hamcrest.Matchers.either;
|
51 | 51 | import static org.hamcrest.Matchers.equalTo;
|
52 | 52 | import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
| 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 | /**
|
@@ -200,6 +202,57 @@ public void testProfileAndStatusTimeout() {
|
200 | 202 | assertThat(driver.profile().iterations(), equalTo((long) inPages.size()));
|
201 | 203 | }
|
202 | 204 |
|
| 205 | + public void testUnchangedStatus() { |
| 206 | + DriverContext driverContext = driverContext(); |
| 207 | + List<Page> inPages = randomList(2, 100, DriverTests::randomPage); |
| 208 | + List<Page> outPages = new ArrayList<>(); |
| 209 | + |
| 210 | + long startEpoch = randomNonNegativeLong(); |
| 211 | + long startNanos = randomLong(); |
| 212 | + long waitTime = randomLongBetween(10000, 100000); |
| 213 | + long tickTime = randomLongBetween(10000, 100000); |
| 214 | + |
| 215 | + Driver driver = new Driver( |
| 216 | + "unset", |
| 217 | + startEpoch, |
| 218 | + startNanos, |
| 219 | + driverContext, |
| 220 | + () -> "unset", |
| 221 | + new CannedSourceOperator(inPages.iterator()), |
| 222 | + List.of(), |
| 223 | + new TestResultPageSinkOperator(outPages::add), |
| 224 | + TimeValue.timeValueNanos(tickTime), |
| 225 | + () -> {} |
| 226 | + ); |
| 227 | + |
| 228 | + NowSupplier nowSupplier = new NowSupplier(startNanos, waitTime, tickTime); |
| 229 | + |
| 230 | + int iterationsPerTick = randomIntBetween(1, 10); |
| 231 | + |
| 232 | + for (int i = 0; i < inPages.size(); i += iterationsPerTick) { |
| 233 | + DriverStatus initialStatus = driver.status(); |
| 234 | + long completedOperatorsHash = initialStatus.completedOperators().hashCode(); |
| 235 | + long activeOperatorsHash = initialStatus.activeOperators().hashCode(); |
| 236 | + long sleepsHash = initialStatus.sleeps().hashCode(); |
| 237 | + |
| 238 | + driver.run(TimeValue.timeValueDays(10), iterationsPerTick, nowSupplier); |
| 239 | + |
| 240 | + DriverStatus newStatus = driver.status(); |
| 241 | + assertThat(newStatus, not(sameInstance(initialStatus))); |
| 242 | + assertThat( |
| 243 | + newStatus.completedOperators() != initialStatus.completedOperators() |
| 244 | + || newStatus.completedOperators().hashCode() == completedOperatorsHash, |
| 245 | + equalTo(true) |
| 246 | + ); |
| 247 | + assertThat( |
| 248 | + newStatus.activeOperators() != initialStatus.activeOperators() |
| 249 | + || newStatus.activeOperators().hashCode() == activeOperatorsHash, |
| 250 | + equalTo(true) |
| 251 | + ); |
| 252 | + assertThat(newStatus.sleeps() != initialStatus.sleeps() || newStatus.sleeps().hashCode() == sleepsHash, equalTo(true)); |
| 253 | + } |
| 254 | + } |
| 255 | + |
203 | 256 | class NowSupplier implements LongSupplier {
|
204 | 257 | private final long startNanos;
|
205 | 258 | private final long waitTime;
|
|
0 commit comments