|
@@ -28,7 +28,11 @@ import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
|
import org.elasticsearch.common.io.stream.ByteBufferStreamInput;
|
|
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
+import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
|
|
+import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|
|
+import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.lucene.uid.Versions;
|
|
|
+import org.elasticsearch.common.network.NetworkModule;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.unit.ByteSizeValue;
|
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
@@ -38,6 +42,7 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.index.VersionType;
|
|
|
import org.elasticsearch.index.mapper.SourceToParse;
|
|
|
import org.elasticsearch.index.seqno.SequenceNumbers;
|
|
|
+import org.elasticsearch.tasks.Task;
|
|
|
import org.elasticsearch.tasks.TaskManager;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -196,6 +201,19 @@ public class PrimaryReplicaSyncerTests extends IndexShardTestCase {
|
|
|
assertEquals(status, serializedStatus);
|
|
|
}
|
|
|
|
|
|
+ public void testStatusSerializationAsNamedWriteable() throws IOException {
|
|
|
+ PrimaryReplicaSyncer.ResyncTask.Status status = new PrimaryReplicaSyncer.ResyncTask.Status(randomAlphaOfLength(10),
|
|
|
+ randomIntBetween(0, 1000), randomIntBetween(0, 1000), randomIntBetween(0, 1000));
|
|
|
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
|
|
|
+ out.writeNamedWriteable(status);
|
|
|
+ try (StreamInput in = new NamedWriteableAwareStreamInput(
|
|
|
+ new ByteBufferStreamInput(ByteBuffer.wrap(out.bytes().toBytesRef().bytes)),
|
|
|
+ new NamedWriteableRegistry(NetworkModule.getNamedWriteables()))) {
|
|
|
+ assertThat(in.readNamedWriteable(Task.Status.class), equalTo(status));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void testStatusEquals() throws IOException {
|
|
|
PrimaryReplicaSyncer.ResyncTask task =
|
|
|
new PrimaryReplicaSyncer.ResyncTask(0, "type", "action", "desc", null, Collections.emptyMap());
|