elasticsearch-extensions 0.0.27 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile +23 -6
- data/LICENSE.txt +199 -10
- data/README.md +6 -21
- data/Rakefile +21 -4
- data/elasticsearch-extensions.gemspec +38 -27
- data/lib/elasticsearch-extensions.rb +5 -0
- data/lib/elasticsearch/extensions.rb +17 -0
- data/lib/elasticsearch/extensions/ansi.rb +17 -0
- data/lib/elasticsearch/extensions/ansi/actions.rb +18 -1
- data/lib/elasticsearch/extensions/ansi/helpers.rb +17 -0
- data/lib/elasticsearch/extensions/ansi/response.rb +17 -0
- data/lib/elasticsearch/extensions/backup.rb +38 -3
- data/lib/elasticsearch/extensions/reindex.rb +32 -15
- data/lib/elasticsearch/extensions/test/cluster.rb +42 -17
- data/lib/elasticsearch/extensions/test/cluster/tasks.rb +17 -0
- data/lib/elasticsearch/extensions/test/profiling.rb +17 -0
- data/lib/elasticsearch/extensions/test/startup_shutdown.rb +17 -0
- data/lib/elasticsearch/extensions/version.rb +18 -1
- data/test/ansi/unit/ansi_test.rb +23 -6
- data/test/backup/unit/backup_test.rb +21 -0
- data/test/reindex/integration/reindex_test.rb +27 -40
- data/test/reindex/unit/reindex_test.rb +21 -4
- data/test/test/cluster/integration/cluster_test.rb +17 -0
- data/test/test/cluster/unit/cluster_test.rb +50 -8
- data/test/test_helper.rb +27 -2
- metadata +44 -41
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
require 'elasticsearch/extensions/test/cluster'
|
2
19
|
|
3
20
|
namespace :elasticsearch do
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
require 'ruby-prof'
|
2
19
|
require 'benchmark'
|
3
20
|
require 'ansi'
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Elasticsearch
|
2
19
|
module Extensions
|
3
20
|
module Test
|
@@ -1,5 +1,22 @@
|
|
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
|
+
|
1
18
|
module Elasticsearch
|
2
19
|
module Extensions
|
3
|
-
VERSION =
|
20
|
+
VERSION = '0.0.32'.freeze
|
4
21
|
end
|
5
22
|
end
|
data/test/ansi/unit/ansi_test.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
require 'test_helper'
|
2
19
|
require 'elasticsearch/extensions/ansi'
|
3
20
|
|
@@ -7,10 +24,10 @@ class Elasticsearch::Extensions::AnsiTest < Elasticsearch::Test::UnitTestCase
|
|
7
24
|
@client = Elasticsearch::Client.new
|
8
25
|
@client.stubs(:perform_request).returns \
|
9
26
|
Elasticsearch::Transport::Transport::Response.new(200, { "ok" => true, "status" => 200, "name" => "Hit-Maker",
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
27
|
+
"version" => { "number" => "0.90.7",
|
28
|
+
"build_hash" => "abc123",
|
29
|
+
"build_timestamp"=>"2013-11-13T12:06:54Z", "build_snapshot"=>false, "lucene_version"=>"4.5.1" },
|
30
|
+
"tagline"=>"You Know, for Search" })
|
14
31
|
end
|
15
32
|
|
16
33
|
should "wrap the response" do
|
@@ -30,7 +47,7 @@ class Elasticsearch::Extensions::AnsiTest < Elasticsearch::Test::UnitTestCase
|
|
30
47
|
should "call the 'awesome_inspect' method when available and no handler found" do
|
31
48
|
@client.stubs(:perform_request).returns \
|
32
49
|
Elasticsearch::Transport::Transport::Response.new(200, {"index-1"=>{"aliases"=>{}}})
|
33
|
-
response = @client.
|
50
|
+
response = @client.cat.aliases
|
34
51
|
|
35
52
|
response.instance_eval do
|
36
53
|
def awesome_inspect; "---PRETTY---"; end
|
@@ -41,7 +58,7 @@ class Elasticsearch::Extensions::AnsiTest < Elasticsearch::Test::UnitTestCase
|
|
41
58
|
should "call `to_s` method when no pretty printer or handler found" do
|
42
59
|
@client.stubs(:perform_request).returns \
|
43
60
|
Elasticsearch::Transport::Transport::Response.new(200, {"index-1"=>{"aliases"=>{}}})
|
44
|
-
response = @client.
|
61
|
+
response = @client.cat.aliases
|
45
62
|
|
46
63
|
assert_equal '{"index-1"=>{"aliases"=>{}}}', response.to_ansi
|
47
64
|
end
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
require 'test_helper'
|
2
19
|
require 'logger'
|
3
20
|
|
@@ -106,5 +123,9 @@ class Elasticsearch::Extensions::BackupTest < Elasticsearch::Test::UnitTestCase
|
|
106
123
|
|
107
124
|
@subject.__perform_single
|
108
125
|
end
|
126
|
+
|
127
|
+
should "sanitize filename" do
|
128
|
+
assert_equal "foo-bar-baz", @subject.__sanitize_filename("foo/bar\nbaz")
|
129
|
+
end
|
109
130
|
end
|
110
131
|
end
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
require 'test_helper'
|
2
19
|
require 'elasticsearch/extensions/reindex'
|
3
20
|
|
@@ -17,7 +34,7 @@ class Elasticsearch::Extensions::ReindexIntegrationTest < Elasticsearch::Test::I
|
|
17
34
|
ANSI.ansi(severity[0] + ' ', color, :faint) + ANSI.ansi(msg, :white, :faint) + "\n"
|
18
35
|
end
|
19
36
|
|
20
|
-
@client = Elasticsearch::Client.new host: "
|
37
|
+
@client = Elasticsearch::Client.new host: "#{TEST_HOST}:#{TEST_PORT}", logger: @logger
|
21
38
|
@client.indices.delete index: '_all'
|
22
39
|
|
23
40
|
@client.index index: 'test1', type: 'd', id: 1, body: { title: 'TEST 1', category: 'one' }
|
@@ -37,83 +54,53 @@ class Elasticsearch::Extensions::ReindexIntegrationTest < Elasticsearch::Test::I
|
|
37
54
|
should "copy documents from one index to another" do
|
38
55
|
reindex = Elasticsearch::Extensions::Reindex.new \
|
39
56
|
source: { index: 'test1', client: @client },
|
40
|
-
|
57
|
+
dest: { index: 'test2' },
|
41
58
|
batch_size: 2,
|
42
59
|
refresh: true
|
43
60
|
|
44
61
|
result = reindex.perform
|
45
62
|
|
46
63
|
assert_equal 0, result[:errors]
|
47
|
-
assert_equal 3, @client.search(index: 'test2')['hits']['total']
|
48
|
-
end
|
49
|
-
|
50
|
-
should "copy documents with parent/child relationship" do
|
51
|
-
mapping = { mappings: { p: {}, c: { _parent: { type: 'p' } } } }
|
52
|
-
@client.indices.create index: 'test_parent_1', body: mapping
|
53
|
-
@client.indices.create index: 'test_parent_2', body: mapping
|
54
|
-
|
55
|
-
@client.index index: 'test_parent_1', type: 'p', id: 1, body: { title: 'Parent 1' }
|
56
|
-
@client.index index: 'test_parent_1', type: 'p', id: 2, body: { title: 'Parent 2' }
|
57
|
-
@client.index index: 'test_parent_1', type: 'c', parent: 1, body: { title: 'Child One' }
|
58
|
-
@client.index index: 'test_parent_1', type: 'c', parent: 1, body: { title: 'Child Two' }
|
59
|
-
|
60
|
-
@client.indices.refresh index: 'test_parent_1'
|
61
|
-
|
62
|
-
reindex = Elasticsearch::Extensions::Reindex.new \
|
63
|
-
source: { index: 'test_parent_1', client: @client },
|
64
|
-
target: { index: 'test_parent_2' },
|
65
|
-
batch_size: 2,
|
66
|
-
refresh: true
|
67
|
-
|
68
|
-
result = reindex.perform
|
69
|
-
|
70
|
-
assert_equal 0, result[:errors]
|
71
|
-
assert_equal 4, @client.search(index: 'test_parent_2')['hits']['total']
|
72
|
-
|
73
|
-
response = @client.search index: 'test_parent_2', body: {
|
74
|
-
query: { has_child: { type: 'c', query: { match: { title: 'two' } } } } }
|
75
|
-
|
76
|
-
assert_equal 1, response['hits']['hits'].size
|
77
|
-
assert_equal 'Parent 1', response['hits']['hits'][0]['_source']['title']
|
64
|
+
assert_equal 3, @client.search(index: 'test2')['hits']['total']['value']
|
78
65
|
end
|
79
66
|
|
80
67
|
should "transform documents with a lambda" do
|
81
68
|
reindex = Elasticsearch::Extensions::Reindex.new \
|
82
69
|
source: { index: 'test1', client: @client },
|
83
|
-
|
70
|
+
dest: { index: 'test2' },
|
84
71
|
transform: lambda { |d| d['_source']['category'].upcase! },
|
85
72
|
refresh: true
|
86
73
|
|
87
74
|
result = reindex.perform
|
88
75
|
|
89
76
|
assert_equal 0, result[:errors]
|
90
|
-
assert_equal 3, @client.search(index: 'test2')['hits']['total']
|
77
|
+
assert_equal 3, @client.search(index: 'test2')['hits']['total']['value']
|
91
78
|
assert_equal 'ONE', @client.get(index: 'test2', type: 'd', id: 1)['_source']['category']
|
92
79
|
end
|
93
80
|
|
94
81
|
should "return the number of errors" do
|
95
|
-
@client.indices.create index: 'test3', body: { mappings: {
|
82
|
+
@client.indices.create index: 'test3', body: { mappings: { properties: { category: { type: 'integer' } }}}
|
96
83
|
@client.cluster.health wait_for_status: 'yellow'
|
97
84
|
|
98
85
|
reindex = Elasticsearch::Extensions::Reindex.new \
|
99
86
|
source: { index: 'test1', client: @client },
|
100
|
-
|
87
|
+
dest: { index: 'test3' }
|
101
88
|
|
102
89
|
result = reindex.perform
|
103
90
|
|
104
91
|
@client.indices.refresh index: 'test3'
|
105
92
|
|
106
93
|
assert_equal 3, result[:errors]
|
107
|
-
assert_equal 0, @client.search(index: 'test3')['hits']['total']
|
94
|
+
assert_equal 0, @client.search(index: 'test3')['hits']['total']['value']
|
108
95
|
end
|
109
96
|
|
110
97
|
should "reindex via the API integration" do
|
111
98
|
@client.indices.create index: 'test4'
|
112
99
|
|
113
|
-
@client.reindex source: { index: 'test1' },
|
100
|
+
@client.reindex source: { index: 'test1' }, dest: { index: 'test4' }
|
114
101
|
@client.indices.refresh index: 'test4'
|
115
102
|
|
116
|
-
assert_equal 3, @client.search(index: 'test4')['hits']['total']
|
103
|
+
assert_equal 3, @client.search(index: 'test4')['hits']['total']['value']
|
117
104
|
end
|
118
105
|
end
|
119
106
|
|
@@ -1,9 +1,26 @@
|
|
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
|
+
|
1
18
|
require 'test_helper'
|
2
19
|
require 'elasticsearch/extensions/reindex'
|
3
20
|
|
4
21
|
class Elasticsearch::Extensions::ReindexTest < Elasticsearch::Test::UnitTestCase
|
5
22
|
context "The Reindex extension module" do
|
6
|
-
DEFAULT_OPTIONS = { source: { index: 'foo', client: Object.new },
|
23
|
+
DEFAULT_OPTIONS = { source: { index: 'foo', client: Object.new }, dest: { index: 'bar' } }
|
7
24
|
|
8
25
|
should "require options" do
|
9
26
|
assert_raise ArgumentError do
|
@@ -50,7 +67,7 @@ class Elasticsearch::Extensions::ReindexTest < Elasticsearch::Test::UnitTestCase
|
|
50
67
|
should "scroll through the index and save batches in bulk" do
|
51
68
|
client = mock()
|
52
69
|
subject = Elasticsearch::Extensions::Reindex.new source: { index: 'foo', client: client },
|
53
|
-
|
70
|
+
dest: { index: 'bar' }
|
54
71
|
|
55
72
|
client.expects(:search)
|
56
73
|
.returns({ '_scroll_id' => 'scroll_id_1' }.merge(Marshal.load(Marshal.dump(@default_response))))
|
@@ -70,7 +87,7 @@ class Elasticsearch::Extensions::ReindexTest < Elasticsearch::Test::UnitTestCase
|
|
70
87
|
should "return the number of errors" do
|
71
88
|
client = mock()
|
72
89
|
subject = Elasticsearch::Extensions::Reindex.new source: { index: 'foo', client: client },
|
73
|
-
|
90
|
+
dest: { index: 'bar' }
|
74
91
|
|
75
92
|
client.expects(:search).returns({ '_scroll_id' => 'scroll_id_1' }.merge(@default_response))
|
76
93
|
client.expects(:scroll).returns(@empty_response)
|
@@ -85,7 +102,7 @@ class Elasticsearch::Extensions::ReindexTest < Elasticsearch::Test::UnitTestCase
|
|
85
102
|
client = mock()
|
86
103
|
subject = Elasticsearch::Extensions::Reindex.new \
|
87
104
|
source: { index: 'foo', client: client },
|
88
|
-
|
105
|
+
dest: { index: 'bar' },
|
89
106
|
transform: lambda { |d| d['_source']['foo'].upcase!; d }
|
90
107
|
|
91
108
|
client.expects(:search).returns({ '_scroll_id' => 'scroll_id_1' }.merge(@default_response))
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
require 'test_helper'
|
2
19
|
require 'pathname'
|
3
20
|
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
require 'test_helper'
|
2
19
|
|
3
20
|
require 'elasticsearch/extensions/test/cluster'
|
@@ -252,7 +269,7 @@ class Elasticsearch::Extensions::TestClusterTest < Elasticsearch::Test::UnitTest
|
|
252
269
|
|
253
270
|
should "return version from lib/elasticsearch.X.Y.Z.jar" do
|
254
271
|
File.expects(:exist?).with('/foo/bar/bin/../lib/').returns(true)
|
255
|
-
Dir.expects(:entries).with('/foo/bar/bin/../lib/').returns(['foo.jar', 'elasticsearch-2.3.0.jar'])
|
272
|
+
Dir.expects(:entries).with('/foo/bar/bin/../lib/').returns(['foo.jar', 'elasticsearch-foo-1.0.0.jar', 'elasticsearch-2.3.0.jar', 'elasticsearch-bar-9.9.9.jar'])
|
256
273
|
|
257
274
|
assert_equal '2.0', @subject.__determine_version
|
258
275
|
end
|
@@ -261,16 +278,37 @@ class Elasticsearch::Extensions::TestClusterTest < Elasticsearch::Test::UnitTest
|
|
261
278
|
File.expects(:exist?).with('/foo/bar/bin/../lib/').returns(false)
|
262
279
|
File.expects(:exist?).with('/foo/bar/bin/elasticsearch').returns(true)
|
263
280
|
|
281
|
+
io = mock('IO')
|
282
|
+
io.expects(:pid).returns(123)
|
283
|
+
io.expects(:read).returns('Version: 2.3.0-SNAPSHOT, Build: d1c86b0/2016-03-30T10:43:20Z, JVM: 1.8.0_60')
|
284
|
+
io.expects(:closed?).returns(false)
|
285
|
+
io.expects(:close)
|
286
|
+
IO.expects(:popen).returns(io)
|
287
|
+
|
264
288
|
Process.stubs(:wait)
|
265
|
-
Process.expects(:spawn).returns(123)
|
266
289
|
Process.expects(:kill).with('INT', 123)
|
267
290
|
|
268
|
-
IO.any_instance.expects(:read)
|
269
|
-
.returns('Version: 2.3.0-SNAPSHOT, Build: d1c86b0/2016-03-30T10:43:20Z, JVM: 1.8.0_60')
|
270
|
-
|
271
291
|
assert_equal '2.0', @subject.__determine_version
|
272
292
|
end
|
273
293
|
|
294
|
+
should "return version from `elasticsearch --version` when version reaches double digits" do
|
295
|
+
File.expects(:exist?).with('/foo/bar/bin/../lib/').returns(false)
|
296
|
+
File.expects(:exist?).with('/foo/bar/bin/elasticsearch').returns(true)
|
297
|
+
|
298
|
+
io = mock('IO')
|
299
|
+
io.expects(:pid).returns(123)
|
300
|
+
io.expects(:read).returns('Version: 7.11.0-SNAPSHOT, Build: d1c86b0/2016-03-30T10:43:20Z, JVM: 1.8.0_60')
|
301
|
+
io.expects(:closed?).returns(false)
|
302
|
+
io.expects(:close)
|
303
|
+
IO.expects(:popen).returns(io)
|
304
|
+
|
305
|
+
Process.stubs(:wait)
|
306
|
+
Process.expects(:kill).with('INT', 123)
|
307
|
+
|
308
|
+
assert_equal '7.0', @subject.__determine_version
|
309
|
+
end
|
310
|
+
|
311
|
+
|
274
312
|
should "return version from arguments" do
|
275
313
|
cluster = Elasticsearch::Extensions::Test::Cluster::Cluster.new command: '/foo/bar/bin/elasticsearch', version: '5.2'
|
276
314
|
assert_equal '5.0', cluster.__determine_version
|
@@ -288,12 +326,16 @@ class Elasticsearch::Extensions::TestClusterTest < Elasticsearch::Test::UnitTest
|
|
288
326
|
File.expects(:exist?).with('/foo/bar/bin/../lib/').returns(false)
|
289
327
|
File.expects(:exist?).with('/foo/bar/bin/elasticsearch').returns(true)
|
290
328
|
|
329
|
+
io = mock('IO')
|
330
|
+
io.expects(:pid).returns(123)
|
331
|
+
io.expects(:read).returns('Version: FOOBAR')
|
332
|
+
io.expects(:closed?).returns(false)
|
333
|
+
io.expects(:close)
|
334
|
+
IO.expects(:popen).returns(io)
|
335
|
+
|
291
336
|
Process.stubs(:wait)
|
292
|
-
Process.expects(:spawn).returns(123)
|
293
337
|
Process.expects(:kill).with('INT', 123)
|
294
338
|
|
295
|
-
IO.any_instance.expects(:read).returns('Version: FOOBAR')
|
296
|
-
|
297
339
|
assert_raise(RuntimeError) { @subject.__determine_version }
|
298
340
|
end
|
299
341
|
|