Skip to content

Commit

Permalink
Adapt to upstream changes made to AbstractStreamableXContentTestCase (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
javanna authored and martijnvg committed Jan 31, 2018
1 parent b5f2813 commit 65ce227
Showing 1 changed file with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import org.elasticsearch.cluster.metadata.MetaData.Custom;
import org.elasticsearch.common.ParseField;
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.Entry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
Expand All @@ -40,8 +40,8 @@
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.Builder;
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.PersistentTask;
import org.elasticsearch.persistent.TestPersistentTasksPlugin.Status;
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor;
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestParams;
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -127,27 +127,13 @@ protected PersistentTasksCustomMetaData doParseInstance(XContentParser parser) t
return PersistentTasksCustomMetaData.fromXContent(parser);
}

/*
@Override
protected XContentBuilder toXContent(Custom instance, XContentType contentType) throws IOException {
return toXContent(instance, contentType, new ToXContent.MapParams(
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) {
String taskId = UUIDs.base64UUID();
Expand Down Expand Up @@ -179,10 +165,9 @@ public void testSerializationContext() throws Exception {
Collections.singletonMap(MetaData.CONTEXT_MODE_PARAM, randomFrom(CONTEXT_MODE_SNAPSHOT, CONTEXT_MODE_GATEWAY)));

XContentType xContentType = randomFrom(XContentType.values());
XContentBuilder builder = toXContent(testInstance, xContentType, params);
XContentBuilder shuffled = shuffleXContent(builder);
BytesReference shuffled = toShuffledXContent(testInstance, xContentType, params, false);

XContentParser parser = createParser(XContentFactory.xContent(xContentType), shuffled.bytes());
XContentParser parser = createParser(XContentFactory.xContent(xContentType), shuffled);
PersistentTasksCustomMetaData newInstance = doParseInstance(parser);
assertNotSame(newInstance, testInstance);

Expand Down

0 comments on commit 65ce227

Please sign in to comment.