-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add XContent Serialization Test to SnapshotShardFailure (#72811)
Adding missing test from #72801
- Loading branch information
1 parent
29e3282
commit b5bbd4d
Showing
2 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
server/src/test/java/org/elasticsearch/snapshots/SnapshotShardFailureSerializationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
package org.elasticsearch.snapshots; | ||
|
||
import org.elasticsearch.common.UUIDs; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.test.AbstractXContentTestCase; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.EqualsHashCodeTestUtils; | ||
|
||
import java.io.IOException; | ||
|
||
public class SnapshotShardFailureSerializationTests extends AbstractXContentTestCase<SnapshotShardFailure> { | ||
|
||
public void testEqualsAndHashCode() { | ||
final SnapshotShardFailure instance = createTestInstance(); | ||
EqualsHashCodeTestUtils.checkEqualsAndHashCode( | ||
instance, | ||
snapshotShardFailure -> new SnapshotShardFailure( | ||
snapshotShardFailure.nodeId(), | ||
snapshotShardFailure.getShardId(), | ||
snapshotShardFailure.reason() | ||
), | ||
snapshotShardFailure -> { | ||
if (randomBoolean()) { | ||
return new SnapshotShardFailure( | ||
randomValueOtherThan(snapshotShardFailure.nodeId(), () -> randomAlphaOfLengthBetween(5, 10)), | ||
snapshotShardFailure.getShardId(), | ||
snapshotShardFailure.reason() | ||
); | ||
} else if (randomBoolean()) { | ||
return new SnapshotShardFailure( | ||
snapshotShardFailure.nodeId(), | ||
snapshotShardFailure.getShardId(), | ||
randomValueOtherThan(snapshotShardFailure.reason(), () -> randomAlphaOfLengthBetween(1, 100)) | ||
); | ||
} else { | ||
final ShardId originalShardId = snapshotShardFailure.getShardId(); | ||
final ShardId mutatedShardId; | ||
if (randomBoolean()) { | ||
mutatedShardId = new ShardId( | ||
originalShardId.getIndex(), | ||
randomValueOtherThan((byte) originalShardId.getId(), ESTestCase::randomNonNegativeByte) | ||
); | ||
} else if (randomBoolean()) { | ||
mutatedShardId = new ShardId( | ||
new Index( | ||
originalShardId.getIndexName(), | ||
randomValueOtherThan( | ||
originalShardId.getIndex().getUUID(), | ||
() -> UUIDs.randomBase64UUID(random()) | ||
) | ||
), | ||
originalShardId.id() | ||
); | ||
} else { | ||
mutatedShardId = randomValueOtherThan(originalShardId, SnapshotShardFailureSerializationTests::randomShardId); | ||
} | ||
return new SnapshotShardFailure(snapshotShardFailure.nodeId(), mutatedShardId, snapshotShardFailure.reason()); | ||
} | ||
} | ||
); | ||
} | ||
|
||
@Override | ||
protected SnapshotShardFailure createTestInstance() { | ||
return new SnapshotShardFailure( | ||
UUIDs.randomBase64UUID(random()), | ||
randomShardId(), | ||
randomAlphaOfLengthBetween(1, 100) | ||
); | ||
} | ||
|
||
private static ShardId randomShardId() { | ||
return new ShardId( | ||
randomAlphaOfLengthBetween(5, 10), | ||
UUIDs.randomBase64UUID(random()), | ||
randomNonNegativeByte() | ||
); | ||
} | ||
|
||
@Override | ||
protected SnapshotShardFailure doParseInstance(XContentParser parser) throws IOException { | ||
return SnapshotShardFailure.fromXContent(parser); | ||
} | ||
|
||
@Override | ||
protected boolean supportsUnknownFields() { | ||
return false; | ||
} | ||
} |