seomoz-riak-client 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/Gemfile +27 -0
  2. data/Guardfile +14 -0
  3. data/Rakefile +76 -0
  4. data/erl_src/riak_kv_test_backend.beam +0 -0
  5. data/erl_src/riak_kv_test_backend.erl +174 -0
  6. data/erl_src/riak_search_test_backend.beam +0 -0
  7. data/erl_src/riak_search_test_backend.erl +175 -0
  8. data/lib/active_support/cache/riak_store.rb +2 -0
  9. data/lib/riak.rb +21 -0
  10. data/lib/riak/bucket.rb +215 -0
  11. data/lib/riak/cache_store.rb +84 -0
  12. data/lib/riak/client.rb +415 -0
  13. data/lib/riak/client/beefcake/messages.rb +147 -0
  14. data/lib/riak/client/beefcake/object_methods.rb +92 -0
  15. data/lib/riak/client/beefcake_protobuffs_backend.rb +176 -0
  16. data/lib/riak/client/excon_backend.rb +65 -0
  17. data/lib/riak/client/http_backend.rb +203 -0
  18. data/lib/riak/client/http_backend/configuration.rb +46 -0
  19. data/lib/riak/client/http_backend/key_streamer.rb +43 -0
  20. data/lib/riak/client/http_backend/object_methods.rb +94 -0
  21. data/lib/riak/client/http_backend/request_headers.rb +34 -0
  22. data/lib/riak/client/http_backend/transport_methods.rb +218 -0
  23. data/lib/riak/client/net_http_backend.rb +79 -0
  24. data/lib/riak/client/protobuffs_backend.rb +97 -0
  25. data/lib/riak/client/pump.rb +30 -0
  26. data/lib/riak/client/search.rb +94 -0
  27. data/lib/riak/core_ext.rb +6 -0
  28. data/lib/riak/core_ext/blank.rb +53 -0
  29. data/lib/riak/core_ext/extract_options.rb +7 -0
  30. data/lib/riak/core_ext/json.rb +15 -0
  31. data/lib/riak/core_ext/slice.rb +18 -0
  32. data/lib/riak/core_ext/stringify_keys.rb +10 -0
  33. data/lib/riak/core_ext/symbolize_keys.rb +10 -0
  34. data/lib/riak/core_ext/to_param.rb +31 -0
  35. data/lib/riak/encoding.rb +6 -0
  36. data/lib/riak/failed_request.rb +81 -0
  37. data/lib/riak/i18n.rb +3 -0
  38. data/lib/riak/json.rb +28 -0
  39. data/lib/riak/link.rb +85 -0
  40. data/lib/riak/locale/en.yml +48 -0
  41. data/lib/riak/map_reduce.rb +206 -0
  42. data/lib/riak/map_reduce/filter_builder.rb +94 -0
  43. data/lib/riak/map_reduce/phase.rb +98 -0
  44. data/lib/riak/map_reduce_error.rb +7 -0
  45. data/lib/riak/robject.rb +290 -0
  46. data/lib/riak/search.rb +3 -0
  47. data/lib/riak/serializers.rb +74 -0
  48. data/lib/riak/stamp.rb +77 -0
  49. data/lib/riak/test_server.rb +252 -0
  50. data/lib/riak/util/escape.rb +45 -0
  51. data/lib/riak/util/fiber1.8.rb +48 -0
  52. data/lib/riak/util/headers.rb +53 -0
  53. data/lib/riak/util/multipart.rb +52 -0
  54. data/lib/riak/util/multipart/stream_parser.rb +62 -0
  55. data/lib/riak/util/tcp_socket_extensions.rb +58 -0
  56. data/lib/riak/util/translation.rb +19 -0
  57. data/lib/riak/walk_spec.rb +105 -0
  58. data/riak-client.gemspec +55 -0
  59. data/seomoz-riak-client.gemspec +55 -0
  60. data/spec/fixtures/cat.jpg +0 -0
  61. data/spec/fixtures/multipart-blank.txt +7 -0
  62. data/spec/fixtures/multipart-mapreduce.txt +10 -0
  63. data/spec/fixtures/multipart-with-body.txt +16 -0
  64. data/spec/fixtures/server.cert.crt +15 -0
  65. data/spec/fixtures/server.cert.key +15 -0
  66. data/spec/fixtures/test.pem +1 -0
  67. data/spec/integration/riak/cache_store_spec.rb +154 -0
  68. data/spec/integration/riak/http_backends_spec.rb +58 -0
  69. data/spec/integration/riak/protobuffs_backends_spec.rb +32 -0
  70. data/spec/integration/riak/test_server_spec.rb +161 -0
  71. data/spec/riak/beefcake_protobuffs_backend_spec.rb +59 -0
  72. data/spec/riak/bucket_spec.rb +205 -0
  73. data/spec/riak/client_spec.rb +517 -0
  74. data/spec/riak/core_ext/to_param_spec.rb +15 -0
  75. data/spec/riak/escape_spec.rb +69 -0
  76. data/spec/riak/excon_backend_spec.rb +64 -0
  77. data/spec/riak/headers_spec.rb +38 -0
  78. data/spec/riak/http_backend/configuration_spec.rb +51 -0
  79. data/spec/riak/http_backend/object_methods_spec.rb +217 -0
  80. data/spec/riak/http_backend/transport_methods_spec.rb +117 -0
  81. data/spec/riak/http_backend_spec.rb +269 -0
  82. data/spec/riak/link_spec.rb +71 -0
  83. data/spec/riak/map_reduce/filter_builder_spec.rb +32 -0
  84. data/spec/riak/map_reduce/phase_spec.rb +136 -0
  85. data/spec/riak/map_reduce_spec.rb +310 -0
  86. data/spec/riak/multipart_spec.rb +23 -0
  87. data/spec/riak/net_http_backend_spec.rb +16 -0
  88. data/spec/riak/robject_spec.rb +427 -0
  89. data/spec/riak/search_spec.rb +178 -0
  90. data/spec/riak/serializers_spec.rb +93 -0
  91. data/spec/riak/stamp_spec.rb +54 -0
  92. data/spec/riak/stream_parser_spec.rb +53 -0
  93. data/spec/riak/walk_spec_spec.rb +195 -0
  94. data/spec/spec_helper.rb +39 -0
  95. data/spec/support/drb_mock_server.rb +39 -0
  96. data/spec/support/http_backend_implementation_examples.rb +266 -0
  97. data/spec/support/integration_setup.rb +10 -0
  98. data/spec/support/mock_server.rb +81 -0
  99. data/spec/support/mocks.rb +4 -0
  100. data/spec/support/test_server.yml.example +2 -0
  101. data/spec/support/unified_backend_examples.rb +255 -0
  102. metadata +271 -0
