rhoconnect 4.0.4 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGELOG.md +54 -5
- data/CREDITS +219 -219
- data/Gemfile +2 -2
- data/Gemfile.lock +68 -79
- data/Rakefile +1 -2
- data/bench/benchapp/spec/models/ruby/mock_adapter_spec.rb +17 -17
- data/bench/benchapp/spec/models/ruby/queue_mock_adapter_spec.rb +17 -17
- data/bench/benchapp/spec/spec_helper.rb +3 -3
- data/bench/blobapp/spec/models/ruby/blob_adapter_spec.rb +17 -17
- data/bench/blobapp/spec/spec_helper.rb +3 -3
- data/bench/lib/bench/runner.rb +1 -69
- data/bench/lib/bench.rb +18 -18
- data/bench/spec/mock_adapter_spec.rb +54 -55
- data/bench/spec/mock_client_spec.rb +47 -48
- data/bench/spec/result_spec.rb +41 -44
- data/bench/spec/utils_spec.rb +24 -25
- data/commands/generators/app.rb +7 -5
- data/commands/generators/controller.rb +7 -5
- data/commands/generators/model.rb +7 -5
- data/commands/generators/source.rb +7 -5
- data/commands/parser.rb +1 -1
- data/commands/redis/redis_download.rb +1 -1
- data/doc/async-jobs.txt +9 -9
- data/doc/supported-platforms.txt +0 -2
- data/generators/rhoconnect.rb +92 -212
- data/generators/templates/application/rcgemfile +3 -3
- data/generators/templates/application/spec/application_controller_spec.rb +14 -16
- data/generators/templates/application/spec/js_spec.rb +20 -20
- data/generators/templates/application/spec/spec_helper.rb +1 -1
- data/generators/templates/source/controllers/ruby/controller_spec.rb +18 -19
- data/generators/templates/source/models/ruby/model_spec.rb +17 -17
- data/install.sh +10 -21
- data/installer/unix-like/rho_connect_install_constants.rb +5 -5
- data/installer/unix-like/rho_connect_install_installers.rb +4 -4
- data/installer/utils/constants.rb +6 -6
- data/installer/utils/nix_install_test.rb +29 -29
- data/installer/utils/package_upload/repos.rake +16 -26
- data/js-adapters/node.rb +4 -4
- data/js-adapters/node_channel.rb +4 -8
- data/lib/rhoconnect/db_adapter.rb +13 -13
- data/lib/rhoconnect/handler/changes/engine.rb +1 -1
- data/lib/rhoconnect/jobs/bulk_data_job.rb +29 -29
- data/lib/rhoconnect/license.rb +7 -7
- data/lib/rhoconnect/model/helpers/find_duplicates_on_update.rb +13 -13
- data/lib/rhoconnect/ping/apple.rb +4 -4
- data/lib/rhoconnect/server.rb +2 -2
- data/lib/rhoconnect/source.rb +2 -2
- data/lib/rhoconnect/store.rb +12 -6
- data/lib/rhoconnect/utilities.rb +2 -2
- data/lib/rhoconnect/version.rb +1 -1
- data/lib/rhoconnect.rb +6 -4
- data/rhoconnect.gemspec +5 -6
- data/spec/api/api_helper.rb +1 -1
- data/spec/api/app/fast_delete_spec.rb +22 -22
- data/spec/api/app/fast_insert_spec.rb +23 -23
- data/spec/api/app/fast_update_spec.rb +63 -63
- data/spec/api/app/push_deletes_spec.rb +11 -13
- data/spec/api/app/push_objects_spec.rb +39 -39
- data/spec/api/client/client_get_db_doc_spec.rb +29 -29
- data/spec/api/client/client_set_db_doc_spec.rb +11 -11
- data/spec/api/client/get_client_params_spec.rb +29 -29
- data/spec/api/client/list_client_docs_spec.rb +32 -34
- data/spec/api/client/reset_spec.rb +30 -30
- data/spec/api/readstate/set_refresh_time_spec.rb +43 -43
- data/spec/api/source/get_source_params_spec.rb +32 -34
- data/spec/api/source/list_sources_spec.rb +13 -13
- data/spec/api/source/update_source_params_spec.rb +19 -19
- data/spec/api/store/get_db_doc_spec.rb +27 -27
- data/spec/api/store/set_db_doc_spec.rb +38 -38
- data/spec/api/system/adapter_spec.rb +27 -29
- data/spec/api/system/get_license_info_spec.rb +11 -11
- data/spec/api/system/login_spec.rb +37 -37
- data/spec/api/system/reset_spec.rb +15 -15
- data/spec/api/system/stats_spec.rb +70 -71
- data/spec/api/user/create_user_spec.rb +37 -37
- data/spec/api/user/delete_client_spec.rb +7 -7
- data/spec/api/user/delete_user_spec.rb +62 -62
- data/spec/api/user/list_clients_spec.rb +24 -24
- data/spec/api/user/list_source_docs_spec.rb +29 -29
- data/spec/api/user/list_users_spec.rb +22 -22
- data/spec/api/user/ping_spec.rb +18 -18
- data/spec/api/user/show_user_spec.rb +10 -10
- data/spec/api/user/update_user_spec.rb +43 -43
- data/spec/api/user/user_get_db_doc_spec.rb +12 -12
- data/spec/api/user/user_set_db_doc_spec.rb +37 -37
- data/spec/api_token_spec.rb +8 -8
- data/spec/app_spec.rb +18 -17
- data/spec/apps/jstestapp/settings/settings.yml +2 -0
- data/spec/async_spec.rb +9 -11
- data/spec/bulk_data/bulk_data_spec.rb +120 -120
- data/spec/cli/cli_spec.rb +50 -53
- data/spec/client_spec.rb +105 -105
- data/spec/client_sync_spec.rb +529 -528
- data/spec/controllers/js_base_spec.rb +147 -141
- data/spec/doc/doc_spec.rb +51 -52
- data/spec/document_spec.rb +58 -58
- data/spec/dynamic_adapter_spec.rb +33 -36
- data/spec/generator/generator_spec.rb +76 -42
- data/spec/jobs/bulk_data_job_spec.rb +101 -102
- data/spec/jobs/ping_job_spec.rb +176 -177
- data/spec/jobs/source_job_spec.rb +24 -25
- data/spec/license_spec.rb +54 -55
- data/spec/models/js_base_spec.rb +121 -120
- data/spec/perf/bulk_data_perf_spec.rb +23 -24
- data/spec/perf/perf_spec_helper.rb +7 -7
- data/spec/perf/store_perf_spec.rb +139 -140
- data/spec/ping/apple_spec.rb +65 -65
- data/spec/ping/gcm_spec.rb +83 -84
- data/spec/ping/rhoconnect_push_spec.rb +52 -53
- data/spec/predefined_adapters/rho_internal_bench_adapter_controller_js_spec.rb +100 -101
- data/spec/predefined_adapters/rho_internal_js_bench_adapter_js_spec.rb +29 -31
- data/spec/read_state_spec.rb +24 -25
- data/spec/rhoconnect_spec.rb +7 -7
- data/spec/server/server_spec.rb +664 -662
- data/spec/server/stats_spec.rb +12 -12
- data/spec/source_adapter_spec.rb +124 -125
- data/spec/source_spec.rb +148 -149
- data/spec/source_sync_spec.rb +736 -736
- data/spec/spec_helper.rb +4 -5
- data/spec/stats/record_spec.rb +22 -21
- data/spec/store_orm_spec.rb +48 -48
- data/spec/store_spec.rb +428 -426
- data/spec/support/shared_examples.rb +5 -7
- data/spec/sync_states_spec.rb +67 -67
- data/spec/test_methods_spec.rb +121 -123
- data/spec/testdata/10000-data.txt +0 -0
- data/spec/testdata/5000-data.txt +0 -0
- data/spec/user_spec.rb +102 -102
- data/tasks/redis.rake +3 -3
- metadata +154 -195
- data/bench/benchapp/tmp/pids/passenger.9292.pid.lock +0 -0
- data/bench/benchapp/tmp/restart.txt +0 -0
- data/bench/blobapp/settings/license.key.bak +0 -2
- data/bench/blobapp/tmp/restart.txt +0 -0
- data/bench/lib/testdata/1-data.txt +0 -0
- data/bench/lib/testdata/10-data.txt +0 -0
- data/bench/lib/testdata/2-data.txt +0 -0
- data/bench/lib/testdata/250-data.txt +0 -0
- data/bench/lib/testdata/5-blob_data.txt +0 -0
- data/bench/lib/testdata/5-data.txt +0 -0
- data/bench/lib/testdata/50-data.txt +0 -0
- data/bench/lib/testdata/500-data.txt +0 -0
- data/doc/protocol.html +0 -1993
- data/spec/coverage/rcov/assets/0.2.3/jquery-1.3.2.min.js +0 -19
- data/spec/coverage/rcov/assets/0.2.3/jquery.tablesorter.min.js +0 -15
- data/spec/coverage/rcov/assets/0.2.3/print.css +0 -12
- data/spec/coverage/rcov/assets/0.2.3/rcov.js +0 -42
- data/spec/coverage/rcov/assets/0.2.3/screen.css +0 -270
- data/spec/coverage/rcov/index.html +0 -88
- data/spec/generator/generator_spec_helper.rb +0 -9
data/spec/client_sync_spec.rb
CHANGED
@@ -1,89 +1,196 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__),'spec_helper')
|
2
2
|
|
3
3
|
describe "ClientSync" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
4
|
+
include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
|
5
|
+
|
6
|
+
it "should handle receive cud for dynamic adapter" do
|
7
|
+
Rhoconnect.appserver = "http://test.com"
|
8
|
+
params = {'create'=>{'1'=>@product1}}
|
9
|
+
@c.source_name = 'Product2'
|
10
|
+
# create handler
|
11
|
+
lv = lambda { @model.create(@params[:create_object]) }
|
12
|
+
@model = Rhoconnect::Model::Base.create(@s2)
|
13
|
+
@cs1 = Rhoconnect::Handler::Changes::Runner.new(['create'],@model,@c,lv,params)
|
14
|
+
stub_request(:post, "http://test.com/rhoconnect/authenticate")
|
15
|
+
stub_request(:post, "http://test.com/rhoconnect/create").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5})
|
16
|
+
@cs1.run
|
17
|
+
verify_source_queue_data(@s2, {:create => [],
|
18
|
+
:update => [],
|
19
|
+
:delete => []})
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
before(:each) do
|
25
|
-
@s = Source.load(@s_fields[:name],@s_params)
|
26
|
-
# CUD handler
|
27
|
-
rhcud = lambda { @model.send params[:operation].to_sym, params["#{params[:operation]}_object".to_sym] }
|
28
|
-
@model = Rhoconnect::Model::Base.create(@s)
|
29
|
-
@cud_handler = Rhoconnect::Handler::Changes::Runner.new(['create','update','delete'],@model,@c,rhcud,{})
|
30
|
-
|
31
|
-
# query handler
|
32
|
-
params = {:p_size => 2}
|
33
|
-
lv = lambda { @model.query(@params[:query]) }
|
34
|
-
@sync_handler = Rhoconnect::Handler::Query::Runner.new(@model,@c, lv, params)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should handle receive cud" do
|
38
|
-
@cud_handler.params = {'create'=>{'1'=>@product1},'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
|
39
|
-
@cud_handler.run
|
40
|
-
verify_source_queue_data(@s, {:create => [],
|
41
|
-
:update => [],
|
42
|
-
:delete => []})
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should handle receive cud that triggers processing of the previously queued data" do
|
46
|
-
queued_create_data = [[@s.name, [['1', @product1]]]]
|
47
|
-
set_source_queue_state(@s, {:create => queued_create_data}, @c.id)
|
48
|
-
verify_source_queue_data(@s, {:create => [queued_create_data],
|
49
|
-
:update => [],
|
50
|
-
:delete => []})
|
51
|
-
@cud_handler.run
|
52
|
-
verify_source_queue_data(@s, {:create => [],
|
53
|
-
:update => [],
|
54
|
-
:delete => []})
|
55
|
-
end
|
22
|
+
let(:mock_schema) { {"property" => { "name" => "string", "brand" => "string" }, "version" => "1.0"} }
|
23
|
+
let(:sha1) { get_sha1(mock_schema['version']) }
|
56
24
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
25
|
+
before(:each) do
|
26
|
+
@s = Source.load(@s_fields[:name],@s_params)
|
27
|
+
# CUD handler
|
28
|
+
rhcud = lambda { @model.send params[:operation].to_sym, params["#{params[:operation]}_object".to_sym] }
|
29
|
+
@model = Rhoconnect::Model::Base.create(@s)
|
30
|
+
@cud_handler = Rhoconnect::Handler::Changes::Runner.new(['create','update','delete'],@model,@c,rhcud,{})
|
31
|
+
|
32
|
+
# query handler
|
33
|
+
params = {:p_size => 2}
|
34
|
+
lv = lambda { @model.query(@params[:query]) }
|
35
|
+
@sync_handler = Rhoconnect::Handler::Query::Runner.new(@model,@c, lv, params)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should handle receive cud" do
|
39
|
+
@cud_handler.params = {'create'=>{'1'=>@product1},'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
|
40
|
+
@cud_handler.run
|
41
|
+
verify_source_queue_data(@s, {:create => [],
|
42
|
+
:update => [],
|
43
|
+
:delete => []})
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should handle receive cud that triggers processing of the previously queued data" do
|
47
|
+
queued_create_data = [[@s.name, [['1', @product1]]]]
|
48
|
+
set_source_queue_state(@s, {:create => queued_create_data}, @c.id)
|
49
|
+
verify_source_queue_data(@s, {:create => [queued_create_data],
|
50
|
+
:update => [],
|
51
|
+
:delete => []})
|
52
|
+
@cud_handler.run
|
53
|
+
verify_source_queue_data(@s, {:create => [],
|
54
|
+
:update => [],
|
55
|
+
:delete => []})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should handle receive cud from the custom queue_key that triggers processing of the previously queued data" do
|
59
|
+
queue_key = "post:/my_custom_create_route"
|
60
|
+
queue_name = "create:#{queue_key}"
|
61
|
+
Source.define_valid_queues([queue_name])
|
62
|
+
queued_create_data = [[@s.name, [['1', @product1]]]]
|
63
|
+
set_source_queue_state(@s, {queue_name => queued_create_data}, @c.id)
|
64
|
+
verify_source_queue_data(@s, {queue_name => [queued_create_data]})
|
65
|
+
@cud_handler.params[:queue_key] = queue_key
|
66
|
+
@cud_handler.engine.params[:queue_key] = queue_key
|
67
|
+
@cud_handler.operations = ["create"]
|
68
|
+
@cud_handler.engine.operations = ["create"]
|
69
|
+
@cud_handler.run
|
70
|
+
verify_source_queue_data(@s, {queue_name => []})
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should handle receive cud with pass through" do
|
74
|
+
params = {'create'=>{'1'=>@product1},'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
|
75
|
+
@s.pass_through = 'true'
|
76
|
+
|
77
|
+
rhcud = lambda { @model.send params[:operation].to_sym, params["#{params[:operation]}_object".to_sym] }
|
78
|
+
@cud_handler = Rhoconnect::Handler::Changes::PassThroughRunner.new(['create','update','delete'],@model,@c,rhcud,params)
|
79
|
+
JSON.parse(@cud_handler.run).should == {"processed" => ['1', '2', '3']}
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should handle exeptions in receive cud with pass through" do
|
83
|
+
params = {'create'=>{'1'=>@error},'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
|
84
|
+
@s.pass_through = 'true'
|
85
|
+
rhcud = lambda { @model.send params[:operation].to_sym, params["#{params[:operation]}_object".to_sym] }
|
86
|
+
@cud_handler = Rhoconnect::Handler::Changes::PassThroughRunner.new(['create','update','delete'],@model,@c,rhcud,params)
|
87
|
+
JSON.parse(@cud_handler.run).should == {"error" => {"message" => "undefined method `[]' for nil:NilClass" }, "processed" => []}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should handle send cud" do
|
91
|
+
data = {'1'=>@product1,'2'=>@product2}
|
92
|
+
expected = {'insert'=>data}
|
93
|
+
set_test_data('test_db_storage',data)
|
94
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>@c.get_value(:page_token)},
|
95
|
+
{'count'=>data.size},{'progress_count'=>0},
|
96
|
+
{'total_count'=>data.size},expected]
|
97
|
+
verify_doc_result(@sync_handler.client, {:page => data,
|
98
|
+
:delete_page => {},
|
99
|
+
:cd => data})
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should handle send cud with page size 0" do
|
103
|
+
data = {'1'=>@product1,'2'=>@product2}
|
104
|
+
expected = {}
|
105
|
+
set_test_data('test_db_storage',data)
|
106
|
+
@sync_handler.p_size = 0
|
107
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>''},
|
108
|
+
{'count'=>0},{'progress_count'=>0},
|
109
|
+
{'total_count'=>data.size},expected]
|
110
|
+
verify_doc_result(@sync_handler.client, {:page => expected,
|
111
|
+
:delete_page => {},
|
112
|
+
:cd => expected})
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should handle send cud for dynamic adapter" do
|
116
|
+
Rhoconnect.appserver = "http://test.com"
|
117
|
+
data = {'1'=>@product1}
|
118
|
+
expected = {'insert'=>data}
|
119
|
+
stub_request(:post, "http://test.com/rhoconnect/authenticate")
|
120
|
+
stub_request(:post, "http://test.com/rhoconnect/query").with(:headers => {'Content-Type' => 'application/json'}).to_return(:status => 200, :body => data.to_json)
|
121
|
+
|
122
|
+
@c.source_name = 'Product2'
|
123
|
+
# query handler
|
124
|
+
lv = lambda { @model.query(params[:query]) }
|
125
|
+
params = { :p_size => 2 }
|
126
|
+
@model = Rhoconnect::Model::Base.create(@s2)
|
127
|
+
@cs1 = Rhoconnect::Handler::Query::Runner.new(@model,@c, lv, params)
|
128
|
+
@cs1.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>@c.get_value(:page_token)},
|
129
|
+
{'count'=>data.size},{'progress_count'=>0},
|
130
|
+
{'total_count'=>data.size},expected]
|
131
|
+
|
132
|
+
verify_doc_result(@cs1.client, {:page => data,
|
133
|
+
:delete_page => {},
|
134
|
+
:cd => data})
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should handle send cud with pass_through" do
|
138
|
+
data = {'1'=>@product1,'2'=>@product2}
|
139
|
+
expected = {'insert'=>data}
|
140
|
+
set_test_data('test_db_storage',data)
|
141
|
+
@s.pass_through = 'true'
|
142
|
+
lv = lambda { @model.query(params[:query]) }
|
143
|
+
params = { :p_size => 2 }
|
144
|
+
@ptsync = Rhoconnect::Handler::Query::PassThroughRunner.new(@model, @c, lv, params)
|
145
|
+
@ptsync.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>@c.get_value(:page_token)},
|
146
|
+
{'count'=>data.size},{'progress_count'=>0},
|
147
|
+
{'total_count'=>data.size},expected]
|
148
|
+
verify_doc_result(@ptsync.client, {:page => {},
|
149
|
+
:cd => {}})
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should handle send cud if with pass_through no data" do
|
153
|
+
data = {}
|
154
|
+
expected = {}
|
155
|
+
#set_test_data('test_db_storage',data)
|
156
|
+
@s.pass_through = 'true'
|
157
|
+
lv = lambda { @model.query(params[:query]) }
|
158
|
+
params = { :p_size => 2 }
|
159
|
+
@ptsync = Rhoconnect::Handler::Query::PassThroughRunner.new(@model, @c, lv, params)
|
160
|
+
@ptsync.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>""},
|
161
|
+
{'count'=>data.size},{'progress_count'=>0},
|
162
|
+
{'total_count'=>data.size},expected]
|
163
|
+
verify_doc_result(@ptsync.client, {:page => {},
|
164
|
+
:cd => {}})
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should return read errors in send cud" do
|
168
|
+
msg = "Error during query"
|
169
|
+
data = {'1'=>@product1,'2'=>@product2}
|
170
|
+
set_test_data('test_db_storage',data,msg,'query error')
|
171
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0},{"total_count"=>0},
|
172
|
+
{"source-error"=>{"query-error"=>{"message"=>msg}}}]
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should return login errors in send cud" do
|
176
|
+
@u.login = nil
|
177
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""},
|
178
|
+
{"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
|
179
|
+
{'source-error'=>{"login-error"=>{"message"=>"Error logging in"}}}]
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should return logoff errors in send cud" do
|
183
|
+
msg = "Error logging off"
|
184
|
+
set_test_data('test_db_storage',{},msg,'logoff error')
|
185
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>@c.get_value(:page_token)},
|
186
|
+
{"count"=>1}, {"progress_count"=>0}, {"total_count"=>1},
|
187
|
+
{"source-error"=>{"logoff-error"=>{"message"=>msg}},
|
188
|
+
"insert"=>{ERROR=>{"name"=>"logoff error", "an_attribute"=>msg}}}]
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "send errors in send_cud" do
|
192
|
+
it "should handle create errors" do
|
193
|
+
receive_and_send_cud('create')
|
87
194
|
end
|
88
195
|
|
89
196
|
it "should handle send cud" do
|
@@ -94,529 +201,423 @@ describe "ClientSync" do
|
|
94
201
|
{'count'=>data.size},{'progress_count'=>0},
|
95
202
|
{'total_count'=>data.size},expected]
|
96
203
|
verify_doc_result(@sync_handler.client, {:page => data,
|
97
|
-
|
98
|
-
|
204
|
+
:delete_page => {},
|
205
|
+
:cd => data})
|
99
206
|
end
|
100
207
|
|
101
|
-
it "should handle send cud with page size 0" do
|
102
|
-
data = {'1'=>@product1,'2'=>@product2}
|
103
|
-
expected = {}
|
104
|
-
set_test_data('test_db_storage',data)
|
105
|
-
@sync_handler.p_size = 0
|
106
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>''},
|
107
|
-
{'count'=>0},{'progress_count'=>0},
|
108
|
-
{'total_count'=>data.size},expected]
|
109
|
-
verify_doc_result(@sync_handler.client, {:page => expected,
|
110
|
-
:delete_page => {},
|
111
|
-
:cd => expected})
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should handle send cud for dynamic adapter" do
|
115
|
-
Rhoconnect.appserver = "http://test.com"
|
116
|
-
data = {'1'=>@product1}
|
117
|
-
expected = {'insert'=>data}
|
118
|
-
stub_request(:post, "http://test.com/rhoconnect/authenticate")
|
119
|
-
stub_request(:post, "http://test.com/rhoconnect/query").with(:headers => {'Content-Type' => 'application/json'}).to_return(:status => 200, :body => data.to_json)
|
120
|
-
|
121
|
-
@c.source_name = 'Product2'
|
122
|
-
# query handler
|
123
|
-
lv = lambda { @model.query(params[:query]) }
|
124
|
-
params = { :p_size => 2 }
|
125
|
-
@model = Rhoconnect::Model::Base.create(@s2)
|
126
|
-
@cs1 = Rhoconnect::Handler::Query::Runner.new(@model,@c, lv, params)
|
127
|
-
@cs1.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>@c.get_value(:page_token)},
|
128
|
-
{'count'=>data.size},{'progress_count'=>0},
|
129
|
-
{'total_count'=>data.size},expected]
|
130
|
-
|
131
|
-
verify_doc_result(@cs1.client, {:page => data,
|
132
|
-
:delete_page => {},
|
133
|
-
:cd => data})
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should handle send cud with pass_through" do
|
137
|
-
data = {'1'=>@product1,'2'=>@product2}
|
138
|
-
expected = {'insert'=>data}
|
139
|
-
set_test_data('test_db_storage',data)
|
140
|
-
@s.pass_through = 'true'
|
141
|
-
lv = lambda { @model.query(params[:query]) }
|
142
|
-
params = { :p_size => 2 }
|
143
|
-
@ptsync = Rhoconnect::Handler::Query::PassThroughRunner.new(@model, @c, lv, params)
|
144
|
-
@ptsync.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>@c.get_value(:page_token)},
|
145
|
-
{'count'=>data.size},{'progress_count'=>0},
|
146
|
-
{'total_count'=>data.size},expected]
|
147
|
-
verify_doc_result(@ptsync.client, {:page => {},
|
148
|
-
:cd => {}})
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should handle send cud if with pass_through no data" do
|
152
|
-
data = {}
|
153
|
-
expected = {}
|
154
|
-
#set_test_data('test_db_storage',data)
|
155
|
-
@s.pass_through = 'true'
|
156
|
-
lv = lambda { @model.query(params[:query]) }
|
157
|
-
params = { :p_size => 2 }
|
158
|
-
@ptsync = Rhoconnect::Handler::Query::PassThroughRunner.new(@model, @c, lv, params)
|
159
|
-
@ptsync.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>""},
|
160
|
-
{'count'=>data.size},{'progress_count'=>0},
|
161
|
-
{'total_count'=>data.size},expected]
|
162
|
-
verify_doc_result(@ptsync.client, {:page => {},
|
163
|
-
:cd => {}})
|
164
|
-
end
|
165
|
-
|
166
208
|
it "should return read errors in send cud" do
|
167
209
|
msg = "Error during query"
|
168
210
|
data = {'1'=>@product1,'2'=>@product2}
|
169
211
|
set_test_data('test_db_storage',data,msg,'query error')
|
170
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0},{"total_count"=>0},
|
212
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0},{"total_count"=>0},
|
171
213
|
{"source-error"=>{"query-error"=>{"message"=>msg}}}]
|
172
214
|
end
|
173
|
-
|
215
|
+
|
174
216
|
it "should return login errors in send cud" do
|
175
217
|
@u.login = nil
|
176
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""},
|
218
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""},
|
177
219
|
{"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
|
178
220
|
{'source-error'=>{"login-error"=>{"message"=>"Error logging in"}}}]
|
179
221
|
end
|
180
|
-
|
222
|
+
|
181
223
|
it "should return logoff errors in send cud" do
|
182
224
|
msg = "Error logging off"
|
183
225
|
set_test_data('test_db_storage',{},msg,'logoff error')
|
184
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>@c.get_value(:page_token)},
|
185
|
-
{"count"=>1}, {"progress_count"=>0}, {"total_count"=>1},
|
186
|
-
{"source-error"=>{"logoff-error"=>{"message"=>msg}},
|
226
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>@c.get_value(:page_token)},
|
227
|
+
{"count"=>1}, {"progress_count"=>0}, {"total_count"=>1},
|
228
|
+
{"source-error"=>{"logoff-error"=>{"message"=>msg}},
|
187
229
|
"insert"=>{ERROR=>{"name"=>"logoff error", "an_attribute"=>msg}}}]
|
188
230
|
end
|
189
|
-
|
231
|
+
|
190
232
|
describe "send errors in send_cud" do
|
191
233
|
it "should handle create errors" do
|
192
234
|
receive_and_send_cud('create')
|
193
235
|
end
|
194
236
|
|
195
|
-
it "should handle
|
196
|
-
|
197
|
-
|
198
|
-
set_test_data('test_db_storage',
|
199
|
-
|
200
|
-
{'count'=>data.size},{'progress_count'=>0},
|
201
|
-
{'total_count'=>data.size},expected]
|
202
|
-
verify_doc_result(@sync_handler.client, {:page => data,
|
203
|
-
:delete_page => {},
|
204
|
-
:cd => data})
|
237
|
+
it "should handle update errors" do
|
238
|
+
broken_object = { ERROR => { 'price' => '99.99' } }
|
239
|
+
set_doc_state(@c, :cd => broken_object)
|
240
|
+
set_test_data('test_db_storage',broken_object)
|
241
|
+
receive_and_send_cud('update')
|
205
242
|
end
|
206
243
|
|
207
|
-
it "should
|
208
|
-
msg = "Error
|
209
|
-
|
210
|
-
|
211
|
-
@
|
212
|
-
|
244
|
+
it "should handle delete errors" do
|
245
|
+
msg = "Error delete record"
|
246
|
+
error_objs = add_error_object({},"Error delete record")
|
247
|
+
op_data = {'delete'=>error_objs}
|
248
|
+
@cud_handler.params = op_data
|
249
|
+
@cud_handler.operations = ["delete"]
|
250
|
+
@cud_handler.engine.operations = ["delete"]
|
251
|
+
@cud_handler.run
|
252
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
|
253
|
+
{"delete-error"=>{"#{ERROR}-error"=>{"message"=>msg},ERROR=>error_objs[ERROR]}}]
|
213
254
|
end
|
214
255
|
|
215
|
-
it "should
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
256
|
+
it "should send cud errors only once" do
|
257
|
+
msg = "Error delete record"
|
258
|
+
error_objs = add_error_object({},"Error delete record")
|
259
|
+
op_data = {'delete'=>error_objs}
|
260
|
+
@cud_handler.params = op_data
|
261
|
+
@cud_handler.operations = ["delete"]
|
262
|
+
@cud_handler.engine.operations = ["delete"]
|
263
|
+
@cud_handler.run
|
264
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
|
265
|
+
{"delete-error"=>{"#{ERROR}-error"=>{"message"=>msg},ERROR=>error_objs[ERROR]}}]
|
266
|
+
verify_result(@c.docname(:delete_errors) => {})
|
267
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},{}]
|
220
268
|
end
|
221
269
|
|
222
|
-
it "should return logoff errors in send cud" do
|
223
|
-
msg = "Error logging off"
|
224
|
-
set_test_data('test_db_storage',{},msg,'logoff error')
|
225
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>@c.get_value(:page_token)},
|
226
|
-
{"count"=>1}, {"progress_count"=>0}, {"total_count"=>1},
|
227
|
-
{"source-error"=>{"logoff-error"=>{"message"=>msg}},
|
228
|
-
"insert"=>{ERROR=>{"name"=>"logoff error", "an_attribute"=>msg}}}]
|
229
|
-
end
|
230
270
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should handle delete errors" do
|
244
|
-
msg = "Error delete record"
|
245
|
-
error_objs = add_error_object({},"Error delete record")
|
246
|
-
op_data = {'delete'=>error_objs}
|
247
|
-
@cud_handler.params = op_data
|
248
|
-
@cud_handler.operations = ["delete"]
|
249
|
-
@cud_handler.engine.operations = ["delete"]
|
250
|
-
@cud_handler.run
|
251
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
|
252
|
-
{"delete-error"=>{"#{ERROR}-error"=>{"message"=>msg},ERROR=>error_objs[ERROR]}}]
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should send cud errors only once" do
|
256
|
-
msg = "Error delete record"
|
257
|
-
error_objs = add_error_object({},"Error delete record")
|
258
|
-
op_data = {'delete'=>error_objs}
|
259
|
-
@cud_handler.params = op_data
|
260
|
-
@cud_handler.operations = ["delete"]
|
261
|
-
@cud_handler.engine.operations = ["delete"]
|
262
|
-
@cud_handler.run
|
263
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
|
264
|
-
{"delete-error"=>{"#{ERROR}-error"=>{"message"=>msg},ERROR=>error_objs[ERROR]}}]
|
265
|
-
verify_result(@c.docname(:delete_errors) => {})
|
266
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},{}]
|
267
|
-
end
|
268
|
-
|
269
|
-
|
270
|
-
end
|
271
|
-
|
272
|
-
it "should handle receive_cud and perform proper operation on the md and cd" do
|
273
|
-
set_doc_state(@s, :md => {'3'=>@product3})
|
274
|
-
set_doc_state(@c, :cd => {'3'=>@product3})
|
275
|
-
params = {'create'=>{'1'=>@product1},
|
276
|
-
'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
|
277
|
-
@cud_handler.params = params
|
278
|
-
@cud_handler.run
|
279
|
-
verify_source_queue_data(@s, {:create => [],
|
280
|
-
:update => [],
|
281
|
-
:delete => []})
|
282
|
-
verify_doc_result(@s, :md => {})
|
283
|
-
verify_doc_result(@c, :cd => {})
|
284
|
-
verify_source_queue_data(@s2, {:create => [],
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should handle receive_cud and perform proper operation on the md and cd" do
|
274
|
+
set_doc_state(@s, :md => {'3'=>@product3})
|
275
|
+
set_doc_state(@c, :cd => {'3'=>@product3})
|
276
|
+
params = {'create'=>{'1'=>@product1},
|
277
|
+
'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
|
278
|
+
@cud_handler.params = params
|
279
|
+
@cud_handler.run
|
280
|
+
verify_source_queue_data(@s, {:create => [],
|
285
281
|
:update => [],
|
286
282
|
:delete => []})
|
287
|
-
|
283
|
+
verify_doc_result(@s, :md => {})
|
284
|
+
verify_doc_result(@c, :cd => {})
|
285
|
+
verify_source_queue_data(@s2, {:create => [],
|
286
|
+
:update => [],
|
287
|
+
:delete => []})
|
288
|
+
end
|
288
289
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
end
|
290
|
+
it "should handle send_cud with query_params" do
|
291
|
+
expected = {'1'=>@product1}
|
292
|
+
set_state('test_db_storage' => {'1'=>@product1,'2'=>@product2,'4'=>@product4})
|
293
|
+
params = {'name' => 'iPhone'}
|
294
|
+
@sync_handler.engine.params = {:query => params}
|
295
|
+
@sync_handler.run
|
296
|
+
verify_doc_result(@s, :md => expected)
|
297
|
+
verify_doc_result(@sync_handler.client, :cd => expected)
|
298
298
|
end
|
299
|
-
|
300
|
-
describe "search" do
|
301
|
-
before(:each) do
|
302
|
-
@s_fields[:name] = 'SimpleAdapter'
|
303
|
-
@c_fields.delete(:id)
|
304
|
-
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
305
|
-
@s1 = Source.create(@s_fields,@s_params)
|
306
|
-
search_handler = lambda { @model.search(params[:search]) }
|
307
|
-
@model1 = Rhoconnect::Model::Base.create(@s2)
|
308
|
-
@cs = Rhoconnect::Handler::Search::Runner.new(@model, @c, search_handler, {})
|
309
|
-
@cs1 = Rhoconnect::Handler::Search::Runner.new(@model1,@c1, search_handler, { :p_size => 2 })
|
310
|
-
end
|
299
|
+
end
|
311
300
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
301
|
+
describe "search" do
|
302
|
+
before(:each) do
|
303
|
+
@s_fields[:name] = 'SimpleAdapter'
|
304
|
+
@c_fields.delete(:id)
|
305
|
+
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
306
|
+
@s1 = Source.create(@s_fields,@s_params)
|
307
|
+
search_handler = lambda { @model.search(params[:search]) }
|
308
|
+
@model1 = Rhoconnect::Model::Base.create(@s2)
|
309
|
+
@cs = Rhoconnect::Handler::Search::Runner.new(@model, @c, search_handler, {})
|
310
|
+
@cs1 = Rhoconnect::Handler::Search::Runner.new(@model1,@c1, search_handler, { :p_size => 2 })
|
311
|
+
end
|
323
312
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
313
|
+
def search_and_verify_res(params)
|
314
|
+
@cs.params = params
|
315
|
+
@cs.engine.params = params
|
316
|
+
res = @cs.run
|
317
|
+
token = @c.get_value(:search_token)
|
318
|
+
res[0]['version'].should == Rhoconnect::SYNC_VERSION
|
319
|
+
res[1]['token'].should == token
|
320
|
+
res[2]['source'].should == @s.name
|
321
|
+
res[3]['count'].should == 1
|
322
|
+
res[4]['insert']
|
323
|
+
end
|
335
324
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
325
|
+
it "should handle search" do
|
326
|
+
params = {:search => {'name' => 'iPhone'}}
|
327
|
+
set_state('test_db_storage' => @data)
|
328
|
+
@cs.engine.params = params
|
329
|
+
res = @cs.run
|
330
|
+
token = @c.get_value(:search_token)
|
331
|
+
res.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>token},
|
332
|
+
{'source'=>@s.name},{'count'=>1},{'insert'=>{'1'=>@product1}}]
|
333
|
+
verify_doc_result(@c, {:search => {'1'=>@product1},
|
334
|
+
:search_errors => {}})
|
335
|
+
end
|
346
336
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
337
|
+
it "should handle search with no params" do
|
338
|
+
@cs.p_size = @data.size
|
339
|
+
set_state('test_db_storage' => @data)
|
340
|
+
res = @cs.run
|
341
|
+
token = @c.get_value(:search_token)
|
342
|
+
res.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>token},
|
343
|
+
{'source'=>@s.name},{'count'=>@data.size},{'insert'=>@data}]
|
344
|
+
verify_doc_result(@c, {:search => @data,
|
345
|
+
:search_errors => {}})
|
346
|
+
end
|
347
|
+
|
348
|
+
it "should handle search with more than one page" do
|
349
|
+
@cs.p_size = 1
|
350
|
+
params = {:search => {'name' => 'iPhone'}}
|
351
|
+
product4 = {'name' => 'iPhone', 'price' => '99.99'}
|
352
|
+
@data['4'] = product4
|
353
|
+
set_state('test_db_storage' => @data)
|
354
|
+
inserts = search_and_verify_res(params)
|
355
|
+
verify_doc_result(@c, {:search => {'1'=>@product1,'4'=>product4},
|
356
|
+
:cd_size => '1',
|
357
|
+
:cd => @c.get_data(:search_page),
|
358
|
+
:search_errors => {}})
|
359
|
+
verify_doc_result(@s, {:md_size => '1',
|
360
|
+
:md => @c.get_data(:search_page)})
|
361
|
+
|
362
|
+
# ack the token
|
363
|
+
params[:token] = @c.get_value(:search_token)
|
364
|
+
new_inserts = search_and_verify_res(params)
|
365
|
+
inserts.merge!(new_inserts)
|
366
|
+
verify_doc_result(@c, {:search => {'1'=>@product1,'4'=>product4},
|
376
367
|
:cd => inserts,
|
377
|
-
:search_errors => {}
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
368
|
+
:search_errors => {}})
|
369
|
+
verify_doc_result(@s, :md => inserts)
|
370
|
+
@c.get_data(:search_page).size.should == 1
|
371
|
+
|
372
|
+
# ack the last token
|
373
|
+
params[:token] = @c.get_value(:search_token)
|
374
|
+
@cs.params = params
|
375
|
+
@cs.run.should == []
|
376
|
+
verify_doc_result(@c, {:search => {},
|
377
|
+
:cd => inserts,
|
378
|
+
:search_errors => {},
|
379
|
+
:search_page => {},
|
380
|
+
:search_token => nil})
|
381
|
+
verify_doc_result(@s, :md => inserts)
|
382
|
+
end
|
382
383
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
384
|
+
it "should handle search with nil result" do
|
385
|
+
params = {:search => {'name' => 'foo'}}
|
386
|
+
set_state('test_db_storage' => @data)
|
387
|
+
@cs.engine.params = params
|
388
|
+
@cs.run.should == []
|
389
|
+
verify_doc_result(@c, {:search => {},
|
390
|
+
:search_errors => {}})
|
391
|
+
end
|
391
392
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
393
|
+
it "should resend search by search_token" do
|
394
|
+
@source = @s
|
395
|
+
set_doc_state(@c, :search_page => {'1'=>@product1})
|
396
|
+
token = @cs.client.compute_token(:search_token)
|
397
|
+
@cs.params = {:resend => true,:token => token}
|
398
|
+
@cs.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'token'=>token},{'source'=>@s.name},{'count'=>1},{'insert'=>{'1'=>@product1}}]
|
399
|
+
verify_doc_result(@c, {:search_page => {'1'=>@product1},
|
400
|
+
:search_errors => {},
|
401
|
+
:search_token => token})
|
402
|
+
end
|
402
403
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
404
|
+
it "should handle search ack" do
|
405
|
+
set_doc_state(@c, {:search => {'1'=>@product1}})
|
406
|
+
set_doc_state(@c, {:cd => {'1'=>@product1}})
|
407
|
+
token = @cs.client.compute_token(:search_token)
|
408
|
+
@cs.params = {:token => token}
|
409
|
+
@cs.run.should == []
|
410
|
+
verify_doc_result(@c, {:search => {},
|
411
|
+
:search_errors => {},
|
412
|
+
:search_token => nil})
|
413
|
+
end
|
414
|
+
|
415
|
+
it "should return error on invalid ack token" do
|
416
|
+
set_doc_state(@c, {:search_page => {'1'=>@product1}})
|
417
|
+
set_doc_state(@c, :search_token => 'validtoken')
|
418
|
+
params = {:token => 'abc',
|
419
|
+
:search => {'name' => 'iPhone'}}
|
420
|
+
@cs.params = params
|
421
|
+
@cs.engine.params = params
|
422
|
+
@cs.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'source'=>@s.name},{'search-error'=>{'search-error'=>
|
423
|
+
{'message'=>"Search error - invalid token"}}}]
|
424
|
+
verify_doc_result(@c, {:search => {},
|
425
|
+
:search_errors => {},
|
426
|
+
:search_token => nil})
|
427
|
+
end
|
413
428
|
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
429
|
+
it "should handle search login error" do
|
430
|
+
@u.login = nil
|
431
|
+
msg = "Error logging in"
|
432
|
+
error = set_test_data('test_db_storage',@data,msg,'search error')
|
433
|
+
@cs.engine.params = {:search => {'name' => 'iPhone'}}
|
434
|
+
@cs.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'source'=>@s.name},
|
435
|
+
{'search-error'=>{'login-error'=>{'message'=>msg}}}]
|
436
|
+
verify_doc_result(@c, {:search => {},
|
437
|
+
:search_token => nil})
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
describe "page methods" do
|
442
|
+
it "should return diffs between master documents and client documents limited by page size" do
|
443
|
+
@s.put_data(:md,@data).should == true
|
444
|
+
@s.get_data(:md).should == @data
|
445
|
+
@s.put_value(:md_size,@data.size)
|
446
|
+
|
447
|
+
total_count, res = @sync_handler.compute_page
|
448
|
+
total_count.to_i.should == 3
|
449
|
+
res.each do |key, value|
|
450
|
+
@data.has_key?(key).should == true
|
451
|
+
@data[key].should == value
|
426
452
|
end
|
427
453
|
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
@cs.engine.params = {:search => {'name' => 'iPhone'}}
|
433
|
-
@cs.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{'source'=>@s.name},
|
434
|
-
{'search-error'=>{'login-error'=>{'message'=>msg}}}]
|
435
|
-
verify_doc_result(@c, {:search => {},
|
436
|
-
:search_token => nil})
|
454
|
+
@sync_handler.client.get_value(:cd_size).to_i.should == 0
|
455
|
+
@sync_handler.client.get_data(:page).each do |key, value|
|
456
|
+
@data.has_key?(key).should == true
|
457
|
+
@data[key].should == value
|
437
458
|
end
|
438
459
|
end
|
439
460
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
total_count.to_i.should == 3
|
448
|
-
res.each do |key, value|
|
449
|
-
@data.has_key?(key).should == true
|
450
|
-
@data[key].should == value
|
451
|
-
end
|
452
|
-
|
453
|
-
@sync_handler.client.get_value(:cd_size).to_i.should == 0
|
454
|
-
@sync_handler.client.get_data(:page).each do |key, value|
|
455
|
-
@data.has_key?(key).should == true
|
456
|
-
@data[key].should == value
|
457
|
-
end
|
458
|
-
end
|
461
|
+
it "appends diff to the client document" do
|
462
|
+
@cd = {'3'=>@product3}
|
463
|
+
@c.put_data(:cd,@cd)
|
464
|
+
@c.get_data(:cd).should == @cd
|
465
|
+
|
466
|
+
@page = {'1'=>@product1,'2'=>@product2}
|
467
|
+
@expected = {'1'=>@product1,'2'=>@product2,'3'=>@product3}
|
459
468
|
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
@c.get_data(:cd).should == @cd
|
469
|
+
@c.put_data(:cd,@page,true).should == true
|
470
|
+
@c.get_data(:cd).should == @expected
|
471
|
+
end
|
464
472
|
|
465
|
-
|
466
|
-
|
473
|
+
it "should delete objects from the client document and return deleted objects in the page" do
|
474
|
+
@s.put_data(:md,@data).should == true
|
475
|
+
@s.get_data(:md).should == @data
|
467
476
|
|
468
|
-
|
469
|
-
|
470
|
-
|
477
|
+
@cd = {'1'=>@product1,'2'=>@product2,'3'=>@product3,'4'=>@product4}
|
478
|
+
@sync_handler.client.put_data(:cd,@cd)
|
479
|
+
@sync_handler.client.get_data(:cd).should == @cd
|
471
480
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>token},
|
494
|
-
{"count"=>1}, {"progress_count"=>0},{"total_count"=>1},{'insert' => expected}]
|
495
|
-
@sync_handler.params[:token] = token
|
496
|
-
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""},
|
497
|
-
{"count"=>0}, {"progress_count"=>0}, {"total_count"=>1}, {}]
|
498
|
-
@sync_handler.client.get_data(:page).should == {}
|
499
|
-
@c.get_value(:page_token).should be_nil
|
500
|
-
end
|
481
|
+
@expected = {'4'=>@product4}
|
482
|
+
@sync_handler.send_new_page
|
483
|
+
@sync_handler.client.get_data(:delete_page).should == @expected
|
484
|
+
@sync_handler.client.get_data(:cd).should == @data
|
485
|
+
end
|
486
|
+
|
487
|
+
it "should resend page if page exists and no token provided" do
|
488
|
+
expected = {'1'=>@product1}
|
489
|
+
set_test_data('test_db_storage',{'1'=>@product1,'2'=>@product2,'4'=>@product4})
|
490
|
+
params = {'name' => 'iPhone'}
|
491
|
+
@sync_handler.engine.params = {:query => params}
|
492
|
+
@sync_handler.run
|
493
|
+
token = @c.get_value(:page_token)
|
494
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>token},
|
495
|
+
{"count"=>1}, {"progress_count"=>0},{"total_count"=>1},{'insert' => expected}]
|
496
|
+
@sync_handler.params[:token] = token
|
497
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""},
|
498
|
+
{"count"=>0}, {"progress_count"=>0}, {"total_count"=>1}, {}]
|
499
|
+
@sync_handler.client.get_data(:page).should == {}
|
500
|
+
@c.get_value(:page_token).should be_nil
|
501
|
+
end
|
501
502
|
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
end
|
503
|
+
it "should send metadata with page" do
|
504
|
+
expected = {'1'=>@product1}
|
505
|
+
set_state('test_db_storage' => expected)
|
506
|
+
metadata = "{\"foo\":\"bar\"}"
|
507
|
+
mock_metadata_method([SampleAdapter]) do
|
508
|
+
result = @sync_handler.run
|
509
|
+
token = @c.get_value(:page_token)
|
510
|
+
result.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>token},
|
511
|
+
{"count"=>1}, {"progress_count"=>0},{"total_count"=>1},
|
512
|
+
{'metadata'=>metadata,'insert'=>expected}]
|
513
|
+
@c.get_value(:metadata_page).should == metadata
|
514
514
|
end
|
515
|
+
end
|
515
516
|
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
end
|
517
|
+
it "should send metadata with resend page" do
|
518
|
+
expected = {'1'=>@product1}
|
519
|
+
set_state('test_db_storage' => expected)
|
520
|
+
mock_metadata_method([SampleAdapter]) do
|
521
|
+
result = @sync_handler.run
|
522
|
+
token = @c.get_value(:page_token)
|
523
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>token},
|
524
|
+
{"count"=>1}, {"progress_count"=>0},{"total_count"=>1},
|
525
|
+
{'metadata'=>"{\"foo\":\"bar\"}",'insert'=>expected}]
|
526
526
|
end
|
527
|
+
end
|
527
528
|
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
end
|
529
|
+
it "should ack metadata page with ack token" do
|
530
|
+
expected = {'1'=>@product1}
|
531
|
+
set_state('test_db_storage' => expected)
|
532
|
+
mock_metadata_method([SampleAdapter]) do
|
533
|
+
result = @sync_handler.run
|
534
|
+
token = @c.get_value(:page_token)
|
535
|
+
@sync_handler.params[:token] = token
|
536
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""},
|
537
|
+
{"count"=>0}, {"progress_count"=>0},{"total_count"=>1},{}]
|
538
|
+
@c.get_value(:metadata_page).should be_nil
|
539
539
|
end
|
540
|
+
end
|
540
541
|
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
end
|
542
|
+
it "shouldn't send schema-changed if client schema sha1 is nil" do
|
543
|
+
expected = {'1'=>@product1}
|
544
|
+
set_state('test_db_storage' => expected)
|
545
|
+
mock_schema_method([SampleAdapter]) do
|
546
|
+
result = @sync_handler.run
|
547
|
+
token = @c.get_value(:page_token)
|
548
|
+
result.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>token},
|
549
|
+
{"count"=>1}, {"progress_count"=>0},{"total_count"=>1},{'insert'=>expected}]
|
550
|
+
@c.get_value(:schema_sha1).should == sha1
|
551
551
|
end
|
552
|
+
end
|
552
553
|
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
end
|
554
|
+
it "should send schema-changed instead of page" do
|
555
|
+
mock_schema_method([SampleAdapter]) do
|
556
|
+
@c.put_value(:schema_sha1,'foo')
|
557
|
+
result = @sync_handler.run
|
558
|
+
token = @c.get_value(:page_token)
|
559
|
+
result.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>token},
|
560
|
+
{"count"=>0}, {"progress_count"=>0},{"total_count"=>0},{'schema-changed'=>'true'}]
|
561
|
+
@c.get_value(:schema_page).should == sha1
|
562
|
+
@c.get_value(:schema_sha1).should == sha1
|
563
563
|
end
|
564
|
+
end
|
564
565
|
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
end
|
566
|
+
it "should re-send schema-changed if no token sent" do
|
567
|
+
mock_schema_method([SampleAdapter]) do
|
568
|
+
@c.put_value(:schema_sha1,'foo')
|
569
|
+
result = @sync_handler.run
|
570
|
+
token = @c.get_value(:page_token)
|
571
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>token},
|
572
|
+
{"count"=>0}, {"progress_count"=>0},{"total_count"=>0},{'schema-changed'=>'true'}]
|
573
|
+
@c.get_value(:schema_page).should == sha1
|
574
|
+
@c.get_value(:schema_sha1).should == sha1
|
575
575
|
end
|
576
|
+
end
|
576
577
|
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
end
|
578
|
+
it "should ack schema-changed with token" do
|
579
|
+
mock_schema_method([SampleAdapter]) do
|
580
|
+
@c.put_value(:schema_sha1,'foo')
|
581
|
+
result = @sync_handler.run
|
582
|
+
token = @c.get_value(:page_token)
|
583
|
+
@sync_handler.params[:token] = token
|
584
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""},
|
585
|
+
{"count"=>0}, {"progress_count"=>0},{"total_count"=>0},{}]
|
586
|
+
@c.get_value(:schema_page).should be_nil
|
587
|
+
@c.get_value(:schema_sha1).should == sha1
|
588
588
|
end
|
589
|
+
end
|
589
590
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
end
|
591
|
+
it "should expire bulk data if schema changed" do
|
592
|
+
docname = bulk_data_docname(@a.id,@u.id)
|
593
|
+
data = BulkData.create(:name => docname,
|
594
|
+
:state => :inprogress,
|
595
|
+
:app_id => @a.id,
|
596
|
+
:user_id => @u.id,
|
597
|
+
:sources => [@s_fields[:name]])
|
598
|
+
data.refresh_time = Time.now.to_i + 600
|
599
|
+
mock_schema_method([SampleAdapter]) do
|
600
|
+
@c.put_value(:schema_sha1,'foo')
|
601
|
+
result = @sync_handler.run
|
602
|
+
token = @c.get_value(:page_token)
|
603
|
+
@sync_handler.params[:token] = token
|
604
|
+
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""},
|
605
|
+
{"count"=>0}, {"progress_count"=>0},{"total_count"=>0},{}]
|
606
|
+
@c.get_value(:schema_page).should be_nil
|
607
|
+
@c.get_value(:schema_sha1).should == sha1
|
608
|
+
data = BulkData.load(docname)
|
609
|
+
data.refresh_time.should <= Time.now.to_i
|
610
610
|
end
|
611
611
|
end
|
612
612
|
end
|
613
|
+
|
613
614
|
def receive_and_send_cud(operation)
|
614
615
|
msg = "Error #{operation} record"
|
615
616
|
op_data = {operation=>{ERROR=>{'an_attribute'=>msg,'name'=>'wrongname'}}}
|
616
617
|
@cud_handler.operations = [operation]
|
617
618
|
@cud_handler.engine.operations = [operation]
|
618
619
|
@cud_handler.params = op_data
|
619
|
-
@cud_handler.run
|
620
|
+
@cud_handler.run
|
620
621
|
if operation == 'update'
|
621
622
|
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>1},
|
622
623
|
{
|