Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/elastomer_client/client/ccr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,34 @@ def follow(follower_index, body, params = {})
response = client.put "/#{follower_index}/_ccr/follow", params.merge(body:, action: "follow", rest_api: "ccr")
response.body
end

# Pauses a follower index.
#
# follower_index - String name of the follower index pause
Comment thread
sarwaan001 marked this conversation as resolved.
Outdated
# params - Hash of the request body
#
# Examples
# ccr.pause_follow("follower_index")
#
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-pause-follow.html
def pause_follow(follower_index, params = {})
response = client.post "/#{follower_index}/_ccr/pause_follow", params.merge(action: "pause_follow", rest_api: "ccr")
response.body
end

# Unfollows a leader index given a follower index.
# The follower index must be paused and closed before unfollowing.
#
# follower_index - String name of the follower index to create
Comment thread
sarwaan001 marked this conversation as resolved.
Outdated
# params - Hash of the request body
#
# Examples
# ccr.unfollow("follower_index")
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-unfollow.html
def unfollow(follower_index, params = {})
response = client.post "/#{follower_index}/_ccr/unfollow", params.merge(action: "unfollow", rest_api: "ccr")
response.body
end
end
end
end
76 changes: 68 additions & 8 deletions test/client/ccr_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative "../test_helper"

describe ElastomerClient::Client::Ccr do
before do
before :each do
Comment thread
sarwaan001 marked this conversation as resolved.
skip "Cannot test Ccr API without a replica cluster" unless $replica_client.available?

@leader_index = $client.index("leader_index")
Expand All @@ -16,24 +16,84 @@
end
@leader_index.create(default_index_settings)
wait_for_index(@leader_index.name, "green")

@leader_index.docs.index(document_wrapper("book", { _id: 1, title: "Book 1" }))
@leader_index.refresh
end

after do
after :each do
@leader_index.delete if @leader_index.exists?
@follower_index.delete if @follower_index.exists?
end

it "successfully follows a leader index" do
def follow_index(follower_index, leader_index)
ccr = $replica_client.ccr
response = ccr.follow(follower_index.name, { leader_index: leader_index.name, remote_cluster: "leader" })
wait_for_index(follower_index.name, "green")
response
end

def pause_follow(follower_index)
ccr = $replica_client.ccr
response = ccr.pause_follow(follower_index.name)
wait_for_index(follower_index.name, "green")
response
end

def unfollow_index(follower_index)
ccr = $replica_client.ccr
response = ccr.unfollow(follower_index.name)
wait_for_index(follower_index.name, "green")
response
end
Comment thread
sarwaan001 marked this conversation as resolved.
Outdated

def create_document(index, type, document)
response = index.docs.index(document_wrapper(type, document))
index.refresh
response
end

it "successfully follows a leader index" do
create_document(@leader_index, "book", { _id: 1, title: "Book 1" })

follow_index(@follower_index, @leader_index)

ccr.follow(@follower_index.name, { leader_index: @leader_index.name, remote_cluster: "leader" })
wait_for_index(@follower_index.name, "green")
doc = @follower_index.docs.get(id: 1, type: "book")

assert_equal "Book 1", doc["_source"]["title"]
end

it "should successfully pauses a follower index" do
Comment thread
sarwaan001 marked this conversation as resolved.
Outdated
follow_index(@follower_index, @leader_index)

response = pause_follow(@follower_index)

assert response["acknowledged"]

create_document(@leader_index, "book", { _id: 2, title: "Book 2" })

doc = @follower_index.docs.get(id: 2, type: "book")

refute doc["found"]
Comment thread
sarwaan001 marked this conversation as resolved.
end

it "should successfully unfollows a leader index" do
Comment thread
sarwaan001 marked this conversation as resolved.
Outdated
follow_index(@follower_index, @leader_index)

pause_follow(@follower_index)

@follower_index.close

response = unfollow_index(@follower_index)

assert response["acknowledged"]

@follower_index.open

wait_for_index(@follower_index.name, "green")

create_document(@leader_index, "book", { _id: 2, title: "Book 2" })

doc = @follower_index.docs.get(id: 2, type: "book")

refute doc["found"]
end

end