Adapt to upstream changes made to AbstractStreamableXContentTestCase (#2117)
This commit is contained in:
parent
b5f281386a
commit
65ce2276eb
|
@ -25,12 +25,12 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData.Custom;
|
import org.elasticsearch.cluster.metadata.MetaData.Custom;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.UUIDs;
|
import org.elasticsearch.common.UUIDs;
|
||||||
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry;
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
@ -40,8 +40,8 @@ import org.elasticsearch.persistent.PersistentTasksCustomMetaData.Assignment;
|
||||||
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.Builder;
|
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.Builder;
|
||||||
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.PersistentTask;
|
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.PersistentTask;
|
||||||
import org.elasticsearch.persistent.TestPersistentTasksPlugin.Status;
|
import org.elasticsearch.persistent.TestPersistentTasksPlugin.Status;
|
||||||
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor;
|
|
||||||
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestParams;
|
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestParams;
|
||||||
|
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -127,27 +127,13 @@ public class PersistentTasksCustomMetaDataTests extends AbstractDiffableSerializ
|
||||||
return PersistentTasksCustomMetaData.fromXContent(parser);
|
return PersistentTasksCustomMetaData.fromXContent(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
protected XContentBuilder toXContent(Custom instance, XContentType contentType) throws IOException {
|
protected XContentBuilder toXContent(Custom instance, XContentType contentType) throws IOException {
|
||||||
return toXContent(instance, contentType, new ToXContent.MapParams(
|
return toXContent(instance, contentType, new ToXContent.MapParams(
|
||||||
Collections.singletonMap(MetaData.CONTEXT_MODE_PARAM, MetaData.XContentContext.API.toString())));
|
Collections.singletonMap(MetaData.CONTEXT_MODE_PARAM, MetaData.XContentContext.API.toString())));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
protected XContentBuilder toXContent(Custom instance, XContentType contentType, ToXContent.MapParams params) throws IOException {
|
|
||||||
// We need all attribute to be serialized/de-serialized for testing
|
|
||||||
XContentBuilder builder = XContentFactory.contentBuilder(contentType);
|
|
||||||
if (randomBoolean()) {
|
|
||||||
builder.prettyPrint();
|
|
||||||
}
|
|
||||||
if (instance.isFragment()) {
|
|
||||||
builder.startObject();
|
|
||||||
}
|
|
||||||
instance.toXContent(builder, params);
|
|
||||||
if (instance.isFragment()) {
|
|
||||||
builder.endObject();
|
|
||||||
}
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String addRandomTask(Builder builder) {
|
private String addRandomTask(Builder builder) {
|
||||||
String taskId = UUIDs.base64UUID();
|
String taskId = UUIDs.base64UUID();
|
||||||
|
@ -179,10 +165,9 @@ public class PersistentTasksCustomMetaDataTests extends AbstractDiffableSerializ
|
||||||
Collections.singletonMap(MetaData.CONTEXT_MODE_PARAM, randomFrom(CONTEXT_MODE_SNAPSHOT, CONTEXT_MODE_GATEWAY)));
|
Collections.singletonMap(MetaData.CONTEXT_MODE_PARAM, randomFrom(CONTEXT_MODE_SNAPSHOT, CONTEXT_MODE_GATEWAY)));
|
||||||
|
|
||||||
XContentType xContentType = randomFrom(XContentType.values());
|
XContentType xContentType = randomFrom(XContentType.values());
|
||||||
XContentBuilder builder = toXContent(testInstance, xContentType, params);
|
BytesReference shuffled = toShuffledXContent(testInstance, xContentType, params, false);
|
||||||
XContentBuilder shuffled = shuffleXContent(builder);
|
|
||||||
|
|
||||||
XContentParser parser = createParser(XContentFactory.xContent(xContentType), shuffled.bytes());
|
XContentParser parser = createParser(XContentFactory.xContent(xContentType), shuffled);
|
||||||
PersistentTasksCustomMetaData newInstance = doParseInstance(parser);
|
PersistentTasksCustomMetaData newInstance = doParseInstance(parser);
|
||||||
assertNotSame(newInstance, testInstance);
|
assertNotSame(newInstance, testInstance);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue