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