Skip to content

Commit c6999a3

Browse files
authored
Fix SnapshotRetentionConfigurationTests (#101603) (#101662)
The test failure happens as we choose same ids with `"snap-" + randomAlphaOfLength(3)`. This change uses UUID for ids to minimize the change of collisions.
1 parent e85c95b commit c6999a3

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

server/src/main/java/org/elasticsearch/repositories/RepositoryData.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,22 @@ public int hashCode() {
12141214
return Objects.hash(snapshotState, version, startTimeMillis, endTimeMillis, slmPolicy);
12151215
}
12161216

1217+
@Override
1218+
public String toString() {
1219+
return "SnapshotDetails{"
1220+
+ "snapshotState="
1221+
+ snapshotState
1222+
+ ", version="
1223+
+ version
1224+
+ ", startTimeMillis="
1225+
+ startTimeMillis
1226+
+ ", endTimeMillis="
1227+
+ endTimeMillis
1228+
+ ", slmPolicy='"
1229+
+ slmPolicy
1230+
+ "'}";
1231+
}
1232+
12171233
public static SnapshotDetails fromSnapshotInfo(SnapshotInfo snapshotInfo) {
12181234
return new SnapshotDetails(
12191235
snapshotInfo.state(),

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.client.internal.Requests;
4444
import org.elasticsearch.cluster.ClusterModule;
4545
import org.elasticsearch.cluster.metadata.IndexMetadata;
46+
import org.elasticsearch.common.UUIDs;
4647
import org.elasticsearch.common.bytes.BytesArray;
4748
import org.elasticsearch.common.bytes.BytesReference;
4849
import org.elasticsearch.common.bytes.CompositeBytesReference;
@@ -996,6 +997,10 @@ public static String randomIdentifier() {
996997
return randomAlphaOfLengthBetween(8, 12).toLowerCase(Locale.ROOT);
997998
}
998999

1000+
public static String randomUUID() {
1001+
return UUIDs.randomBase64UUID(random());
1002+
}
1003+
9991004
public static String randomUnicodeOfLengthBetween(int minCodeUnits, int maxCodeUnits) {
10001005
return RandomizedTest.randomUnicodeOfLengthBetween(minCodeUnits, maxCodeUnits);
10011006
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/SnapshotRetentionConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private SnapshotInfo makeInfo(long startTime) {
313313
meta.put(SnapshotsService.POLICY_ID_METADATA_FIELD, REPO);
314314
final int totalShards = between(1, 20);
315315
SnapshotInfo snapInfo = new SnapshotInfo(
316-
new Snapshot(REPO, new SnapshotId("snap-" + randomAlphaOfLength(3), "uuid")),
316+
new Snapshot(REPO, new SnapshotId("snap-" + randomUUID(), "uuid")),
317317
Collections.singletonList("foo"),
318318
Collections.singletonList("bar"),
319319
Collections.emptyList(),

0 commit comments

Comments
 (0)