Skip to content

Instantly share code, notes, and snippets.

@carlthuringer
Created May 27, 2016 15:52
Show Gist options
  • Save carlthuringer/99e941796a5841b98ca6d5eac150481d to your computer and use it in GitHub Desktop.
Save carlthuringer/99e941796a5841b98ca6d5eac150481d to your computer and use it in GitHub Desktop.
Supposed to create a workflow in backbeat
it "runs a workflow from java to ruby, back to java" do
# Because our Backbeat client is set up with the ruby credentials, we cannot use it to prove this test's functionality.
# Instead, we have to craft the requests by hand.
backbeat_host = URI("http://#{ENV['BACKBEAT_SERVER_HOST']}:#{ENV['BACKBEAT_SERVER_PORT']}")
# Create the workflow
create_workflow_request = Net::HTTP::Post.new(URI.join(backbeat_host, "/workflows"))
set_client_headers(create_workflow_request, :java)
create_workflow_request.body = JSON.dump({
name: "multi-client-to-ruby.start",
subject: SecureRandom.uuid,
decider: "multi-client-to-ruby.start"
})
create_workflow_res = Net::HTTP.start(backbeat_host.host, backbeat_host.port) do |http|
http.request create_workflow_request
end
parsed_create = JSON.parse(create_workflow_res.body)
expect(create_workflow_res.code).to eq("201")
workflow_id = parsed_create["id"]
# Signal the first activity
signal_activity_request = Net::HTTP::Post.new(URI.join(backbeat_host, "/workflows/", workflow_id + "/signal"))
set_client_headers(signal_activity_request, :java)
signal_activity_request.body = JSON.dump({
name: "multi-client-to-ruby.start",
subject: SecureRandom.uuid,
decider: "multi-client-to-ruby.start",
legacy_type: 'activity'
})
signal_activity_response = Net::HTTP.start(backbeat_host.host, backbeat_host.port) do |http|
http.request(signal_activity_request)
end
parsed_signal_create = JSON.parse(signal_activity_response.body)
expect(signal_activity_response.code).to eq("201")
activity_id = parsed_signal_create["id"]
# Get activity status
get_activity_request = Net::HTTP::Get.new(URI.join(backbeat_host, "/activities/#{activity_id}"))
set_client_headers(get_activity_request, :java)
activity_data = nil
wait_with_timeout(10) do
res = Net::HTTP.start(backbeat_host.host, backbeat_host.port) do |http|
http.request get_activity_request
end
activity_data = JSON.parse(res.body)
p activity_data
activity_data['currentClientStatus'] == "complete" && activity_data['currentServerStatus'] == "complete"
end
expect(activity_data['userId']).to eq(ENV['JAVA_CLIENT_ID'])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment