rhoconnect 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (361) hide show
  1. data/CHANGELOG +208 -0
  2. data/CREDITS +38 -0
  3. data/Gemfile +18 -0
  4. data/Gemfile.lock +97 -0
  5. data/LICENSE +75 -0
  6. data/README.md +10 -0
  7. data/Rakefile +82 -0
  8. data/bench/bench +7 -0
  9. data/bench/bench_runner.rb +112 -0
  10. data/bench/benchapp/Gemfile +21 -0
  11. data/bench/benchapp/Gemfile.lock +76 -0
  12. data/bench/benchapp/Rakefile +22 -0
  13. data/bench/benchapp/application.rb +39 -0
  14. data/bench/benchapp/config.ru +36 -0
  15. data/bench/benchapp/settings/license.key +1 -0
  16. data/bench/benchapp/settings/settings.yml +20 -0
  17. data/bench/benchapp/sources/mock_adapter.rb +55 -0
  18. data/bench/benchapp/sources/queue_mock_adapter.rb +2 -0
  19. data/bench/benchapp/spec/sources/mock_adapter_spec.rb +25 -0
  20. data/bench/benchapp/spec/sources/queue_mock_adapter_spec.rb +25 -0
  21. data/bench/benchapp/spec/spec_helper.rb +42 -0
  22. data/bench/blobapp/Gemfile +31 -0
  23. data/bench/blobapp/Gemfile.lock +103 -0
  24. data/bench/blobapp/Rakefile +25 -0
  25. data/bench/blobapp/application.rb +44 -0
  26. data/bench/blobapp/config.ru +36 -0
  27. data/bench/blobapp/settings/license.key +1 -0
  28. data/bench/blobapp/settings/settings.yml +16 -0
  29. data/bench/blobapp/sources/blob_adapter.rb +71 -0
  30. data/bench/blobapp/spec/sources/blob_adapter_spec.rb +25 -0
  31. data/bench/blobapp/spec/spec_helper.rb +42 -0
  32. data/bench/lib/bench/cli.rb +16 -0
  33. data/bench/lib/bench/logging.rb +13 -0
  34. data/bench/lib/bench/mock_client.rb +41 -0
  35. data/bench/lib/bench/result.rb +50 -0
  36. data/bench/lib/bench/runner.rb +107 -0
  37. data/bench/lib/bench/session.rb +67 -0
  38. data/bench/lib/bench/statistics.rb +56 -0
  39. data/bench/lib/bench/test_data.rb +98 -0
  40. data/bench/lib/bench/timer.rb +10 -0
  41. data/bench/lib/bench/utils.rb +49 -0
  42. data/bench/lib/bench.rb +129 -0
  43. data/bench/lib/testdata/100-data.txt +148 -0
  44. data/bench/lib/testdata/5-data.txt +9 -0
  45. data/bench/lib/testdata/images/icon.ico +0 -0
  46. data/bench/lib/testdata/images/icon.png +0 -0
  47. data/bench/lib/testdata/images/loading-Landscape.png +0 -0
  48. data/bench/lib/testdata/images/loading-LandscapeLeft.png +0 -0
  49. data/bench/lib/testdata/images/loading-LandscapeRight.png +0 -0
  50. data/bench/lib/testdata/images/loading-Portrait.png +0 -0
  51. data/bench/lib/testdata/images/loading-PortraitUpsideDown.png +0 -0
  52. data/bench/lib/testdata/images/loading.png +0 -0
  53. data/bench/lib/testdata/images/loading@2x.png +0 -0
  54. data/bench/run_bench.sh +42 -0
  55. data/bench/run_blob_script.sh +3 -0
  56. data/bench/run_cud_script.sh +3 -0
  57. data/bench/run_query_md_script.sh +3 -0
  58. data/bench/run_query_only_script.sh +3 -0
  59. data/bench/run_query_script.sh +3 -0
  60. data/bench/scripts/blob_cud_script.rb +98 -0
  61. data/bench/scripts/cud_script.rb +92 -0
  62. data/bench/scripts/helpers.rb +101 -0
  63. data/bench/scripts/query_md_script.rb +45 -0
  64. data/bench/scripts/query_only_script.rb +51 -0
  65. data/bench/scripts/query_script.rb +45 -0
  66. data/bench/spec/bench_spec_helper.rb +33 -0
  67. data/bench/spec/logging_spec.rb +15 -0
  68. data/bench/spec/mock_adapter_spec.rb +61 -0
  69. data/bench/spec/mock_client_spec.rb +65 -0
  70. data/bench/spec/result_spec.rb +61 -0
  71. data/bench/spec/utils_spec.rb +36 -0
  72. data/bin/rhoconnect +34 -0
  73. data/bin/rhoconnect-setup +84 -0
  74. data/doc/async-jobs.txt +69 -0
  75. data/doc/authentication.txt +76 -0
  76. data/doc/benchmarks.txt +168 -0
  77. data/doc/blob-sync.txt +130 -0
  78. data/doc/bulk-sync.txt +102 -0
  79. data/doc/client.txt +432 -0
  80. data/doc/command-line.txt +210 -0
  81. data/doc/contributing.txt +60 -0
  82. data/doc/deploying.txt +82 -0
  83. data/doc/install.txt +28 -0
  84. data/doc/introduction.txt +20 -0
  85. data/doc/licensing.txt +18 -0
  86. data/doc/metadata.txt +458 -0
  87. data/doc/migration.txt +182 -0
  88. data/doc/public/css/print.css +29 -0
  89. data/doc/public/css/screen.css +257 -0
  90. data/doc/public/css/style.css +20 -0
  91. data/doc/push.txt +135 -0
  92. data/doc/release.txt +41 -0
  93. data/doc/rest-api.txt +367 -0
  94. data/doc/source-adapters.txt +325 -0
  95. data/doc/stats-middleware.txt +69 -0
  96. data/doc/testing.txt +222 -0
  97. data/doc/tutorial.txt +315 -0
  98. data/doc/web-console.txt +35 -0
  99. data/examples/simple/Rakefile +14 -0
  100. data/examples/simple/application.rb +27 -0
  101. data/examples/simple/config.ru +49 -0
  102. data/examples/simple/settings/license.key +1 -0
  103. data/examples/simple/settings/settings.yml +23 -0
  104. data/examples/simple/sources/sample_adapter.rb +5 -0
  105. data/examples/simple/sources/simple_adapter.rb +5 -0
  106. data/generators/rhoconnect.rb +119 -0
  107. data/generators/templates/application/Gemfile +21 -0
  108. data/generators/templates/application/Rakefile +22 -0
  109. data/generators/templates/application/application.rb +39 -0
  110. data/generators/templates/application/config.ru +36 -0
  111. data/generators/templates/application/settings/license.key +1 -0
  112. data/generators/templates/application/settings/settings.yml +14 -0
  113. data/generators/templates/application/spec/spec_helper.rb +42 -0
  114. data/generators/templates/source/source_adapter.rb +47 -0
  115. data/generators/templates/source/source_spec.rb +25 -0
  116. data/install.sh +408 -0
  117. data/installer/unix-like/rho_connect_install_checkers.rb +140 -0
  118. data/installer/unix-like/rho_connect_install_constants.rb +51 -0
  119. data/installer/unix-like/rho_connect_install_debian.rb +63 -0
  120. data/installer/unix-like/rho_connect_install_dnd.rb +58 -0
  121. data/installer/unix-like/rho_connect_install_get_params.rb +30 -0
  122. data/installer/unix-like/rho_connect_install_installers.rb +142 -0
  123. data/installer/unix-like/rho_connect_install_utilities.rb +85 -0
  124. data/installer/unix-like/rho_connect_install_yum.rb +63 -0
  125. data/installer/unix-like/rhoinstaller.rb +89 -0
  126. data/installer/utils/create_texts.rb +366 -0
  127. data/installer/utils/install_test.rb +140 -0
  128. data/installer/windows/EnvVarUpdate.nsh +328 -0
  129. data/installer/windows/ServiceLib.nsh +369 -0
  130. data/installer/windows/configUi.ini +44 -0
  131. data/installer/windows/icon.ico +0 -0
  132. data/installer/windows/rhosync.nsi +418 -0
  133. data/installer/windows/uninstall.bat +7 -0
  134. data/lib/rhoconnect/api/admin/get_api_token.rb +14 -0
  135. data/lib/rhoconnect/api/admin/get_license_info.rb +8 -0
  136. data/lib/rhoconnect/api/admin/login.rb +6 -0
  137. data/lib/rhoconnect/api/admin/reset.rb +10 -0
  138. data/lib/rhoconnect/api/admin/stats.rb +21 -0
  139. data/lib/rhoconnect/api/application/bulk_data.rb +7 -0
  140. data/lib/rhoconnect/api/application/clientcreate.rb +8 -0
  141. data/lib/rhoconnect/api/application/clientlogin.rb +6 -0
  142. data/lib/rhoconnect/api/application/clientregister.rb +6 -0
  143. data/lib/rhoconnect/api/application/clientreset.rb +6 -0
  144. data/lib/rhoconnect/api/application/query.rb +7 -0
  145. data/lib/rhoconnect/api/application/queue_updates.rb +6 -0
  146. data/lib/rhoconnect/api/application/search.rb +6 -0
  147. data/lib/rhoconnect/api/client/create_client.rb +3 -0
  148. data/lib/rhoconnect/api/client/delete_client.rb +5 -0
  149. data/lib/rhoconnect/api/client/get_client_params.rb +3 -0
  150. data/lib/rhoconnect/api/client/list_client_docs.rb +12 -0
  151. data/lib/rhoconnect/api/client/list_clients.rb +3 -0
  152. data/lib/rhoconnect/api/client/ping.rb +7 -0
  153. data/lib/rhoconnect/api/source/get_adapter.rb +3 -0
  154. data/lib/rhoconnect/api/source/get_db_doc.rb +7 -0
  155. data/lib/rhoconnect/api/source/get_source_params.rb +3 -0
  156. data/lib/rhoconnect/api/source/list_source_docs.rb +10 -0
  157. data/lib/rhoconnect/api/source/list_sources.rb +15 -0
  158. data/lib/rhoconnect/api/source/push_deletes.rb +8 -0
  159. data/lib/rhoconnect/api/source/push_objects.rb +8 -0
  160. data/lib/rhoconnect/api/source/save_adapter.rb +3 -0
  161. data/lib/rhoconnect/api/source/set_db_doc.rb +8 -0
  162. data/lib/rhoconnect/api/source/set_refresh_time.rb +8 -0
  163. data/lib/rhoconnect/api/source/upload_file.rb +4 -0
  164. data/lib/rhoconnect/api/user/create_user.rb +7 -0
  165. data/lib/rhoconnect/api/user/delete_user.rb +9 -0
  166. data/lib/rhoconnect/api/user/list_users.rb +3 -0
  167. data/lib/rhoconnect/api/user/update_user.rb +4 -0
  168. data/lib/rhoconnect/api_token.rb +19 -0
  169. data/lib/rhoconnect/app.rb +76 -0
  170. data/lib/rhoconnect/bulk_data/bulk_data.rb +88 -0
  171. data/lib/rhoconnect/bulk_data/syncdb.index.schema +4 -0
  172. data/lib/rhoconnect/bulk_data/syncdb.schema +41 -0
  173. data/lib/rhoconnect/bulk_data.rb +2 -0
  174. data/lib/rhoconnect/client.rb +96 -0
  175. data/lib/rhoconnect/client_sync.rb +412 -0
  176. data/lib/rhoconnect/console/app/helpers/auth_helper.rb +22 -0
  177. data/lib/rhoconnect/console/app/helpers/extensions.rb +19 -0
  178. data/lib/rhoconnect/console/app/helpers/helpers.rb +57 -0
  179. data/lib/rhoconnect/console/app/public/ThickBox.css +649 -0
  180. data/lib/rhoconnect/console/app/public/home.css +438 -0
  181. data/lib/rhoconnect/console/app/public/images/foot_logo_rhoconnect.png +0 -0
  182. data/lib/rhoconnect/console/app/public/images/header_halo.jpg +0 -0
  183. data/lib/rhoconnect/console/app/public/images/land_separator.gif +0 -0
  184. data/lib/rhoconnect/console/app/public/images/landing_header.jpg +0 -0
  185. data/lib/rhoconnect/console/app/public/images/logo_rhoconnect.png +0 -0
  186. data/lib/rhoconnect/console/app/public/images/rhomobile_rhohub_logo.png +0 -0
  187. data/lib/rhoconnect/console/app/public/images/tabs_separator.png +0 -0
  188. data/lib/rhoconnect/console/app/public/jqplot/excanvas.min.js +35 -0
  189. data/lib/rhoconnect/console/app/public/jqplot/jqplot.barRenderer.min.js +34 -0
  190. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisLabelRenderer.js +187 -0
  191. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisTickRenderer.js +226 -0
  192. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasTextRenderer.js +408 -0
  193. data/lib/rhoconnect/console/app/public/jqplot/jqplot.categoryAxisRenderer.min.js +34 -0
  194. data/lib/rhoconnect/console/app/public/jqplot/jqplot.cursor.js +952 -0
  195. data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.js +313 -0
  196. data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.min.js +34 -0
  197. data/lib/rhoconnect/console/app/public/jqplot/jqplot.pointLabels.min.js +34 -0
  198. data/lib/rhoconnect/console/app/public/jqplot/jquery-1.4.2.min.js +154 -0
  199. data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.css +1 -0
  200. data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.js +34 -0
  201. data/lib/rhoconnect/console/app/public/main.css +7 -0
  202. data/lib/rhoconnect/console/app/public/reset.css +76 -0
  203. data/lib/rhoconnect/console/app/public/style.css +2201 -0
  204. data/lib/rhoconnect/console/app/public/text.txt +0 -0
  205. data/lib/rhoconnect/console/app/routes/adapter.rb +28 -0
  206. data/lib/rhoconnect/console/app/routes/auth.rb +29 -0
  207. data/lib/rhoconnect/console/app/routes/client.rb +31 -0
  208. data/lib/rhoconnect/console/app/routes/docs.rb +145 -0
  209. data/lib/rhoconnect/console/app/routes/heroku.rb +19 -0
  210. data/lib/rhoconnect/console/app/routes/home.rb +63 -0
  211. data/lib/rhoconnect/console/app/routes/timing.rb +242 -0
  212. data/lib/rhoconnect/console/app/routes/user.rb +117 -0
  213. data/lib/rhoconnect/console/app/views/adapter.erb +16 -0
  214. data/lib/rhoconnect/console/app/views/client.erb +30 -0
  215. data/lib/rhoconnect/console/app/views/content.erb +14 -0
  216. data/lib/rhoconnect/console/app/views/doc.erb +8 -0
  217. data/lib/rhoconnect/console/app/views/docdata.erb +28 -0
  218. data/lib/rhoconnect/console/app/views/docs.erb +30 -0
  219. data/lib/rhoconnect/console/app/views/edituser.erb +13 -0
  220. data/lib/rhoconnect/console/app/views/headermenu.erb +40 -0
  221. data/lib/rhoconnect/console/app/views/home.erb +24 -0
  222. data/lib/rhoconnect/console/app/views/index.erb +58 -0
  223. data/lib/rhoconnect/console/app/views/jqplot.erb +52 -0
  224. data/lib/rhoconnect/console/app/views/layout.erb +165 -0
  225. data/lib/rhoconnect/console/app/views/login.erb +26 -0
  226. data/lib/rhoconnect/console/app/views/newuser.erb +17 -0
  227. data/lib/rhoconnect/console/app/views/ping.erb +28 -0
  228. data/lib/rhoconnect/console/app/views/result.erb +11 -0
  229. data/lib/rhoconnect/console/app/views/rightboxlinks.erb +15 -0
  230. data/lib/rhoconnect/console/app/views/select_doc.erb +17 -0
  231. data/lib/rhoconnect/console/app/views/upload_doc.erb +23 -0
  232. data/lib/rhoconnect/console/app/views/user.erb +29 -0
  233. data/lib/rhoconnect/console/app/views/users.erb +12 -0
  234. data/lib/rhoconnect/console/rhoconnect_api.rb +245 -0
  235. data/lib/rhoconnect/console/server.rb +32 -0
  236. data/lib/rhoconnect/console.rb +3 -0
  237. data/lib/rhoconnect/cors.rb +229 -0
  238. data/lib/rhoconnect/credential.rb +9 -0
  239. data/lib/rhoconnect/db_adapter.rb +46 -0
  240. data/lib/rhoconnect/document.rb +49 -0
  241. data/lib/rhoconnect/dynamic_adapter.rb +91 -0
  242. data/lib/rhoconnect/generator.rb +1 -0
  243. data/lib/rhoconnect/jobs/bulk_data_job.rb +203 -0
  244. data/lib/rhoconnect/jobs/ping_job.rb +46 -0
  245. data/lib/rhoconnect/jobs/source_job.rb +16 -0
  246. data/lib/rhoconnect/license.rb +86 -0
  247. data/lib/rhoconnect/lock_ops.rb +11 -0
  248. data/lib/rhoconnect/model.rb +414 -0
  249. data/lib/rhoconnect/ping/android.rb +56 -0
  250. data/lib/rhoconnect/ping/apple.rb +52 -0
  251. data/lib/rhoconnect/ping/blackberry.rb +56 -0
  252. data/lib/rhoconnect/ping.rb +3 -0
  253. data/lib/rhoconnect/read_state.rb +31 -0
  254. data/lib/rhoconnect/rho_indifferent_access.rb +88 -0
  255. data/lib/rhoconnect/server/views/index.erb +13 -0
  256. data/lib/rhoconnect/server.rb +286 -0
  257. data/lib/rhoconnect/source.rb +289 -0
  258. data/lib/rhoconnect/source_adapter.rb +123 -0
  259. data/lib/rhoconnect/source_sync.rb +302 -0
  260. data/lib/rhoconnect/stats/middleware.rb +20 -0
  261. data/lib/rhoconnect/stats/record.rb +108 -0
  262. data/lib/rhoconnect/store.rb +232 -0
  263. data/lib/rhoconnect/tasks.rb +350 -0
  264. data/lib/rhoconnect/test_methods.rb +220 -0
  265. data/lib/rhoconnect/user.rb +95 -0
  266. data/lib/rhoconnect/version.rb +3 -0
  267. data/lib/rhoconnect/x_domain_session_wrapper.rb +53 -0
  268. data/lib/rhoconnect.rb +285 -0
  269. data/rhoconnect.gemspec +67 -0
  270. data/spec/api/admin/api_token_spec.rb +14 -0
  271. data/spec/api/admin/get_api_token_spec.rb +36 -0
  272. data/spec/api/admin/get_license_info_spec.rb +38 -0
  273. data/spec/api/admin/reset_spec.rb +22 -0
  274. data/spec/api/admin/stats_spec.rb +66 -0
  275. data/spec/api/api_helper.rb +21 -0
  276. data/spec/api/application/rhoconnect_api_spec.rb +548 -0
  277. data/spec/api/client/create_client_spec.rb +13 -0
  278. data/spec/api/client/delete_client_spec.rb +13 -0
  279. data/spec/api/client/get_client_params_spec.rb +18 -0
  280. data/spec/api/client/list_client_docs_spec.rb +32 -0
  281. data/spec/api/client/list_clients_spec.rb +22 -0
  282. data/spec/api/client/ping_spec.rb +23 -0
  283. data/spec/api/rhosync_api_spec.rb.orig +606 -0
  284. data/spec/api/source/adapter_spec.rb +29 -0
  285. data/spec/api/source/get_db_doc_spec.rb +21 -0
  286. data/spec/api/source/get_source_params_spec.rb +32 -0
  287. data/spec/api/source/list_source_docs_spec.rb +25 -0
  288. data/spec/api/source/list_sources_spec.rb +26 -0
  289. data/spec/api/source/push_deletes_spec.rb +18 -0
  290. data/spec/api/source/push_objects_spec.rb +27 -0
  291. data/spec/api/source/set_db_doc_spec.rb +19 -0
  292. data/spec/api/source/set_refresh_time_spec.rb +43 -0
  293. data/spec/api/source/upload_file_spec.rb +26 -0
  294. data/spec/api/user/create_user_spec.rb +16 -0
  295. data/spec/api/user/delete_user_spec.rb +36 -0
  296. data/spec/api/user/list_users_spec.rb +30 -0
  297. data/spec/api/user/update_user_spec.rb +31 -0
  298. data/spec/api_token_spec.rb +14 -0
  299. data/spec/app_spec.rb +18 -0
  300. data/spec/apps/emptyapp/application.rb +27 -0
  301. data/spec/apps/emptyapp/settings/license.key +1 -0
  302. data/spec/apps/emptyapp/settings/settings.yml +14 -0
  303. data/spec/apps/rhotestapp/Rakefile +1 -0
  304. data/spec/apps/rhotestapp/application.rb +19 -0
  305. data/spec/apps/rhotestapp/config.ru +1 -0
  306. data/spec/apps/rhotestapp/settings/apple_fake_cert.pem +1 -0
  307. data/spec/apps/rhotestapp/settings/license.key +1 -0
  308. data/spec/apps/rhotestapp/settings/settings.yml +36 -0
  309. data/spec/apps/rhotestapp/sources/base_adapter.rb +9 -0
  310. data/spec/apps/rhotestapp/sources/fixed_schema_adapter.rb +28 -0
  311. data/spec/apps/rhotestapp/sources/sample_adapter.rb +71 -0
  312. data/spec/apps/rhotestapp/sources/simple_adapter.rb +41 -0
  313. data/spec/apps/rhotestapp/sources/sub_adapter.rb +7 -0
  314. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem/mygem.rb +8 -0
  315. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem.rb +1 -0
  316. data/spec/bulk_data/bulk_data_spec.rb +97 -0
  317. data/spec/client_spec.rb +124 -0
  318. data/spec/client_sync_spec.rb +774 -0
  319. data/spec/doc/base.html +72 -0
  320. data/spec/doc/doc_spec.rb +376 -0
  321. data/spec/doc/footer.html +4 -0
  322. data/spec/doc/header.html +30 -0
  323. data/spec/document_spec.rb +31 -0
  324. data/spec/dynamic_adapter_spec.rb +43 -0
  325. data/spec/factories/factories.rb +17 -0
  326. data/spec/generator/generator_spec.rb +58 -0
  327. data/spec/generator/generator_spec_helper.rb +9 -0
  328. data/spec/jobs/bulk_data_job_spec.rb +125 -0
  329. data/spec/jobs/ping_job_spec.rb +102 -0
  330. data/spec/jobs/source_job_spec.rb +29 -0
  331. data/spec/license_spec.rb +66 -0
  332. data/spec/model_spec.rb +273 -0
  333. data/spec/perf/bulk_data_perf_spec.rb +32 -0
  334. data/spec/perf/perf_spec_helper.rb +50 -0
  335. data/spec/perf/store_perf_spec.rb +27 -0
  336. data/spec/ping/android_spec.rb +91 -0
  337. data/spec/ping/apple_spec.rb +70 -0
  338. data/spec/ping/blackberry_spec.rb +62 -0
  339. data/spec/read_state_spec.rb +35 -0
  340. data/spec/rhosync_spec.rb +75 -0
  341. data/spec/server/cors_spec.rb +287 -0
  342. data/spec/server/server_spec.rb +470 -0
  343. data/spec/server/x_domain_session_wrapper_spec.rb +150 -0
  344. data/spec/source_adapter_spec.rb +125 -0
  345. data/spec/source_spec.rb +114 -0
  346. data/spec/source_sync_spec.rb +328 -0
  347. data/spec/spec.opts +4 -0
  348. data/spec/spec_helper.rb +231 -0
  349. data/spec/stats/middleware_spec.rb +53 -0
  350. data/spec/stats/record_spec.rb +92 -0
  351. data/spec/store_spec.rb +251 -0
  352. data/spec/support/shared_examples.rb +168 -0
  353. data/spec/sync_states_spec.rb +72 -0
  354. data/spec/test_methods_spec.rb +134 -0
  355. data/spec/testdata/1000-data.txt +1414 -0
  356. data/spec/testdata/compressed/compress-data.txt +1 -0
  357. data/spec/testdata/upload1.txt +1 -0
  358. data/spec/testdata/upload2.txt +1 -0
  359. data/spec/user_spec.rb +139 -0
  360. data/tasks/redis.rake +206 -0
  361. metadata +706 -0
