rhoconnect 4.0.4 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +5 -13
  2. data/CHANGELOG.md +54 -5
  3. data/CREDITS +219 -219
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +68 -79
  6. data/Rakefile +1 -2
  7. data/bench/benchapp/spec/models/ruby/mock_adapter_spec.rb +17 -17
  8. data/bench/benchapp/spec/models/ruby/queue_mock_adapter_spec.rb +17 -17
  9. data/bench/benchapp/spec/spec_helper.rb +3 -3
  10. data/bench/blobapp/spec/models/ruby/blob_adapter_spec.rb +17 -17
  11. data/bench/blobapp/spec/spec_helper.rb +3 -3
  12. data/bench/lib/bench/runner.rb +1 -69
  13. data/bench/lib/bench.rb +18 -18
  14. data/bench/spec/mock_adapter_spec.rb +54 -55
  15. data/bench/spec/mock_client_spec.rb +47 -48
  16. data/bench/spec/result_spec.rb +41 -44
  17. data/bench/spec/utils_spec.rb +24 -25
  18. data/commands/generators/app.rb +7 -5
  19. data/commands/generators/controller.rb +7 -5
  20. data/commands/generators/model.rb +7 -5
  21. data/commands/generators/source.rb +7 -5
  22. data/commands/parser.rb +1 -1
  23. data/commands/redis/redis_download.rb +1 -1
  24. data/doc/async-jobs.txt +9 -9
  25. data/doc/supported-platforms.txt +0 -2
  26. data/generators/rhoconnect.rb +92 -212
  27. data/generators/templates/application/rcgemfile +3 -3
  28. data/generators/templates/application/spec/application_controller_spec.rb +14 -16
  29. data/generators/templates/application/spec/js_spec.rb +20 -20
  30. data/generators/templates/application/spec/spec_helper.rb +1 -1
  31. data/generators/templates/source/controllers/ruby/controller_spec.rb +18 -19
  32. data/generators/templates/source/models/ruby/model_spec.rb +17 -17
  33. data/install.sh +10 -21
  34. data/installer/unix-like/rho_connect_install_constants.rb +5 -5
  35. data/installer/unix-like/rho_connect_install_installers.rb +4 -4
  36. data/installer/utils/constants.rb +6 -6
  37. data/installer/utils/nix_install_test.rb +29 -29
  38. data/installer/utils/package_upload/repos.rake +16 -26
  39. data/js-adapters/node.rb +4 -4
  40. data/js-adapters/node_channel.rb +4 -8
  41. data/lib/rhoconnect/db_adapter.rb +13 -13
  42. data/lib/rhoconnect/handler/changes/engine.rb +1 -1
  43. data/lib/rhoconnect/jobs/bulk_data_job.rb +29 -29
  44. data/lib/rhoconnect/license.rb +7 -7
  45. data/lib/rhoconnect/model/helpers/find_duplicates_on_update.rb +13 -13
  46. data/lib/rhoconnect/ping/apple.rb +4 -4
  47. data/lib/rhoconnect/server.rb +2 -2
  48. data/lib/rhoconnect/source.rb +2 -2
  49. data/lib/rhoconnect/store.rb +12 -6
  50. data/lib/rhoconnect/utilities.rb +2 -2
  51. data/lib/rhoconnect/version.rb +1 -1
  52. data/lib/rhoconnect.rb +6 -4
  53. data/rhoconnect.gemspec +5 -6
  54. data/spec/api/api_helper.rb +1 -1
  55. data/spec/api/app/fast_delete_spec.rb +22 -22
  56. data/spec/api/app/fast_insert_spec.rb +23 -23
  57. data/spec/api/app/fast_update_spec.rb +63 -63
  58. data/spec/api/app/push_deletes_spec.rb +11 -13
  59. data/spec/api/app/push_objects_spec.rb +39 -39
  60. data/spec/api/client/client_get_db_doc_spec.rb +29 -29
  61. data/spec/api/client/client_set_db_doc_spec.rb +11 -11
  62. data/spec/api/client/get_client_params_spec.rb +29 -29
  63. data/spec/api/client/list_client_docs_spec.rb +32 -34
  64. data/spec/api/client/reset_spec.rb +30 -30
  65. data/spec/api/readstate/set_refresh_time_spec.rb +43 -43
  66. data/spec/api/source/get_source_params_spec.rb +32 -34
  67. data/spec/api/source/list_sources_spec.rb +13 -13
  68. data/spec/api/source/update_source_params_spec.rb +19 -19
  69. data/spec/api/store/get_db_doc_spec.rb +27 -27
  70. data/spec/api/store/set_db_doc_spec.rb +38 -38
  71. data/spec/api/system/adapter_spec.rb +27 -29
  72. data/spec/api/system/get_license_info_spec.rb +11 -11
  73. data/spec/api/system/login_spec.rb +37 -37
  74. data/spec/api/system/reset_spec.rb +15 -15
  75. data/spec/api/system/stats_spec.rb +70 -71
  76. data/spec/api/user/create_user_spec.rb +37 -37
  77. data/spec/api/user/delete_client_spec.rb +7 -7
  78. data/spec/api/user/delete_user_spec.rb +62 -62
  79. data/spec/api/user/list_clients_spec.rb +24 -24
  80. data/spec/api/user/list_source_docs_spec.rb +29 -29
  81. data/spec/api/user/list_users_spec.rb +22 -22
  82. data/spec/api/user/ping_spec.rb +18 -18
  83. data/spec/api/user/show_user_spec.rb +10 -10
  84. data/spec/api/user/update_user_spec.rb +43 -43
  85. data/spec/api/user/user_get_db_doc_spec.rb +12 -12
  86. data/spec/api/user/user_set_db_doc_spec.rb +37 -37
  87. data/spec/api_token_spec.rb +8 -8
  88. data/spec/app_spec.rb +18 -17
  89. data/spec/apps/jstestapp/settings/settings.yml +2 -0
  90. data/spec/async_spec.rb +9 -11
  91. data/spec/bulk_data/bulk_data_spec.rb +120 -120
  92. data/spec/cli/cli_spec.rb +50 -53
  93. data/spec/client_spec.rb +105 -105
  94. data/spec/client_sync_spec.rb +529 -528
  95. data/spec/controllers/js_base_spec.rb +147 -141
  96. data/spec/doc/doc_spec.rb +51 -52
  97. data/spec/document_spec.rb +58 -58
  98. data/spec/dynamic_adapter_spec.rb +33 -36
  99. data/spec/generator/generator_spec.rb +76 -42
  100. data/spec/jobs/bulk_data_job_spec.rb +101 -102
  101. data/spec/jobs/ping_job_spec.rb +176 -177
  102. data/spec/jobs/source_job_spec.rb +24 -25
  103. data/spec/license_spec.rb +54 -55
  104. data/spec/models/js_base_spec.rb +121 -120
  105. data/spec/perf/bulk_data_perf_spec.rb +23 -24
  106. data/spec/perf/perf_spec_helper.rb +7 -7
  107. data/spec/perf/store_perf_spec.rb +139 -140
  108. data/spec/ping/apple_spec.rb +65 -65
  109. data/spec/ping/gcm_spec.rb +83 -84
  110. data/spec/ping/rhoconnect_push_spec.rb +52 -53
  111. data/spec/predefined_adapters/rho_internal_bench_adapter_controller_js_spec.rb +100 -101
  112. data/spec/predefined_adapters/rho_internal_js_bench_adapter_js_spec.rb +29 -31
  113. data/spec/read_state_spec.rb +24 -25
  114. data/spec/rhoconnect_spec.rb +7 -7
  115. data/spec/server/server_spec.rb +664 -662
  116. data/spec/server/stats_spec.rb +12 -12
  117. data/spec/source_adapter_spec.rb +124 -125
  118. data/spec/source_spec.rb +148 -149
  119. data/spec/source_sync_spec.rb +736 -736
  120. data/spec/spec_helper.rb +4 -5
  121. data/spec/stats/record_spec.rb +22 -21
  122. data/spec/store_orm_spec.rb +48 -48
  123. data/spec/store_spec.rb +428 -426
  124. data/spec/support/shared_examples.rb +5 -7
  125. data/spec/sync_states_spec.rb +67 -67
  126. data/spec/test_methods_spec.rb +121 -123
  127. data/spec/testdata/10000-data.txt +0 -0
  128. data/spec/testdata/5000-data.txt +0 -0
  129. data/spec/user_spec.rb +102 -102
  130. data/tasks/redis.rake +3 -3
  131. metadata +154 -195
  132. data/bench/benchapp/tmp/pids/passenger.9292.pid.lock +0 -0
  133. data/bench/benchapp/tmp/restart.txt +0 -0
  134. data/bench/blobapp/settings/license.key.bak +0 -2
  135. data/bench/blobapp/tmp/restart.txt +0 -0
  136. data/bench/lib/testdata/1-data.txt +0 -0
  137. data/bench/lib/testdata/10-data.txt +0 -0
  138. data/bench/lib/testdata/2-data.txt +0 -0
  139. data/bench/lib/testdata/250-data.txt +0 -0
  140. data/bench/lib/testdata/5-blob_data.txt +0 -0
  141. data/bench/lib/testdata/5-data.txt +0 -0
  142. data/bench/lib/testdata/50-data.txt +0 -0
  143. data/bench/lib/testdata/500-data.txt +0 -0
  144. data/doc/protocol.html +0 -1993
  145. data/spec/coverage/rcov/assets/0.2.3/jquery-1.3.2.min.js +0 -19
  146. data/spec/coverage/rcov/assets/0.2.3/jquery.tablesorter.min.js +0 -15
  147. data/spec/coverage/rcov/assets/0.2.3/print.css +0 -12
  148. data/spec/coverage/rcov/assets/0.2.3/rcov.js +0 -42
  149. data/spec/coverage/rcov/assets/0.2.3/screen.css +0 -270
  150. data/spec/coverage/rcov/index.html +0 -88
  151. data/spec/generator/generator_spec_helper.rb +0 -9
