From efebb8d5154d487c9a9ee4eefd5cb957ca305d23 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 20 Jan 2014 18:18:06 +0100 Subject: [PATCH] [TESTS] Added percolator rest tests. --- rest-api-spec/test/mpercolate/10_basic.yaml | 41 +++++++++ rest-api-spec/test/percolate/15_new.yaml | 12 +++ .../test/percolate/16_existing_doc.yaml | 86 +++++++++++++++++++ .../TransportMultiPercolateAction.java | 11 ++- .../indices/IndicesOptionsTests.java | 4 +- 5 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 rest-api-spec/test/mpercolate/10_basic.yaml create mode 100644 rest-api-spec/test/percolate/16_existing_doc.yaml diff --git a/rest-api-spec/test/mpercolate/10_basic.yaml b/rest-api-spec/test/mpercolate/10_basic.yaml new file mode 100644 index 00000000000..70118c93da1 --- /dev/null +++ b/rest-api-spec/test/mpercolate/10_basic.yaml @@ -0,0 +1,41 @@ +--- +"Basic multi-percolate": + - do: + index: + index: percolator_index + type: my_type + id: 1 + body: {foo: bar} + + - do: + index: + index: percolator_index + type: .percolator + id: test_percolator + body: + query: + match_all: {} + + - do: + mpercolate: + body: + - percolate: + index: percolator_index + type: my_type + - doc: + foo: bar + - percolate: + index: percolator_index1 + type: my_type + - doc: + foo: bar + - percolate: + index: percolator_index + type: my_type + id: 1 + - doc: + foo: bar + + - match: { responses.0.total: 1 } + - match: { responses.1.error: "IndexMissingException[[percolator_index1] missing]" } + - match: { responses.2.total: 1 } diff --git a/rest-api-spec/test/percolate/15_new.yaml b/rest-api-spec/test/percolate/15_new.yaml index 7ce2d9de9ca..63c5b9a44e8 100644 --- a/rest-api-spec/test/percolate/15_new.yaml +++ b/rest-api-spec/test/percolate/15_new.yaml @@ -25,4 +25,16 @@ doc: foo: bar + - match: {'total': 1} - match: {'matches': [{_index: test_index, _id: test_percolator}]} + + - do: + count_percolate: + index: test_index + type: test_type + body: + doc: + foo: bar + + - is_false: matches + - match: {'total': 1} diff --git a/rest-api-spec/test/percolate/16_existing_doc.yaml b/rest-api-spec/test/percolate/16_existing_doc.yaml new file mode 100644 index 00000000000..c7c0248c44c --- /dev/null +++ b/rest-api-spec/test/percolate/16_existing_doc.yaml @@ -0,0 +1,86 @@ +--- +"Percolate existing documents": + + - do: + indices.create: + index: percolator_index + + - do: + index: + index: percolator_index + type: .percolator + id: test_percolator + body: + query: + match_all: {} + + - do: + index: + index: percolator_index + type: test_type + id: 1 + body: + foo: bar + + - do: + indices.create: + index: my_index + + - do: + index: + index: my_index + type: my_type + id: 1 + body: + foo: bar + + - do: + indices.refresh: {} + + - do: + percolate: + index: percolator_index + type: test_type + id: 1 + + - match: {'matches': [{_index: percolator_index, _id: test_percolator}]} + + - do: + percolate: + index: my_index + type: my_type + id: 1 + percolate_index: percolator_index + percolate_type: test_type + + - match: {'matches': [{_index: percolator_index, _id: test_percolator}]} + + + - do: + index: + index: my_index + type: my_type + id: 1 + body: + foo: bar + + - do: + percolate: + index: my_index + type: my_type + id: 1 + version: 2 + percolate_index: percolator_index + percolate_type: test_type + + - match: {'matches': [{_index: percolator_index, _id: test_percolator}]} + + - do: + catch: conflict + percolate: + index: my_index + type: my_type + id: 1 + version: 1 + percolate_index: percolator_index + percolate_type: test_type \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java b/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java index 408a66bcea1..e58e5f4f85d 100644 --- a/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java +++ b/src/main/java/org/elasticsearch/action/percolate/TransportMultiPercolateAction.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.index.engine.DocumentMissingException; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.percolator.PercolatorService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BaseTransportRequestHandler; @@ -163,7 +164,15 @@ public class TransportMultiPercolateAction extends TransportAction> routing = clusterState.metaData().resolveSearchRouting(percolateRequest.routing(), percolateRequest.indices()); // TODO: I only need shardIds, ShardIterator(ShardRouting) is only needed in TransportShardMultiPercolateAction GroupShardsIterator shards = clusterService.operationRouting().searchShards( diff --git a/src/test/java/org/elasticsearch/indices/IndicesOptionsTests.java b/src/test/java/org/elasticsearch/indices/IndicesOptionsTests.java index ff1b391657a..357dbed2d24 100644 --- a/src/test/java/org/elasticsearch/indices/IndicesOptionsTests.java +++ b/src/test/java/org/elasticsearch/indices/IndicesOptionsTests.java @@ -92,7 +92,7 @@ public class IndicesOptionsTests extends ElasticsearchIntegrationTest { verify(typesExists("test1", "test2"), true); verify(deleteByQuery("test1", "test2"), true); verify(percolate("test1", "test2"), true); - verify(mpercolate(null, "test1", "test2"), true); + verify(mpercolate(null, "test1", "test2"), false); verify(suggest("test1", "test2"), true); verify(getAliases("test1", "test2"), true); verify(getFieldMapping("test1", "test2"), true); @@ -117,7 +117,7 @@ public class IndicesOptionsTests extends ElasticsearchIntegrationTest { verify(typesExists("test1", "test2").setIndicesOptions(options), true); verify(deleteByQuery("test1", "test2").setIndicesOptions(options), true); verify(percolate("test1", "test2").setIndicesOptions(options), true); - verify(mpercolate(options, "test1", "test2").setIndicesOptions(options), true); + verify(mpercolate(options, "test1", "test2").setIndicesOptions(options), false); verify(suggest("test1", "test2").setIndicesOptions(options), true); verify(getAliases("test1", "test2").setIndicesOptions(options), true); verify(getFieldMapping("test1", "test2").setIndicesOptions(options), true);