use of org.elasticsearch.index.shard.ShardId in project elasticsearch by elastic.
the class ExceptionSerializationTests method testShardLockObtainFailedException.
public void testShardLockObtainFailedException() throws IOException {
ShardId shardId = new ShardId("foo", "_na_", 1);
ShardLockObtainFailedException orig = new ShardLockObtainFailedException(shardId, "boom");
Version version = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, Version.CURRENT);
if (version.before(Version.V_5_0_2)) {
version = Version.V_5_0_2;
}
ShardLockObtainFailedException ex = serialize(orig, version);
assertEquals(orig.getMessage(), ex.getMessage());
assertEquals(orig.getShardId(), ex.getShardId());
}
use of org.elasticsearch.index.shard.ShardId in project elasticsearch by elastic.
the class ExceptionSerializationTests method testRecoverFilesRecoveryException.
public void testRecoverFilesRecoveryException() throws IOException {
ShardId id = new ShardId("foo", "_na_", 1);
ByteSizeValue bytes = new ByteSizeValue(randomIntBetween(0, 10000));
RecoverFilesRecoveryException ex = serialize(new RecoverFilesRecoveryException(id, 10, bytes, null));
assertEquals(ex.getShardId(), id);
assertEquals(ex.numberOfFiles(), 10);
assertEquals(ex.totalFilesSize(), bytes);
assertEquals(ex.getMessage(), "Failed to transfer [10] files with total size of [" + bytes + "]");
assertNull(ex.getCause());
ex = serialize(new RecoverFilesRecoveryException(null, 10, bytes, new NullPointerException()));
assertNull(ex.getShardId());
assertEquals(ex.numberOfFiles(), 10);
assertEquals(ex.totalFilesSize(), bytes);
assertEquals(ex.getMessage(), "Failed to transfer [10] files with total size of [" + bytes + "]");
assertTrue(ex.getCause() instanceof NullPointerException);
}
use of org.elasticsearch.index.shard.ShardId in project elasticsearch by elastic.
the class ExceptionSerializationTests method testRecoveryEngineException.
public void testRecoveryEngineException() throws IOException {
ShardId id = new ShardId("foo", "_na_", 1);
RecoveryEngineException ex = serialize(new RecoveryEngineException(id, 10, "total failure", new NullPointerException()));
assertEquals(id, ex.getShardId());
assertEquals("Phase[10] total failure", ex.getMessage());
assertEquals(10, ex.phase());
ex = serialize(new RecoveryEngineException(null, -1, "total failure", new NullPointerException()));
assertNull(ex.getShardId());
assertEquals(-1, ex.phase());
assertTrue(ex.getCause() instanceof NullPointerException);
}
use of org.elasticsearch.index.shard.ShardId in project elasticsearch by elastic.
the class DocWriteResponseTests method testToXContentDoesntIncludeForcedRefreshUnlessForced.
/**
* Tests that {@link DocWriteResponse#toXContent(XContentBuilder, ToXContent.Params)} doesn't include {@code forced_refresh} unless it
* is true. We can't assert this in the yaml tests because "not found" is also "false" there....
*/
public void testToXContentDoesntIncludeForcedRefreshUnlessForced() throws IOException {
DocWriteResponse response = new DocWriteResponse(new ShardId("index", "uuid", 0), "type", "id", SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, Result.CREATED) {
};
response.setShardInfo(new ShardInfo(1, 1));
response.setForcedRefresh(false);
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes())) {
assertThat(parser.map(), not(hasKey("forced_refresh")));
}
}
response.setForcedRefresh(true);
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes())) {
assertThat(parser.map(), hasEntry("forced_refresh", true));
}
}
}
use of org.elasticsearch.index.shard.ShardId in project elasticsearch by elastic.
the class DocWriteResponseTests method testGetLocationNonAscii.
public void testGetLocationNonAscii() {
final DocWriteResponse response = new DocWriteResponse(new ShardId("index", "uuid", 0), "type", "❤", SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, Result.CREATED) {
};
assertEquals("/index/type/%E2%9D%A4", response.getLocation(null));
assertEquals("/index/type/%E2%9D%A4?routing=%C3%A4", response.getLocation("ä"));
}
Aggregations