@@ -1,41 +1,41 @@
1
1
  require File.join(File.dirname(__FILE__),'..','api_helper')
2
2
 
3
3
  describe "RhoconnectApiUserSetDbDoc" do
4
- it_should_behave_like "ApiHelper" do
5
- it "should set user's db document by doc key and data" do
6
- data = {'1' => {'foo' => 'bar'}}
7
- dockey = 'myuserdoc'
8
- sdocname = @s2.docname(dockey)
9
-
10
- post "/rc/#{Rhoconnect::API_VERSION}/users/#{@u.id}/sources/#{@s2.name}/docs/#{dockey}", {:data => data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
11
- last_response.should be_ok
12
- verify_result(sdocname => data)
13
- end
14
-
15
- it "should append data to the user's db document by doc name and data" do
16
- data = {'1' => {'foo' => 'bar'}}
17
- data2 = {'2' => {'foo1' => 'bar1'}}
18
- data3 = data.merge(data2)
19
- dockey = 'abc:abc'
20
- sdocname = @s2.docname(dockey)
21
- post "/rc/#{Rhoconnect::API_VERSION}/users/#{@u.id}/sources/#{@s2.name}/docs/#{dockey}", {:data => data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
22
- last_response.should be_ok
23
- verify_result(sdocname => data)
24
-
25
- post "/rc/#{Rhoconnect::API_VERSION}/users/#{@u.id}/sources/#{@s2.name}/docs/#{dockey}", {:data => data2, :append => true}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
26
- last_response.should be_ok
27
- verify_result(sdocname => data3)
28
- end
29
-
30
- it "should error out in ateempt to set a db doc for a non-existent user" do
31
- data = {'1' => {'foo' => 'bar'}}
32
- data2 = {'2' => {'foo1' => 'bar1'}}
33
- data3 = data.merge(data2)
34
- dockey = 'abc:abc'
35
- sdocname = @s2.docname(dockey)
36
- post "/rc/#{Rhoconnect::API_VERSION}/users/invalid_user/sources/#{@s2.name}/docs/#{dockey}", {:data => data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
37
- last_response.status.should == 500
38
- last_response.should_not be_ok
39
- end
40
- end
4
+ include_examples "ApiHelper"
5
+
6
+ it "should set user's db document by doc key and data" do
7
+ data = {'1' => {'foo' => 'bar'}}
8
+ dockey = 'myuserdoc'
9
+ sdocname = @s2.docname(dockey)
10
+
11
+ post "/rc/#{Rhoconnect::API_VERSION}/users/#{@u.id}/sources/#{@s2.name}/docs/#{dockey}", {:data => data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
12
+ last_response.should be_ok
13
+ verify_result(sdocname => data)
14
+ end
15
+
16
+ it "should append data to the user's db document by doc name and data" do
17
+ data = {'1' => {'foo' => 'bar'}}
18
+ data2 = {'2' => {'foo1' => 'bar1'}}
19
+ data3 = data.merge(data2)
20
+ dockey = 'abc:abc'
21
+ sdocname = @s2.docname(dockey)
22
+ post "/rc/#{Rhoconnect::API_VERSION}/users/#{@u.id}/sources/#{@s2.name}/docs/#{dockey}", {:data => data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
23
+ last_response.should be_ok
24
+ verify_result(sdocname => data)
25
+
26
+ post "/rc/#{Rhoconnect::API_VERSION}/users/#{@u.id}/sources/#{@s2.name}/docs/#{dockey}", {:data => data2, :append => true}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
27
+ last_response.should be_ok
28
+ verify_result(sdocname => data3)
29
+ end
30
+
31
+ it "should error out in ateempt to set a db doc for a non-existent user" do
32
+ data = {'1' => {'foo' => 'bar'}}
33
+ data2 = {'2' => {'foo1' => 'bar1'}}
34
+ data3 = data.merge(data2)
35
+ dockey = 'abc:abc'
36
+ sdocname = @s2.docname(dockey)
37
+ post "/rc/#{Rhoconnect::API_VERSION}/users/invalid_user/sources/#{@s2.name}/docs/#{dockey}", {:data => data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
38
+ last_response.status.should == 500
39
+ last_response.should_not be_ok
40
+ end
41
41
  end
@@ -1,13 +1,13 @@
1
1
  require File.join(File.dirname(__FILE__),'spec_helper')
2
2
 
3
3
  describe "ApiToken" do
4
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do
5
- it "should generate api token with user" do
6
- token = ApiToken.create(:user_id => @u.id)
7
- token.value.length.should == 32
8
- token.user_id.should == @u.id
9
- token.user.login.should == @u.login
10
- token.delete
11
- end
4
+ include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
5
+
6
+ it "should generate api token with user" do
7
+ token = ApiToken.create(:user_id => @u.id)
8
+ token.value.length.should == 32
9
+ token.user_id.should == @u.id
10
+ token.user.login.should == @u.login
11
+ token.delete
12
12
  end
13
13
  end
data/spec/app_spec.rb CHANGED
@@ -1,24 +1,25 @@
1
1
  require File.join(File.dirname(__FILE__),'spec_helper')
2
2
 
3
3
  describe "App" do
4
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
5
- it "should create app with fields" do
6
- @a.id.should == @a_fields[:name]
7
- @a1 = App.load(@a_fields[:name])
8
- @a1.id.should == @a.id
9
- @a1.name.should == @a_fields[:name]
10
- end
4
+ include_examples "SharedRhoconnectHelper", :rhoconnect_data => false
11
5
 
12
- it "should add source adapters" do
13
- @a1 = App.load(@a_fields[:name])
14
- @a1.sources.sort.should == ["FixedSchemaAdapter", "JsSample", "OtherAdapter", "SampleAdapter", "SimpleAdapter"]
15
- end
6
+ it "should create app with fields" do
7
+ @a.id.should == @a_fields[:name]
8
+ @a1 = App.load(@a_fields[:name])
9
+ @a1.id.should == @a.id
10
+ @a1.name.should == @a_fields[:name]
11
+ end
12
+
13
+ it "should add source adapters" do
14
+ @a1 = App.load(@a_fields[:name])
15
+ @a1.sources.sort.should == ["FixedSchemaAdapter", "JsSample", "OtherAdapter", "SampleAdapter", "SimpleAdapter"]
16
+ end
16
17
 
17
- it "should force environment default and override setting" do
18
- poll_interval_default = Rhoconnect.source_config('OtherAdapter')[:poll_interval]
19
- poll_interval_default.should == 201
20
- poll_interval_override = Rhoconnect.source_config('SimpleAdapter')[:poll_interval]
21
- poll_interval_override.should == 600
22
- end
18
+ it "should force environment default and override setting" do
19
+ poll_interval_default = Rhoconnect.source_config('OtherAdapter')[:poll_interval]
20
+ poll_interval_default.should == 201
21
+ poll_interval_override = Rhoconnect.source_config('SimpleAdapter')[:poll_interval]
22
+ poll_interval_override.should == 600
23
23
  end
24
+
24
25
  end
@@ -7,6 +7,8 @@
7
7
  :licensefile: settings/license.key
8
8
  :redis: localhost:6379
9
9
  :syncserver: http://localhost:9292/
10
+ # set :node_channel_timeout to 60 secs.
11
+ :node_channel_timeout: 60
10
12
  :production:
11
13
  :licensefile: settings/license.key
12
14
  :redis: localhost:6379
data/spec/async_spec.rb CHANGED
@@ -3,17 +3,15 @@ require File.join(File.dirname(__FILE__),'api','api_helper')
3
3
  # these specs are executed only with Async support
4
4
  if not defined?(JRUBY_VERSION)
5
5
  describe "BasicEventMachineTest with Threads" do
6
- it_should_behave_like "ApiHelper" do
7
- it "should run EventMachine gracefully and schedule callback execution in thread" do
8
- f = Fiber.current
9
- operation = proc { res = 1 }
10
- operation_res = 0
11
- callback = proc { |proc_res| operation_res = proc_res; f.resume }
12
- EventMachine.defer operation, callback
13
- Fiber.yield
14
- # this code should be executed only after the thread's return
15
- operation_res.should == 1
16
- end
6
+ it "should run EventMachine gracefully and schedule callback execution in thread" do
7
+ f = Fiber.current
8
+ operation = proc { res = 1 }
9
+ operation_res = 0
10
+ callback = proc { |proc_res| operation_res = proc_res; f.resume }
11
+ EventMachine.defer operation, callback
12
+ Fiber.yield
13
+ # this code should be executed only after the thread's return
14
+ operation_res.should == 1
17
15
  end
18
16
  end
19
17
  end
@@ -1,132 +1,132 @@
1
1
  require File.join(File.dirname(__FILE__),'..','spec_helper')
2
2
 
3
3
  describe "BulkData" do
4
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do
5
- before(:each) do
6
- @s = Source.load(@s_fields[:name],@s_params)
7
- @s1 = Source.load(@s1_fields[:name], @s_params)
8
- end
9
-
10
- after(:each) do
11
- delete_data_directory
12
- end
13
-
14
- it "should return true if bulk data is completed" do
15
- dbfile = create_datafile(File.join(@a.name,@u.id.to_s),@u.id.to_s)
16
- data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
17
- :state => :completed,
18
- :app_id => @a.id,
19
- :user_id => @u.id,
20
- :sources => [@s_fields[:name]])
21
- data.dbfile = dbfile
22
- data.completed?.should == true
23
- end
4
+ include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
24
5
 
25
- it "should return false if bulk data isn't completed" do
26
- data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
27
- :state => :inprogress,
28
- :app_id => @a.id,
29
- :user_id => @u.id,
30
- :sources => [@s_fields[:name]])
31
- data.completed?.should == false
32
- end
6
+ before(:each) do
7
+ @s = Source.load(@s_fields[:name],@s_params)
8
+ @s1 = Source.load(@s1_fields[:name], @s_params)
9
+ end
33
10
 
34
- it "should expire_bulk_data from a source adapter" do
11
+ after(:each) do
12
+ delete_data_directory
13
+ end
35
14
 
36
- @model = Rhoconnect::Model::Base.create(@s)
37
- @engine = Rhoconnect::Handler::Query::Engine.new(@model, lambda { @model.query }, {})
38
- time = Time.now.to_i + 10000
39
- data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
40
- :state => :inprogress,
41
- :app_id => @a.id,
42
- :user_id => @u.id,
43
- :sources => [@s_fields[:name]],
44
- :refresh_time => time)
45
- @model.expire_bulk_data
46
- data = BulkData.load(bulk_data_docname(@a.id,@u.id))
47
- data.refresh_time.should <= Time.now.to_i
48
- end
49
-
50
- it "should enqueue sqlite db type" do
51
- BulkData.enqueue
52
- Resque.peek(:bulk_data).should == {"args"=>[{}],
53
- "class"=>"Rhoconnect::BulkDataJob"}
54
- end
55
-
56
- it "should generate correct bulk data name for user partition" do
57
- BulkData.get_name(:user,@c.user_id).should == File.join(@a_fields[:name],@u_fields[:login],@u_fields[:login])
58
- end
59
-
60
- it "should generate correct bulk data name for app partition" do
61
- BulkData.get_name(:app,@c.user_id).should ==
62
- File.join(@a_fields[:name],@a_fields[:name])
63
- end
64
-
65
- it "should have ordered sources list by priority" do
66
- data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
67
- :state => :inprogress,
68
- :app_id => @a.id,
69
- :user_id => @u.id,
70
- :sources => @a.partition_sources(:user, @u.id))
71
-
72
- data.sources[0, -1].should == ["SampleAdapter", "JsSample", "FixedSchemaAdapter"]
73
- p1 = Source.load("SampleAdapter", {:app_id => data.app_id, :user_id => data.user_id}).priority
74
- p2 = Source.load("JsSample", {:app_id => data.app_id, :user_id => data.user_id}).priority
75
- p1.should < p2
76
- end
77
-
78
- it "should process_sources for bulk data" do
79
- current = Time.now.to_i
80
- @s.read_state.refresh_time = current
81
- data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
82
- :state => :inprogress,
83
- :app_id => @a.id,
84
- :user_id => @u.id,
85
- :sources => [@s_fields[:name], @s1_fields[:name]])
86
- data.process_sources
87
- @s.read_state.refresh_time.should > current + @s_fields[:poll_interval].to_i
88
- @s1.read_state.refresh_time.should > current + @s1_fields[:poll_interval].to_i
89
- end
90
-
91
- it "should process specific sources for bulk data" do
92
- current = Time.now.to_i
93
- @s.read_state.refresh_time = current
94
- data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
95
- :state => :inprogress,
96
- :app_id => @a.id,
97
- :user_id => @u.id,
98
- :sources => [@s1_fields[:name]])
99
- data.process_sources
100
- @s.read_state.refresh_time.should <= current
101
- @s1.read_state.refresh_time.should > current + @s1_fields[:poll_interval].to_i
102
- end
103
-
104
- it "should delete source masterdoc copy on delete" do
105
- set_state('test_db_storage' => @data)
106
- data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
15
+ it "should return true if bulk data is completed" do
16
+ dbfile = create_datafile(File.join(@a.name,@u.id.to_s),@u.id.to_s)
17
+ data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
18
+ :state => :completed,
19
+ :app_id => @a.id,
20
+ :user_id => @u.id,
21
+ :sources => [@s_fields[:name]])
22
+ data.dbfile = dbfile
23
+ data.completed?.should == true
24
+ end
25
+
26
+ it "should return false if bulk data isn't completed" do
27
+ data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
28
+ :state => :inprogress,
29
+ :app_id => @a.id,
30
+ :user_id => @u.id,
31
+ :sources => [@s_fields[:name]])
32
+ data.completed?.should == false
33
+ end
34
+
35
+ it "should expire_bulk_data from a source adapter" do
36
+
37
+ @model = Rhoconnect::Model::Base.create(@s)
38
+ @engine = Rhoconnect::Handler::Query::Engine.new(@model, lambda { @model.query }, {})
39
+ time = Time.now.to_i + 10000
40
+ data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
41
+ :state => :inprogress,
42
+ :app_id => @a.id,
43
+ :user_id => @u.id,
44
+ :sources => [@s_fields[:name]],
45
+ :refresh_time => time)
46
+ @model.expire_bulk_data
47
+ data = BulkData.load(bulk_data_docname(@a.id,@u.id))
48
+ data.refresh_time.should <= Time.now.to_i
49
+ end
50
+
51
+ it "should enqueue sqlite db type" do
52
+ BulkData.enqueue
53
+ Resque.peek(:bulk_data).should == {"args"=>[{}],
54
+ "class"=>"Rhoconnect::BulkDataJob"}
55
+ end
56
+
57
+ it "should generate correct bulk data name for user partition" do
58
+ BulkData.get_name(:user,@c.user_id).should == File.join(@a_fields[:name],@u_fields[:login],@u_fields[:login])
59
+ end
60
+
61
+ it "should generate correct bulk data name for app partition" do
62
+ BulkData.get_name(:app,@c.user_id).should ==
63
+ File.join(@a_fields[:name],@a_fields[:name])
64
+ end
65
+
66
+ it "should have ordered sources list by priority" do
67
+ data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
68
+ :state => :inprogress,
69
+ :app_id => @a.id,
70
+ :user_id => @u.id,
71
+ :sources => @a.partition_sources(:user, @u.id))
72
+
73
+ data.sources[0, -1].should == ["SampleAdapter", "JsSample", "FixedSchemaAdapter"]
74
+ p1 = Source.load("SampleAdapter", {:app_id => data.app_id, :user_id => data.user_id}).priority
75
+ p2 = Source.load("JsSample", {:app_id => data.app_id, :user_id => data.user_id}).priority
76
+ p1.should < p2
77
+ end
78
+
79
+ it "should process_sources for bulk data" do
80
+ current = Time.now.to_i
81
+ @s.read_state.refresh_time = current
82
+ data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
83
+ :state => :inprogress,
84
+ :app_id => @a.id,
85
+ :user_id => @u.id,
86
+ :sources => [@s_fields[:name], @s1_fields[:name]])
87
+ data.process_sources
88
+ @s.read_state.refresh_time.should > current + @s_fields[:poll_interval].to_i
89
+ @s1.read_state.refresh_time.should > current + @s1_fields[:poll_interval].to_i
90
+ end
91
+
92
+ it "should process specific sources for bulk data" do
93
+ current = Time.now.to_i
94
+ @s.read_state.refresh_time = current
95
+ data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
96
+ :state => :inprogress,
97
+ :app_id => @a.id,
98
+ :user_id => @u.id,
99
+ :sources => [@s1_fields[:name]])
100
+ data.process_sources
101
+ @s.read_state.refresh_time.should <= current
102
+ @s1.read_state.refresh_time.should > current + @s1_fields[:poll_interval].to_i
103
+ end
104
+
105
+ it "should delete source masterdoc copy on delete" do
106
+ set_state('test_db_storage' => @data)
107
+ data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
108
+ :state => :inprogress,
109
+ :app_id => @a.id,
110
+ :user_id => @u.id,
111
+ :sources => [@s_fields[:name]])
112
+ data.process_sources
113
+ verify_doc_result(@s, :md_copy => @data)
114
+ data.delete
115
+ verify_doc_result(@s, {:md_copy => {},
116
+ :md => @data})
117
+ end
118
+
119
+ it "should escape bulk data url" do
120
+ name = 'a b'
121
+ data = BulkData.create(:name => bulk_data_docname(@a.id,name),
107
122
  :state => :inprogress,
108
123
  :app_id => @a.id,
109
- :user_id => @u.id,
124
+ :user_id => name,
110
125
  :sources => [@s_fields[:name]])
