-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
spec/esse/integrations/elasticsearch-5/transport/documents_delete_by_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/shared_examples/transport_delete_by_query' | ||
|
||
stack_describe 'elasticsearch', '5.x', Esse::Transport, '#delete_by_query' do | ||
include_examples 'transport#delete_by_query', doc_type: true | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/esse/integrations/elasticsearch-6/transport/documents_delete_by_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/shared_examples/transport_delete_by_query' | ||
|
||
stack_describe 'elasticsearch', '6.x', Esse::Transport, '#delete_by_query' do | ||
include_examples 'transport#delete_by_query', doc_type: true | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/esse/integrations/elasticsearch-7/index/documents_delete_by_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/shared_examples/index_documents_delete_by_query' | ||
|
||
stack_describe 'elasticsearch', '7.x', Esse::Index, '.delete_by_query' do | ||
include_examples 'index.delete_by_query' | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/esse/integrations/elasticsearch-7/transport/documents_delete_by_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/shared_examples/transport_delete_by_query' | ||
|
||
stack_describe 'elasticsearch', '7.x', Esse::Transport, '#delete_by_query' do | ||
include_examples 'transport#delete_by_query' | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/esse/integrations/elasticsearch-8/indices/documents_delete_by_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/shared_examples/index_documents_delete_by_query' | ||
|
||
stack_describe 'elasticsearch', '8.x', Esse::Index, '.delete_by_query' do | ||
include_examples 'index.delete_by_query' | ||
end |
61 changes: 61 additions & 0 deletions
61
spec/support/shared_examples/index_documents_delete_by_query.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples 'index.delete_by_query' do |doc_type: false| | ||
include_context 'with venues index definition' | ||
|
||
let(:params) do | ||
doc_type ? { type: 'venue' } : {} | ||
end | ||
let(:doc_params) do | ||
doc_type ? { _type: 'venue' } : {} | ||
end | ||
let(:index_suffix) { SecureRandom.hex(8) } | ||
let(:body) { { query: { match_all: {} } } } | ||
|
||
it 'raises an Esse::Transport::ReadonlyClusterError exception when the cluster is readonly' do | ||
es_client do |client, _conf, cluster| | ||
cluster.warm_up! | ||
expect(client).not_to receive(:perform_request) | ||
cluster.readonly = true | ||
expect { | ||
VenuesIndex.delete_by_query(body: body, **params) | ||
}.to raise_error(Esse::Transport::ReadonlyClusterError) | ||
end | ||
end | ||
|
||
it 'raises an Esse::Transport::ServerError exception when api throws an error' do | ||
es_client do |client, _conf, cluster| | ||
expect { | ||
VenuesIndex.delete_by_query(body: body, **params) | ||
}.to raise_error(Esse::Transport::NotFoundError) | ||
end | ||
end | ||
|
||
it 'deletes the documents in the aliased index' do | ||
es_client do |client, _conf, cluster| | ||
VenuesIndex.create_index(alias: true, suffix: index_suffix) | ||
VenuesIndex.import(refresh: true, suffix: index_suffix, **params) | ||
|
||
resp = nil | ||
expect { | ||
resp = VenuesIndex.delete_by_query(body: body, **params) | ||
}.not_to raise_error | ||
expect(resp['total']).to eq(total_venues) | ||
expect(resp['deleted']).to eq(total_venues) | ||
end | ||
end | ||
|
||
it 'deletes the documents in the unaliased index' do | ||
es_client do |client, _conf, cluster| | ||
VenuesIndex.create_index(alias: false, suffix: index_suffix) | ||
VenuesIndex.import(refresh: true, suffix: index_suffix, **params) | ||
|
||
resp = nil | ||
expect { | ||
resp = VenuesIndex.delete_by_query(body: body, suffix: index_suffix, **params) | ||
}.not_to raise_error | ||
expect(resp['total']).to eq(total_venues) | ||
expect(resp['deleted']).to eq(total_venues) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples 'transport#delete_by_query' do |doc_type: false| | ||
let(:params) do | ||
doc_type ? { type: 'geo' } : {} | ||
end | ||
let(:body) do | ||
{ | ||
settings: { | ||
index: { | ||
number_of_shards: 1, | ||
number_of_replicas: 0 | ||
} | ||
} | ||
} | ||
end | ||
|
||
it 'raises an Esse::Transport::ReadonlyClusterError exception when the cluster is readonly' do | ||
es_client do |client, _conf, cluster| | ||
cluster.warm_up! | ||
expect(client).not_to receive(:perform_request) | ||
cluster.readonly = true | ||
expect { | ||
cluster.api.delete_by_query(**params, index: "#{cluster.index_prefix}_redonly", body: { q: '*' }) | ||
}.to raise_error(Esse::Transport::ReadonlyClusterError) | ||
end | ||
end | ||
|
||
it 'raises an #<Esse::Transport::NotFoundError exception when the source index does not exist' do | ||
es_client do |_client, _conf, cluster| | ||
expect { | ||
cluster.api.delete_by_query(**params, index: "#{cluster.index_prefix}_non_existent_index", body: { query: { match_all: {} } }) | ||
}.to raise_error(Esse::Transport::NotFoundError) | ||
end | ||
end | ||
|
||
context 'when the index exists' do | ||
it 'reindexes the source index to the destination index' do | ||
es_client do |client, _conf, cluster| | ||
index_name = "#{cluster.index_prefix}_delete_by_query" | ||
cluster.api.create_index(index: index_name, body: body) | ||
cluster.api.index(**params, index: index_name, id: 1, body: { title: 'old title' }, refresh: true) | ||
|
||
resp = nil | ||
expect { | ||
resp = cluster.api.delete_by_query(**params, index: index_name, body: { query: { match_all: {} } }) | ||
}.not_to raise_error | ||
expect(resp['total']).to eq(1) | ||
expect(resp['deleted']).to eq(1) | ||
end | ||
end | ||
end | ||
end |