@@ -0,0 +1,71 @@
1
+ class BlobAdapter < SourceAdapter
2
+ def initialize(source)
3
+ super(source)
4
+ end
5
+
6
+ def login
7
+ # TODO: Login to your data source here if necessary
8
+ true
9
+ end
10
+
11
+ def query(params=nil)
12
+ Store.lock(lock_name,1) do
13
+ @result = Store.get_data(db_name)
14
+ end
15
+ @result
16
+ end
17
+
18
+ def sync
19
+ # Manipulate @result before it is saved, or save it
20
+ # yourself using the Rhoconnect::Store interface.
21
+ # By default, super is called below which simply saves @result
22
+ super
23
+ end
24
+
25
+ def create(create_hash)
26
+ file_name = create_hash['filename']
27
+ if file_name
28
+ path_to_img_file = create_hash['image_uri']
29
+ # Simple verification that image successfully uploaded
30
+ expected_size, actual_size = create_hash["img_file_size"].to_i, File.size(path_to_img_file)
31
+ raise "BlobAdapter#create: expected image size #{expected_size}, but actual is #{actual_size}" if expected_size != actual_size
32
+
33
+ # Adjust create_hash to match expected md
34
+ create_hash['img_file-rhoblob'] = file_name
35
+ create_hash.delete('image_uri')
36
+ end
37
+
38
+ id = create_hash['mock_id']
39
+ Store.lock(lock_name,1) do
40
+ Store.put_data(db_name,{id => create_hash}, true) if id
41
+ end
42
+ id
43
+ end
44
+
45
+ def update(update_hash)
46
+ # TODO: Update an existing record in your backend data source
47
+ raise "Please provide some code to update a single record in the backend data source using the update_hash"
48
+ end
49
+
50
+ def delete(delete_hash)
51
+ # TODO: write some code here if applicable
52
+ # be sure to have a hash key and value for "object"
53
+ # for now, we'll say that its OK to not have a delete operation
54
+ # raise "Please provide some code to delete a single object in the backend application using the object_id"
55
+ end
56
+
57
+ def logoff
58
+ # TODO: Logout from the data source if necessary
59
+ end
60
+
61
+ private
62
+
63
+ def db_name
64
+ "test_db_storage:#{@source.app_id}:#{@source.user_id}"
65
+ end
66
+
67
+ def lock_name
68
+ "lock:#{db_name}"
69
+ end
70
+
71
+ end
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__),'..','spec_helper')
2
+
3
+ describe "BlobAdapter" do
4
+ it_should_behave_like "SpecHelper" do
5
+ before(:each) do
6
+ setup_test_for BlobAdapter,'testuser'
7
+ end
8
+
9
+ it "should process BlobAdapter query" do
10
+ pending
11
+ end
12
+
13
+ it "should process BlobAdapter create" do
14
+ pending
15
+ end
16
+
17
+ it "should process BlobAdapter update" do
18
+ pending
19
+ end
20
+
21
+ it "should process BlobAdapter delete" do
22
+ pending
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+
3
+ # Set environment to test
4
+ ENV['RHO_ENV'] = 'test'
5
+ ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__),'..'))
6
+ Bundler.require(:default, ENV['RHO_ENV'].to_sym)
7
+
8
+ # Try to load vendor-ed rhoconnect, otherwise load the gem
9
+ begin
10
+ require 'vendor/rhoconnect/lib/rhoconnect'
11
+ rescue LoadError
12
+ require 'rhoconnect'
13
+ end
14
+
15
+ $:.unshift File.join(File.dirname(__FILE__), "..") # FIXME:
16
+ # Load our rhoconnect application
17
+ require 'application'
18
+ include Rhoconnect
19
+
20
+ require 'rhoconnect/test_methods'
21
+
22
+ # Monkey patch to fix the following issue:
23
+ # /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:45:
24
+ # in `ensure_shared_example_group_name_not_taken': Shared example group '...' already exists (ArgumentError)
25
+ module RSpec
26
+ module Core
27
+ module SharedExampleGroup
28
+ private
29
+ def ensure_shared_example_group_name_not_taken(name)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ shared_examples_for "SpecHelper" do
36
+ include Rhoconnect::TestMethods
37
+
38
+ before(:each) do
39
+ Store.db.flushdb
40
+ Application.initializer(ROOT_PATH)
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ require 'thor'
2
+
3
+ module Bench
4
+ class Cli < Thor
5
+ include Logging
6
+ desc "start path/to/bench/script", "Start performance test"
7
+ def start(script,login,password='')
8
+ Bench.admin_login = login
9
+ Bench.admin_password = password
10
+ load(script)
11
+ Statistics.new(Bench.concurrency,Bench.iterations,
12
+ Bench.total_time,Bench.sessions).process.print_stats
13
+ bench_log "Bench completed..."
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Bench
2
+ module Logging
3
+ def log_prefix
4
+ # FIXME: in ruby1.8: "%d" % nil => 0
5
+ # but in ruby 1.9.2: TypeError: can't convert nil into Integer
6
+ "[T:%03d|I:%03d]" % [@thread_id.to_i, @iteration.to_i]
7
+ end
8
+
9
+ def bench_log(msg)
10
+ Rhoconnect.log msg
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ require 'redis'
2
+ $:.unshift File.join(File.dirname(__FILE__),'..','..','..','lib')
3
+ require 'rhoconnect'
4
+ include Rhoconnect
5
+
6
+ module Bench
7
+ class MockClient
8
+ include Logging
9
+
10
+ def initialize(thread_id,iteration,client_id)
11
+ @thread_id,@iteration,@client_id = thread_id,iteration,client_id
12
+ end
13
+
14
+ def parse(message)
15
+ msg = JSON.parse(message)
16
+ raise Exception.new("#{log_prefix} Wrong message format. Message: #{message.inspect}") if msg.size < 6
17
+ raise Exception.new("#{log_prefix} Wrong protocol version. Message: #{message.inspect}") if msg[0]['version'] != 3
18
+ msg.each do |p|
19
+ insert(p['insert']) if p['insert']
20
+ delete(p['delete']) if p['delete']
21
+ end
22
+ end
23
+
24
+ def insert(objects)
25
+ Store.put_data(doc_type,objects,true)
26
+ end
27
+
28
+ def delete(objects)
29
+ Store.delete_data(doc_type,objects)
30
+ end
31
+
32
+ def verify(objects)
33
+ Store.get_data(doc_type) == objects
34
+ end
35
+
36
+ def doc_type
37
+ "#{@client_id.to_s}:mock:cd"
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ require 'set'
2
+
3
+ module Bench
4
+ class Result
5
+ attr_accessor :last_response,:time,:marker,:url,:verb,:error,:verification_error
6
+ include Logging
7
+ include Utils
8
+
9
+ def initialize(marker,verb,url,thread_id,iteration)
10
+ @marker,@verb,@url,@thread_id,@iteration = marker,verb,url,thread_id,iteration
11
+ @verification_error = 0
12
+ @time = 0
13
+ end
14
+
15
+ def code
16
+ @last_response.code
17
+ end
18
+
19
+ def body
20
+ @last_response.to_s
21
+ end
22
+
23
+ def cookies
24
+ @last_response.cookies
25
+ end
26
+
27
+ def headers
28
+ @last_response.headers
29
+ end
30
+
31
+ def verify_body(expected)
32
+ expected,actual = JSON.parse(expected),JSON.parse(@last_response.to_s)
33
+ @verification_error += compare_and_log(expected,actual,caller(1)[0].to_s)
34
+ end
35
+
36
+ def verify_code(expected)
37
+ if expected != @last_response.code
38
+ bench_log "#{log_prefix} Verify error at: " + caller(1)[0].to_s
39
+ bench_log "#{log_prefix} Code diff: "
40
+ bench_log "#{log_prefix} expected: #{expected.inspect}"
41
+ bench_log "#{log_prefix} but got: #{@last_response.code}"
42
+ @verification_error += 1
43
+ end
44
+ end
45
+
46
+ def verify_headers
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,107 @@
1
+ module Bench
2
+ class Runner
3
+ include Logging
4
+ include Timer
5
+ attr_reader :threads
6
+
7
+ def initialize
8
+ @threads = []
9
+ @sessions = []
10
+ end
11
+
12
+ def test(concurrency,iterations,&block)
13
+ total_time = time do
14
+ 0.upto(concurrency - 1) do |thread_id|
15
+ sleep rand(2)
16
+ threads << Thread.new(block) do |t|
17
+ 0.upto(iterations - 1) do |iteration|
18
+ s = Session.new(thread_id, iteration)
19
+ @sessions << s
20
+ begin
21
+ yield Bench,s
22
+ rescue Exception => e
23
+ puts "error running script: #{e.inspect}"
24
+ puts e.backtrace.join("\n")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ begin
30
+ threads.each { |t| t.join }
31
+ rescue RestClient::RequestTimeout => e
32
+ bench_log "Request timed out #{e}"
33
+ end
34
+ end
35
+ Bench.sessions = @sessions
36
+ Bench.total_time = total_time
37
+ end
38
+
39
+ =begin
40
+ if defined?(JRUBY_VERSION)
41
+ def test(concurrency,iterations,&block)
42
+ total_time = time do
43
+ 0.upto(concurrency - 1) do |thread_id|
44
+ sleep rand(2)
45
+ threads << Thread.new(block) do |t|
46
+ 0.upto(iterations - 1) do |iteration|
47
+ s = Session.new(thread_id, iteration)
48
+ @sessions << s
49
+ begin
50
+ yield Bench,s
51
+ rescue Exception => e
52
+ puts "error running script: #{e.inspect}"
53
+ puts e.backtrace.join("\n")
54
+ end
55
+ end
56
+ end
57
+ end
58
+ begin
59
+ threads.each { |t| t.join }
60
+ rescue RestClient::RequestTimeout => e
61
+ bench_log "Request timed out #{e}"
62
+ end
63
+ end
64
+ Bench.sessions = @sessions
65
+ Bench.total_time = total_time
66
+ end
67
+ else
68
+ def test(concurrency,iterations,&block)
69
+ total_time = time do
70
+ 0.upto(concurrency - 1) do |thread_id|
71
+ sleep rand(2)
72
+ threads << Process.fork do
73
+ pid = $$ # child process id
74
+ 0.upto(iterations - 1) do |iteration|
75
+ s = Session.new(thread_id, iteration)
76
+ begin
77
+ yield Bench,s
78
+ rescue Exception => e
79
+ puts "error running script: #{e.inspect}"
80
+ puts e.backtrace.join("\n")
81
+ end
82
+ File.open("/tmp/runner_#{iteration}.#{pid}", "w+") { |f| Marshal.dump(s, f) }
83
+ end
84
+ end
85
+ end
86
+ begin
87
+ @pid_stats = Process.waitall # returning an array of pid/status pairs
88
+ rescue RestClient::RequestTimeout => e
89
+ bench_log "Request timed out #{e}"
90
+ end
91
+ end
92
+ @pid_stats.each do |ps|
93
+ 0.upto(iterations - 1) do |iteration|
94
+ filename = "/tmp/runner_#{iteration}.#{ps[0]}"
95
+ s = Marshal.load(File.open(filename))
96
+ @sessions << s
97
+ File.delete(filename)
98
+ end
99
+ end
100
+ Bench.sessions = @sessions
101
+ Bench.total_time = total_time
102
+ end
103
+ end
104
+ =end
105
+
106
+ end
107
+ end
@@ -0,0 +1,67 @@
1
+ module Bench
2
+ class Session
3
+ include Logging
4
+ include Timer
5
+ attr_accessor :cookies, :last_result, :results, :thread_id, :iteration, :client_id
6
+
7
+ def initialize(thread_id,iteration)
8
+ @cookies = {}
9
+ @results = {}
10
+ @thread_id,@iteration = thread_id,iteration
11
+ end
12
+
13
+ def post(marker,url,headers={})
14
+ @body = yield
15
+ _request(marker,:_post,url,headers)
16
+ end
17
+
18
+ def get(marker,url,headers={})
19
+ params = yield if block_given?
20
+ url_params = url.clone
21
+ url_params << "?" + _url_params(params) if params
22
+ _request(marker,:_get,url_params,headers)
23
+ end
24
+
25
+ protected
26
+ def _request(marker,verb,url,headers)
27
+ result = Result.new(marker,verb,url,@thread_id,@iteration)
28
+ @results[result.marker] ||= []
29
+ @results[result.marker] << result
30
+ begin
31
+ result.time = time do
32
+ headers.merge!(:cookies => @cookies)
33
+ result.last_response = send(verb,url,headers)
34
+ @last_result = result
35
+ end
36
+ bench_log "#{log_prefix} #{verb.to_s.upcase.gsub(/_/,'')} #{url} #{@last_result.code} #{result.time}"
37
+ rescue RestClient::Exception => e
38
+ result.error = e
39
+ bench_log "#{log_prefix} #{verb.to_s.upcase.gsub(/_/,'')} #{url}"
40
+ bench_log "#{log_prefix} #{e.http_code.to_s} #{e.message}\n"
41
+ raise e
42
+ end
43
+ @last_result.cookies['rhoconnect_session'] =
44
+ CGI.escape(@last_result.cookies['rhoconnect_session']) if @last_result.cookies['rhoconnect_session']
45
+ @cookies = @cookies.merge(@last_result.cookies)
46
+ @last_result
47
+ end
48
+
49
+ def _get(url,headers)
50
+ #bench_log "GET #{url}"
51
+ RestClient.get(url, headers)
52
+ end
53
+
54
+ def _post(url,headers)
55
+ #bench_log "POST #{url}"
56
+ RestClient.post(url, @body, headers)
57
+ end
58
+
59
+ def _url_params(params)
60
+ elements = []
61
+ params.each do |key,value|
62
+ elements << "#{key}=#{value}"
63
+ end
64
+ elements.join('&')
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,56 @@
1
+ module Bench
2
+ class Statistics
3
+ include Logging
4
+
5
+ def initialize(concurrency,iterations,total_time,sessions)
6
+ @sessions = sessions
7
+ @rows = {} # row key is result.marker;
8
+ @total_count = 0
9
+ @total_time = total_time
10
+ @concurrency,@iterations = concurrency,iterations
11
+ end
12
+
13
+ def process
14
+ @sessions.each do |session|
15
+ session.results.each do |marker,results|
16
+ results.each do |result|
17
+ @rows[result.marker] ||= {}
18
+ row = @rows[result.marker]
19
+ row[:min] ||= 0.0
20
+ row[:max] ||= 0.0
21
+ row[:count] ||= 0
22
+ row[:total_time] ||= 0.0
23
+ row[:errors] ||= 0
24
+ row[:verification_errors] ||= 0
25
+ row[:min] = result.time if result.time < row[:min] || row[:min] == 0
26
+ row[:max] = result.time if result.time > row[:max]
27
+ row[:count] += 1.0
28
+ row[:total_time] += result.time
29
+ row[:errors] += 1 if result.error
30
+ row[:verification_errors] += result.verification_error
31
+ @total_count += 1
32
+ end
33
+ end
34
+ end
35
+ self
36
+ end
37
+
38
+ def average(row)
39
+ row[:total_time] / row[:count]
40
+ end
41
+
42
+ def print_stats
43
+ bench_log "Statistics:"
44
+ @rows.each do |marker,row|
45
+ bench_log "Request %-15s: min: %0.4f, max: %0.4f, avg: %0.4f, err: %d, verification err: %d" % [marker, row[:min], row[:max], average(row), row[:errors], row[:verification_errors]]
46
+ end
47
+ bench_log "State of MD : #{Bench.verify_error == 0 ? true : false}"
48
+ bench_log "Concurrency : #{@concurrency}"
49
+ bench_log "Iterations : #{@iterations}"
50
+ bench_log "Total Count : #{@total_count}"
51
+ bench_log "Total Time : #{@total_time}"
52
+ bench_log "Throughput(req/s) : #{@total_count / @total_time}"
53
+ bench_log "Throughput(req/min): #{(@total_count / @total_time) * 60.0}"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,98 @@
1
+ require 'ffaker'
2
+ require 'uuidtools'
3
+
4
+ module Bench
5
+ module TestData
6
+ def get_test_data(num=1000, generate=false, generate_blob=false)
7
+ file_name = generate_blob ? "#{num}-blob_data.txt" : "#{num}-data.txt"
8
+ file = File.join(File.dirname(__FILE__), '..', "testdata", file_name)
9
+ data = nil
10
+ if File.exists?(file) and not generate
11
+ data = open(file, 'r') {|f| Marshal.load(f)}
12
+ else
13
+ data = generate_fake_data(num, generate_blob)
14
+ f = File.new(file, 'w')
15
+ f.write Marshal.dump(data)
16
+ f.close
17
+ end
18
+ data
19
+ end
20
+
21
+ def get_image_data(objs)
22
+ blobs = {}
23
+ objs.keys.each do |key|
24
+ img_file_name = objs["#{key}"]["filename"]
25
+ blobs["img_file-rhoblob-#{key}"] =
26
+ File.new(File.join(File.dirname(__FILE__), "..", "testdata", "images", "#{img_file_name}"), 'rb')
27
+ end
28
+ blobs
29
+ end
30
+
31
+ BenchUser = Struct.new(:user_name, :password)
32
+
33
+ def get_bench_users(num=1)
34
+ users = []
35
+ num.times do |i|
36
+ user_name = Faker::Internet.user_name
37
+ password = Faker::Lorem.words[0] # for more real passwords use 'forgery' gem
38
+ users << BenchUser.new(user_name, password)
39
+ end
40
+ users
41
+ end
42
+
43
+ private
44
+
45
+ PREFIX = ["Account", "Administrative", "Advertising", "Assistant", "Banking", "Business Systems",
46
+ "Computer", "Distribution", "IT", "Electronics", "Environmental", "Financial", "General", "Head",
47
+ "Laboratory", "Maintenance", "Medical", "Production", "Quality Assurance", "Software", "Technical",
48
+ "Chief", "Senior"] unless defined? PREFIX
49
+ SUFFIX = ["Clerk", "Analyst", "Manager", "Supervisor", "Plant Manager", "Mechanic", "Technician", "Engineer",
50
+ "Director", "Superintendent", "Specialist", "Technologist", "Estimator", "Scientist", "Foreman", "Nurse",
51
+ "Worker", "Helper", "Intern", "Sales", "Mechanic", "Planner", "Recruiter", "Officer", "Superintendent",
52
+ "Vice President", "Buyer", "Production Supervisor", "Chef", "Accountant", "Executive"] unless defined? SUFFIX
53
+
54
+ IMAGE_FILES = %w{
55
+ icon.ico loading-LandscapeLeft.png loading-PortraitUpsideDown.png
56
+ icon.png loading-LandscapeRight.png loading.png
57
+ loading-Landscape.png loading-Portrait.png loading@2x.png }
58
+
59
+ EXCLUDE_LIST = %w{ id mock_id img_file-rhoblob img_file_size filename }
60
+
61
+ def title
62
+ prefix = PREFIX[rand(PREFIX.length)]
63
+ suffix = SUFFIX[rand(SUFFIX.length)]
64
+
65
+ "#{prefix} #{suffix}"
66
+ end
67
+
68
+ def generate_fake_data(num, generate_blob)
69
+ res = {}
70
+ num.times do |n|
71
+ mock_id = UUIDTools::UUID.random_create.to_s.gsub(/\-/,'')
72
+ res[mock_id] = {
73
+ "mock_id" => mock_id,
74
+ "FirstName" => Faker::Name.first_name,
75
+ "LastName" => Faker::Name.last_name,
76
+ "Email" => Faker::Internet.free_email,
77
+ "Company" => Faker::Company.name,
78
+ "JobTitle" => title,
79
+ "Phone1" => Faker::PhoneNumber.phone_number
80
+ }
81
+ if generate_blob
82
+ img_file_name = IMAGE_FILES[rand(IMAGE_FILES.size)]
83
+ res[mock_id]["img_file-rhoblob"] = img_file_name
84
+ res[mock_id]["img_file_size"] =
85
+ File.size(File.join(File.dirname(__FILE__), "..", "testdata", "images", "#{img_file_name}")).to_s
86
+ res[mock_id]["filename"] = img_file_name
87
+
88
+ # Additional fields: from 0 to 50 will be added to existing 10 ones (total upto 60)
89
+ words = Faker::Lorem.words(rand(50))
90
+ words.each do |word|
91
+ res[mock_id]["#{word}"] = word unless EXCLUDE_LIST.include?(word)
92
+ end
93
+ end
94
+ end
95
+ res
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,10 @@
1
+ module Bench
2
+ module Timer
3
+ def time
4
+ start = Time.now
5
+ yield
6
+ end_time = Time.now
7
+ end_time.to_f - start.to_f
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,49 @@
1
+ module Bench
2
+ module Utils
3
+ include Logging
4
+
5
+ def compare(name1,s1,name2,s2)
6
+ r1 = diff([],name1,s1,name2,s2)
7
+ r2 = diff([],name2,s2,name1,s1)
8
+ r1.size > r2.size ? r1 : r2
9
+ end
10
+
11
+ def diff(res,lname,lvalue,rname,rvalue,path=[])
12
+
13
+ return res if lvalue == rvalue
14
+
15
+ if lvalue.is_a?(Array) and rvalue
16
+ lvalue.each_index do |index|
17
+ p = Array.new(path)
18
+ p << index
19
+ diff(res,lname,lvalue[index],rname,rvalue.at(index),p)
20
+ end
21
+ elsif lvalue.is_a?(Hash) and rvalue
22
+ lvalue.each do |key,value|
23
+ p = Array.new(path)
24
+ p << key
25
+ diff(res,lname,value,rname,rvalue[key],p)
26
+ end
27
+ else
28
+ res << {:path=>path,lname=>lvalue,rname=>rvalue}
29
+ end
30
+
31
+ res
32
+ end
33
+
34
+ def compare_and_log(expected,actual,caller)
35
+ if expected != actual
36
+ bench_log "#{log_prefix} Verify error at: " + caller
37
+ bench_log "#{log_prefix} Message diff: "
38
+ compare(:expected,expected,:actual,actual).each do |diff|
39
+ bench_log "#{log_prefix} Path: #{diff[:path].join('/')}"
40
+ bench_log "#{log_prefix} Expected: #{diff[:expected].inspect}"
41
+ bench_log "#{log_prefix} Actual: #{diff[:actual].inspect}"
42
+ end
43
+ 1
44
+ else
45
+ 0
46
+ end
47
+ end
48
+ end
49
+ end