111
- data.process_sources
112
- verify_doc_result(@s, :md_copy => @data)
113
- data.delete
114
- verify_doc_result(@s, {:md_copy => {},
115
- :md => @data})
116
- end
117
-
118
- it "should escape bulk data url" do
119
- name = 'a b'
120
- data = BulkData.create(:name => bulk_data_docname(@a.id,name),
121
- :state => :inprogress,
122
- :app_id => @a.id,
123
- :user_id => name,
124
- :sources => [@s_fields[:name]])
125
- do_bulk_data_job("data_name" => bulk_data_docname(@a.id,name))
126
- data = BulkData.load(bulk_data_docname(@a.id,name))
127
- data.url.should match /a%20b/
128
- data.delete
129
- end
126
+ do_bulk_data_job("data_name" => bulk_data_docname(@a.id,name))
127
+ data = BulkData.load(bulk_data_docname(@a.id,name))
128
+ data.url.should match /a%20b/
129
+ data.delete
130
130
  end
131
131
 
132
132
  def create_datafile(dir,name)
data/spec/cli/cli_spec.rb CHANGED
@@ -41,10 +41,29 @@ describe "RhoconnectCommandLineInterface" do
41
41
  end
42
42
  end
43
43
 
44
- before(:all) do
45
- @cur_dir = Dir.pwd
46
- @tmpdir = Dir.mktmpdir
47
- Dir.chdir @tmpdir
44
+ # Captures $stdout and $stderr into strings
45
+ def capture_io
46
+ require 'stringio'
47
+
48
+ orig_stdout, orig_stderr = $stdout, $stderr
49
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
50
+ $stdout, $stderr = captured_stdout, captured_stderr
51
+
52
+ yield
53
+
54
+ return captured_stdout.string, captured_stderr.string
55
+ ensure
56
+ $stdout = orig_stdout
57
+ $stderr = orig_stderr
58
+ end
59
+
60
+ def run_in_sandbox
61
+ Dir.mktmpdir do |tmp_dir|
62
+ Dir.chdir(tmp_dir) do
63
+ # Run example in a sandbox on the file system
64
+ yield
65
+ end
66
+ end
48
67
  end
