Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected DeleteSampleConfigurationAction.Request mutateInstance(DeleteSampleCon
instance.masterNodeTimeout(),
instance.ackTimeout()
);
String[] newIndices = randomValueOtherThan(instance.indices(), () -> new String[] { randomAlphaOfLength(10) });
String[] newIndices = randomArrayOtherThan(instance.indices(), () -> new String[] { randomAlphaOfLength(10) });
mutated.indices(newIndices);
yield mutated;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected PutSampleConfigurationAction.Request mutateInstance(PutSampleConfigura
instance.masterNodeTimeout(),
instance.ackTimeout()
);
mutated.indices(randomValueOtherThan(instance.indices(), () -> new String[] { randomAlphaOfLengthBetween(1, 10) }));
mutated.indices(randomArrayOtherThan(instance.indices(), () -> new String[] { randomAlphaOfLengthBetween(1, 10) }));
yield mutated;
}
default -> throw new IllegalStateException("Invalid mutation case");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import org.elasticsearch.test.AbstractWireSerializingTestCase;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import static org.elasticsearch.action.synonyms.SynonymsTestUtils.randomSynonymsSet;

Expand All @@ -34,14 +32,14 @@ protected PutSynonymsAction.Request createTestInstance() {
@Override
protected PutSynonymsAction.Request mutateInstance(PutSynonymsAction.Request instance) throws IOException {
String synonymsSetId = instance.synonymsSetId();
List<SynonymRule> synonymRules = Arrays.asList(instance.synonymRules());
SynonymRule[] synonymRules = instance.synonymRules();
boolean refresh = instance.refresh();
switch (between(0, 2)) {
case 0 -> synonymsSetId = randomValueOtherThan(synonymsSetId, () -> randomIdentifier());
case 1 -> synonymRules = randomValueOtherThan(synonymRules, () -> Arrays.asList(randomSynonymsSet()));
case 1 -> synonymRules = randomArrayOtherThan(synonymRules, () -> randomSynonymsSet());
case 2 -> refresh = refresh == false;
default -> throw new AssertionError("Illegal randomisation branch");
}
return new PutSynonymsAction.Request(synonymsSetId, synonymRules.toArray(new SynonymRule[0]), refresh);
return new PutSynonymsAction.Request(synonymsSetId, synonymRules, refresh);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ yield new KnnSearchBuilder(
).boost(instance.boost);
}
case 1 -> {
float[] newVector = randomValueOtherThan(instance.queryVector.asFloatVector(), () -> randomVector(5));
float[] newVector = randomArrayOtherThan(instance.queryVector.asFloatVector(), () -> randomVector(5));
yield new KnnSearchBuilder(
instance.field,
newVector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1501,9 +1501,74 @@ public static <T> void maybeSet(Consumer<T> consumer, T value) {
* helper to get a random value in a certain range that's different from the input
*/
public static <T> T randomValueOtherThan(T input, Supplier<T> randomSupplier) {
assert input == null || input.getClass().isArray() == false
: "randomValueOtherThan() does not work as expected with arrays, use randomArrayOtherThan() instead";
return randomValueOtherThanMany(v -> Objects.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input, for object arrays
*/
public static <T> T[] randomArrayOtherThan(T[] input, Supplier<T[]> randomSupplier) {
return randomValueOtherThanMany(v -> Arrays.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input, for boolean arrays
*/
public static boolean[] randomArrayOtherThan(boolean[] input, Supplier<boolean[]> randomSupplier) {
return randomValueOtherThanMany(v -> Arrays.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input, for byte arrays
*/
public static byte[] randomArrayOtherThan(byte[] input, Supplier<byte[]> randomSupplier) {
return randomValueOtherThanMany(v -> Arrays.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input, for char arrays
*/
public static char[] randomArrayOtherThan(char[] input, Supplier<char[]> randomSupplier) {
return randomValueOtherThanMany(v -> Arrays.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input, for short arrays
*/
public static short[] randomArrayOtherThan(short[] input, Supplier<short[]> randomSupplier) {
return randomValueOtherThanMany(v -> Arrays.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input, for int arrays
*/
public static int[] randomArrayOtherThan(int[] input, Supplier<int[]> randomSupplier) {
return randomValueOtherThanMany(v -> Arrays.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input, for long arrays
*/
public static long[] randomArrayOtherThan(long[] input, Supplier<long[]> randomSupplier) {
return randomValueOtherThanMany(v -> Arrays.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input, for float arrays
*/
public static float[] randomArrayOtherThan(float[] input, Supplier<float[]> randomSupplier) {
return randomValueOtherThanMany(v -> Arrays.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input, for double arrays
*/
public static double[] randomArrayOtherThan(double[] input, Supplier<double[]> randomSupplier) {
return randomValueOtherThanMany(v -> Arrays.equals(input, v), randomSupplier);
}

/**
* helper to get a random value in a certain range that's different from the input
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected ClusterComputeRequest mutateInstance(ClusterComputeRequest in) throws
in.configuration(),
new RemoteClusterPlan(
plan.plan(),
randomValueOtherThan(plan.targetIndices(), () -> generateRandomStringArray(10, 10, false, false)),
randomArrayOtherThan(plan.targetIndices(), () -> generateRandomStringArray(10, 10, false, false)),
plan.originalIndices()
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected DataNodeRequest mutateInstance(DataNodeRequest in) throws IOException
yield request;
}
case 7 -> {
var indices = randomValueOtherThan(in.indices(), () -> generateRandomStringArray(10, 10, false, false));
var indices = randomArrayOtherThan(in.indices(), () -> generateRandomStringArray(10, 10, false, false));
var request = new DataNodeRequest(
in.sessionId(),
in.configuration(),
Expand Down