|
49 | 49 |
|
50 | 50 | import static org.hamcrest.Matchers.either;
|
51 | 51 | import static org.hamcrest.Matchers.equalTo;
|
| 52 | +import static org.hamcrest.Matchers.not; |
| 53 | +import static org.hamcrest.Matchers.sameInstance; |
52 | 54 |
|
53 | 55 | public class DriverTests extends ESTestCase {
|
54 | 56 | /**
|
@@ -204,6 +206,47 @@ public void testProfileAndStatusInterval() {
|
204 | 206 | assertThat(driver.profile().iterations(), equalTo((long) inPages.size()));
|
205 | 207 | }
|
206 | 208 |
|
| 209 | + public void testUnchangedStatus() { |
| 210 | + DriverContext driverContext = driverContext(); |
| 211 | + List<Page> inPages = randomList(2, 100, DriverTests::randomPage); |
| 212 | + List<Page> outPages = new ArrayList<>(); |
| 213 | + |
| 214 | + long startEpoch = randomNonNegativeLong(); |
| 215 | + long startNanos = randomLong(); |
| 216 | + long waitTime = randomLongBetween(10000, 100000); |
| 217 | + long tickTime = randomLongBetween(10000, 100000); |
| 218 | + long statusInterval = randomLongBetween(1, 10); |
| 219 | + |
| 220 | + Driver driver = createDriver(startEpoch, startNanos, driverContext, inPages, outPages, TimeValue.timeValueNanos(statusInterval)); |
| 221 | + |
| 222 | + NowSupplier nowSupplier = new NowSupplier(startNanos, waitTime, tickTime); |
| 223 | + |
| 224 | + int iterationsPerTick = randomIntBetween(1, 10); |
| 225 | + |
| 226 | + for (int i = 0; i < inPages.size(); i += iterationsPerTick) { |
| 227 | + DriverStatus initialStatus = driver.status(); |
| 228 | + long completedOperatorsHash = initialStatus.completedOperators().hashCode(); |
| 229 | + long activeOperatorsHash = initialStatus.activeOperators().hashCode(); |
| 230 | + long sleepsHash = initialStatus.sleeps().hashCode(); |
| 231 | + |
| 232 | + driver.run(TimeValue.timeValueDays(10), iterationsPerTick, nowSupplier); |
| 233 | + |
| 234 | + DriverStatus newStatus = driver.status(); |
| 235 | + assertThat(newStatus, not(sameInstance(initialStatus))); |
| 236 | + assertThat( |
| 237 | + newStatus.completedOperators() != initialStatus.completedOperators() |
| 238 | + || newStatus.completedOperators().hashCode() == completedOperatorsHash, |
| 239 | + equalTo(true) |
| 240 | + ); |
| 241 | + assertThat( |
| 242 | + newStatus.activeOperators() != initialStatus.activeOperators() |
| 243 | + || newStatus.activeOperators().hashCode() == activeOperatorsHash, |
| 244 | + equalTo(true) |
| 245 | + ); |
| 246 | + assertThat(newStatus.sleeps() != initialStatus.sleeps() || newStatus.sleeps().hashCode() == sleepsHash, equalTo(true)); |
| 247 | + } |
| 248 | + } |
| 249 | + |
207 | 250 | private static Driver createDriver(
|
208 | 251 | long startEpoch,
|
209 | 252 | long startNanos,
|
|
0 commit comments