49
68
 
50
69
  after(:each) do
@@ -52,70 +71,48 @@ describe "RhoconnectCommandLineInterface" do
52
71
  puts "\nExecuting 'rhoconnect stop' command ..." if pid
53
72
  Execute.start ["stop"] # 'rhoconnect stop'
54
73
  File.exist?("/tmp/rhoconnect.pid").should == false
55
- `ps -p #{pid} -o pid=`.should be_empty if pid
56
- end
57
-
58
- after(:all) do
59
- Dir.chdir @cur_dir
60
- FileUtils.remove_entry @tmpdir
74
+ # `ps -p #{pid} -o pid=`.should be_empty if pid
61
75
  end
62
76
 
63
77
  it "'rhoconnect help' cmd should display list of available commands" do
64
- begin
65
- out = StringIO.new
66
- $stdout = out
67
- Execute.start ["help"] # 'rhoconnect help'
68
- ensure
69
- $stdout = STDOUT
78
+ run_in_sandbox do
79
+ out = capture_io{ Execute.start ["help"] }.join ''
80
+ out.strip.should start_with "Commands:"
70
81
  end
71
- out.string.strip.should start_with "Commands:"
72
82
  end
73
83
 
74
84
  it "'rhoconnect version' cmd should display gem version" do
75
- begin
76
- out = StringIO.new
77
- $stdout = out
78
- Execute.start ["version"] # 'rhoconnect version'
79
- ensure
80
- $stdout = STDOUT
85
+ run_in_sandbox do
86
+ out = capture_io{ Execute.start ["version"] }.join ''
87
+ out.strip.should == Rhoconnect::VERSION
81
88
  end