@@ -0,0 +1,55 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{seomoz-riak-client}
5
+ s.version = "1.0.0.pre"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Sean Cribbs"]
9
+ s.date = %q{2011-11-18}
10
+ s.description = %q{riak-client is a rich client for Riak, the distributed database by Basho. It supports the full HTTP interface including storage operations, bucket configuration, link-walking and map-reduce.}
11
+ s.email = %q{sean@basho.com}
12
+ s.files = ["erl_src/riak_kv_test_backend.beam", "erl_src/riak_kv_test_backend.erl", "erl_src/riak_search_test_backend.beam", "erl_src/riak_search_test_backend.erl", "Gemfile", "Guardfile", "lib/active_support/cache/riak_store.rb", "lib/riak/bucket.rb", "lib/riak/cache_store.rb", "lib/riak/client/beefcake/messages.rb", "lib/riak/client/beefcake/object_methods.rb", "lib/riak/client/beefcake_protobuffs_backend.rb", "lib/riak/client/excon_backend.rb", "lib/riak/client/http_backend/configuration.rb", "lib/riak/client/http_backend/key_streamer.rb", "lib/riak/client/http_backend/object_methods.rb", "lib/riak/client/http_backend/request_headers.rb", "lib/riak/client/http_backend/transport_methods.rb", "lib/riak/client/http_backend.rb", "lib/riak/client/net_http_backend.rb", "lib/riak/client/protobuffs_backend.rb", "lib/riak/client/pump.rb", "lib/riak/client/search.rb", "lib/riak/client.rb", "lib/riak/core_ext/blank.rb", "lib/riak/core_ext/extract_options.rb", "lib/riak/core_ext/json.rb", "lib/riak/core_ext/slice.rb", "lib/riak/core_ext/stringify_keys.rb", "lib/riak/core_ext/symbolize_keys.rb", "lib/riak/core_ext/to_param.rb", "lib/riak/core_ext.rb", "lib/riak/encoding.rb", "lib/riak/failed_request.rb", "lib/riak/i18n.rb", "lib/riak/json.rb", "lib/riak/link.rb", "lib/riak/locale/en.yml", "lib/riak/map_reduce/filter_builder.rb", "lib/riak/map_reduce/phase.rb", "lib/riak/map_reduce.rb", "lib/riak/map_reduce_error.rb", "lib/riak/robject.rb", "lib/riak/search.rb", "lib/riak/serializers.rb", "lib/riak/stamp.rb", "lib/riak/test_server.rb", "lib/riak/util/escape.rb", "lib/riak/util/fiber1.8.rb", "lib/riak/util/headers.rb", "lib/riak/util/multipart/stream_parser.rb", "lib/riak/util/multipart.rb", "lib/riak/util/tcp_socket_extensions.rb", "lib/riak/util/translation.rb", "lib/riak/walk_spec.rb", "lib/riak.rb", "Rakefile", "riak-client.gemspec", "seomoz-riak-client.gemspec", "spec/fixtures/cat.jpg", "spec/fixtures/multipart-blank.txt", "spec/fixtures/multipart-mapreduce.txt", "spec/fixtures/multipart-with-body.txt", "spec/fixtures/server.cert.crt", "spec/fixtures/server.cert.key", "spec/fixtures/test.pem", "spec/integration/riak/cache_store_spec.rb", "spec/integration/riak/http_backends_spec.rb", "spec/integration/riak/protobuffs_backends_spec.rb", "spec/integration/riak/test_server_spec.rb", "spec/riak/beefcake_protobuffs_backend_spec.rb", "spec/riak/bucket_spec.rb", "spec/riak/client_spec.rb", "spec/riak/core_ext/to_param_spec.rb", "spec/riak/escape_spec.rb", "spec/riak/excon_backend_spec.rb", "spec/riak/headers_spec.rb", "spec/riak/http_backend/configuration_spec.rb", "spec/riak/http_backend/object_methods_spec.rb", "spec/riak/http_backend/transport_methods_spec.rb", "spec/riak/http_backend_spec.rb", "spec/riak/link_spec.rb", "spec/riak/map_reduce/filter_builder_spec.rb", "spec/riak/map_reduce/phase_spec.rb", "spec/riak/map_reduce_spec.rb", "spec/riak/multipart_spec.rb", "spec/riak/net_http_backend_spec.rb", "spec/riak/robject_spec.rb", "spec/riak/search_spec.rb", "spec/riak/serializers_spec.rb", "spec/riak/stamp_spec.rb", "spec/riak/stream_parser_spec.rb", "spec/riak/walk_spec_spec.rb", "spec/spec_helper.rb", "spec/support/drb_mock_server.rb", "spec/support/http_backend_implementation_examples.rb", "spec/support/integration_setup.rb", "spec/support/mock_server.rb", "spec/support/mocks.rb", "spec/support/test_server.yml.example", "spec/support/unified_backend_examples.rb"]
13
+ s.homepage = %q{http://seancribbs.github.com/ripple}
14
+ s.require_paths = ["lib"]
15
+ s.rubygems_version = %q{1.3.5}
16
+ s.summary = %q{riak-client is a rich client for Riak, the distributed database by Basho.}
17
+ s.test_files = ["lib/riak/walk_spec.rb", "spec/integration/riak/cache_store_spec.rb", "spec/integration/riak/http_backends_spec.rb", "spec/integration/riak/protobuffs_backends_spec.rb", "spec/integration/riak/test_server_spec.rb", "spec/riak/beefcake_protobuffs_backend_spec.rb", "spec/riak/bucket_spec.rb", "spec/riak/client_spec.rb", "spec/riak/core_ext/to_param_spec.rb", "spec/riak/escape_spec.rb", "spec/riak/excon_backend_spec.rb", "spec/riak/headers_spec.rb", "spec/riak/http_backend/configuration_spec.rb", "spec/riak/http_backend/object_methods_spec.rb", "spec/riak/http_backend/transport_methods_spec.rb", "spec/riak/http_backend_spec.rb", "spec/riak/link_spec.rb", "spec/riak/map_reduce/filter_builder_spec.rb", "spec/riak/map_reduce/phase_spec.rb", "spec/riak/map_reduce_spec.rb", "spec/riak/multipart_spec.rb", "spec/riak/net_http_backend_spec.rb", "spec/riak/robject_spec.rb", "spec/riak/search_spec.rb", "spec/riak/serializers_spec.rb", "spec/riak/stamp_spec.rb", "spec/riak/stream_parser_spec.rb", "spec/riak/walk_spec_spec.rb"]
18
+
19
+ if s.respond_to? :specification_version then
20
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
21
+ s.specification_version = 3
22
+
23
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
24
+ s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
25
+ s.add_development_dependency(%q<fakeweb>, [">= 1.2"])
26
+ s.add_development_dependency(%q<rack>, [">= 1.0"])
27
+ s.add_development_dependency(%q<excon>, ["~> 0.6.1"])
28
+ s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
29
+ s.add_runtime_dependency(%q<i18n>, [">= 0.4.0"])
30
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
31
+ s.add_runtime_dependency(%q<beefcake>, ["= 0.3.2"])
32
+ s.add_runtime_dependency(%q<multi_json>, ["~> 1.0.0"])
33
+ else
34
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
35
+ s.add_dependency(%q<fakeweb>, [">= 1.2"])
36
+ s.add_dependency(%q<rack>, [">= 1.0"])
37
+ s.add_dependency(%q<excon>, ["~> 0.6.1"])
38
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
39
+ s.add_dependency(%q<i18n>, [">= 0.4.0"])
40
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
41
+ s.add_dependency(%q<beefcake>, ["= 0.3.2"])
42
+ s.add_dependency(%q<multi_json>, ["~> 1.0.0"])
43
+ end
44
+ else
45
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
46
+ s.add_dependency(%q<fakeweb>, [">= 1.2"])
47
+ s.add_dependency(%q<rack>, [">= 1.0"])
48
+ s.add_dependency(%q<excon>, ["~> 0.6.1"])
49
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
50
+ s.add_dependency(%q<i18n>, [">= 0.4.0"])
51
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
52
+ s.add_dependency(%q<beefcake>, ["= 0.3.2"])
53
+ s.add_dependency(%q<multi_json>, ["~> 1.0.0"])
54
+ end
55
+ end
Binary file
@@ -0,0 +1,7 @@
1
+
2
+ --73NmmA8dJxSB5nL2dVerpFIi8ze
3
+ Content-Type: multipart/mixed; boundary=8fPXq9XfV15txMoV1IbA3hovEij
4
+
5
+ --8fPXq9XfV15txMoV1IbA3hovEij--
6
+
7
+ --73NmmA8dJxSB5nL2dVerpFIi8ze--
@@ -0,0 +1,10 @@
1
+
2
+ --NT6cqYFYCfbYZsocVt15tNWCpG9
3
+ Content-Type: application/json
4
+
5
+ {"phase":0,"data":["source :gemcutter\n\ngem 'i18n'\ngem 'builder'\ngem 'rspec', \"~>2.0.0\"\ngem 'fakeweb', \">=1.2\"\ngem 'rack', '>=1.0'\ngem 'rake'\ngem 'bundler'\ngem 'excon', \"~>0.3.4\"\n\nif defined? JRUBY_VERSION\n gem 'json'\n gem 'jruby-openssl'\nelse\n gem 'curb', '>=0.6'\n gem 'yajl-ruby'\nend\n\ngroup :integration do\n gem 'activesupport', '~>3.0'\nend\n"]}
6
+ --NT6cqYFYCfbYZsocVt15tNWCpG9
7
+ Content-Type: application/json
8
+
9
+ {"phase":0,"data":["source \"http://rubygems.org\"\n\ngem 'rake'\ngem 'gollum-site'\ngem 'rdiscount'\ngem 'RedCloth'\ngem 'rspec'\n"]}
10
+ --NT6cqYFYCfbYZsocVt15tNWCpG9--
@@ -0,0 +1,16 @@
1
+
2
+ --5EiMOjuGavQ2IbXAqsJPLLfJNlA
3
+ Content-Type: multipart/mixed; boundary=7extjTzvYIKVMVHowUiTn0LfvSs
4
+
5
+ --7extjTzvYIKVMVHowUiTn0LfvSs
6
+ X-Riak-Vclock: a85hYGBgyWDKBVHMr9s3ZzAlMuaxMtyZcPAIH1RYyObHDqiwxIZjcOG1M98chAq3bUQIz7SSFQEKM4FUbwMKZwEA
7
+ Location: /riak/foo/baz
8
+ Content-Type: text/plain
9
+ Link: </riak/foo>; rel="up"
10
+ Etag: 6JdI51eFrvv5lDwY6un7a2
11
+ Last-Modified: Sat, 16 Jan 2010 22:13:44 GMT
12
+
13
+ SCP sloooow....
14
+ --7extjTzvYIKVMVHowUiTn0LfvSs--
15
+
16
+ --5EiMOjuGavQ2IbXAqsJPLLfJNlA--
@@ -0,0 +1,15 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICPzCCAagCCQDfZhEdJjSgTDANBgkqhkiG9w0BAQUFADBkMQswCQYDVQQGEwJV
3
+ UzELMAkGA1UECBMCTkMxEjAQBgNVBAcTCUNoYXJsb3R0ZTEOMAwGA1UEChMFQmFz
4
+ aG8xEDAOBgNVBAsTB1N1cHBvcnQxEjAQBgNVBAMTCTEyNy4wLjAuMTAeFw0xMTAz
5
+ MjYxNjMzMzNaFw0zODA4MTAxNjMzMzNaMGQxCzAJBgNVBAYTAlVTMQswCQYDVQQI
6
+ EwJOQzESMBAGA1UEBxMJQ2hhcmxvdHRlMQ4wDAYDVQQKEwVCYXNobzEQMA4GA1UE
7
+ CxMHU3VwcG9ydDESMBAGA1UEAxMJMTI3LjAuMC4xMIGfMA0GCSqGSIb3DQEBAQUA
8
+ A4GNADCBiQKBgQCtfHMCsR86HQEAsO52/WvtFWCEigXll0rxYjXvdqeszEPEMFIy
9
+ Qlg3GlRxH51YrBzp46ReF9Qv5sf0Nh6SR7HGzlWmMEVfPeuAKcz1fzVcjD+IXWHK
10
+ qklAQjpxz+18dvaGxQ7ZJMPsBlq1v64siTLXI0yhjxXOuQPJWrWsvuuXkQIDAQAB
11
+ MA0GCSqGSIb3DQEBBQUAA4GBAIqt1A5Ah7s2oUoYQ8YCKC83fKbXbbNCiLFLwIzy
12
+ TGYXd8j7JTfeY8ettbtitlYgP+ouf23LzonuMo47GRuMgVKRWm4l+ZVMP5Qbkx9t
13
+ uspx+6lHUWnMT9aRdP9/2I7dscyfuhtzs0UxddADLzL9Cif4Y06E1NhR/KK+zo46
14
+ Nep8
15
+ -----END CERTIFICATE-----
@@ -0,0 +1,15 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIICXQIBAAKBgQCtfHMCsR86HQEAsO52/WvtFWCEigXll0rxYjXvdqeszEPEMFIy
3
+ Qlg3GlRxH51YrBzp46ReF9Qv5sf0Nh6SR7HGzlWmMEVfPeuAKcz1fzVcjD+IXWHK
4
+ qklAQjpxz+18dvaGxQ7ZJMPsBlq1v64siTLXI0yhjxXOuQPJWrWsvuuXkQIDAQAB
5
+ AoGBAJIguzdPPgBTId8VKSes+lVupie9oo3qy8NaeBfGGCIixAnisbmHzIpNcUb/
6
+ 3CcuggQ4LODcrWvTtiTr2QBZx1FL7E4POBJl/N7zJMaQd+pGjmrJGfv5haSSQN+H
7
+ r74Ix3HCd0RPdSgt5pmlT4KfsqkfRmqsPd6Nw54zbyLFMlTpAkEA4ar3ZJi2+Y+u
8
+ FH3AycXuPdDtVW0tKFtxfvKlS48gshB6gmkd06Ugss5eZkdbSY0voAp88Tr2shOJ
9
+ +pXc++Zl6wJBAMTN9K9k728cVCf41pR6mDVxIaaqjJeY4DWppGQFSqw/fmYz/Quu
10
+ PlTvk6pGRYiGN6y9CZFNoL2I/SWcd4ukrXMCQCyfYOHsbKn2Zka5Awki8VQZ3wQ4
11
+ XWiQhGXE1ziUqbNsHL1yyaoTCd8xfWseCwgFOficek49CZD22h7JyXOqAFcCQCn2
12
+ mFPFu9//NFqJjod+VHIgu0IkX3H7oOMQVwMUtcVgjH0SXMRe1N+bbesCrNTdeYWV
13
+ kTKwULPZP9EDOeJGrM0CQQCsX+8VZ15yKTy6ADINrOt26PNpD4ib4552TE6T/1wG
14
+ LKdjn5l0qB5K7ILc22z3LCenNBa0Uxbg5/RSdoX57aHA
15
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1 @@
1
+ i-am-a-pem
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+ require 'riak/cache_store'
3
+
4
+ describe Riak::CacheStore do
5
+ before :all do
6
+ if $test_server
7
+ @web_port = 9000
8
+ $test_server.start
9
+ end
10
+ end
11
+
12
+ before do
13
+ @web_port ||= 8098
14
+ @cache = ActiveSupport::Cache.lookup_store(:riak_store, :http_port => @web_port)
15
+ @cleanup = true
16
+ end
17
+
18
+ after do
19
+ if @cleanup
20
+ if $test_server
21
+ $test_server.recycle
22
+ Thread.current[:curl_easy_handle] = nil
23
+ else
24
+ @cache.bucket.keys(:force => true).each do |k|
25
+ @cache.bucket.delete(k, :rw => 1) unless k.blank?
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "Riak integration" do
32
+ before do
33
+ @cleanup = false
34
+ end
35
+
36
+ it "should have a client" do
37
+ @cache.should respond_to(:client)
38
+ @cache.client.should be_kind_of(Riak::Client)
39
+ end
40
+
41
+ it "should have a bucket to store entries in" do
42
+ @cache.bucket.should be_kind_of(Riak::Bucket)
43
+ end
44
+
45
+ it "should configure the client according to the initialized options" do
46
+ @cache = ActiveSupport::Cache.lookup_store(:riak_store, :http_port => 10000)
47
+ @cache.client.http_port.should == 10000
48
+ end
49
+
50
+ it "should choose the bucket according to the initializer option" do
51
+ @cache = ActiveSupport::Cache.lookup_store(:riak_store, :bucket => "foobar", :http_port => @web_port)
52
+ @cache.bucket.name.should == "foobar"
53
+ end
54
+
55
+ it "should set the N value to 2 by default" do
56
+ @cache.bucket.n_value.should == 2
57
+ end
58
+
59
+ it "should set the N value to the specified value" do
60
+ @cache = ActiveSupport::Cache.lookup_store(:riak_store, :n_value => 1, :http_port => @web_port)
61
+ @cache.bucket.n_value.should == 1
62
+ end
63
+
64
+ it "should set the bucket R value to 1 by default" do
65
+ @cache.bucket.r.should == 1
66
+ end
67
+
68
+ it "should set the bucket R default to the specified value" do
69
+ @cache = ActiveSupport::Cache.lookup_store(:riak_store, :r => "quorum", :http_port => @web_port)
70
+ @cache.bucket.r.should == "quorum"
71
+ end
72
+
73
+ it "should set the bucket W value to 1 by default" do
74
+ @cache.bucket.w.should == 1
75
+ end
76
+
77
+ it "should set the bucket W default to the specified value" do
78
+ @cache = ActiveSupport::Cache.lookup_store(:riak_store, :w => "all", :http_port => @web_port)
79
+ @cache.bucket.w.should == "all"
80
+ end
81
+
82
+ it "should set the bucket DW value to 0 by default" do
83
+ @cache.bucket.dw.should == 0
84
+ end
85
+
86
+ it "should set the bucket DW default to the specified value" do
87
+ @cache = ActiveSupport::Cache.lookup_store(:riak_store, :dw => "quorum", :http_port => @web_port)
88
+ @cache.bucket.dw.should == "quorum"
89
+ end
90
+
91
+ it "should set the bucket RW value to quorum by default" do
92
+ @cache.bucket.rw.should == "quorum"
93
+ end
94
+
95
+ it "should set the bucket RW default to the specified value" do
96
+ @cache = ActiveSupport::Cache.lookup_store(:riak_store, :rw => "all", :http_port => @web_port)
97
+ @cache.bucket.rw.should == "all"
98
+ end
99
+ end
100
+
101
+
102
+ it "should read and write strings" do
103
+ @cache.write('foo', 'bar')
104
+ @cache.read('foo').should == 'bar'
105
+ end
106
+
107
+ it "should read and write hashes" do
108
+ @cache.write('foo', {:a => "b"})
109
+ @cache.read('foo').should == {:a => "b"}
110
+ end
111
+
112
+ it "should read and write integers" do
113
+ @cache.write('foo', 1)
114
+ @cache.read('foo').should == 1
115
+ end
116
+
117
+ it "should read and write nil" do
118
+ @cache.write('foo', nil)
119
+ @cache.read('foo').should be_nil
120
+ end
121
+
122
+ it "should return the stored value when fetching on hit" do
123
+ @cache.write('foo', 'bar')
124
+ @cache.fetch('foo'){'baz'}.should == 'bar'
125
+ end
126
+
127
+ it "should return the default value when fetching on miss" do
128
+ @cache.fetch('foo'){ 'baz' }.should == 'baz'
129
+ end
130
+
131
+ it "should return the default value when forcing a miss" do
132
+ @cache.fetch('foo', :force => true){'bar'}.should == 'bar'
133
+ end
134
+
135
+ it "should detect if a value exists in the cache" do
136
+ @cache.write('foo', 'bar')
137
+ @cache.exist?('foo').should be_true
138
+ end
139
+
140
+ it "should delete matching keys from the cache" do
141
+ @cache.write('foo', 'bar')
142
+ @cache.write('green', 'thumb')
143
+ @cache.delete_matched(/foo/)
144
+ @cache.read('foo').should be_nil
145
+ @cache.read('green').should == 'thumb'
146
+ end
147
+
148
+ it "should delete a single key from the cache" do
149
+ @cache.write('foo', 'bar')
150
+ @cache.read('foo').should == 'bar'
151
+ @cache.delete('foo')
152
+ @cache.read('foo').should be_nil
153
+ end
154
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe "HTTP" do
4
+ before :all do
5
+ if $test_server
6
+ @web_port = 9000
7
+ $test_server.start
8
+ end
9
+ end
10
+
11
+ before do
12
+ @web_port ||= 8098
13
+ @client = Riak::Client.new(:http_port => @web_port)
14
+ end
15
+
16
+ after do
17
+ $test_server.recycle if $test_server.started?
18
+ end
19
+
20
+ [:ExconBackend, :NetHTTPBackend].each do |klass|
21
+ bklass = Riak::Client.const_get(klass)
22
+ if bklass.configured?
23
+ describe klass.to_s do
24
+ before do
25
+ @backend = bklass.new(@client)
26
+ end
27
+
28
+ it_should_behave_like "Unified backend API"
29
+ end
30
+ end
31
+ end
32
+
33
+ class Reader < Array
34
+ def read(*args)
35
+ shift
36
+ end
37
+
38
+ def size
39
+ join.size
40
+ end
41
+ end
42
+
43
+ class SizelessReader < Reader
44
+ undef :size
45
+ end
46
+
47
+ describe 'NetHTTPBackend' do
48
+ subject { Riak::Client::NetHTTPBackend.new(@client) }
49
+ let(:file) { File.open(__FILE__) }
50
+ let(:sized) { Reader.new(["foo", "bar", "baz"]) }
51
+ let(:sizeless) { SizelessReader.new(["foo", "bar", "baz"]) }
52
+ it "should set the content-length or transfer-encoding properly on IO uploads" do
53
+ lambda { subject.put(204, "/riak/nethttp", "test-file", file, {"Content-Type" => "text/plain"}) }.should_not raise_error
54
+ lambda { subject.put(204, "/riak/nethttp", "test-sized", sized, {"Content-Type" => "text/plain"}) }.should_not raise_error
55
+ lambda { subject.put(204, "/riak/nethttp", "test-file", sizeless, {"Content-Type" => "text/plain"}) }.should_not raise_error
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Protocol Buffers" do
4
+ before :all do
5
+ if $test_server
6
+ @pbc_port = 9002
7
+ $test_server.start
8
+ end
9
+ end
10
+
11
+ before do
12
+ @pbc_port ||= 8087
13
+ @client = Riak::Client.new(:pb_port => @pbc_port, :protocol => "pbc")
14
+ end
15
+
16
+ after do
17
+ $test_server.recycle if $test_server.started?
18
+ end
19
+
20
+ [:BeefcakeProtobuffsBackend].each do |klass|
21
+ bklass = Riak::Client.const_get(klass)
22
+ if bklass.configured?
23
+ describe klass.to_s do
24
+ before do
25
+ @backend = bklass.new(@client)
26
+ end
27
+
28
+ it_should_behave_like "Unified backend API"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,161 @@
1
+ require 'spec_helper'
2
+
3
+ if $test_server
4
+ describe Riak::TestServer do
5
+ before do
6
+ @server = $test_server
7
+ end
8
+
9
+ after do
10
+ @server.stop
11
+ @server.cleanup
12
+ end
13
+
14
+ describe "isolation from and modification of the existing install" do
15
+ before do
16
+ @server.prepare!
17
+ @riak_bin = "#{@server.temp_dir}/bin/riak"
18
+ @vm_args = "#{@server.temp_dir}/etc/vm.args"
19
+ @app_config = "#{@server.temp_dir}/etc/app.config"
20
+ end
21
+
22
+ describe "for app.config" do
23
+ it "should create the app.config file in the temporary directory" do
24
+ File.should be_exist(File.expand_path(@app_config))
25
+ end
26
+
27
+ it "should be a correct Erlang config" do
28
+ config = File.read(@app_config)
29
+ config[-2..-1].should == '].'
30
+ config[0..0].should == '['
31
+ end
32
+
33
+ it "should set the backend to use the test backend" do
34
+ File.readlines(@app_config).should be_any do |line|
35
+ line =~ /\{storage_backend\s*,\s*(.*)\}/ && $1 == "riak_kv_test_backend"
36
+ end
37
+ end
38
+
39
+ it "should set the default ports to 9000-9002" do
40
+ config = File.readlines(@app_config)
41
+ config.should be_any do |line|
42
+ line =~ /\{web_port\s*,\s*(.*)\}/ && $1 == "9000"
43
+ end
44
+ config.should be_any do |line|
45
+ line =~ /\{handoff_port\s*,\s*(.*)\}/ && $1 == "9001"
46
+ end
47
+ config.should be_any do |line|
48
+ line =~ /\{pb_port\s*,\s*(.*)\}/ && $1 == "9002"
49
+ end
50
+ end
51
+
52
+ it "should set the ring directory to point to the temporary directory" do
53
+ config = File.readlines(@app_config)
54
+ config.should be_any do |line|
55
+ line =~ /\{ring_state_dir\s*,\s*(.*)\}/ && $1 == File.join(@server.temp_dir, "data", "ring")
56
+ end
57
+ end
58
+ end
59
+
60
+ describe "for vm.args" do
61
+ it "should create the vm.args file in the temporary directory" do
62
+ File.should be_exist(File.expand_path(@vm_args))
63
+ end
64
+
65
+ it "should set a quasi-random node name" do
66
+ File.readlines(@vm_args).should be_any do |line|
67
+ line =~ /^-name (.*)/ && $1 =~ /riaktest\d+@/
68
+ end
69
+ end
70
+
71
+ it "should set a quasi-random cookie" do
72
+ File.readlines(@vm_args).should be_any do |line|
73
+ line =~ /^-setcookie (.*)/ && $1 != "riak"
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "for the riak script" do
79
+ it "should create the script in the temporary directory" do
80
+ File.should be_exist(File.expand_path(@riak_bin))
81
+ end
82
+
83
+ it "should modify the RUNNER_SCRIPT_DIR to point to the temporary directory" do
84
+ File.readlines(@riak_bin).should be_any do |line|
85
+ line =~ /RUNNER_SCRIPT_DIR=(.*)/ && $1 == File.expand_path("#{@server.temp_dir}/bin")
86
+
87
+ end
88
+ end
89
+
90
+ it "should modify the RUNNER_ETC_DIR to point to the temporary directory" do
91
+ File.readlines(@riak_bin).should be_any do |line|
92
+ line =~ /RUNNER_ETC_DIR=(.*)/ && $1 == File.expand_path("#{@server.temp_dir}/etc")
93
+ end
94
+ end
95
+
96
+ it "should modify the RUNNER_USER to point to the current user" do
97
+ File.readlines(@riak_bin).should be_any do |line|
98
+ line =~ /RUNNER_USER=(.*)/ && $1 == (ENV['USER'] || `whoami`)
99
+ end
100
+ end
101
+
102
+ it "should modify the RUNNER_LOG_DIR to point to the temporary directory" do
103
+ File.readlines(@riak_bin).should be_any do |line|
104
+ line =~ /RUNNER_LOG_DIR=(.*)/ && $1 == File.expand_path("#{@server.temp_dir}/log")
105
+ end
106
+ end
107
+
108
+ it "should modify the RUNNER_BASE_DIR so that it is not relative" do
109
+ File.readlines(@riak_bin).should be_any do |line|
110
+ line =~ /RUNNER_BASE_DIR=(.*)/ && $1.strip != "${RUNNER_SCRIPT_DIR%/*}" && File.directory?($1)
111
+ end
112
+ end
113
+
114
+ it "should modify the PIPE_DIR to point to the temporary directory" do
115
+ File.readlines(@riak_bin).should be_any do |line|
116
+ line =~ /PIPE_DIR=(.*)/ && $1 == File.expand_path("#{@server.temp_dir}/pipe") && File.directory?($1)
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ it "should cleanup the existing config" do
123
+ @server.prepare!
124
+ @server.cleanup
125
+ File.should_not be_directory(@server.temp_dir)
126
+ end
127
+
128
+ it "should start Riak in the background" do
129
+ @server.prepare!
130
+ @server.start.should be_true
131
+ @server.should be_started
132
+ end
133
+
134
+ it "should stop a started test server" do
135
+ @server.prepare!
136
+ @server.start.should be_true
137
+ @server.stop
138
+ @server.should_not be_started
139
+ end
140
+
141
+ it "should recycle the server contents" do
142
+ begin
143
+ @server.prepare!
144
+ @server.start.should be_true
145
+
146
+ client = Riak::Client.new(:http_port => 9000)
147
+ obj = client['test_bucket'].new("test_item")
148
+ obj.data = {"data" => "testing"}
149
+ obj.store rescue nil
150
+
151
+ @server.recycle
152
+ @server.should be_started
153
+ lambda do
154
+ client['test_bucket']['test_item']
155
+ end.should raise_error(Riak::FailedRequest)
156
+ ensure
157
+ @server.stop
158
+ end
159
+ end
160
+ end
161
+ end