Search in sources :

Example 81 with ShardId

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());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException)

Example 82 with ShardId

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);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) RecoverFilesRecoveryException(org.elasticsearch.indices.recovery.RecoverFilesRecoveryException) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Example 83 with ShardId

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);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) RecoveryEngineException(org.elasticsearch.index.engine.RecoveryEngineException)

Example 84 with ShardId

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));
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) ShardInfo(org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo)

Example 85 with ShardId

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("ä"));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId)

Aggregations

ShardId (org.elasticsearch.index.shard.ShardId)478 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)106 Index (org.elasticsearch.index.Index)101 ClusterState (org.elasticsearch.cluster.ClusterState)98 Test (org.junit.Test)83 ArrayList (java.util.ArrayList)78 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)69 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)67 HashMap (java.util.HashMap)66 IOException (java.io.IOException)61 IndexShard (org.elasticsearch.index.shard.IndexShard)61 Map (java.util.Map)55 List (java.util.List)51 Settings (org.elasticsearch.common.settings.Settings)49 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)45 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)44 HashSet (java.util.HashSet)43 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)43 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)42 Matchers.containsString (org.hamcrest.Matchers.containsString)42