Skip to content

Commit

Permalink
merge add batch_no_streaming method
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Apr 27, 2014
2 parents 2e2ebb1 + 496ed9c commit f311511
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 14 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v1.4.2
=======
ee25406 Bump to 1.4.2
c56574f Add batch_no_streaming method

v1.3.11
=======
49e310d Bump to 1.3.11
Expand Down
16 changes: 10 additions & 6 deletions lib/neography/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def configuration

def merge_options(options)
merged_options = options.merge!(@authentication)
merged_options[:headers].merge!(@user_agent) if merged_options[:headers]
merged_options[:headers].merge!('X-Stream' => true) if merged_options[:headers]
merged_options[:headers].merge!(@max_execution_time) if merged_options[:headers]
if merged_options[:headers]
merged_options[:headers].merge!(@user_agent)
merged_options[:headers].merge!('X-Stream' => true) unless merged_options[:headers].key?('X-Stream')
merged_options[:headers].merge!(@max_execution_time)
end
merged_options
end

Expand All @@ -49,7 +51,9 @@ def merge_options(options)
query_path = configuration + path
query_body = merge_options(options)[:body]
log path, query_body do
evaluate_response(@client.send(action.to_sym, query_path, query_body, merge_options(options)[:headers]), path, query_body)
headers = merge_options(options)[:headers]
evaluate_response(@client.send(action.to_sym, query_path, query_body, headers),
path, query_body, headers && (headers['X-Stream'] == true))
end
end
end
Expand Down Expand Up @@ -127,8 +131,8 @@ def evaluate_chunk_response(response, result)
return_result(code, result)
end

def evaluate_response(response, path, query_body)
if response.http_header.request_uri.request_uri == "/db/data/batch"
def evaluate_response(response, path, query_body, streaming)
if streaming && response.http_header.request_uri.request_uri == "/db/data/batch"
code, body, parsed = handle_batch(response)
else
code = response.code
Expand Down
20 changes: 15 additions & 5 deletions lib/neography/rest/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ def batch(*args)
do_batch(*args)
end

def batch_no_streaming(*args)
do_batch_no_streaming(*args)
end

private

def do_batch(*args)
@connection.post("/batch", compute_batch_options(*args))
end

def do_batch_no_streaming(*args)
options = compute_batch_options(*args)
options[:headers].merge!({ 'X-Stream' => false })
@connection.post("/batch", options)
end

def compute_batch_options(*args)
batch = []
Array(args).each_with_index do |c, i|
batch << {:id => i }.merge(get_batch(c))
end
options = {
:body => batch.to_json,
:headers => json_content_type
}
@connection.post("/batch", options)
{:body => batch.to_json, :headers => json_content_type}
end

def get_batch(args)
Expand Down
2 changes: 1 addition & 1 deletion lib/neography/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Neography
VERSION = "1.4.1"
VERSION = "1.4.2"
end
41 changes: 41 additions & 0 deletions spec/integration/rest_batch_no_streaming_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'spec_helper'

describe Neography::Rest do
before(:each) do
@neo = Neography::Rest.new
end

describe "no streaming" do

it "can send a 1000 item batch" do
commands = []
1000.times do |x|
commands << [:create_node, {"name" => "Max " + x.to_s}]
end
batch_result = @neo.batch_no_streaming *commands
batch_result.first["body"]["data"]["name"].should == "Max 0"
batch_result.last["body"]["data"]["name"].should == "Max 999"
end

it "can send a 5000 item batch" do
commands = []
5000.times do |x|
commands << [:get_node, 0]
end
batch_result = @neo.batch_no_streaming *commands
batch_result.first["body"]["self"].split('/').last.should == "0"
batch_result.last["body"]["self"].split('/').last.should == "0"
end

it "can send a 20000 item batch" do
commands = []
20000.times do |x|
commands << [:create_node, {"name" => "Max " + x.to_s}]
end
batch_result = @neo.batch_no_streaming *commands
batch_result.first["body"]["data"]["name"].should == "Max 0"
batch_result.last["body"]["data"]["name"].should == "Max 19999"
end
end

end
14 changes: 12 additions & 2 deletions spec/integration/rest_batch_streaming_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
batch_result = @neo.batch *commands
batch_result.first["body"]["data"]["name"].should == "Max 0"
batch_result.last["body"]["data"]["name"].should == "Max 999"
end
end

it "can send a 5000 item batch" do
commands = []
Expand All @@ -25,8 +25,18 @@
batch_result = @neo.batch *commands
batch_result.first["body"]["self"].split('/').last.should == "0"
batch_result.last["body"]["self"].split('/').last.should == "0"
end
end

# fails in batch streaming
#it "can send a 20000 item batch" do
# commands = []
# 20000.times do |x|
# commands << [:create_node, {"name" => "Max " + x.to_s}]
# end
# batch_result = @neo.batch *commands
# batch_result.first["body"]["data"]["name"].should == "Max 0"
# batch_result.last["body"]["data"]["name"].should == "Max 19999"
#end
end

end

0 comments on commit f311511

Please sign in to comment.