|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.elasticsearch.compute.operator; |
| 9 | + |
| 10 | +import org.elasticsearch.common.Strings; |
| 11 | +import org.elasticsearch.common.io.stream.Writeable; |
| 12 | +import org.elasticsearch.test.AbstractWireSerializingTestCase; |
| 13 | +import org.elasticsearch.test.ESTestCase; |
| 14 | + |
| 15 | +import static org.hamcrest.Matchers.equalTo; |
| 16 | + |
| 17 | +public class SampleOperatorStatusTests extends AbstractWireSerializingTestCase<SampleOperator.Status> { |
| 18 | + public static SampleOperator.Status simple() { |
| 19 | + return new SampleOperator.Status(500012, 200012, 123, 111, 222); |
| 20 | + } |
| 21 | + |
| 22 | + public static String simpleToJson() { |
| 23 | + return """ |
| 24 | + { |
| 25 | + "collect_nanos" : 500012, |
| 26 | + "collect_time" : "500micros", |
| 27 | + "emit_nanos" : 200012, |
| 28 | + "emit_time" : "200micros", |
| 29 | + "pages_processed" : 123, |
| 30 | + "rows_received" : 111, |
| 31 | + "rows_emitted" : 222 |
| 32 | + }"""; |
| 33 | + } |
| 34 | + |
| 35 | + public void testToXContent() { |
| 36 | + assertThat(Strings.toString(simple(), true, true), equalTo(simpleToJson())); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + protected Writeable.Reader<SampleOperator.Status> instanceReader() { |
| 41 | + return SampleOperator.Status::new; |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public SampleOperator.Status createTestInstance() { |
| 46 | + return new SampleOperator.Status( |
| 47 | + randomNonNegativeLong(), |
| 48 | + randomNonNegativeLong(), |
| 49 | + randomNonNegativeInt(), |
| 50 | + randomNonNegativeLong(), |
| 51 | + randomNonNegativeLong() |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + protected SampleOperator.Status mutateInstance(SampleOperator.Status instance) { |
| 57 | + long collectNanos = instance.collectNanos(); |
| 58 | + long emitNanos = instance.emitNanos(); |
| 59 | + int pagesProcessed = instance.pagesProcessed(); |
| 60 | + long rowsReceived = instance.rowsReceived(); |
| 61 | + long rowsEmitted = instance.rowsEmitted(); |
| 62 | + switch (between(0, 4)) { |
| 63 | + case 0 -> collectNanos = randomValueOtherThan(collectNanos, ESTestCase::randomNonNegativeLong); |
| 64 | + case 1 -> emitNanos = randomValueOtherThan(emitNanos, ESTestCase::randomNonNegativeLong); |
| 65 | + case 2 -> pagesProcessed = randomValueOtherThan(pagesProcessed, ESTestCase::randomNonNegativeInt); |
| 66 | + case 3 -> rowsReceived = randomValueOtherThan(rowsReceived, ESTestCase::randomNonNegativeLong); |
| 67 | + case 4 -> rowsEmitted = randomValueOtherThan(rowsEmitted, ESTestCase::randomNonNegativeLong); |
| 68 | + default -> throw new UnsupportedOperationException(); |
| 69 | + } |
| 70 | + return new SampleOperator.Status(collectNanos, emitNanos, pagesProcessed, rowsReceived, rowsEmitted); |
| 71 | + } |
| 72 | +} |
0 commit comments