|
38 | 38 | import java.util.function.LongSupplier;
|
39 | 39 |
|
40 | 40 | import static org.hamcrest.Matchers.equalTo;
|
| 41 | +import static org.hamcrest.Matchers.not; |
| 42 | +import static org.hamcrest.Matchers.sameInstance; |
41 | 43 |
|
42 | 44 | public class DriverTests extends ESTestCase {
|
43 | 45 | /**
|
@@ -188,6 +190,57 @@ public void testProfileAndStatusTimeout() {
|
188 | 190 | assertThat(driver.profile().iterations(), equalTo((long) inPages.size()));
|
189 | 191 | }
|
190 | 192 |
|
| 193 | + public void testUnchangedStatus() { |
| 194 | + DriverContext driverContext = driverContext(); |
| 195 | + List<Page> inPages = randomList(2, 100, DriverTests::randomPage); |
| 196 | + List<Page> outPages = new ArrayList<>(); |
| 197 | + |
| 198 | + long startEpoch = randomNonNegativeLong(); |
| 199 | + long startNanos = randomLong(); |
| 200 | + long waitTime = randomLongBetween(10000, 100000); |
| 201 | + long tickTime = randomLongBetween(10000, 100000); |
| 202 | + |
| 203 | + Driver driver = new Driver( |
| 204 | + "unset", |
| 205 | + startEpoch, |
| 206 | + startNanos, |
| 207 | + driverContext, |
| 208 | + () -> "unset", |
| 209 | + new CannedSourceOperator(inPages.iterator()), |
| 210 | + List.of(), |
| 211 | + new TestResultPageSinkOperator(outPages::add), |
| 212 | + TimeValue.timeValueNanos(tickTime), |
| 213 | + () -> {} |
| 214 | + ); |
| 215 | + |
| 216 | + NowSupplier nowSupplier = new NowSupplier(startNanos, waitTime, tickTime); |
| 217 | + |
| 218 | + int iterationsPerTick = randomIntBetween(1, 10); |
| 219 | + |
| 220 | + for (int i = 0; i < inPages.size(); i += iterationsPerTick) { |
| 221 | + DriverStatus initialStatus = driver.status(); |
| 222 | + long completedOperatorsHash = initialStatus.completedOperators().hashCode(); |
| 223 | + long activeOperatorsHash = initialStatus.activeOperators().hashCode(); |
| 224 | + long sleepsHash = initialStatus.sleeps().hashCode(); |
| 225 | + |
| 226 | + driver.run(TimeValue.timeValueDays(10), iterationsPerTick, nowSupplier); |
| 227 | + |
| 228 | + DriverStatus newStatus = driver.status(); |
| 229 | + assertThat(newStatus, not(sameInstance(initialStatus))); |
| 230 | + assertThat( |
| 231 | + newStatus.completedOperators() != initialStatus.completedOperators() |
| 232 | + || newStatus.completedOperators().hashCode() == completedOperatorsHash, |
| 233 | + equalTo(true) |
| 234 | + ); |
| 235 | + assertThat( |
| 236 | + newStatus.activeOperators() != initialStatus.activeOperators() |
| 237 | + || newStatus.activeOperators().hashCode() == activeOperatorsHash, |
| 238 | + equalTo(true) |
| 239 | + ); |
| 240 | + assertThat(newStatus.sleeps() != initialStatus.sleeps() || newStatus.sleeps().hashCode() == sleepsHash, equalTo(true)); |
| 241 | + } |
| 242 | + } |
| 243 | + |
191 | 244 | class NowSupplier implements LongSupplier {
|
192 | 245 | private final long startNanos;
|
193 | 246 | private final long waitTime;
|
|
0 commit comments