|
@@ -27,13 +27,14 @@ import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|
import org.elasticsearch.common.Strings;
|
|
import org.elasticsearch.common.Strings;
|
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
|
+import org.elasticsearch.common.io.stream.Writeable;
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
import org.elasticsearch.index.Index;
|
|
import org.elasticsearch.index.Index;
|
|
import org.elasticsearch.index.IndexNotFoundException;
|
|
import org.elasticsearch.index.IndexNotFoundException;
|
|
import org.elasticsearch.index.shard.ShardId;
|
|
import org.elasticsearch.index.shard.ShardId;
|
|
-import org.elasticsearch.test.ESTestCase;
|
|
|
|
|
|
+import org.elasticsearch.test.AbstractWireSerializingTestCase;
|
|
import org.elasticsearch.transport.ActionNotFoundTransportException;
|
|
import org.elasticsearch.transport.ActionNotFoundTransportException;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -51,7 +52,80 @@ import static org.hamcrest.Matchers.is;
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
|
|
|
|
-public class CloseIndexResponseTests extends ESTestCase {
|
|
|
|
|
|
+public class CloseIndexResponseTests extends AbstractWireSerializingTestCase<CloseIndexResponse> {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected CloseIndexResponse createTestInstance() {
|
|
|
|
+ return randomResponse();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected Writeable.Reader<CloseIndexResponse> instanceReader() {
|
|
|
|
+ return CloseIndexResponse::new;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void assertEqualInstances(CloseIndexResponse expected, CloseIndexResponse actual) {
|
|
|
|
+ assertNotSame(expected, actual);
|
|
|
|
+ assertThat(actual.isAcknowledged(), equalTo(expected.isAcknowledged()));
|
|
|
|
+ assertThat(actual.isShardsAcknowledged(), equalTo(expected.isShardsAcknowledged()));
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < expected.getIndices().size(); i++) {
|
|
|
|
+ CloseIndexResponse.IndexResult expectedIndexResult = expected.getIndices().get(i);
|
|
|
|
+ CloseIndexResponse.IndexResult actualIndexResult = actual.getIndices().get(i);
|
|
|
|
+ assertNotSame(expectedIndexResult, actualIndexResult);
|
|
|
|
+ assertThat(actualIndexResult.getIndex(), equalTo(expectedIndexResult.getIndex()));
|
|
|
|
+ assertThat(actualIndexResult.hasFailures(), equalTo(expectedIndexResult.hasFailures()));
|
|
|
|
+
|
|
|
|
+ if (expectedIndexResult.hasFailures() == false) {
|
|
|
|
+ assertThat(actualIndexResult.getException(), nullValue());
|
|
|
|
+ if (actualIndexResult.getShards() != null) {
|
|
|
|
+ assertThat(Arrays.stream(actualIndexResult.getShards())
|
|
|
|
+ .allMatch(shardResult -> shardResult.hasFailures() == false), is(true));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (expectedIndexResult.getException() != null) {
|
|
|
|
+ assertThat(actualIndexResult.getShards(), nullValue());
|
|
|
|
+ assertThat(actualIndexResult.getException(), notNullValue());
|
|
|
|
+ assertThat(actualIndexResult.getException().getMessage(), equalTo(expectedIndexResult.getException().getMessage()));
|
|
|
|
+ assertThat(actualIndexResult.getException().getClass(), equalTo(expectedIndexResult.getException().getClass()));
|
|
|
|
+ assertArrayEquals(actualIndexResult.getException().getStackTrace(), expectedIndexResult.getException().getStackTrace());
|
|
|
|
+ } else {
|
|
|
|
+ assertThat(actualIndexResult.getException(), nullValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (expectedIndexResult.getShards() != null) {
|
|
|
|
+ assertThat(actualIndexResult.getShards().length, equalTo(expectedIndexResult.getShards().length));
|
|
|
|
+
|
|
|
|
+ for (int j = 0; j < expectedIndexResult.getShards().length; j++) {
|
|
|
|
+ CloseIndexResponse.ShardResult expectedShardResult = expectedIndexResult.getShards()[j];
|
|
|
|
+ CloseIndexResponse.ShardResult actualShardResult = actualIndexResult.getShards()[j];
|
|
|
|
+ assertThat(actualShardResult.getId(), equalTo(expectedShardResult.getId()));
|
|
|
|
+ assertThat(actualShardResult.hasFailures(), equalTo(expectedShardResult.hasFailures()));
|
|
|
|
+
|
|
|
|
+ if (expectedShardResult.hasFailures()) {
|
|
|
|
+ assertThat(actualShardResult.getFailures().length, equalTo(expectedShardResult.getFailures().length));
|
|
|
|
+
|
|
|
|
+ for (int k = 0; k < expectedShardResult.getFailures().length; k++) {
|
|
|
|
+ CloseIndexResponse.ShardResult.Failure expectedFailure = expectedShardResult.getFailures()[k];
|
|
|
|
+ CloseIndexResponse.ShardResult.Failure actualFailure = actualShardResult.getFailures()[k];
|
|
|
|
+ assertThat(actualFailure.getNodeId(), equalTo(expectedFailure.getNodeId()));
|
|
|
|
+ assertThat(actualFailure.index(), equalTo(expectedFailure.index()));
|
|
|
|
+ assertThat(actualFailure.shardId(), equalTo(expectedFailure.shardId()));
|
|
|
|
+ assertThat(actualFailure.getCause().getMessage(), equalTo(expectedFailure.getCause().getMessage()));
|
|
|
|
+ assertThat(actualFailure.getCause().getClass(), equalTo(expectedFailure.getCause().getClass()));
|
|
|
|
+ assertArrayEquals(actualFailure.getCause().getStackTrace(), expectedFailure.getCause().getStackTrace());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ assertThat(actualShardResult.getFailures(), nullValue());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ assertThat(actualIndexResult.getShards(), nullValue());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Test that random responses can be written to xcontent without errors.
|
|
* Test that random responses can be written to xcontent without errors.
|
|
@@ -85,18 +159,6 @@ public class CloseIndexResponseTests extends ESTestCase {
|
|
Strings.toString(closeIndexResponse));
|
|
Strings.toString(closeIndexResponse));
|
|
}
|
|
}
|
|
|
|
|
|
- public void testSerialization() throws Exception {
|
|
|
|
- final CloseIndexResponse response = randomResponse();
|
|
|
|
- try (BytesStreamOutput out = new BytesStreamOutput()) {
|
|
|
|
- response.writeTo(out);
|
|
|
|
-
|
|
|
|
- try (StreamInput in = out.bytes().streamInput()) {
|
|
|
|
- final CloseIndexResponse deserializedResponse = new CloseIndexResponse(in);
|
|
|
|
- assertCloseIndexResponse(deserializedResponse, response);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void testBwcSerialization() throws Exception {
|
|
public void testBwcSerialization() throws Exception {
|
|
{
|
|
{
|
|
final CloseIndexResponse response = randomResponse();
|
|
final CloseIndexResponse response = randomResponse();
|
|
@@ -150,7 +212,7 @@ public class CloseIndexResponseTests extends ESTestCase {
|
|
|
|
|
|
final List<CloseIndexResponse.IndexResult> indexResults = new ArrayList<>();
|
|
final List<CloseIndexResponse.IndexResult> indexResults = new ArrayList<>();
|
|
for (String indexName : indicesNames) {
|
|
for (String indexName : indicesNames) {
|
|
- final Index index = new Index(indexName, "_na_");
|
|
|
|
|
|
+ final Index index = new Index(indexName, randomAlphaOfLength(5));
|
|
if (randomBoolean()) {
|
|
if (randomBoolean()) {
|
|
indexResults.add(new CloseIndexResponse.IndexResult(index));
|
|
indexResults.add(new CloseIndexResponse.IndexResult(index));
|
|
} else {
|
|
} else {
|
|
@@ -178,7 +240,6 @@ public class CloseIndexResponseTests extends ESTestCase {
|
|
indexResults.add(new CloseIndexResponse.IndexResult(index, shards));
|
|
indexResults.add(new CloseIndexResponse.IndexResult(index, shards));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
final boolean shardsAcknowledged = acknowledged ? randomBoolean() : false;
|
|
final boolean shardsAcknowledged = acknowledged ? randomBoolean() : false;
|
|
@@ -191,64 +252,4 @@ public class CloseIndexResponseTests extends ESTestCase {
|
|
new ActionNotFoundTransportException("test"),
|
|
new ActionNotFoundTransportException("test"),
|
|
new NoShardAvailableActionException(new ShardId(index, id)));
|
|
new NoShardAvailableActionException(new ShardId(index, id)));
|
|
}
|
|
}
|
|
-
|
|
|
|
- private static void assertCloseIndexResponse(final CloseIndexResponse actual, final CloseIndexResponse expected) {
|
|
|
|
- assertThat(actual.isAcknowledged(), equalTo(expected.isAcknowledged()));
|
|
|
|
- assertThat(actual.isShardsAcknowledged(), equalTo(expected.isShardsAcknowledged()));
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < expected.getIndices().size(); i++) {
|
|
|
|
- CloseIndexResponse.IndexResult expectedIndexResult = expected.getIndices().get(i);
|
|
|
|
- CloseIndexResponse.IndexResult actualIndexResult = actual.getIndices().get(i);
|
|
|
|
- assertThat(actualIndexResult.getIndex(), equalTo(expectedIndexResult.getIndex()));
|
|
|
|
- assertThat(actualIndexResult.hasFailures(), equalTo(expectedIndexResult.hasFailures()));
|
|
|
|
-
|
|
|
|
- if (expectedIndexResult.hasFailures() == false) {
|
|
|
|
- assertThat(actualIndexResult.getException(), nullValue());
|
|
|
|
- if (actualIndexResult.getShards() != null) {
|
|
|
|
- assertThat(Arrays.stream(actualIndexResult.getShards())
|
|
|
|
- .allMatch(shardResult -> shardResult.hasFailures() == false), is(true));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (expectedIndexResult.getException() != null) {
|
|
|
|
- assertThat(actualIndexResult.getShards(), nullValue());
|
|
|
|
- assertThat(actualIndexResult.getException(), notNullValue());
|
|
|
|
- assertThat(actualIndexResult.getException().getMessage(), equalTo(expectedIndexResult.getException().getMessage()));
|
|
|
|
- assertThat(actualIndexResult.getException().getClass(), equalTo(expectedIndexResult.getException().getClass()));
|
|
|
|
- assertArrayEquals(actualIndexResult.getException().getStackTrace(), expectedIndexResult.getException().getStackTrace());
|
|
|
|
- } else {
|
|
|
|
- assertThat(actualIndexResult.getException(), nullValue());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (expectedIndexResult.getShards() != null) {
|
|
|
|
- assertThat(actualIndexResult.getShards().length, equalTo(expectedIndexResult.getShards().length));
|
|
|
|
-
|
|
|
|
- for (int j = 0; j < expectedIndexResult.getShards().length; j++) {
|
|
|
|
- CloseIndexResponse.ShardResult expectedShardResult = expectedIndexResult.getShards()[j];
|
|
|
|
- CloseIndexResponse.ShardResult actualShardResult = actualIndexResult.getShards()[j];
|
|
|
|
- assertThat(actualShardResult.getId(), equalTo(expectedShardResult.getId()));
|
|
|
|
- assertThat(actualShardResult.hasFailures(), equalTo(expectedShardResult.hasFailures()));
|
|
|
|
-
|
|
|
|
- if (expectedShardResult.hasFailures()) {
|
|
|
|
- assertThat(actualShardResult.getFailures().length, equalTo(expectedShardResult.getFailures().length));
|
|
|
|
-
|
|
|
|
- for (int k = 0; k < expectedShardResult.getFailures().length; k++) {
|
|
|
|
- CloseIndexResponse.ShardResult.Failure expectedFailure = expectedShardResult.getFailures()[k];
|
|
|
|
- CloseIndexResponse.ShardResult.Failure actualFailure = actualShardResult.getFailures()[k];
|
|
|
|
- assertThat(actualFailure.getNodeId(), equalTo(expectedFailure.getNodeId()));
|
|
|
|
- assertThat(actualFailure.index(), equalTo(expectedFailure.index()));
|
|
|
|
- assertThat(actualFailure.shardId(), equalTo(expectedFailure.shardId()));
|
|
|
|
- assertThat(actualFailure.getCause().getMessage(), equalTo(expectedFailure.getCause().getMessage()));
|
|
|
|
- assertThat(actualFailure.getCause().getClass(), equalTo(expectedFailure.getCause().getClass()));
|
|
|
|
- assertArrayEquals(actualFailure.getCause().getStackTrace(), expectedFailure.getCause().getStackTrace());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- assertThat(actualShardResult.getFailures(), nullValue());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- assertThat(actualIndexResult.getShards(), nullValue());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|