summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/action/support
diff options
context:
space:
mode:
authorNik Everett <nik9000@gmail.com>2016-12-20 11:05:24 -0500
committerGitHub <noreply@github.com>2016-12-20 11:05:24 -0500
commita04dcfb95b1defb954c7be5016ad5865e9099c97 (patch)
tree4b6b4414013c422ef5543311a4844a47aba116fe /core/src/test/java/org/elasticsearch/action/support
parent73320566c1e6c6cfd6b3f40c1a70b23ff2cbdf29 (diff)
Introduce XContentParser#namedObject (#22003)
Introduces `XContentParser#namedObject which works a little like `StreamInput#readNamedWriteable`: on startup components register parsers under names and a superclass. At runtime we look up the parser and call it to parse the object. Right now the parsers take a context object they use to help with the parsing but I hope to be able to eliminate the need for this context as most what it is used for at this point is to move around parser registries which should be replaced by this method eventually. I make no effort to do so in this PR because it is big enough already. This is meant to the a start down a road that allows us to remove classes like `QueryParseContext`, `AggregatorParsers`, `IndicesQueriesRegistry`, and `ParseFieldRegistry`. The goal here is to reduce the amount of plumbing required to allow parsing pluggable things. With this you don't have to pass registries all over the place. Instead you must pass a super registry to fewer places and use it to wrap the reader. This is the same tradeoff that we use for NamedWriteable and it allows much, much simpler binary serialization. We think we want that same thing for xcontent serialization. The only parsing actually converted to this method is parsing `ScoreFunctions` inside of `FunctionScoreQuery`. I chose this because it is relatively self contained.
Diffstat (limited to 'core/src/test/java/org/elasticsearch/action/support')
-rw-r--r--core/src/test/java/org/elasticsearch/action/support/replication/ReplicationResponseTests.java12
-rw-r--r--core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java4
2 files changed, 8 insertions, 8 deletions
diff --git a/core/src/test/java/org/elasticsearch/action/support/replication/ReplicationResponseTests.java b/core/src/test/java/org/elasticsearch/action/support/replication/ReplicationResponseTests.java
index 966bee8f85..ca8f0a4c6b 100644
--- a/core/src/test/java/org/elasticsearch/action/support/replication/ReplicationResponseTests.java
+++ b/core/src/test/java/org/elasticsearch/action/support/replication/ReplicationResponseTests.java
@@ -122,7 +122,7 @@ public class ReplicationResponseTests extends ESTestCase {
final BytesReference shardInfoBytes = XContentHelper.toXContent(shardInfo, xContentType, true);
// Expected JSON is {"_shards":{"total":5,"successful":3,"failed":0}}
- try (XContentParser parser = xContentType.xContent().createParser(shardInfoBytes)) {
+ try (XContentParser parser = createParser(xContentType.xContent(), shardInfoBytes)) {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
assertEquals("_shards", parser.currentName());
@@ -152,7 +152,7 @@ public class ReplicationResponseTests extends ESTestCase {
final BytesReference shardInfoBytes = XContentHelper.toXContent(shardInfo, xContentType, true);
ReplicationResponse.ShardInfo parsedShardInfo;
- try (XContentParser parser = xContentType.xContent().createParser(shardInfoBytes)) {
+ try (XContentParser parser = createParser(xContentType.xContent(), shardInfoBytes)) {
// Move to the start object that was manually added when building the object
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedShardInfo = ReplicationResponse.ShardInfo.fromXContent(parser);
@@ -172,7 +172,7 @@ public class ReplicationResponseTests extends ESTestCase {
final ReplicationResponse.ShardInfo shardInfo = randomShardInfo();
final BytesReference shardInfoBytes = XContentHelper.toXContent(shardInfo, xContentType, true);
- try (XContentParser parser = xContentType.xContent().createParser(shardInfoBytes)) {
+ try (XContentParser parser = createParser(xContentType.xContent(), shardInfoBytes)) {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
assertEquals("_shards", parser.currentName());
@@ -214,7 +214,7 @@ public class ReplicationResponseTests extends ESTestCase {
final BytesReference shardInfoBytes = XContentHelper.toXContent(shardInfo, xContentType, true);
ReplicationResponse.ShardInfo parsedShardInfo;
- try (XContentParser parser = xContentType.xContent().createParser(shardInfoBytes)) {
+ try (XContentParser parser = createParser(xContentType.xContent(), shardInfoBytes)) {
// Move to the start object that was manually added when building the object
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedShardInfo = ReplicationResponse.ShardInfo.fromXContent(parser);
@@ -254,7 +254,7 @@ public class ReplicationResponseTests extends ESTestCase {
final ReplicationResponse.ShardInfo.Failure shardInfoFailure = randomFailure();
final BytesReference shardInfoBytes = XContentHelper.toXContent(shardInfoFailure, xContentType, false);
- try (XContentParser parser = xContentType.xContent().createParser(shardInfoBytes)) {
+ try (XContentParser parser = createParser(xContentType.xContent(), shardInfoBytes)) {
assertFailure(parser, shardInfoFailure);
}
}
@@ -266,7 +266,7 @@ public class ReplicationResponseTests extends ESTestCase {
final BytesReference shardInfoBytes = XContentHelper.toXContent(shardInfoFailure, xContentType, false);
ReplicationResponse.ShardInfo.Failure parsedFailure;
- try (XContentParser parser = xContentType.xContent().createParser(shardInfoBytes)) {
+ try (XContentParser parser = createParser(xContentType.xContent(), shardInfoBytes)) {
// Move to the first start object
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedFailure = ReplicationResponse.ShardInfo.Failure.fromXContent(parser);
diff --git a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java
index 7644c88df3..d2c56f45b3 100644
--- a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java
+++ b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java
@@ -360,8 +360,8 @@ public class TransportReplicationActionTests extends ESTestCase {
public void testClosedIndexOnReroute() throws InterruptedException {
final String index = "test";
// no replicas in oder to skip the replication part
- setState(clusterService,
- new ClusterStateChanges().closeIndices(state(index, true, ShardRoutingState.UNASSIGNED), new CloseIndexRequest(index)));
+ setState(clusterService, new ClusterStateChanges(xContentRegistry()).closeIndices(state(index, true, ShardRoutingState.UNASSIGNED),
+ new CloseIndexRequest(index)));
logger.debug("--> using initial state:\n{}", clusterService.state());
Request request = new Request(new ShardId("test", "_na_", 0)).timeout("1ms");
PlainActionFuture<Response> listener = new PlainActionFuture<>();