Skip to content

Commit 961164c

Browse files
committed
Use List.copyOf() and add test
1 parent 9a464cc commit 961164c

File tree

2 files changed

+39
-1
lines changed
  • x-pack/plugin/esql/compute/src

2 files changed

+39
-1
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/Driver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ private void updateStatus(long extraCpuNanos, int extraIterations, DriverStatus.
556556
prev.cpuNanos() + extraCpuNanos,
557557
prev.iterations() + extraIterations,
558558
status,
559-
new ArrayList<>(statusOfCompletedOperators),
559+
List.copyOf(statusOfCompletedOperators),
560560
activeOperators.stream().map(op -> new OperatorStatus(op.toString(), op.status())).toList(),
561561
sleeps
562562
);

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/DriverTests.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@
4747
import java.util.concurrent.atomic.AtomicInteger;
4848
import java.util.function.LongSupplier;
4949

50+
import static net.bytebuddy.matcher.ElementMatchers.is;
51+
import static org.hamcrest.Matchers.any;
52+
import static org.hamcrest.Matchers.comparesEqualTo;
5053
import static org.hamcrest.Matchers.either;
5154
import static org.hamcrest.Matchers.equalTo;
55+
import static org.hamcrest.Matchers.not;
56+
import static org.hamcrest.Matchers.sameInstance;
5257

5358
public class DriverTests extends ESTestCase {
5459
/**
@@ -204,6 +209,39 @@ public void testProfileAndStatusInterval() {
204209
assertThat(driver.profile().iterations(), equalTo((long) inPages.size()));
205210
}
206211

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+
207245
private static Driver createDriver(
208246
long startEpoch,
209247
long startNanos,

0 commit comments

Comments
 (0)