diff --git a/ChangeLog b/ChangeLog index 41805f8..0d3870c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/lib/neography/connection.rb b/lib/neography/connection.rb index 282b7d3..60dbf93 100644 --- a/lib/neography/connection.rb +++ b/lib/neography/connection.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/neography/rest/batch.rb b/lib/neography/rest/batch.rb index b48b099..9d7d062 100644 --- a/lib/neography/rest/batch.rb +++ b/lib/neography/rest/batch.rb @@ -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) diff --git a/lib/neography/version.rb b/lib/neography/version.rb index d658692..6864ef0 100644 --- a/lib/neography/version.rb +++ b/lib/neography/version.rb @@ -1,3 +1,3 @@ module Neography - VERSION = "1.4.1" + VERSION = "1.4.2" end diff --git a/spec/integration/rest_batch_no_streaming_spec.rb b/spec/integration/rest_batch_no_streaming_spec.rb new file mode 100644 index 0000000..471cbc3 --- /dev/null +++ b/spec/integration/rest_batch_no_streaming_spec.rb @@ -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 diff --git a/spec/integration/rest_batch_streaming_spec.rb b/spec/integration/rest_batch_streaming_spec.rb index a72a747..a62a101 100644 --- a/spec/integration/rest_batch_streaming_spec.rb +++ b/spec/integration/rest_batch_streaming_spec.rb @@ -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 = [] @@ -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