82
- out.string.strip.should == Rhoconnect::VERSION
83
89
  end
84
90
 
85
91
  it "'rhoconnect routes' cmd should display list of available routes" do
86
- begin
87
- @prev_dir = Dir.pwd
88
- @appdir = File.join(File.dirname(__FILE__), "..", "apps", "rhotestapp")
89
- puts " we have here #{@appdir}"
90
- Dir.chdir @appdir
91
- out = StringIO.new
92
- $stdout = out
93
- Execute.start ["routes"] # 'rhoconnect routes'
94
- ensure
95
- $stdout = STDOUT
96
- Dir.chdir @prev_dir
92
+ Dir.chdir(File.join(File.dirname(__FILE__), "..", "apps", "rhotestapp")) do
93
+ out = capture_io{ Execute.start ['routes'] }.join ''
94
+ out.strip.should include("SampleAdapterController: /app/v1/SampleAdapter")
95
+ out.strip.should include("FixedSchemaAdapterController: /app/v1/FixedSchemaAdapter")
96
+ out.strip.should_not include("FooAdapterController: /app/v1/FooAdapter")
97
97
  end
98
- out.string.strip.should include("SampleAdapterController: /app/v1/SampleAdapter")
99
- out.string.strip.should include("FixedSchemaAdapterController: /app/v1/FixedSchemaAdapter")
100
- out.string.strip.should_not include("FooAdapterController: /app/v1/FooAdapter")
101
98
  end
