From c56574ff25951ea637d8d64f3e752a7c0c7e4964 Mon Sep 17 00:00:00 2001 From: Radu Kopetz Date: Tue, 15 Apr 2014 15:51:26 +0200 Subject: [PATCH 1/4] add batch_no_streaming method --- ChangeLog | 4 ++++ lib/neography/connection.rb | 16 +++++++++------ lib/neography/rest/batch.rb | 20 ++++++++++++++----- lib/neography/version.rb | 2 +- spec/integration/rest_batch_streaming_spec.rb | 14 +++++++++++-- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 41805f8..5d18e91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +v1.4.2 +======= + + v1.3.11 ======= 49e310d Bump to 1.3.11 diff --git a/lib/neography/connection.rb b/lib/neography/connection.rb index b3256e1..f66a5b6 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['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_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 From ee25406abe4f584d1840f9bdb2fb238175c04e13 Mon Sep 17 00:00:00 2001 From: Radu Kopetz Date: Tue, 15 Apr 2014 15:52:30 +0200 Subject: [PATCH 2/4] Bump to 1.4.2 --- ChangeLog | 2 +- .../rest_batch_no_streaming_spec.rb | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 spec/integration/rest_batch_no_streaming_spec.rb diff --git a/ChangeLog b/ChangeLog index 5d18e91..2428875 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ v1.4.2 ======= - +c56574f Add batch_no_streaming method v1.3.11 ======= 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 From 5141a2018dbd82fbb159aca74bbda2d3ab9b0582 Mon Sep 17 00:00:00 2001 From: Radu Kopetz Date: Tue, 15 Apr 2014 15:53:08 +0200 Subject: [PATCH 3/4] Bump to 1.4.2 --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 2428875..0d3870c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ v1.4.2 ======= +ee25406 Bump to 1.4.2 c56574f Add batch_no_streaming method v1.3.11 From 496ed9c43ca695f99fc1ec6b7f62daed932b7acc Mon Sep 17 00:00:00 2001 From: Radu Kopetz Date: Wed, 16 Apr 2014 16:25:50 +0200 Subject: [PATCH 4/4] test for the absence of headers --- lib/neography/connection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/neography/connection.rb b/lib/neography/connection.rb index f66a5b6..3810437 100644 --- a/lib/neography/connection.rb +++ b/lib/neography/connection.rb @@ -53,7 +53,7 @@ def merge_options(options) log path, query_body do headers = merge_options(options)[:headers] evaluate_response(@client.send(action.to_sym, query_path, query_body, headers), - path, query_body, headers['X-Stream'] == true) + path, query_body, headers && (headers['X-Stream'] == true)) end end end