Skip to content

Commit fd5bf04

Browse files
committed
[XPACK] Adds async_search.status and unit tests for async_search
1 parent c5be393 commit fd5bf04

File tree

5 files changed

+217
-0
lines changed

5 files changed

+217
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module AsyncSearch
22+
module Actions
23+
# Retrieves the status of a previously submitted async search request given its ID.
24+
#
25+
# @option arguments [String] :id The async search ID
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
#
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/async-search.html
29+
#
30+
def status(arguments = {})
31+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
32+
33+
headers = arguments.delete(:headers) || {}
34+
35+
arguments = arguments.clone
36+
37+
_id = arguments.delete(:id)
38+
39+
method = Elasticsearch::API::HTTP_GET
40+
path = "_async_search/status/#{Elasticsearch::API::Utils.__listify(_id)}"
41+
params = {}
42+
43+
body = nil
44+
perform_request(method, path, params, body, headers).body
45+
end
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackAsyncSearchDelete < Minitest::Test
23+
subject { FakeClient.new }
24+
25+
context 'XPack: Async Search Delete' do
26+
should 'perform correct request' do
27+
subject.expects(:perform_request).with do |method, url, params, body|
28+
assert_equal('DELETE', method)
29+
assert_equal('_async_search/foo', url)
30+
assert_equal({}, params)
31+
assert_nil(body)
32+
end.returns(FakeResponse.new)
33+
34+
subject.xpack.async_search.delete(id: 'foo')
35+
end
36+
end
37+
end
38+
end
39+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackAsyncSearchGet < Minitest::Test
23+
subject { FakeClient.new }
24+
25+
context 'XPack: Async Search Get' do
26+
should 'perform correct request' do
27+
subject.expects(:perform_request).with do |method, url, params, body|
28+
assert_equal('GET', method)
29+
assert_equal('_async_search/foo', url)
30+
assert_equal({}, params)
31+
assert_nil(body)
32+
end.returns(FakeResponse.new)
33+
34+
subject.xpack.async_search.get(id: 'foo')
35+
end
36+
end
37+
end
38+
end
39+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackAsyncSearchStatus < Minitest::Test
23+
subject { FakeClient.new }
24+
25+
context 'XPack: Async Search Status' do
26+
should 'perform correct request' do
27+
subject.expects(:perform_request).with do |method, url, params, body|
28+
assert_equal('GET', method)
29+
assert_equal('_async_search/status/foo', url)
30+
assert_equal({}, params)
31+
assert_nil(body)
32+
end.returns(FakeResponse.new)
33+
34+
subject.xpack.async_search.status(id: 'foo')
35+
end
36+
end
37+
end
38+
end
39+
end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackAsyncSearchSubmit < Minitest::Test
23+
subject { FakeClient.new }
24+
25+
context 'XPack: Async Search Submit' do
26+
should 'perform correct request' do
27+
subject.expects(:perform_request).with do |method, url, params, body|
28+
assert_equal('POST', method)
29+
assert_equal('_async_search', url)
30+
assert_equal({}, params)
31+
assert_nil(body)
32+
end.returns(FakeResponse.new)
33+
34+
subject.xpack.async_search.submit
35+
end
36+
37+
should 'perform correct request with index' do
38+
subject.expects(:perform_request).with do |method, url, params, body|
39+
assert_equal('POST', method)
40+
assert_equal('foo/_async_search', url)
41+
assert_equal({}, params)
42+
assert_nil(body)
43+
end.returns(FakeResponse.new)
44+
45+
subject.xpack.async_search.submit(index: 'foo')
46+
end
47+
end
48+
end
49+
end
50+
end

0 commit comments

Comments
 (0)