elastomer-client 0.4.1 → 0.5.0
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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +15 -0
- data/README.md +6 -7
- data/Rakefile +21 -0
- data/docs/README.md +44 -0
- data/docs/bulk_indexing.md +3 -0
- data/docs/client.md +240 -0
- data/docs/cluster.md +148 -0
- data/docs/docs.md +254 -0
- data/docs/index.md +161 -0
- data/docs/multi_search.md +3 -0
- data/docs/notifications.md +24 -11
- data/docs/scan_scroll.md +3 -0
- data/docs/snapshots.md +3 -0
- data/docs/templates.md +3 -0
- data/docs/warmers.md +3 -0
- data/elastomer-client.gemspec +2 -2
- data/lib/elastomer/client.rb +70 -43
- data/lib/elastomer/client/bulk.rb +2 -2
- data/lib/elastomer/client/cluster.rb +2 -2
- data/lib/elastomer/client/docs.rb +190 -54
- data/lib/elastomer/client/errors.rb +4 -2
- data/lib/elastomer/client/index.rb +111 -43
- data/lib/elastomer/client/multi_search.rb +1 -1
- data/lib/elastomer/client/nodes.rb +9 -4
- data/lib/elastomer/client/repository.rb +2 -2
- data/lib/elastomer/client/scroller.rb +235 -0
- data/lib/elastomer/client/snapshot.rb +1 -1
- data/lib/elastomer/client/template.rb +1 -1
- data/lib/elastomer/client/warmer.rb +1 -1
- data/lib/elastomer/notifications.rb +1 -1
- data/lib/elastomer/version.rb +1 -1
- data/script/bootstrap +0 -7
- data/script/cibuild +8 -3
- data/script/test +6 -0
- data/test/client/bulk_test.rb +2 -2
- data/test/client/cluster_test.rb +23 -2
- data/test/client/docs_test.rb +137 -6
- data/test/client/errors_test.rb +12 -8
- data/test/client/index_test.rb +88 -5
- data/test/client/multi_search_test.rb +29 -0
- data/test/client/repository_test.rb +36 -37
- data/test/client/{scan_test.rb → scroller_test.rb} +25 -6
- data/test/client/snapshot_test.rb +53 -43
- data/test/client/stubbed_client_test.rb +1 -1
- data/test/client_test.rb +60 -0
- data/test/notifications_test.rb +69 -0
- data/test/test_helper.rb +54 -11
- metadata +36 -23
- data/.ruby-version +0 -1
- data/lib/elastomer/client/scan.rb +0 -161
- data/script/testsuite +0 -10
data/test/client/errors_test.rb
CHANGED
@@ -27,22 +27,26 @@ describe Elastomer::Client::Error do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "is fatal by default" do
|
30
|
-
assert Elastomer::Client::Error.fatal
|
30
|
+
assert Elastomer::Client::Error.fatal, "client errors are fatal by default"
|
31
31
|
|
32
32
|
error = Elastomer::Client::Error.new "oops!"
|
33
33
|
assert !error.retry?, "client errors are not retryable by default"
|
34
34
|
end
|
35
35
|
|
36
|
+
it "supports .fatal? alias" do
|
37
|
+
assert Elastomer::Client::Error.fatal?, "client errors support .fatal?"
|
38
|
+
end
|
39
|
+
|
36
40
|
it "has some fatal subclasses" do
|
37
|
-
assert Elastomer::Client::ResourceNotFound.fatal
|
38
|
-
assert Elastomer::Client::ParsingError.fatal
|
39
|
-
assert Elastomer::Client::SSLError.fatal
|
40
|
-
assert Elastomer::Client::RequestError.fatal
|
41
|
+
assert Elastomer::Client::ResourceNotFound.fatal, "Resource not found is fatal"
|
42
|
+
assert Elastomer::Client::ParsingError.fatal, "Parsing error is fatal"
|
43
|
+
assert Elastomer::Client::SSLError.fatal, "SSL error is fatal"
|
44
|
+
assert Elastomer::Client::RequestError.fatal, "Request error is fatal"
|
41
45
|
end
|
42
46
|
|
43
47
|
it "has some non-fatal subclasses" do
|
44
|
-
assert !Elastomer::Client::TimeoutError.fatal
|
45
|
-
assert !Elastomer::Client::ConnectionFailed.fatal
|
46
|
-
assert !Elastomer::Client::ServerError.fatal
|
48
|
+
assert !Elastomer::Client::TimeoutError.fatal, "Timeouts are not fatal"
|
49
|
+
assert !Elastomer::Client::ConnectionFailed.fatal, "Connection failures are not fatal"
|
50
|
+
assert !Elastomer::Client::ServerError.fatal, "Server errors are not fatal"
|
47
51
|
end
|
48
52
|
end
|
data/test/client/index_test.rb
CHANGED
@@ -12,19 +12,46 @@ describe Elastomer::Client::Index do
|
|
12
12
|
@index.delete if @index.exists?
|
13
13
|
end
|
14
14
|
|
15
|
-
it '
|
16
|
-
|
15
|
+
it 'does not require an index name' do
|
16
|
+
index = $client.index
|
17
|
+
assert_nil index.name
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'determines if an index exists' do
|
20
21
|
assert !@index.exists?, 'the index should not yet exist'
|
21
22
|
end
|
22
23
|
|
24
|
+
it 'determines if an index exists with .exist?' do
|
25
|
+
assert !@index.exist?, 'the index should not yet exist'
|
26
|
+
end
|
27
|
+
|
23
28
|
describe 'when creating an index' do
|
24
29
|
it 'creates an index' do
|
25
|
-
@index.create
|
30
|
+
@index.create({})
|
26
31
|
assert @index.exists?, 'the index should now exist'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'creates an index with settings' do
|
35
|
+
@index.create :settings => { :number_of_shards => 3, :number_of_replicas => 0 }
|
36
|
+
settings = @index.get_settings[@name]['settings']
|
37
|
+
|
38
|
+
# COMPATIBILITY
|
39
|
+
# ES 1.0 changed the default return format of index settings to always
|
40
|
+
# expand nested properties, e.g.
|
41
|
+
# {"index.number_of_replicas": "1"} changed to
|
42
|
+
# {"index": {"number_of_replicas":"1"}}
|
43
|
+
|
44
|
+
# To support both versions, we check for either return format.
|
45
|
+
value = settings['index.number_of_shards'] ||
|
46
|
+
settings['index']['number_of_shards']
|
47
|
+
assert_equal '3', value
|
48
|
+
value = settings['index.number_of_replicas'] ||
|
49
|
+
settings['index']['number_of_replicas']
|
50
|
+
assert_equal '0', value
|
51
|
+
end
|
27
52
|
|
53
|
+
it 'creates an index with settings with .settings' do
|
54
|
+
@index.create :settings => { :number_of_shards => 3, :number_of_replicas => 0 }
|
28
55
|
settings = @index.settings[@name]['settings']
|
29
56
|
|
30
57
|
# COMPATIBILITY
|
@@ -57,6 +84,25 @@ describe Elastomer::Client::Index do
|
|
57
84
|
}
|
58
85
|
)
|
59
86
|
|
87
|
+
assert @index.exists?, 'the index should now exist'
|
88
|
+
assert_mapping_exists @index.get_mapping[@name], 'doco'
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'adds mappings for document types with .mapping' do
|
92
|
+
@index.create(
|
93
|
+
:settings => { :number_of_shards => 1, :number_of_replicas => 0 },
|
94
|
+
:mappings => {
|
95
|
+
:doco => {
|
96
|
+
:_source => { :enabled => false },
|
97
|
+
:_all => { :enabled => false },
|
98
|
+
:properties => {
|
99
|
+
:title => { :type => 'string', :analyzer => 'standard' },
|
100
|
+
:author => { :type => 'string', :index => 'not_analyzed' }
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
)
|
105
|
+
|
60
106
|
assert @index.exists?, 'the index should now exist'
|
61
107
|
assert_mapping_exists @index.mapping[@name], 'doco'
|
62
108
|
end
|
@@ -107,6 +153,33 @@ describe Elastomer::Client::Index do
|
|
107
153
|
assert_property_exists @index.mapping[@name], 'mux_mool', 'song'
|
108
154
|
end
|
109
155
|
|
156
|
+
it 'updates document mappings with .put_mapping' do
|
157
|
+
@index.create(
|
158
|
+
:mappings => {
|
159
|
+
:doco => {
|
160
|
+
:_source => { :enabled => false },
|
161
|
+
:_all => { :enabled => false },
|
162
|
+
:properties => {:title => { :type => 'string', :analyzer => 'standard' }}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
)
|
166
|
+
|
167
|
+
assert_property_exists @index.mapping[@name], 'doco', 'title'
|
168
|
+
|
169
|
+
@index.put_mapping 'doco', { :doco => { :properties => {
|
170
|
+
:author => { :type => 'string', :index => 'not_analyzed' }
|
171
|
+
}}}
|
172
|
+
|
173
|
+
assert_property_exists @index.mapping[@name], 'doco', 'author'
|
174
|
+
assert_property_exists @index.mapping[@name], 'doco', 'title'
|
175
|
+
|
176
|
+
@index.put_mapping 'mux_mool', { :mux_mool => { :properties => {
|
177
|
+
:song => { :type => 'string', :index => 'not_analyzed' }
|
178
|
+
}}}
|
179
|
+
|
180
|
+
assert_property_exists @index.mapping[@name], 'mux_mool', 'song'
|
181
|
+
end
|
182
|
+
|
110
183
|
it 'deletes document mappings' do
|
111
184
|
@index.create(
|
112
185
|
:mappings => {
|
@@ -121,12 +194,22 @@ describe Elastomer::Client::Index do
|
|
121
194
|
|
122
195
|
response = @index.delete_mapping 'doco'
|
123
196
|
assert_acknowledged response
|
124
|
-
|
197
|
+
|
198
|
+
mapping = @index.get_mapping
|
199
|
+
mapping = mapping[@name] if mapping.key? @name
|
200
|
+
mapping = mapping["mappings"] if mapping.key? "mappings"
|
201
|
+
|
202
|
+
assert_empty mapping, "no mappings are present"
|
125
203
|
end
|
126
204
|
|
127
205
|
it 'lists all aliases to the index' do
|
128
206
|
@index.create(nil)
|
129
|
-
|
207
|
+
|
208
|
+
if es_version_always_returns_aliases?
|
209
|
+
assert_equal({@name => {'aliases' => {}}}, @index.get_aliases)
|
210
|
+
else
|
211
|
+
assert_equal({@name => {}}, @index.get_aliases)
|
212
|
+
end
|
130
213
|
|
131
214
|
$client.cluster.update_aliases :add => {:index => @name, :alias => 'foofaloo'}
|
132
215
|
assert_equal({@name => {'aliases' => {'foofaloo' => {}}}}, @index.get_aliases)
|
@@ -65,6 +65,35 @@ describe Elastomer::Client::MultiSearch do
|
|
65
65
|
assert_equal "2", response1["hits"]["hits"][0]["_id"]
|
66
66
|
end
|
67
67
|
|
68
|
+
it 'performs multisearches with .msearch' do
|
69
|
+
populate!
|
70
|
+
|
71
|
+
body = [
|
72
|
+
'{"index" : "elastomer-msearch-test", "search_type" : "count"}',
|
73
|
+
'{"query" : {"match_all" : {}}}',
|
74
|
+
'{"index" : "elastomer-msearch-test", "type": "doc2"}',
|
75
|
+
'{"query" : {"match": {"author" : "grantr"}}}',
|
76
|
+
nil
|
77
|
+
]
|
78
|
+
body = body.join "\n"
|
79
|
+
h = $client.msearch body
|
80
|
+
response1, response2 = h["responses"]
|
81
|
+
assert_equal 4, response1["hits"]["total"]
|
82
|
+
assert_equal 1, response2["hits"]["total"]
|
83
|
+
assert_equal "2", response2["hits"]["hits"][0]["_id"]
|
84
|
+
|
85
|
+
body = [
|
86
|
+
'{}',
|
87
|
+
'{"query" : {"match": {"author" : "grantr"}}}',
|
88
|
+
nil
|
89
|
+
]
|
90
|
+
body = body.join "\n"
|
91
|
+
h = $client.msearch body, :index => @name
|
92
|
+
response1 = h["responses"].first
|
93
|
+
assert_equal 1, response1["hits"]["total"]
|
94
|
+
assert_equal "2", response1["hits"]["hits"][0]["_id"]
|
95
|
+
end
|
96
|
+
|
68
97
|
it 'supports a nice block syntax' do
|
69
98
|
populate!
|
70
99
|
|
@@ -7,53 +7,45 @@ describe Elastomer::Client::Repository do
|
|
7
7
|
before do
|
8
8
|
@name = 'elastomer-repository-test'
|
9
9
|
@repo = $client.repository(@name)
|
10
|
-
@repo.delete if @repo.exists?
|
11
|
-
end
|
12
|
-
|
13
|
-
after do
|
14
|
-
@repo.delete if @repo.exists?
|
15
10
|
end
|
16
11
|
|
17
12
|
it 'determines if a repo exists' do
|
18
13
|
assert_equal false, @repo.exists?
|
19
14
|
assert_equal false, @repo.exist?
|
20
|
-
with_tmp_repo do
|
15
|
+
with_tmp_repo(@name) do
|
21
16
|
assert_equal true, @repo.exists?
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
25
20
|
it 'creates repos' do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
21
|
+
response = create_repo(@name)
|
22
|
+
assert_equal true, response["acknowledged"]
|
23
|
+
delete_repo(@name)
|
30
24
|
end
|
31
25
|
|
32
26
|
it 'cannot create a repo without a name' do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
}.must_raise ArgumentError
|
37
|
-
end
|
27
|
+
lambda {
|
28
|
+
create_repo(nil)
|
29
|
+
}.must_raise ArgumentError
|
38
30
|
end
|
39
31
|
|
40
32
|
it 'gets repos' do
|
41
|
-
with_tmp_repo do
|
42
|
-
response =
|
43
|
-
refute_nil response[
|
33
|
+
with_tmp_repo do |repo|
|
34
|
+
response = repo.get
|
35
|
+
refute_nil response[repo.name]
|
44
36
|
end
|
45
37
|
end
|
46
38
|
|
47
39
|
it 'gets all repos' do
|
48
|
-
with_tmp_repo do
|
40
|
+
with_tmp_repo do |repo|
|
49
41
|
response = $client.repository.get
|
50
|
-
refute_nil response[
|
42
|
+
refute_nil response[repo.name]
|
51
43
|
end
|
52
44
|
end
|
53
45
|
|
54
46
|
it 'gets repo status' do
|
55
|
-
with_tmp_repo do
|
56
|
-
response =
|
47
|
+
with_tmp_repo do |repo|
|
48
|
+
response = repo.status
|
57
49
|
assert_equal [], response["snapshots"]
|
58
50
|
end
|
59
51
|
end
|
@@ -64,28 +56,28 @@ describe Elastomer::Client::Repository do
|
|
64
56
|
end
|
65
57
|
|
66
58
|
it 'updates repos' do
|
67
|
-
|
68
|
-
|
69
|
-
response =
|
59
|
+
with_tmp_repo do |repo|
|
60
|
+
settings = repo.get[repo.name]['settings']
|
61
|
+
response = repo.update(:type => 'fs', :settings => settings.merge('compress' => true))
|
70
62
|
assert_equal true, response["acknowledged"]
|
71
|
-
|
72
|
-
assert_equal "true", response[@name]["settings"]["compress"]
|
63
|
+
assert_equal "true", repo.get[repo.name]["settings"]["compress"]
|
73
64
|
end
|
74
65
|
end
|
75
66
|
|
76
67
|
it 'cannot update a repo without a name' do
|
77
|
-
|
68
|
+
with_tmp_repo do |repo|
|
78
69
|
lambda {
|
79
|
-
|
70
|
+
settings = repo.get[repo.name]['settings']
|
71
|
+
$client.repository.update(:type => 'fs', :settings => settings.merge('compress' => true))
|
80
72
|
}.must_raise ArgumentError
|
81
73
|
end
|
82
74
|
end
|
83
75
|
|
84
76
|
it 'deletes repos' do
|
85
|
-
with_tmp_repo do
|
86
|
-
response =
|
77
|
+
with_tmp_repo do |repo|
|
78
|
+
response = repo.delete
|
87
79
|
assert_equal true, response["acknowledged"]
|
88
|
-
assert_equal false,
|
80
|
+
assert_equal false, repo.exists?
|
89
81
|
end
|
90
82
|
end
|
91
83
|
|
@@ -96,12 +88,19 @@ describe Elastomer::Client::Repository do
|
|
96
88
|
end
|
97
89
|
|
98
90
|
it 'gets snapshots' do
|
99
|
-
with_tmp_repo do
|
100
|
-
response =
|
91
|
+
with_tmp_repo do |repo|
|
92
|
+
response = repo.snapshots.get
|
101
93
|
assert_equal [], response["snapshots"]
|
102
|
-
|
103
|
-
|
104
|
-
|
94
|
+
|
95
|
+
create_snapshot(repo, 'test-snapshot')
|
96
|
+
response = repo.snapshot.get
|
97
|
+
assert_equal ['test-snapshot'], response["snapshots"].collect { |info| info["snapshot"] }
|
98
|
+
|
99
|
+
snapshot2 = create_snapshot(repo, 'test-snapshot2')
|
100
|
+
response = repo.snapshots.get
|
101
|
+
snapshot_names = response["snapshots"].collect { |info| info["snapshot"] }
|
102
|
+
assert_includes snapshot_names, 'test-snapshot'
|
103
|
+
assert_includes snapshot_names, 'test-snapshot2'
|
105
104
|
end
|
106
105
|
end
|
107
106
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
|
3
|
-
describe Elastomer::Client::
|
3
|
+
describe Elastomer::Client::Scroller do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@name = 'elastomer-
|
6
|
+
@name = 'elastomer-scroller-test'
|
7
7
|
@index = $client.index(@name)
|
8
8
|
|
9
9
|
unless @index.exists?
|
@@ -14,14 +14,16 @@ describe Elastomer::Client::Scan do
|
|
14
14
|
:_source => { :enabled => true }, :_all => { :enabled => false },
|
15
15
|
:properties => {
|
16
16
|
:message => { :type => 'string', :analyzer => 'standard' },
|
17
|
-
:author => { :type => 'string', :index => 'not_analyzed' }
|
17
|
+
:author => { :type => 'string', :index => 'not_analyzed' },
|
18
|
+
:sorter => { :type => 'integer' }
|
18
19
|
}
|
19
20
|
},
|
20
21
|
:book => {
|
21
22
|
:_source => { :enabled => true }, :_all => { :enabled => false },
|
22
23
|
:properties => {
|
23
24
|
:title => { :type => 'string', :analyzer => 'standard' },
|
24
|
-
:author => { :type => 'string', :index => 'not_analyzed' }
|
25
|
+
:author => { :type => 'string', :index => 'not_analyzed' },
|
26
|
+
:sorter => { :type => 'integer' }
|
25
27
|
}
|
26
28
|
}
|
27
29
|
}
|
@@ -31,6 +33,10 @@ describe Elastomer::Client::Scan do
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
36
|
+
after do
|
37
|
+
@index.delete if @index.exists?
|
38
|
+
end
|
39
|
+
|
34
40
|
it 'scans over all documents in an index' do
|
35
41
|
scan = @index.scan '{"query":{"match_all":{}}}', :size => 10
|
36
42
|
|
@@ -64,17 +70,30 @@ describe Elastomer::Client::Scan do
|
|
64
70
|
assert_equal 1, counts['book']
|
65
71
|
end
|
66
72
|
|
73
|
+
it 'scrolls and sorts over all documents' do
|
74
|
+
scroll = @index.scroll({
|
75
|
+
:query => {:match_all => {}},
|
76
|
+
:sort => {:sorter => {:order => :asc}}
|
77
|
+
}, :type => 'tweet')
|
78
|
+
|
79
|
+
tweets = []
|
80
|
+
scroll.each_document { |h| tweets << h['_id'].to_i }
|
81
|
+
|
82
|
+
expected = (0...50).to_a.reverse
|
83
|
+
assert_equal expected, tweets
|
84
|
+
end
|
85
|
+
|
67
86
|
def populate!
|
68
87
|
h = @index.bulk do |b|
|
69
88
|
50.times { |num|
|
70
|
-
b.index %Q({"author":"pea53","message":"this is tweet number #{num}"}), :_id => num, :_type => 'tweet'
|
89
|
+
b.index %Q({"author":"pea53","message":"this is tweet number #{num}","sorter":#{50-num}}), :_id => num, :_type => 'tweet'
|
71
90
|
}
|
72
91
|
end
|
73
92
|
h['items'].each {|item| assert_bulk_index(item) }
|
74
93
|
|
75
94
|
h = @index.bulk do |b|
|
76
95
|
25.times { |num|
|
77
|
-
b.index %Q({"author":"Pratchett","title":"DiscWorld Book #{num}"}), :_id => num, :_type => 'book'
|
96
|
+
b.index %Q({"author":"Pratchett","title":"DiscWorld Book #{num}","sorter":#{25-num}}), :_id => num, :_type => 'book'
|
78
97
|
}
|
79
98
|
end
|
80
99
|
h['items'].each {|item| assert_bulk_index(item) }
|
@@ -6,58 +6,53 @@ describe Elastomer::Client::Snapshot do
|
|
6
6
|
before do
|
7
7
|
@index_name = 'elastomer-snapshot-test-index'
|
8
8
|
@index = $client.index(@index_name)
|
9
|
-
@repo_name = 'elastomer-snapshot-test'
|
10
9
|
@name = 'elastomer-test'
|
11
|
-
@repo = $client.repository(@repo_name)
|
12
|
-
@snapshot = $client.snapshot(@repo_name, @name)
|
13
|
-
@repo.delete if @repo.exists?
|
14
|
-
# No need to delete snapshots because each with_tmp_repo location is unique
|
15
10
|
end
|
16
11
|
|
17
12
|
after do
|
18
|
-
@repo.delete if @repo.exists?
|
19
13
|
@index.delete if @index.exists?
|
20
14
|
end
|
21
15
|
|
22
16
|
it 'determines if a snapshot exists' do
|
23
|
-
with_tmp_repo do
|
24
|
-
|
25
|
-
assert_equal false,
|
26
|
-
|
27
|
-
|
17
|
+
with_tmp_repo do |repo|
|
18
|
+
snapshot = repo.snapshot(@name)
|
19
|
+
assert_equal false, snapshot.exists?
|
20
|
+
assert_equal false, snapshot.exist?
|
21
|
+
snapshot.create({}, :wait_for_completion => true)
|
22
|
+
assert_equal true, snapshot.exist?
|
28
23
|
end
|
29
24
|
end
|
30
25
|
|
31
26
|
it 'creates snapshots' do
|
32
|
-
with_tmp_repo do
|
33
|
-
response = @
|
27
|
+
with_tmp_repo do |repo|
|
28
|
+
response = repo.snapshot(@name).create({}, :wait_for_completion => true)
|
34
29
|
assert_equal @name, response["snapshot"]["snapshot"]
|
35
30
|
end
|
36
31
|
end
|
37
32
|
|
38
33
|
it 'creates snapshots with options' do
|
39
34
|
@index.create(:number_of_shards => 1, :number_of_replicas => 0)
|
40
|
-
with_tmp_repo do
|
41
|
-
response = @
|
35
|
+
with_tmp_repo do |repo|
|
36
|
+
response = repo.snapshot(@name).create({:indices => [@index_name]}, :wait_for_completion => true)
|
42
37
|
assert_equal [@index_name], response["snapshot"]["indices"]
|
43
38
|
assert_equal 1, response["snapshot"]["shards"]["total"]
|
44
39
|
end
|
45
40
|
end
|
46
41
|
|
47
42
|
it 'gets snapshot info for one and all' do
|
48
|
-
with_tmp_snapshot do
|
49
|
-
response =
|
50
|
-
assert_equal
|
51
|
-
response =
|
52
|
-
assert_equal
|
43
|
+
with_tmp_snapshot do |snapshot, repo|
|
44
|
+
response = snapshot.get
|
45
|
+
assert_equal snapshot.name, response["snapshots"][0]["snapshot"]
|
46
|
+
response = repo.snapshots.get
|
47
|
+
assert_equal snapshot.name, response["snapshots"][0]["snapshot"]
|
53
48
|
end
|
54
49
|
end
|
55
50
|
|
56
51
|
it 'gets snapshot status for one and all' do
|
57
52
|
@index.create(:number_of_shards => 1, :number_of_replicas => 0)
|
58
|
-
with_tmp_repo do
|
59
|
-
@
|
60
|
-
response = @
|
53
|
+
with_tmp_repo do |repo|
|
54
|
+
repo.snapshot(@name).create({:indices => [@index_name]}, :wait_for_completion => true)
|
55
|
+
response = repo.snapshot(@name).status
|
61
56
|
assert_equal 1, response["snapshots"][0]["shards_stats"]["total"]
|
62
57
|
end
|
63
58
|
end
|
@@ -65,10 +60,12 @@ describe Elastomer::Client::Snapshot do
|
|
65
60
|
it 'gets status of snapshots in progress' do
|
66
61
|
# we can't reliably get status of an in-progress snapshot in tests, so
|
67
62
|
# check for an empty result instead
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
with_tmp_repo do |repo|
|
64
|
+
response = repo.snapshots.status
|
65
|
+
assert_equal [], response["snapshots"]
|
66
|
+
response = $client.snapshot.status
|
67
|
+
assert_equal [], response["snapshots"]
|
68
|
+
end
|
72
69
|
end
|
73
70
|
|
74
71
|
it 'disallows nil repo name with non-nil snapshot name' do
|
@@ -77,8 +74,8 @@ describe Elastomer::Client::Snapshot do
|
|
77
74
|
end
|
78
75
|
|
79
76
|
it 'deletes snapshots' do
|
80
|
-
with_tmp_snapshot do
|
81
|
-
response =
|
77
|
+
with_tmp_snapshot do |snapshot|
|
78
|
+
response = snapshot.delete
|
82
79
|
assert_equal true, response["acknowledged"]
|
83
80
|
end
|
84
81
|
end
|
@@ -86,25 +83,38 @@ describe Elastomer::Client::Snapshot do
|
|
86
83
|
it 'restores snapshots' do
|
87
84
|
@index.create(:number_of_shards => 1, :number_of_replicas => 0)
|
88
85
|
wait_for_index(@index_name)
|
89
|
-
with_tmp_repo do
|
90
|
-
|
86
|
+
with_tmp_repo do |repo|
|
87
|
+
snapshot = repo.snapshot(@name)
|
88
|
+
snapshot.create({:indices => [@index_name]}, :wait_for_completion => true)
|
91
89
|
@index.delete
|
92
|
-
response =
|
90
|
+
response = snapshot.restore({}, :wait_for_completion => true)
|
93
91
|
assert_equal 1, response["snapshot"]["shards"]["total"]
|
94
92
|
end
|
95
93
|
end
|
96
94
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
95
|
+
describe "restoring to a different index" do
|
96
|
+
before do
|
97
|
+
@restored_index_name = "#{@index_name}-restored"
|
98
|
+
@restored_index = $client.index(@restored_index_name)
|
99
|
+
end
|
100
|
+
|
101
|
+
after do
|
102
|
+
@restored_index.delete if @restored_index.exists?
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'restores snapshots with options' do
|
106
|
+
@index.create(:number_of_shards => 1, :number_of_replicas => 0)
|
107
|
+
wait_for_index(@index_name)
|
108
|
+
with_tmp_repo do |repo|
|
109
|
+
snapshot = repo.snapshot(@name)
|
110
|
+
snapshot.create({:indices => [@index_name]}, :wait_for_completion => true)
|
111
|
+
response = snapshot.restore({
|
112
|
+
:rename_pattern => @index_name,
|
113
|
+
:rename_replacement => @restored_index_name
|
114
|
+
}, :wait_for_completion => true)
|
115
|
+
assert_equal [@restored_index_name], response["snapshot"]["indices"]
|
116
|
+
assert_equal 1, response["snapshot"]["shards"]["total"]
|
117
|
+
end
|
108
118
|
end
|
109
119
|
end
|
110
120
|
end
|