102
99
 
103
100
  it "'rhoconnect start' cmd should start blank app from any directory" do
104
- thread = Thread.new do
105
- puts "Executing 'rhoconnect start' command ..."
106
- # Array of params expected
107
- Execute.start ["start"] # 'rhoconnect start'
108
- end
109
- 30.times do
110
- sleep 1
111
- raise "'rhoconnect start' failed to start with exception" if thread.status.nil?
112
- break if File.exist?("/tmp/rhoconnect.pid")
101
+ run_in_sandbox do
102
+ thread = Thread.new do
103
+ puts "Executing 'rhoconnect start' command ..."
104
+ # Array of params expected
105
+ Execute.start ["start"] # 'rhoconnect start'
106
+ end
107
+ 30.times do
108
+ sleep 1
109
+ raise "'rhoconnect start' failed to start with exception" if thread.status.nil?
110
+ break if File.exist?("/tmp/rhoconnect.pid")
111
+ end
112
+ File.exist?("/tmp/rhoconnect.pid").should == true
113
+ pid = `cat /tmp/rhoconnect.pid`
114
+ puts "Rhoconnect app is running with pid=#{pid}"
115
+ `ps -p #{pid} -o pid=`.should_not be_empty
113
116
  end
114
-
115
- File.exist?("/tmp/rhoconnect.pid").should == true
116
- pid = `cat /tmp/rhoconnect.pid`
117
- puts "Rhoconnect app is running with pid=#{pid}"
118
- `ps -p #{pid} -o pid=`.should_not be_empty
119
117
  end
120
-
121
118
  end