├── .document ├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .gitmodules ├── .rspec ├── .rubocop.yml ├── .rubocop_todo.yml ├── .travis.yml ├── Gemfile ├── Guardfile ├── LICENSE.md ├── Makefile ├── NOTICE ├── README.md ├── RELNOTES.md ├── Rakefile ├── benchmark └── multiget.rb ├── build └── publish ├── lib ├── riak.rb └── riak │ ├── bucket.rb │ ├── bucket_properties.rb │ ├── bucket_type.rb │ ├── bucket_typed │ └── bucket.rb │ ├── client.rb │ ├── client │ ├── beefcake │ │ ├── bucket_properties_operator.rb │ │ ├── crdt │ │ │ ├── counter_loader.rb │ │ │ ├── grow_only_set_loader.rb │ │ │ ├── hyper_log_log_loader.rb │ │ │ ├── map_loader.rb │ │ │ └── set_loader.rb │ │ ├── crdt_loader.rb │ │ ├── crdt_operator.rb │ │ ├── footer │ │ ├── header │ │ ├── message_codes.rb │ │ ├── message_overlay.rb │ │ ├── messages.rb │ │ ├── object_methods.rb │ │ ├── operator.rb │ │ ├── protocol.rb │ │ ├── socket.rb │ │ ├── time_series_delete_operator.rb │ │ ├── time_series_get_operator.rb │ │ ├── time_series_list_operator.rb │ │ ├── time_series_put_operator.rb │ │ ├── time_series_query_operator.rb │ │ └── ts_cell_codec.rb │ ├── beefcake_protobuffs_backend.rb │ ├── decaying.rb │ ├── feature_detection.rb │ ├── instrumentation.rb │ ├── node.rb │ ├── protobuffs_backend.rb │ ├── search.rb │ └── yokozuna.rb │ ├── conflict.rb │ ├── core_ext.rb │ ├── core_ext │ ├── blank.rb │ ├── deep_dup.rb │ ├── extract_options.rb │ ├── json.rb │ ├── slice.rb │ ├── stringify_keys.rb │ ├── symbolize_keys.rb │ └── to_param.rb │ ├── counter.rb │ ├── crdt.rb │ ├── crdt │ ├── base.rb │ ├── batch_counter.rb │ ├── batch_map.rb │ ├── counter.rb │ ├── grow_only_set.rb │ ├── hyper_log_log.rb │ ├── inner_counter.rb │ ├── inner_flag.rb │ ├── inner_map.rb │ ├── inner_register.rb │ ├── inner_set.rb │ ├── map.rb │ ├── operation.rb │ ├── set.rb │ └── typed_collection.rb │ ├── encoding.rb │ ├── errors │ ├── backend_creation.rb │ ├── base.rb │ ├── connection_error.rb │ ├── crdt_error.rb │ ├── failed_request.rb │ ├── list_error.rb │ ├── protobuffs_error.rb │ ├── search_error.rb │ └── time_series.rb │ ├── i18n.rb │ ├── index_collection.rb │ ├── instrumentation.rb │ ├── json.rb │ ├── link.rb │ ├── list_buckets.rb │ ├── locale │ ├── en.yml │ └── fr.yml │ ├── map_reduce.rb │ ├── map_reduce │ ├── filter_builder.rb │ ├── phase.rb │ └── results.rb │ ├── map_reduce_error.rb │ ├── multi.rb │ ├── multiexist.rb │ ├── multiget.rb │ ├── preflist_item.rb │ ├── rcontent.rb │ ├── robject.rb │ ├── search.rb │ ├── search │ ├── index.rb │ ├── query.rb │ ├── result_collection.rb │ ├── result_document.rb │ └── schema.rb │ ├── secondary_index.rb │ ├── serializers.rb │ ├── stamp.rb │ ├── time_series.rb │ ├── time_series │ ├── collection.rb │ ├── deletion.rb │ ├── list.rb │ ├── query.rb │ ├── read.rb │ ├── row.rb │ └── submission.rb │ ├── tombstone.rb │ ├── util │ ├── escape.rb │ ├── gzip.rb │ ├── string.rb │ ├── tcp_socket_extensions.rb │ └── translation.rb │ ├── version.rb │ └── walk_spec.rb ├── riak-client.gemspec └── spec ├── failover └── failover.rb ├── fixtures ├── bitcask.txt ├── cat.jpg ├── multipart-basic-conflict.txt ├── multipart-blank.txt ├── multipart-mapreduce.txt ├── multipart-with-body.txt ├── multipart-with-marked-tombstones.txt ├── multipart-with-unmarked-tombstone.txt ├── server.cert.crt ├── server.cert.key ├── test.pem └── yz_schema_template.xml ├── integration ├── riak │ ├── bucket_types_spec.rb │ ├── conflict_resolution_spec.rb │ ├── counters_spec.rb │ ├── crdt │ │ └── configuration_spec.rb │ ├── crdt_search_spec.rb │ ├── crdt_spec.rb │ ├── crdt_validation │ │ ├── grow_only_set_spec.rb │ │ ├── map_spec.rb │ │ └── set_spec.rb │ ├── encodings │ │ ├── crdt_spec.rb │ │ ├── kv_spec.rb │ │ └── yz_spec.rb │ ├── preflist_spec.rb │ ├── properties_spec.rb │ ├── protobuffs │ │ ├── interrupted_request_spec.rb │ │ └── timeouts_spec.rb │ ├── protobuffs_backends_spec.rb │ ├── search_spec.rb │ ├── secondary_index_spec.rb │ ├── security_spec.rb │ ├── threading_spec.rb │ └── time_series_spec.rb └── yokozuna │ ├── index_spec.rb │ ├── queries_spec.rb │ └── schema_spec.rb ├── riak ├── beefcake_protobuffs_backend │ ├── bucket_properties_operator_spec.rb │ ├── crdt_operator_spec.rb │ ├── object_methods_spec.rb │ ├── protocol_spec.rb │ └── ts_cell_codec_spec.rb ├── beefcake_protobuffs_backend_spec.rb ├── bucket_properties_spec.rb ├── bucket_spec.rb ├── bucket_type_spec.rb ├── bucket_typed │ └── bucket_spec.rb ├── client_spec.rb ├── core_ext │ └── to_param_spec.rb ├── counter_spec.rb ├── crdt │ ├── counter_spec.rb │ ├── grow_only_set_spec.rb │ ├── hyper_log_log_spec.rb │ ├── inner_counter_spec.rb │ ├── inner_flag_spec.rb │ ├── inner_map_spec.rb │ ├── inner_register_spec.rb │ ├── inner_set_spec.rb │ ├── map_spec.rb │ ├── set_spec.rb │ ├── shared_examples.rb │ └── typed_collection_spec.rb ├── escape_spec.rb ├── feature_detection_spec.rb ├── index_collection_spec.rb ├── instrumentation_spec.rb ├── link_spec.rb ├── list_buckets_spec.rb ├── map_reduce │ ├── filter_builder_spec.rb │ └── phase_spec.rb ├── map_reduce_spec.rb ├── multi_spec.rb ├── multiexist_spec.rb ├── multiget_spec.rb ├── node_spec.rb ├── robject_spec.rb ├── search │ ├── index_spec.rb │ ├── query_spec.rb │ ├── result_collection_spec.rb │ ├── result_document_spec.rb │ └── schema_spec.rb ├── search_spec.rb ├── secondary_index_spec.rb ├── serializers_spec.rb ├── stamp_spec.rb ├── time_series │ ├── deletion_spec.rb │ ├── listing_spec.rb │ └── submission_spec.rb ├── util │ └── gzip_spec.rb └── walk_spec_spec.rb ├── spec_helper.rb └── support ├── certs ├── README.md ├── ca.crt ├── client.crl ├── client.crt ├── client.csr ├── client.key ├── empty_ca.crt ├── server.crl ├── server.crt └── server.key ├── crdt_prerequisites.rb ├── crdt_search_config.rb ├── crdt_search_fixtures.rb ├── integration_setup.rb ├── search_config.rb ├── search_corpus_setup.rb ├── test_client.rb ├── test_client.yml.example ├── unified_backend_examples.rb ├── version_filter.rb └── wait_until.rb /.document: -------------------------------------------------------------------------------- 1 | README.rdoc 2 | lib/**/*.rb 3 | bin/* 4 | features/**/*.feature 5 | LICENSE 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ##Contributing 2 | 3 | This repo's maintainers are engineers at Basho and welcome your contribution to this project. 4 | 5 | ## How-to contribute to the Ruby client 6 | 7 | **_IMPORTANT_**: This is an open source project licensed under the Apache 2.0 License. We encourage contributions to the project from the community. We ask that you keep in mind these considerations when planning your contribution. 8 | 9 | * Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/basho/riak-ruby-client/issues)** and let us know what you are thinking. 10 | * **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created. 11 | * **For feature requests**, we want to improve upon the library incrementally which means small changes at a time. In order ensure your PR can be reviewed in a timely manner, please keep PRs small, e.g. <10 files and <500 lines changed. If you think this is unrealistic, then mention that within the Issue and we can discuss it. 12 | 13 | ### Pull Request Process 14 | 15 | Here’s how to get started: 16 | 17 | * Fork the appropriate sub-projects that are affected by your change. 18 | * Create a topic branch for your change and checkout that branch. 19 | `git checkout -b some-topic-branch` 20 | * Make your changes and run the test suite. 21 | * Commit your changes and push them to your fork. 22 | * Open pull-requests for the appropriate projects. 23 | * Contributors will review your pull request, suggest changes, and merge it when it’s ready and/or offer feedback. 24 | * To report a bug or issue, please open a new issue against this repository. 25 | 26 | You can [read the full guidelines for bug reporting and code contributions](http://docs.basho.com/riak/latest/community/bugs/) on the Riak Docs. 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please ensure the following information is supplied for new issues: 2 | 3 | - [ ] Riak Ruby Client version 4 | - [ ] Ruby version 5 | - [ ] Riak version 6 | - [ ] Operating System / Distribution & Version 7 | - [ ] Riak `error.log` file, if applicable 8 | - [ ] What methods were being executed during the error 9 | - [ ] What you *expected* to have happen 10 | - [ ] Sample data, if applicable 11 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please ensure the following is present in your PR: 2 | 3 | - [ ] Unit tests for your change 4 | - [ ] Integration tests (if applicable) 5 | 6 | Pull requests that are small and limited in scope are most welcome. 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## NOTE: This file must be manually kept in sync with the gemspec, but 2 | ## should not normally need to be modified unless new top-level files 3 | ## or directory trees are being added. 4 | 5 | ## MAC OS 6 | .DS_Store 7 | 8 | ## TEXTMATE 9 | *.tmproj 10 | tmtags 11 | 12 | ## EMACS 13 | *~ 14 | \#* 15 | .\#* 16 | 17 | ## VIM 18 | *.swp 19 | 20 | ## VS Code 21 | .vscode/ 22 | 23 | ## PROJECT::GENERAL 24 | coverage 25 | rdoc 26 | pkg 27 | 28 | ## PROJECT::SPECIFIC 29 | _notes 30 | doc 31 | .yardoc 32 | .bundle 33 | spec/support/test_client.yml 34 | Gemfile.lock 35 | **/bin 36 | *.rbc 37 | .rvmrc 38 | 39 | .riaktest 40 | **/.riaktest 41 | .ruby-version 42 | tmp 43 | tags 44 | vendor/ 45 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tools"] 2 | path = tools 3 | url = https://github.com/basho/riak-client-tools 4 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | -fd 3 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: .rubocop_todo.yml -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: ruby 4 | rvm: 5 | - 1.9.3 6 | - 2.0 7 | - 2.1 8 | - 2.2 9 | - 2.3 10 | - jruby-9.1.5.0 11 | before_install: 12 | - gem update --system 13 | - gem --version 14 | - gem update bundler 15 | bundler_args: "--binstubs --path=vendor --without=guard" 16 | env: 17 | - RIAK_DOWNLOAD_URL=http://s3.amazonaws.com/downloads.basho.com/riak/2.0/2.0.7/ubuntu/trusty/riak_2.0.7-1_amd64.deb 18 | - RIAK_DOWNLOAD_URL=http://s3.amazonaws.com/downloads.basho.com/riak/2.2/2.2.0/ubuntu/trusty/riak_2.2.0-1_amd64.deb 19 | before_script: 20 | - jdk_switcher use oraclejdk8 21 | - sudo ./tools/travis-ci/riak-install -d "$RIAK_DOWNLOAD_URL" 22 | - sudo ./tools/setup-riak -s 23 | script: 24 | - sudo riak-admin security disable 25 | - make test 26 | - sudo riak-admin security enable 27 | - make security-test 28 | notifications: 29 | slack: 30 | secure: nryEZNlLs0xpMJcrmTRzJIaFdfHWigsD4i9zEI8SgDdHqEgJ52/UfCifWHC7N4UckpRkmMUc8yt/Y4YS7G4Gu4yx4qXNIL33VmuudUe2YEVv+oVnG9oHVPkHDvOkRSLlWyAIqd4uXbLzghYBrHigoinfCcmjjRq5HNocRrvnwdE= 31 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec 4 | 5 | group :guard do 6 | gem 'guard-rspec' 7 | gem 'rb-fsevent' 8 | gem 'terminal-notifier-guard' 9 | end 10 | 11 | platforms :mri do 12 | gem 'yajl-ruby' 13 | end 14 | 15 | platforms :jruby, :rbx do 16 | gem 'json' 17 | end 18 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | # Note: The cmd option is now required due to the increasing number of ways 5 | # rspec may be run, below are examples of the most common uses. 6 | # * bundler: 'bundle exec rspec' 7 | # * bundler binstubs: 'bin/rspec' 8 | # * spring: 'bin/rsspec' (This will use spring if running and you have 9 | # installed the spring binstubs per the docs) 10 | # * zeus: 'zeus rspec' (requires the server to be started separetly) 11 | # * 'just' rspec: 'rspec' 12 | guard :rspec, cmd: 'bundle exec rspec', all_after_pass: true, all_on_start: true do 13 | watch(%r{^spec/.+_spec\.rb$}) 14 | watch(%r{^lib/riak/(.+)\.rb$}) { |m| "spec/riak/#{m[1]}_spec.rb" } 15 | watch(%r{^lib/riak/client/}) { 'spec/riak/beefcake_protobuffs_backend' } 16 | watch('spec/spec_helper.rb') { "spec" } 17 | 18 | watch(/^spec\/integration/) { 'spec:integration' } 19 | end 20 | 21 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2010-2016 Sean Cribbs and Basho Technologies, Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | All of the files in this project are under the project-wide license 16 | unless they are otherwise marked. 17 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Riak Ruby Client 2 | Copyright 2010-present Basho Technologies, Inc. 3 | -------------------------------------------------------------------------------- /benchmark/multiget.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'benchmark' 16 | require 'yaml' 17 | 18 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 19 | require 'riak' 20 | # require 'riak/test_server' 21 | 22 | puts "Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}" 23 | puts Time.now.to_s 24 | 25 | count = ENV['MULTIGET_COUNT'].to_i 26 | puts "Count #{count}" 27 | 28 | threads = ENV['MULTIGET_THREADS'].to_i 29 | puts "Threads #{threads}" 30 | 31 | # config = YAML.load_file(File.expand_path("../../spec/support/test_server.yml", __FILE__)) 32 | 33 | cluster = (1..4).map do |n| 34 | {host: '10.0.38.132', http_port: "100#{n}8" } 35 | end 36 | 37 | client = Riak::Client.new nodes: cluster 38 | client.multiget_threads = threads 39 | 40 | bucket = client.bucket 'mooltiget' 41 | 42 | keys = (0..count).map(&:to_s) 43 | 44 | # puts "Inserting #{count} key value pairs" 45 | # 46 | # keys.each do |n| 47 | # if n % 100 == 0 48 | # print "\r#{n}" 49 | # end 50 | # obj = bucket.get_or_new n.to_s 51 | # obj.content_type = 'text/plain' 52 | # obj.data = n.to_s 53 | # obj.store 54 | # end 55 | 56 | # puts "waiting" 57 | 58 | # sleep 10 59 | 60 | puts "benchmarking" 61 | 62 | Benchmark.bmbm do |x| 63 | x.report 'individual' do 64 | keys.each {|k| bucket[k]} 65 | end 66 | 67 | x.report 'multiget' do 68 | bucket.get_many keys 69 | end 70 | end 71 | 72 | # puts "deleting #{count} key value pairs" 73 | 74 | # keys.each do |k| 75 | # bucket.delete k 76 | # end 77 | 78 | puts 79 | -------------------------------------------------------------------------------- /lib/riak.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/encoding' 16 | require 'riak/core_ext' 17 | require 'riak/client' 18 | require 'riak/map_reduce' 19 | require 'riak/util/translation' 20 | require 'riak/crdt' 21 | require 'riak/instrumentation' 22 | 23 | # The Riak module contains all aspects of the client interface to 24 | # Riak. 25 | module Riak 26 | # Utility classes and mixins 27 | module Util; end 28 | extend Util::Translation 29 | 30 | class NullLogger 31 | def fatal(msg) end 32 | 33 | def error(msg) end 34 | 35 | def warn(msg) end 36 | 37 | def info(msg) end 38 | 39 | def debug(msg) end 40 | end 41 | 42 | class << self 43 | # Only change this if you really know what you're doing. Better to 44 | # err on the side of caution and assume you don't. 45 | # @private 46 | attr_accessor :disable_list_exceptions 47 | 48 | # backwards compat 49 | alias :disable_list_keys_warnings :disable_list_exceptions 50 | alias :disable_list_keys_warnings= :disable_list_exceptions= 51 | 52 | # Set a custom logger object (e.g. Riak.logger = Rails.logger) 53 | attr_accessor :logger 54 | end 55 | self.disable_list_exceptions = false 56 | self.logger = NullLogger.new 57 | end 58 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/crdt/counter_loader.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | class Riak::Client::BeefcakeProtobuffsBackend 16 | class CrdtLoader 17 | class CounterLoader 18 | def self.for_value(resp) 19 | return nil unless resp.counter_value 20 | new resp.counter_value 21 | end 22 | 23 | def initialize(counter_value) 24 | @value = counter_value 25 | end 26 | 27 | def rubyfy 28 | @value 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/crdt/grow_only_set_loader.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | class Riak::Client::BeefcakeProtobuffsBackend 16 | class CrdtLoader 17 | class GrowOnlySetLoader 18 | def self.for_value(resp) 19 | return nil unless resp.gset_value 20 | new resp.gset_value 21 | end 22 | 23 | def initialize(gset_value) 24 | @value = gset_value 25 | end 26 | 27 | def rubyfy 28 | ::Set.new @value 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/crdt/hyper_log_log_loader.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | class Riak::Client::BeefcakeProtobuffsBackend 16 | class CrdtLoader 17 | class HyperLogLogLoader 18 | def self.for_value(resp) 19 | return nil unless resp.hll_value 20 | new resp.hll_value 21 | end 22 | 23 | def initialize(hll_value) 24 | @value = hll_value 25 | end 26 | 27 | def rubyfy 28 | @value 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/crdt/map_loader.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | class Riak::Client::BeefcakeProtobuffsBackend 16 | class CrdtLoader 17 | class MapLoader 18 | def self.for_value(resp) 19 | return nil unless resp.map_value 20 | new resp.map_value 21 | end 22 | 23 | def initialize(map_value) 24 | @value = map_value 25 | end 26 | 27 | def rubyfy 28 | accum = { 29 | counters: {}, 30 | flags: {}, 31 | maps: {}, 32 | registers: {}, 33 | sets: {} 34 | } 35 | 36 | contents_loop @value, accum 37 | end 38 | 39 | private 40 | 41 | def rubyfy_inner(accum, map_value) 42 | destination = accum[:maps][map_value.field.name] 43 | if destination.nil? 44 | destination = accum[:maps][map_value.field.name] = { 45 | counters: {}, 46 | flags: {}, 47 | maps: {}, 48 | registers: {}, 49 | sets: {} 50 | } 51 | end 52 | 53 | contents_loop map_value.map_value, destination 54 | end 55 | 56 | def contents_loop(rolling_value, destination) 57 | return destination if rolling_value.nil? 58 | 59 | rolling_value.each do |inner| 60 | case inner.field.type 61 | when MapField::MapFieldType::COUNTER 62 | destination[:counters][inner.field.name] = inner.counter_value 63 | when MapField::MapFieldType::FLAG 64 | destination[:flags][inner.field.name] = inner.flag_value 65 | when MapField::MapFieldType::MAP 66 | rubyfy_inner destination, inner 67 | when MapField::MapFieldType::REGISTER 68 | destination[:registers][inner.field.name] = inner.register_value 69 | when MapField::MapFieldType::SET 70 | destination[:sets][inner.field.name] = ::Set.new inner.set_value 71 | end 72 | end 73 | 74 | return destination 75 | end 76 | end 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/crdt/set_loader.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | class Riak::Client::BeefcakeProtobuffsBackend 16 | class CrdtLoader 17 | class SetLoader 18 | def self.for_value(resp) 19 | return nil unless resp.set_value 20 | new resp.set_value 21 | end 22 | 23 | def initialize(set_value) 24 | @value = set_value 25 | end 26 | 27 | def rubyfy 28 | ::Set.new @value 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/footer: -------------------------------------------------------------------------------- 1 | 2 | end 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/header: -------------------------------------------------------------------------------- 1 | require 'beefcake' 2 | 3 | module Riak 4 | class Client 5 | # @private 6 | class BeefcakeProtobuffsBackend 7 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/operator.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | class Riak::Client::BeefcakeProtobuffsBackend 16 | class Operator 17 | attr_reader :backend 18 | 19 | def initialize(backend) 20 | @backend = backend 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/time_series_delete_operator.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require_relative './ts_cell_codec' 16 | require_relative './operator' 17 | 18 | class Riak::Client::BeefcakeProtobuffsBackend 19 | def time_series_delete_operator 20 | TimeSeriesDeleteOperator.new(self) 21 | end 22 | 23 | class TimeSeriesDeleteOperator < Operator 24 | def delete(table_name, key_components, options = {}) 25 | codec = TsCellCodec.new 26 | 27 | request_options = options.merge(table: table_name, 28 | key: codec.cells_for(key_components)) 29 | 30 | request = TsDelReq.new request_options 31 | 32 | backend.protocol do |p| 33 | p.write :TsDelReq, request 34 | p.expect :TsDelResp, TsDelResp, empty_body_acceptable: true 35 | end 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/time_series_get_operator.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require_relative './ts_cell_codec' 16 | require_relative './operator' 17 | 18 | class Riak::Client::BeefcakeProtobuffsBackend 19 | def time_series_get_operator(convert_timestamp) 20 | TimeSeriesGetOperator.new(self, convert_timestamp) 21 | end 22 | 23 | class TimeSeriesGetOperator < Operator 24 | def initialize(backend, convert_timestamp) 25 | super(backend) 26 | @convert_timestamp = convert_timestamp 27 | end 28 | 29 | def get(table_name, key_components, options = {}) 30 | codec = TsCellCodec.new(@convert_timestamp) 31 | 32 | request_options = options.merge(table: table_name, 33 | key: codec.cells_for(key_components)) 34 | 35 | request = TsGetReq.new request_options 36 | 37 | result = begin 38 | backend.protocol do |p| 39 | p.write :TsGetReq, request 40 | result = p.expect :TsGetResp, TsGetResp, empty_body_acceptable: true 41 | end 42 | rescue Riak::ProtobuffsErrorResponse => e 43 | raise unless e.code == 10 44 | return nil 45 | end 46 | 47 | return nil if result == :empty 48 | 49 | Riak::TimeSeries::Collection.new(result.rows.map do |row| 50 | Riak::TimeSeries::Row.new codec.scalars_for row.cells 51 | end.to_a) 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/time_series_list_operator.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require_relative './ts_cell_codec' 16 | require_relative './operator' 17 | 18 | class Riak::Client::BeefcakeProtobuffsBackend 19 | def time_series_list_operator(convert_timestamp) 20 | TimeSeriesListOperator.new(self, convert_timestamp) 21 | end 22 | 23 | class TimeSeriesListOperator < Operator 24 | def initialize(backend, convert_timestamp) 25 | super(backend) 26 | @convert_timestamp = convert_timestamp 27 | end 28 | 29 | def list(table_name, block, options = { }) 30 | request = TsListKeysReq.new options.merge(table: table_name) 31 | 32 | return streaming_list_keys(request, &block) unless block.nil? 33 | 34 | Riak::TimeSeries::Collection.new.tap do |key_buffer| 35 | streaming_list_keys(request) do |key_row| 36 | key_buffer << key_row 37 | end 38 | end 39 | end 40 | 41 | private 42 | 43 | def streaming_list_keys(request) 44 | backend.protocol do |p| 45 | p.write :TsListKeysReq, request 46 | 47 | codec = TsCellCodec.new(@convert_timestamp) 48 | 49 | while resp = p.expect(:TsListKeysResp, TsListKeysResp) 50 | break if resp.done 51 | resp.keys.each do |row| 52 | key_fields = codec.scalars_for row.cells 53 | yield key_fields 54 | end 55 | end 56 | end 57 | 58 | true 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/time_series_put_operator.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require_relative './ts_cell_codec' 16 | require_relative './operator' 17 | 18 | class Riak::Client::BeefcakeProtobuffsBackend 19 | def time_series_put_operator 20 | TimeSeriesPutOperator.new(self) 21 | end 22 | 23 | class TimeSeriesPutOperator < Operator 24 | def put(table_name, measurements) 25 | rows = rows_for measurements 26 | 27 | request = TsPutReq.new table: table_name, rows: rows 28 | 29 | backend.protocol do |p| 30 | p.write :TsPutReq, request 31 | p.expect :TsPutResp, TsPutResp, empty_body_acceptable: true 32 | end 33 | end 34 | 35 | private 36 | def rows_for(measurements) 37 | codec = TsCellCodec.new 38 | measurements.map do |measurement| 39 | # expect a measurement to be mappable 40 | TsRow.new(cells: measurement.map do |measure| 41 | codec.cell_for measure 42 | end) 43 | end 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/riak/client/beefcake/time_series_query_operator.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require_relative './ts_cell_codec' 16 | require_relative './operator' 17 | 18 | class Riak::Client::BeefcakeProtobuffsBackend 19 | def time_series_query_operator(convert_timestamp) 20 | TimeSeriesQueryOperator.new(self, convert_timestamp) 21 | end 22 | 23 | class TimeSeriesQueryOperator < Operator 24 | def initialize(backend, convert_timestamp) 25 | super(backend) 26 | @convert_timestamp = convert_timestamp 27 | end 28 | 29 | def query(base, interpolations = { }) 30 | interpolator = TsInterpolation.new base: base 31 | interpolator.interpolations = pairs_for interpolations 32 | 33 | request = TsQueryReq.new query: interpolator 34 | 35 | result = backend.protocol do |p| 36 | p.write :TsQueryReq, request 37 | p.expect :TsQueryResp, TsQueryResp, empty_body_acceptable: true 38 | end 39 | 40 | return [] if :empty == result 41 | 42 | codec = TsCellCodec.new(@convert_timestamp) 43 | 44 | collection = Riak::TimeSeries::Collection. 45 | new(result.rows.map do |row| 46 | Riak::TimeSeries::Row.new codec.scalars_for row.cells 47 | end) 48 | 49 | collection.columns = result.columns 50 | 51 | collection 52 | end 53 | 54 | private 55 | def pairs_for(interpolations) 56 | interpolations.map do |key, value| 57 | RpbPair.new key: key.to_s, value: value.to_s 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/riak/client/decaying.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | class Client 17 | # A float value which decays exponentially toward 0 over time. 18 | # @private 19 | class Decaying 20 | attr_accessor :e 21 | attr_accessor :p 22 | 23 | # @param [Hash] opts options 24 | # @option options [Float] :p (0.0) The initial value 25 | # @option options [Float] :e (Math::E) Exponent base 26 | # @option options [Float] :r (Math.log(0.5) / 10) Timescale 27 | # factor - defaulting to decay 50% every 10 seconds 28 | def initialize(opts = {}) 29 | @p = opts[:p] || 0.0 30 | @e = opts[:e] || Math::E 31 | @r = opts[:r] || Math.log(0.5) / 10 32 | @t0 = Time.now 33 | end 34 | 35 | # Add to current value. 36 | # @param [Float] d the value to add 37 | def <<(d) 38 | @p = value + d 39 | end 40 | 41 | # @return [Float] the current value (adjusted for the time decay) 42 | def value 43 | now = Time.now 44 | dt = now - @t0 45 | @t0 = now 46 | @p = @p * (@e ** (@r * dt)) 47 | end 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /lib/riak/client/instrumentation.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | class Riak::Client 16 | include Instrumentable 17 | 18 | client_payload = {client_id: :client_id} 19 | 20 | instrument_method :buckets, 'riak.list_buckets', client_payload 21 | instrument_method :list_buckets, 'riak.list_buckets', client_payload 22 | instrument_method :list_keys, 'riak.list_keys', client_payload 23 | instrument_method :set_bucket_props, 'riak.set_bucket_props', client_payload 24 | instrument_method :get_bucket_props, 'riak.get_bucket_props', client_payload 25 | instrument_method :clear_bucket_props, 'riak.clear_bucket_props', client_payload 26 | instrument_method :get_index, 'riak.get_index', client_payload 27 | instrument_method :store_object, 'riak.store_object', client_payload 28 | instrument_method :get_object, 'riak.get_object', client_payload 29 | instrument_method :reload_object, 'riak.reload_object', client_payload 30 | instrument_method :delete_object, 'riak.delete_object', client_payload 31 | instrument_method :mapred, 'riak.map_reduce', client_payload 32 | instrument_method :ping, 'riak.ping', client_payload 33 | end 34 | -------------------------------------------------------------------------------- /lib/riak/client/node.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | class Client 17 | class Node 18 | # Represents a single riak node in a cluster. 19 | 20 | include Util::Translation 21 | include Util::Escape 22 | 23 | VALID_OPTIONS = [:host, :pb_port] 24 | 25 | # For a score which halves in 10 seconds, choose 26 | # ln(1/2)/10 27 | ERRORS_DECAY_RATE = Math.log(0.5)/10 28 | 29 | # What IP address or hostname does this node listen on? 30 | attr_accessor :host 31 | 32 | # Which port does the protocol buffers interface listen on? 33 | attr_accessor :pb_port 34 | 35 | # A Decaying rate of errors. 36 | attr_reader :error_rate 37 | 38 | def initialize(client, opts = {}) 39 | @client = client 40 | @host = opts[:host] || "127.0.0.1" 41 | @pb_port = opts[:pb_port] || 8087 42 | 43 | @error_rate = Decaying.new 44 | end 45 | 46 | def ==(o) 47 | o.kind_of? Node and 48 | @host == o.host and 49 | @pb_port == o.pb_port 50 | end 51 | 52 | # Can this node be used for protocol buffers requests? 53 | def protobuffs? 54 | # TODO: Need to sort out capabilities 55 | true 56 | end 57 | 58 | def inspect 59 | "#" 60 | end 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/riak/client/search.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | class Client 17 | # (Riak Search) Performs a search via the Solr interface. 18 | # @overload search(index, query, options={}) 19 | # @param [String] index the index to query on 20 | # @param [String] query a Lucene query string 21 | # @overload search(query, options={}) 22 | # Queries the default index 23 | # @param [String] query a Lucene query string 24 | # @param [Hash] options extra options for the Solr query 25 | # @option options [String] :df the default field to search in 26 | # @option options [String] :'q.op' the default operator between terms ("or", "and") 27 | # @option options [String] :wt ("json") the response type - "json" and "xml" are valid 28 | # @option options [String] :sort ('none') the field and direction to sort, e.g. "name asc" 29 | # @option options [Fixnum] :start (0) the offset into the query to start from, e.g. for pagination 30 | # @option options [Fixnum] :rows (10) the number of results to return 31 | # @return [Hash] the query result, containing the 'responseHeaders' and 'response' keys 32 | def search(*args) 33 | options = args.extract_options! 34 | index, query = args[-2], args[-1] # Allows nil index, while keeping it as firstargument 35 | backend do |b| 36 | b.search(index, query, options) 37 | end 38 | end 39 | alias :select :search 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /lib/riak/client/yokozuna.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | class Client 17 | def create_search_index(name, schema = nil, n_val = nil, timeout = nil) 18 | raise ArgumentError, t("zero_length_index") if name.nil? || name.empty? 19 | backend do |b| 20 | b.create_search_index(name, schema, n_val, timeout) 21 | end 22 | true 23 | end 24 | 25 | def get_search_index(name) 26 | raise ArgumentError, t("zero_length_index") if name.nil? || name.empty? 27 | resp = [] 28 | backend do |b| 29 | resp = b.get_search_index(name) 30 | end 31 | resp.index && Array === resp.index ? resp.index.first : resp 32 | end 33 | 34 | def list_search_indexes() 35 | resp = [] 36 | backend do |b| 37 | resp = b.get_search_index(nil) 38 | end 39 | resp.index ? resp.index : resp 40 | end 41 | 42 | def delete_search_index(name) 43 | raise ArgumentError, t("zero_length_index") if name.nil? || name.empty? 44 | backend do |b| 45 | b.delete_search_index(name) 46 | end 47 | true 48 | end 49 | 50 | def create_search_schema(name, content) 51 | raise ArgumentError, t("zero_length_schema") if name.nil? || name.empty? 52 | raise ArgumentError, t("zero_length_content") if content.nil? || content.empty? 53 | backend do |b| 54 | b.create_search_schema(name, content) 55 | end 56 | true 57 | end 58 | 59 | def get_search_schema(name) 60 | raise ArgumentError, t("zero_length_schema") if name.nil? || name.empty? 61 | backend do |b| 62 | return b.get_search_schema(name) 63 | end 64 | end 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /lib/riak/conflict.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/util/translation' 16 | 17 | module Riak 18 | # Raised when an object that is in conflict (i.e. has siblings) is 19 | # stored or manipulated as if it had a single value. 20 | class Conflict < StandardError 21 | include Util::Translation 22 | 23 | def initialize(robject) 24 | super t('object_in_conflict', :robject => robject.inspect) 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/riak/core_ext.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/core_ext/blank' 16 | require 'riak/core_ext/extract_options' 17 | require 'riak/core_ext/slice' 18 | require 'riak/core_ext/stringify_keys' 19 | require 'riak/core_ext/symbolize_keys' 20 | require 'riak/core_ext/to_param' 21 | require 'riak/core_ext/deep_dup' 22 | -------------------------------------------------------------------------------- /lib/riak/core_ext/blank.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'set' 16 | 17 | unless Object.new.respond_to? :blank? 18 | class Object 19 | def blank? 20 | false 21 | end 22 | end 23 | 24 | class NilClass 25 | def blank? 26 | true 27 | end 28 | end 29 | 30 | class FalseClass 31 | def blank? 32 | true 33 | end 34 | end 35 | 36 | class TrueClass 37 | def blank? 38 | false 39 | end 40 | end 41 | 42 | class Set 43 | alias :blank? :empty? 44 | end 45 | 46 | class String 47 | def blank? 48 | self !~ /[^\s]/ 49 | end 50 | end 51 | 52 | class Array 53 | alias :blank? :empty? 54 | end 55 | 56 | class Hash 57 | alias :blank? :empty? 58 | end 59 | end 60 | 61 | unless Object.new.respond_to? :present? 62 | class Object 63 | def present? 64 | !blank? 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /lib/riak/core_ext/deep_dup.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | unless {}.respond_to?(:deep_dup) 16 | class Hash 17 | # Returns a deep copy of hash. 18 | def deep_dup 19 | duplicate = self.dup 20 | duplicate.each_pair do |k, v| 21 | tv = duplicate[k] 22 | duplicate[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_dup : v 23 | end 24 | duplicate 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/riak/core_ext/extract_options.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | unless Array.new.respond_to? :extract_options! 16 | class Array 17 | def extract_options! 18 | last.is_a?(::Hash) ? pop : {} 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/riak/core_ext/json.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | unless Object.new.respond_to?(:to_json) 16 | # @private 17 | class Object 18 | def to_json(*args) 19 | Riak::JSON.encode(self) 20 | end 21 | end 22 | 23 | # @private 24 | class Symbol 25 | def to_json(*args) 26 | to_s.to_json(*args) 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/riak/core_ext/slice.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | unless {}.respond_to? :slice 16 | class Hash 17 | def slice(*keys) 18 | allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) 19 | hash = {} 20 | allowed.each { |k| hash[k] = self[k] if has_key?(k) } 21 | hash 22 | end 23 | 24 | def slice!(*keys) 25 | keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key) 26 | omit = slice(*self.keys - keys) 27 | hash = slice(*keys) 28 | replace(hash) 29 | omit 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/riak/core_ext/stringify_keys.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | unless {}.respond_to? :stringify_keys 16 | class Hash 17 | def stringify_keys 18 | inject({}) do |hash, pair| 19 | hash[pair[0].to_s] = pair[1] 20 | hash 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/riak/core_ext/symbolize_keys.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | unless {}.respond_to? :symbolize_keys 16 | class Hash 17 | def symbolize_keys 18 | inject({}) do |hash, pair| 19 | hash[pair[0].to_sym] = pair[1] 20 | hash 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/riak/core_ext/to_param.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | unless Object.new.respond_to? :to_query and Object.new.respond_to? :to_param 16 | class Object 17 | def to_param 18 | to_s 19 | end 20 | 21 | def to_query(key) 22 | require 'cgi' unless defined?(CGI) && defined?(CGI::escape) 23 | "#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}" 24 | end 25 | end 26 | 27 | class Array 28 | def to_param 29 | map(&:to_param).join('/') 30 | end 31 | 32 | def to_query(key) 33 | prefix = "#{key}[]" 34 | collect { |value| value.to_query(prefix) }.join '&' 35 | end 36 | end 37 | 38 | class Hash 39 | def to_param(namespace = nil) 40 | collect do |key, value| 41 | value.to_query(namespace ? "#{namespace}[#{key}]" : key) 42 | end.sort * '&' 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/riak/crdt.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/crdt_error' 16 | 17 | %w{ operation base inner_register inner_flag counter inner_counter batch_counter hyper_log_log map inner_map batch_map grow_only_set set inner_set typed_collection }.each do |f| 18 | require "riak/crdt/#{f}" 19 | end 20 | 21 | module Riak 22 | # Container module for Convergent Replicated Data Type 23 | # features. 24 | module Crdt 25 | 26 | # These are the default bucket types for the three top-level data types. 27 | # Broadly, CRDTs require allow_mult to be enabled, and the `datatype` 28 | # property to be set to the appropriate atom (`counter`, `map`, `set`, 29 | # 'hll', or 'gset'). 30 | DEFAULT_BUCKET_TYPES = { 31 | counter: 'counters', 32 | map: 'maps', 33 | set: 'sets', 34 | hll: 'hlls', 35 | gset: 'gsets', 36 | } 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/riak/crdt/batch_counter.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | module Crdt 17 | class BatchCounter 18 | attr_reader :accumulator 19 | 20 | def initialize 21 | @accumulator = 0 22 | end 23 | 24 | def increment(amount = 1) 25 | @accumulator += amount 26 | end 27 | 28 | def decrement(amount = 1) 29 | increment -amount 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/riak/crdt/batch_map.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | module Crdt 17 | # A map that queues up its operations for the parent {Map} to send to 18 | # Riak all at once. 19 | class BatchMap 20 | attr_reader :counters, :flags, :maps, :registers, :sets 21 | 22 | # @api private 23 | def initialize(parent) 24 | @parent = parent 25 | @queue = [] 26 | 27 | initialize_collections 28 | end 29 | 30 | # @api private 31 | def operate(operation) 32 | @queue << operation 33 | end 34 | 35 | # @api private 36 | def operations 37 | @queue.map do |q| 38 | Operation::Update.new.tap do |op| 39 | op.type = :map 40 | op.value = q 41 | end 42 | end 43 | end 44 | 45 | private 46 | def initialize_collections 47 | @counters = @parent.counters.reparent self 48 | @flags = @parent.flags.reparent self 49 | @maps = @parent.maps.reparent self 50 | @registers = @parent.registers.reparent self 51 | @sets = @parent.sets.reparent self 52 | end 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /lib/riak/crdt/inner_flag.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | module Crdt 17 | # The {InnerFlag} is a boolean member of a {Map}. Since flag operations are 18 | # extremely simple, this object simply provides internal API methods for 19 | # {TypedCollection} to use. 20 | # 21 | # @api private 22 | class InnerFlag 23 | def self.new(parent, value = false) 24 | ensure_boolean value 25 | 26 | return value 27 | end 28 | 29 | def self.update(value) 30 | ensure_boolean value 31 | 32 | Operation::Update.new.tap do |op| 33 | op.value = value 34 | op.type = :flag 35 | end 36 | end 37 | 38 | def self.delete 39 | Operation::Delete.new.tap do |op| 40 | op.type = :flag 41 | end 42 | end 43 | 44 | private 45 | def self.ensure_boolean(value) 46 | return if value.is_a? TrueClass 47 | return if value.is_a? FalseClass 48 | 49 | raise FlagError, t('crdt.flag.not_boolean') 50 | end 51 | 52 | class FlagError < ArgumentError 53 | end 54 | end 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /lib/riak/crdt/inner_map.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | module Crdt 17 | # A map that exists inside a {TypedCollection} inside another map. 18 | class InnerMap 19 | attr_reader :counters, :flags, :maps, :registers, :sets 20 | 21 | attr_accessor :name 22 | 23 | # The parent of this counter. 24 | # 25 | # @api private 26 | attr_reader :parent 27 | 28 | # @api private 29 | def initialize(parent, value = {}) 30 | @parent = parent 31 | @value = value.symbolize_keys 32 | 33 | initialize_collections 34 | end 35 | 36 | # @api private 37 | def operate(inner_operation) 38 | wrapped_operation = Operation::Update.new.tap do |op| 39 | op.value = inner_operation 40 | op.type = :map 41 | end 42 | 43 | @parent.operate(name, wrapped_operation) 44 | end 45 | 46 | def pretty_print(pp) 47 | pp.object_group self do 48 | %w{counters flags maps registers sets}.each do |h| 49 | pp.comma_breakable 50 | pp.text "#{h}=" 51 | pp.pp send h 52 | end 53 | end 54 | end 55 | 56 | def pretty_print_cycle(pp) 57 | pp.text "InnerMap" 58 | end 59 | 60 | def to_value_h 61 | %w{counters flags maps registers sets}.map do |k| 62 | [k, send(k).to_value_h] 63 | end.to_h 64 | end 65 | 66 | alias :value :to_value_h 67 | 68 | # @api private 69 | def self.delete 70 | Operation::Delete.new.tap do |op| 71 | op.type = :map 72 | end 73 | end 74 | 75 | def context? 76 | @parent.context? 77 | end 78 | 79 | private 80 | def initialize_collections 81 | @counters = TypedCollection.new InnerCounter, self, @value[:counters] 82 | @flags = TypedCollection.new InnerFlag, self, @value[:flags] 83 | @maps = TypedCollection.new InnerMap, self, @value[:maps] 84 | @registers = TypedCollection.new InnerRegister, self, @value[:registers] 85 | @sets = TypedCollection.new InnerSet, self, @value[:sets] 86 | end 87 | end 88 | end 89 | end 90 | -------------------------------------------------------------------------------- /lib/riak/crdt/inner_register.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | module Crdt 17 | class InnerRegister < String 18 | attr_reader :parent 19 | 20 | def initialize(parent, *args, &block) 21 | @parent = parent 22 | super(*args, &block) 23 | freeze 24 | end 25 | 26 | def self.update(value) 27 | Operation::Update.new.tap do |op| 28 | op.value = value 29 | op.type = :register 30 | end 31 | end 32 | 33 | def self.delete 34 | Operation::Delete.new.tap do |op| 35 | op.type = :register 36 | end 37 | end 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/riak/crdt/operation.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | module Crdt 17 | # @api private 18 | module Operation 19 | class Update 20 | attr_accessor :parent 21 | attr_accessor :name 22 | attr_accessor :type 23 | attr_accessor :value 24 | end 25 | 26 | class Delete 27 | attr_accessor :parent 28 | attr_accessor :name 29 | attr_accessor :type 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/riak/encoding.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | if defined? Encoding 16 | Encoding.default_internal = "UTF-8" if Encoding.default_internal.nil? || 17 | !Encoding.default_internal.ascii_compatible? 18 | else 19 | $KCODE = "U" 20 | end 21 | -------------------------------------------------------------------------------- /lib/riak/errors/backend_creation.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/base' 16 | 17 | module Riak 18 | class BackendCreationError < Error 19 | def initialize(backend) 20 | super t('protobuffs_configuration', backend: backend) 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/riak/errors/base.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | 17 | # Superclass for all errors raised by riak-client. If you catch an error 18 | # that the client raises that isn't descended from this class, please 19 | # file a bug. Thanks! 20 | class Error < StandardError 21 | include Util::Translation 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/riak/errors/connection_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/base' 16 | 17 | module Riak 18 | class ConnectionError < Error 19 | end 20 | 21 | class TlsError < ConnectionError 22 | class SslVersionConfigurationError < TlsError 23 | def initialize 24 | super t('ssl.version_configuration_error') 25 | end 26 | end 27 | 28 | class CertHostMismatchError < TlsError 29 | def initialize 30 | super t('ssl.cert_host_mismatch') 31 | end 32 | end 33 | 34 | class CertNotValidError < TlsError 35 | def initialize 36 | super t('ssl.cert_not_valid') 37 | end 38 | end 39 | 40 | class CertRevokedError < TlsError 41 | def initialize 42 | super t('ssl.cert_revoked') 43 | end 44 | end 45 | 46 | class ReadDataError < TlsError 47 | def initialize(actual, candidate) 48 | super t('ssl.read_data_error', actual: actual, candidate: candidate) 49 | end 50 | end 51 | 52 | class UnknownKeyTypeError < TlsError 53 | def initialize 54 | super t('ssl.unknown_key_type') 55 | end 56 | end 57 | end 58 | 59 | class UserConfigurationError < ConnectionError 60 | def initialize 61 | super t('pbc.user_not_username') 62 | end 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /lib/riak/errors/crdt_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/base' 16 | 17 | module Riak 18 | class CrdtError < Error 19 | 20 | class SetRemovalWithoutContextError < CrdtError 21 | def initialize 22 | super t('crdt.set_removal_without_context') 23 | end 24 | end 25 | 26 | class PreconditionError < CrdtError 27 | def initialize(message) 28 | super t('crdt.precondition', message: message) 29 | end 30 | end 31 | 32 | class UnrecognizedDataType < CrdtError 33 | def initialize(given_type) 34 | super t('crdt.unrecognized_type', type: given_type) 35 | end 36 | end 37 | 38 | class UnexpectedDataType < CrdtError 39 | def initialize(given_type, expected_type) 40 | super t('crdt.unexpected_type', 41 | given: given_type, 42 | expected: expected_type) 43 | end 44 | end 45 | 46 | class NotACrdt < CrdtError 47 | def initialize 48 | super t('crdt.not_a_crdt') 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/riak/errors/failed_request.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/base' 16 | 17 | module Riak 18 | class FailedRequest < Error 19 | def initialize(message) 20 | super(message || t('failed_request')) 21 | end 22 | end 23 | 24 | # Exception raised when receiving an unexpected Protocol Buffers response from Riak 25 | class ProtobuffsFailedRequest < FailedRequest 26 | attr_reader :code, :original_message 27 | def initialize(code, message) 28 | super t('protobuffs_failed_request', :code => code, :body => message) 29 | @original_message = message 30 | @code = code 31 | @not_found = code == :not_found 32 | @server_error = code == :server_error 33 | end 34 | 35 | # @return [true, false] whether the error response is in JSON 36 | def is_json? 37 | begin 38 | JSON.parse(@original_message) 39 | true 40 | rescue 41 | false 42 | end 43 | end 44 | 45 | # @return [true,false] whether the error represents a "not found" response 46 | def not_found? 47 | @not_found 48 | end 49 | 50 | # @return [true,false] whether the error represents an internal 51 | # server error 52 | def server_error? 53 | @server_error 54 | end 55 | 56 | def body 57 | @original_message 58 | end 59 | end 60 | 61 | class ProtobuffsUnexpectedResponse < ProtobuffsFailedRequest 62 | def initialize(code, expected) 63 | super code, t('pbc.unexpected_response', expected: expected, actual: code) 64 | end 65 | end 66 | 67 | class ProtobuffsErrorResponse < ProtobuffsFailedRequest 68 | def initialize(payload) 69 | super payload.errcode, payload.errmsg 70 | end 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /lib/riak/errors/list_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/base' 16 | 17 | module Riak 18 | # Exception raised when listing objects in Riak 19 | class ListError < Error 20 | def initialize(message) 21 | super(message) 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/riak/errors/protobuffs_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/base' 16 | module Riak 17 | class ProtobuffsError < Error 18 | end 19 | 20 | class ProtobuffsFailedHeader < ProtobuffsError 21 | def initialize 22 | super t('pbc.failed_header') 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/riak/errors/search_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/base' 16 | 17 | module Riak 18 | class SearchError < Error 19 | class IndexExistsError < SearchError 20 | def initialize(name) 21 | super t('search.index_exists', name: name) 22 | end 23 | end 24 | 25 | class SchemaExistsError < SearchError 26 | def initialize(name) 27 | super t('search.schema_exists', name: name) 28 | end 29 | end 30 | 31 | class IndexArgumentError < SearchError 32 | def initialize(index) 33 | super t('search.index_argument_error', index: index) 34 | end 35 | end 36 | 37 | class IndexNonExistError < SearchError 38 | def initialize(index) 39 | super t('search.index_non_exist', index: index) 40 | end 41 | end 42 | 43 | class UnexpectedResultError < SearchError 44 | def initialize(expected, actual) 45 | super t('search.unexpected_result', expected: expected, actual: actual) 46 | end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /lib/riak/errors/time_series.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/base' 16 | 17 | module Riak 18 | class TimeSeriesError < Error 19 | class SerializeComplexNumberError < TimeSeriesError 20 | def initialize 21 | super t('time_series.serialize_complex_number') 22 | end 23 | end 24 | 25 | class SerializeRationalNumberError < TimeSeriesError 26 | def initialize 27 | super t('time_series.serialize_rational_number') 28 | end 29 | end 30 | 31 | class SerializeBigIntegerError < TimeSeriesError 32 | def initialize(bignum) 33 | super t('time_series.serialize_big_integer', bignum: bignum) 34 | end 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/riak/i18n.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'i18n' 16 | 17 | I18n.config.enforce_available_locales = true unless I18n.config.enforce_available_locales == false 18 | 19 | Dir.glob(File.expand_path("../locale/*.yml", __FILE__)).each do |locale_file| 20 | I18n.load_path << locale_file 21 | end 22 | -------------------------------------------------------------------------------- /lib/riak/index_collection.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | 17 | # IndexCollection provides extra tools for managing index matches returned by 18 | # a Secondary Index query. In Riak 1.4, these queries can be paginaged, and 19 | # match keys up with the index values they matched against. 20 | class IndexCollection < Array 21 | 22 | # @return [String] The continuation used to retrieve the next page of a 23 | # paginated query. 24 | attr_accessor :continuation 25 | 26 | # @return [Hash] A hash of index keys (String or 27 | # Integer, depending on whether the query was a binary or integer) to 28 | # arrays of keys. 29 | attr_accessor :with_terms 30 | 31 | def self.new_from_json(json) 32 | parsed = JSON.parse json 33 | fresh = nil 34 | if parsed['keys'] 35 | fresh = new parsed['keys'] 36 | elsif parsed['results'] 37 | fresh_terms = load_json_terms(parsed) 38 | fresh = new fresh_terms.values.flatten 39 | fresh.with_terms = fresh_terms 40 | else 41 | fresh = new [] 42 | end 43 | fresh.continuation = parsed['continuation'] 44 | 45 | fresh 46 | end 47 | 48 | def self.new_from_protobuf(message) 49 | fresh = nil 50 | if message.keys 51 | fresh = new message.keys 52 | elsif message.results 53 | fresh_terms = load_pb_terms(message) 54 | fresh = new fresh_terms.values.flatten 55 | fresh.with_terms = fresh_terms 56 | else 57 | fresh = new 58 | end 59 | fresh.continuation = message.continuation 60 | 61 | fresh 62 | end 63 | 64 | private 65 | def self.load_json_terms(parsed) 66 | fresh_terms = Hash.new{Array.new} 67 | parsed['results'].each do |r| 68 | k = r.keys.first 69 | v = r[k] 70 | fresh_terms[k] += [v] 71 | end 72 | 73 | fresh_terms 74 | end 75 | 76 | def self.load_pb_terms(message) 77 | fresh_terms = Hash.new{Array.new} 78 | message.results.each do |r| 79 | fresh_terms[r.key] += [r.value] 80 | end 81 | 82 | fresh_terms 83 | end 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /lib/riak/instrumentation.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | begin 16 | require 'instrumentable' 17 | require 'riak/client/instrumentation' 18 | rescue LoadError => e 19 | # Go quietly into the night...(?) 20 | end 21 | -------------------------------------------------------------------------------- /lib/riak/json.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'multi_json' 16 | if MultiJson.respond_to?(:adapter) 17 | MultiJson.adapter 18 | else 19 | MultiJson.engine # Force loading of an engine 20 | end 21 | require 'riak/core_ext/json' 22 | 23 | module Riak 24 | class << self 25 | # Options that will be passed to the JSON parser and encoder. 26 | # Defaults to `{:max_nesting => 20}` 27 | attr_accessor :json_options 28 | end 29 | self.json_options = {:max_nesting => 20} 30 | 31 | # JSON module for internal use inside riak-client 32 | module JSON 33 | class << self 34 | if MultiJson.respond_to?(:dump) # MultiJson 1.2 or later 35 | # Parse a JSON string 36 | # @param [String] str a JSON payload 37 | # @return [Array,Hash] a Ruby object decoded from the JSON payload 38 | def parse(str) 39 | MultiJson.load(str, Riak.json_options) 40 | end 41 | 42 | # Generate a JSON string 43 | # @param [Array, Hash] obj an object to JSON-encode 44 | # @return [String] a JSON payload 45 | def encode(obj) 46 | MultiJson.dump(obj) 47 | end 48 | else 49 | # Parse a JSON string 50 | # @param [String] str a JSON payload 51 | # @return [Array,Hash] a Ruby object decoded from the JSON payload 52 | def parse(str) 53 | MultiJson.decode(str, Riak.json_options) 54 | end 55 | 56 | # Generate a JSON string 57 | # @param [Array, Hash] obj an object to JSON-encode 58 | # @return [String] a JSON payload 59 | def encode(obj) 60 | MultiJson.encode(obj) 61 | end 62 | end 63 | alias :dump :encode 64 | end 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /lib/riak/list_buckets.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | class ListBuckets 17 | def initialize(client, options, block) 18 | @client = client 19 | @block = block 20 | @options = options 21 | perform_request 22 | end 23 | 24 | def perform_request 25 | @client.backend do |be| 26 | be.list_buckets @options, &wrapped_block 27 | end 28 | end 29 | 30 | private 31 | 32 | def wrapped_block 33 | proc do |bucket_names| 34 | next if bucket_names.nil? 35 | bucket_names.each do |bucket_name| 36 | bucket = @client.bucket bucket_name 37 | @block.call bucket 38 | end 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/riak/map_reduce/results.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | class MapReduce 17 | # @api private 18 | # Collects and normalizes results from MapReduce requests 19 | class Results 20 | # Creates a new result collector 21 | # @param [MapReduce] mr the MapReduce query 22 | def initialize(mr) 23 | @keep_count = mr.query.select {|p| p.keep }.size 24 | @hash = create_results_hash(mr.query) 25 | end 26 | 27 | # Adds a new result to the collector 28 | # @param [Fixnum] phase the phase index 29 | # @param [Array] result the phase result 30 | def add(phase, result) 31 | @hash[phase] += result 32 | end 33 | 34 | # Coalesces the query results 35 | # @return [Array] the query results, coalesced according to the 36 | # phase configuration 37 | def report 38 | if @keep_count > 1 39 | @hash.to_a.sort.map {|(num, results)| results } 40 | else 41 | @hash[@hash.keys.first] 42 | end 43 | end 44 | 45 | private 46 | def create_results_hash(query) 47 | # When the query is empty, only bucket/key pairs are returned, 48 | # but implicitly in phase 0. 49 | return { 0 => [] } if query.empty? 50 | 51 | # Pre-populate the hash with empty results for kept phases. 52 | # Additionally, the last phase is always implictly kept, even 53 | # when keep is false. 54 | query.inject({}) do |hash, phase| 55 | if phase.keep || query[-1] == phase 56 | hash[query.index(phase)] = [] 57 | end 58 | hash 59 | end 60 | end 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/riak/map_reduce_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/util/translation' 16 | 17 | module Riak 18 | # Raised when an error occurred in the Javascript map-reduce chain. 19 | # The message will be the body of the JSON error response. 20 | class MapReduceError < StandardError; end 21 | end 22 | -------------------------------------------------------------------------------- /lib/riak/multiexist.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/client' 16 | require 'riak/bucket' 17 | require 'riak/multi' 18 | 19 | module Riak 20 | # Coordinates a parallel exist? operation for multiple keys. 21 | class Multiexist < Multi 22 | private 23 | 24 | def work(bucket, key) 25 | bucket.exists?(key) 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/riak/multiget.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/client' 16 | require 'riak/bucket' 17 | require 'riak/multi' 18 | 19 | module Riak 20 | # Coordinates a parallel fetch operation for multiple keys. 21 | class Multiget < Multi 22 | # @deprecated use perform 23 | class << self 24 | alias_method :get_all, :perform 25 | end 26 | 27 | private 28 | 29 | def work(bucket, key) 30 | bucket[key] 31 | rescue Riak::FailedRequest => e 32 | raise e unless e.not_found? 33 | nil 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/riak/preflist_item.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak' 16 | 17 | module Riak 18 | # @abstract Parent module for preflist items 19 | module PreflistItem 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/riak/search.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | module Search 17 | end 18 | end 19 | 20 | require 'riak/search/index' 21 | require 'riak/search/query' 22 | require 'riak/search/result_collection' 23 | require 'riak/search/result_document' 24 | require 'riak/search/schema' 25 | require 'riak/errors/search_error' 26 | -------------------------------------------------------------------------------- /lib/riak/search/schema.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/search' 16 | require 'riak/errors/search_error' 17 | 18 | module Riak::Search 19 | # A schema is a Riak Search 2 concept that describes how to index documents. 20 | # They're implemented as a standard Solr XML schema. 21 | class Schema 22 | # @return [String] the name of the schema 23 | attr_reader :name 24 | 25 | # Initializes a schema object, that may or may not exist. 26 | # 27 | # @param [Riak::Client] client the client connected to the Riak cluster 28 | # you wish to operate on 29 | # @param [String] name the name of the schema 30 | def initialize(client, name) 31 | @client = client 32 | @name = name 33 | end 34 | 35 | # @return [Boolean] does this schema exist on Riak? 36 | def exists? 37 | !!schema_data 38 | end 39 | 40 | # @return [String] the XML content of this schema 41 | def content 42 | schema_data.content 43 | end 44 | 45 | # @param [String] content the XML content of this schema 46 | # @raise [Riak::SearchError::SchemaExistsError] if a schema with the given 47 | # name already exists 48 | def create!(content) 49 | fail Riak::SearchError::SchemaExistsError.new name if exists? 50 | 51 | @client.backend do |b| 52 | b.create_search_schema name, content 53 | end 54 | 55 | @schema_data = nil 56 | 57 | true 58 | end 59 | 60 | private 61 | 62 | def schema_data 63 | return @schema_data if defined?(@schema_data) && @schema_data 64 | 65 | sd = nil 66 | 67 | begin 68 | sd = @client.backend do |b| 69 | b.get_search_schema name 70 | end 71 | rescue Riak::ProtobuffsFailedRequest => e 72 | return nil if e.not_found? 73 | raise e 74 | end 75 | 76 | @schema_data = sd 77 | end 78 | end 79 | end 80 | -------------------------------------------------------------------------------- /lib/riak/serializers.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | module Serializers 17 | include Util::Translation 18 | extend self 19 | 20 | def [](content_type) 21 | serializers[content_type] 22 | end 23 | 24 | def []=(content_type, serializer) 25 | serializers[content_type] = serializer 26 | end 27 | 28 | def serialize(content_type, content) 29 | serializer_for(content_type).dump(content) 30 | end 31 | 32 | def deserialize(content_type, content) 33 | serializer_for(content_type).load(content) 34 | end 35 | 36 | private 37 | 38 | def serializer_for(content_type) 39 | serializers.fetch(content_type[/^[^;\s]+/]) do 40 | raise IOError.new(t('serializer_not_implemented', :content_type => content_type.inspect)) 41 | end 42 | end 43 | 44 | def serializers 45 | @serializers ||= {} 46 | end 47 | 48 | module TextPlain 49 | extend self 50 | 51 | def dump(object) 52 | object.to_s 53 | end 54 | 55 | def load(string) 56 | string 57 | end 58 | end 59 | 60 | module ApplicationJSON 61 | extend self 62 | 63 | def dump(object) 64 | object.to_json(Riak.json_options) 65 | end 66 | 67 | def load(string) 68 | Riak::JSON.parse(string) 69 | end 70 | end 71 | 72 | Serializers['text/plain'] = TextPlain 73 | Serializers['application/json'] = ApplicationJSON 74 | Serializers['application/x-ruby-marshal'] = ::Marshal 75 | 76 | YAML_MIME_TYPES = %w[ 77 | text/yaml 78 | text/x-yaml 79 | application/yaml 80 | application/x-yaml 81 | ] 82 | 83 | YAML_MIME_TYPES.each do |mime_type| 84 | Serializers[mime_type] = ::YAML 85 | end 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /lib/riak/time_series.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | 17 | # Container module for Riak Time Series features. 18 | module TimeSeries 19 | end 20 | end 21 | 22 | require 'riak/errors/time_series' 23 | 24 | require 'riak/time_series/collection' 25 | require 'riak/time_series/row' 26 | 27 | require 'riak/time_series/deletion' 28 | require 'riak/time_series/list' 29 | require 'riak/time_series/query' 30 | require 'riak/time_series/submission' 31 | require 'riak/time_series/read' 32 | -------------------------------------------------------------------------------- /lib/riak/time_series/collection.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak::TimeSeries 16 | class Collection < Array 17 | attr_accessor :columns 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/riak/time_series/deletion.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak::TimeSeries 16 | 17 | # Delete entries from Riak Time Series. 18 | class Deletion 19 | attr_accessor :key 20 | attr_accessor :options 21 | 22 | attr_reader :client 23 | attr_reader :table_name 24 | 25 | def initialize(client, table_name) 26 | @client = client 27 | @table_name = table_name 28 | @options = Hash.new 29 | end 30 | 31 | def delete! 32 | client.backend do |be| 33 | be.time_series_delete_operator.delete(table_name, 34 | key, 35 | options) 36 | end 37 | true 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/riak/time_series/list.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/errors/list_error' 16 | 17 | module Riak::TimeSeries 18 | 19 | # A request to list keys in a Riak Time Series collection. Very expensive, 20 | # not recommended for use in production. 21 | class List 22 | include Riak::Util::Translation 23 | 24 | # @!attribute [r] table_name 25 | # @return [String] the table name to list keys in 26 | attr_reader :table_name 27 | 28 | # @!attribute [r] client 29 | # @return [Riak::Client] the Riak client to use for the list keys operation 30 | attr_reader :client 31 | 32 | # @!attribute [rw] timeout 33 | # @return [Integer] how many milliseconds Riak should wait for listing 34 | attr_accessor :timeout 35 | 36 | # @!attribute [r] results 37 | # @return [Riak::TimeSeries::Collection] each key 38 | # as a row in a collection; nil if keys were streamed to a block 39 | attr_reader :results 40 | 41 | # Initializes but does not issue the list keys operation 42 | # 43 | # @param [Riak::Client] client the Riak Client to list keys with 44 | # @param [String] table_name the table name to list keys in 45 | def initialize(client, table_name) 46 | @client = client 47 | @table_name = table_name 48 | @timeout = nil 49 | end 50 | 51 | # Issue the list keys request. Takes a block for streaming results, or 52 | # sets the #results read-only attribute iff no block is given. 53 | # 54 | # @yieldparam key [Riak::TimeSeries::Row] a listed key 55 | def issue!(&block) 56 | unless Riak.disable_list_exceptions 57 | msg = t('time_series.list_keys', :backtrace => caller.join("\n ")) 58 | raise Riak::ListError.new(msg) 59 | end 60 | 61 | options = { timeout: self.timeout } 62 | 63 | potential_results = nil 64 | 65 | client.backend do |be| 66 | op = be.time_series_list_operator(client.convert_timestamp) 67 | potential_results = op.list(table_name, block, options) 68 | end 69 | 70 | return @results = potential_results unless block_given? 71 | 72 | true 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /lib/riak/time_series/query.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak::TimeSeries 16 | 17 | # A query for Riak Time Series. Supports SQL for querying (data 18 | # manipulation language, or DML). 19 | class Query 20 | 21 | # @!attribute [rw] query_text 22 | # @return [String] the SQL query to run 23 | attr_accessor :query_text 24 | 25 | # Values to be interpolated into the query, support planned in Riak TS 26 | # 1.2 27 | attr_accessor :interpolations 28 | 29 | # @!attribute [r] client 30 | # @return [Riak::Client] the Riak client to use for the TS query 31 | attr_reader :client 32 | 33 | # #!attribute [r] results 34 | # @return [Riak::Client::BeefcakeProtobuffsBackend::TsQueryResp] 35 | # backend-dependent results object 36 | attr_reader :results 37 | 38 | # Initialize a query object 39 | # 40 | # @param [Riak::Client] client the client connected to the riak cluster 41 | # @param [String] query_text the SQL query to run 42 | # @param interpolations planned for Riak TS 1.1 43 | def initialize(client, query_text, interpolations = {}) 44 | @client = client 45 | @query_text = query_text 46 | @interpolations = interpolations 47 | end 48 | 49 | # Run the query against Riak TS, and store the results in the `results` 50 | # attribute 51 | def issue! 52 | @results = client.backend do |be| 53 | op = be.time_series_query_operator(client.convert_timestamp) 54 | op.query(query_text, interpolations) 55 | end 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /lib/riak/time_series/read.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak::TimeSeries 16 | class Read 17 | attr_accessor :key 18 | attr_reader :client 19 | attr_reader :table_name 20 | 21 | def initialize(client, table_name) 22 | @client = client 23 | @table_name = table_name 24 | end 25 | 26 | def read! 27 | client.backend do |be| 28 | op = be.time_series_get_operator(client.convert_timestamp) 29 | op.get(table_name, key) 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/riak/time_series/row.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak::TimeSeries 16 | class Row < Array 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/riak/time_series/submission.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak::TimeSeries 16 | class Submission 17 | 18 | # @!attributes [rw] measurements 19 | # @return [Array>] measurements to write to Riak TS 20 | attr_accessor :measurements 21 | 22 | # @!attribute [r] client 23 | # @return [Riak::Client] the client to write submissions to 24 | attr_reader :client 25 | 26 | # @!attribute [r] table_name 27 | # @return [String] the table name to write submissions to 28 | attr_reader :table_name 29 | 30 | # Initializes the submission object with a client and table name 31 | # 32 | # @param [Riak::Client] client the client connected to the Riak TS cluster 33 | # @param [String] table_name the table name in the cluster 34 | def initialize(client, table_name) 35 | @client = client 36 | @table_name = table_name 37 | end 38 | 39 | # Write the submitted data to Riak. 40 | def write! 41 | client.backend do |be| 42 | be.time_series_put_operator.put(table_name, measurements) 43 | end 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/riak/tombstone.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/util/translation' 16 | 17 | module Riak 18 | # Raised when a tombstone object (i.e. has vclock, but no rcontent values) is 19 | # stored or manipulated as if it had a single value. 20 | class Tombstone < StandardError 21 | include Util::Translation 22 | 23 | def initialize(robject) 24 | super t('tombstone_object', :robject => robject.inspect) 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/riak/util/gzip.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'zlib' 16 | require 'stringio' 17 | 18 | module Riak 19 | module Util 20 | # Borrowed from ActiveSupport 21 | # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/gzip.rb 22 | # 23 | # A convenient wrapper for the zlib standard library that allows 24 | # compression/decompression of strings with gzip. 25 | # 26 | # gzip = Riak::Util::Gzip.compress('compress me!') 27 | # # => "\x1F\x8B\b\x00o\x8D\xCDO\x00\x03K\xCE\xCF-(J-.V\xC8MU\x04\x00R>n\x83\f\x00\x00\x00" 28 | # 29 | # Riak::Util::Gzip.decompress(gzip) 30 | # # => "compress me!" 31 | module Gzip 32 | class Stream < StringIO 33 | def initialize(*) 34 | super 35 | set_encoding "BINARY" 36 | end 37 | 38 | def close 39 | rewind 40 | end 41 | end 42 | 43 | # Decompresses a gzipped string. 44 | def self.decompress(source) 45 | Zlib::GzipReader.new(StringIO.new(source)).read 46 | end 47 | 48 | # Compresses a string using gzip. 49 | def self.compress(source, level = Zlib::DEFAULT_COMPRESSION, strategy = Zlib::DEFAULT_STRATEGY) 50 | output = Stream.new 51 | gz = Zlib::GzipWriter.new(output, level, strategy) 52 | gz.write(source) 53 | gz.close 54 | output.string 55 | end 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /lib/riak/util/string.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | module Util 17 | # Methods comparing strings 18 | module String 19 | def equal_bytes?(a, b) 20 | return true if a.nil? && b.nil? 21 | 22 | return false unless a.respond_to?(:bytesize) 23 | return false unless b.respond_to?(:bytesize) 24 | return false unless a.bytesize == b.bytesize 25 | 26 | return false unless a.respond_to?(:bytes) 27 | return false unless b.respond_to?(:bytes) 28 | 29 | b1 = a.bytes.to_a 30 | b2 = b.bytes.to_a 31 | i = 0 32 | loop do 33 | c1 = b1[i] 34 | c2 = b2[i] 35 | return false unless c1 == c2 36 | i += 1 37 | break if i > b1.length 38 | end 39 | true 40 | end 41 | 42 | module_function :equal_bytes? 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/riak/util/tcp_socket_extensions.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'time' 16 | require 'timeout' 17 | require 'socket' 18 | 19 | # Borrowed from Webrat and Selenium client, watches for TCP port 20 | # liveness of the spawned server. 21 | # @private 22 | class TCPSocket 23 | def self.wait_for_service(options) 24 | verbose_wait until listening_service?(options) 25 | end 26 | 27 | def self.wait_for_service_termination(options) 28 | verbose_wait while listening_service?(options) 29 | end 30 | 31 | def self.listening_service?(options) 32 | Timeout::timeout(options[:timeout] || 20) do 33 | begin 34 | socket = TCPSocket.new(options[:host], options[:port]) 35 | socket.close unless socket.nil? 36 | true 37 | rescue Errno::ECONNREFUSED, 38 | Errno::EBADF # Windows 39 | false 40 | end 41 | end 42 | end 43 | 44 | def self.verbose_wait 45 | # Removed the puts call so as not to clutter up test output. 46 | sleep 2 47 | end 48 | 49 | def self.wait_for_service_with_timeout(options) 50 | start_time = Time.now 51 | 52 | until listening_service?(options) 53 | verbose_wait 54 | 55 | if options[:timeout] && (Time.now > start_time + options[:timeout]) 56 | raise SocketError.new("Socket did not open within #{options[:timeout]} seconds") 57 | end 58 | end 59 | end 60 | 61 | def self.wait_for_service_termination_with_timeout(options) 62 | start_time = Time.now 63 | 64 | while listening_service?(options) 65 | verbose_wait 66 | 67 | if options[:timeout] && (Time.now > start_time + options[:timeout]) 68 | raise SocketError.new("Socket did not terminate within #{options[:timeout]} seconds") 69 | end 70 | end 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /lib/riak/util/translation.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'riak/i18n' 16 | 17 | module Riak 18 | module Util 19 | # Methods for doing i18n string lookup 20 | module Translation 21 | # The scope of i18n messages 22 | def i18n_scope 23 | :riak 24 | end 25 | 26 | # Provides the translation for a given internationalized message 27 | def t(message, options = {}) 28 | I18n.t("#{i18n_scope}.#{message}", options) 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/riak/version.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module Riak 16 | VERSION = "2.6.0" 17 | end 18 | -------------------------------------------------------------------------------- /riak-client.gemspec: -------------------------------------------------------------------------------- 1 | require './lib/riak/version' 2 | 3 | Gem::Specification.new do |gem| 4 | gem.name = "riak-client" 5 | gem.version = Riak::VERSION 6 | gem.summary = %Q{riak-client is a rich client for Riak, the distributed database by Basho.} 7 | gem.description = %Q{#{gem.summary} It supports the full HTTP and Protocol Buffers interfaces including storage operations, bucket configuration, link-walking, secondary indexes and map-reduce.} 8 | gem.email = ['lbakken@basho.com'] 9 | gem.homepage = "http://github.com/basho/riak-ruby-client" 10 | gem.authors = ['Bryce Kerley', 'Luke Bakken'] 11 | gem.license = 'Apache-2.0' 12 | 13 | gem.required_ruby_version = '>= 1.9.3' 14 | 15 | gem.add_development_dependency 'activesupport', '~> 4.2' 16 | gem.add_development_dependency 'instrumentable', '~> 1.1' 17 | gem.add_development_dependency 'kramdown', '~> 1.4' 18 | gem.add_development_dependency 'rake', '~> 10.1' 19 | gem.add_development_dependency 'rspec', '~> 3.0' 20 | gem.add_development_dependency 'rubocop', '~> 0.40.0' 21 | gem.add_development_dependency 'single_cov', '0.5.7' 22 | gem.add_development_dependency 'yard', '~> 0.8' 23 | 24 | gem.add_runtime_dependency 'beefcake', '~> 1.1' 25 | gem.add_runtime_dependency 'cert_validator', '~> 0.0.1' 26 | gem.add_runtime_dependency 'i18n', '~> 0.6' 27 | gem.add_runtime_dependency 'innertube', '~> 1.0' 28 | gem.add_runtime_dependency 'multi_json', '~> 1.0' 29 | 30 | gem.files = Dir['LICENSE.md', 'README.md', 'RELNOTES.md', 'lib/**/*'] 31 | end 32 | -------------------------------------------------------------------------------- /spec/failover/failover.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib') 16 | require 'riak' 17 | 18 | # This is not a formal spec yet. It's designed to be run agains a local dev 19 | # cluster while you bring nodes up and down. 20 | [ 21 | {:protocol => 'pbc', :protobuffs_backend => :Beefcake}, 22 | {:protocol => 'http', :http_backend => :NetHTTP}, 23 | {:protocol => 'http', :http_backend => :Excon} 24 | ].each do |opts| 25 | @client = Riak::Client.new( 26 | { 27 | :nodes => (1..3).map { |i| 28 | { 29 | :http_port => 8090 + i, 30 | :pb_port => 8080 + i 31 | } 32 | } 33 | }.merge(opts) 34 | ) 35 | 36 | errors = [] 37 | p opts 38 | 39 | n = 10 40 | c = 1000 41 | 42 | (0...n).map do |t| 43 | Thread.new do 44 | # Generate a stream of put reqs. Put a . for each success, an X for 45 | # each failure. 46 | c.times do |i| 47 | begin 48 | o = @client['test'].new("#{t}:#{i}") 49 | o.content_type = 'text/plain' 50 | o.data = i.to_s 51 | o.store 52 | o2 = @client['test'].get("#{t}:#{i}") 53 | o2.data == i.to_s or raise "wrong data" 54 | print '.' 55 | rescue => e 56 | print 'X' 57 | errors << e 58 | end 59 | end 60 | end 61 | end.each do |thread| 62 | thread.join 63 | end 64 | 65 | # Put errors 66 | puts 67 | errors.each do |e| 68 | puts e.inspect 69 | puts e.backtrace.map { |x| " #{x}" }.join("\n") 70 | end 71 | 72 | puts "\n\n" 73 | end 74 | -------------------------------------------------------------------------------- /spec/fixtures/bitcask.txt: -------------------------------------------------------------------------------- 1 | Bitcask is an Erlang application that provides an API for storing and retrieving key/value data into a log-structured hash table that provides very fast access. The design owes a lot to the principles found in log-structured file systems and draws inspiration from a number of designs that involve log file merging. 2 | 3 | Strengths 4 | Low latency per item read or written 5 | This is due to the write-once, append-only nature of the Bitcask database files. High throughput, especially when writing an incoming stream of random items Because the data being written doesn't need to be ordered on disk and because the log structured design allows for minimal disk head movement during writes these operations generally saturate the I/O and disk bandwidth. 6 | 7 | Ability to handle datasets larger than RAM w/o degradation 8 | Because access to data in Bitcask is direct lookup from an in-memory hash table finding data on disk is very efficient, even when data sets are very large. 9 | 10 | Single Seek to Retrieve Any Value 11 | Bitcask's in-memory hash-table of keys point directly to locations on disk where the data lives. Bitcask never uses more than one disk seek to read a value and sometimes, due to file-system caching done by the operating system, even that isn't necessary. 12 | 13 | Predictable Lookup and Insert Performance 14 | As you might expect from the description above, read operations have a fixed, predictable behavior. What you might not expect is that this is also true for writes. Write operations are at most a seek to the end of the current file open writing and an append to that file. 15 | 16 | Fast, bounded Crash Recovery 17 | Due to the append-only write once nature of Bitcask files, recovery is easy and fast. The only items that might be lost are partially written records at the tail of the file last opened for writes. Recovery need only review the last record or two written and verify CRC data to ensure that the data is consistent. 18 | 19 | Easy Backup 20 | In most systems backup can be very complicated but here again Bitcask simplifies this process due to its append-only write once disk format. Any utility that archives or copies files in disk-block order will properly backup or copy a Bitcask database. 21 | 22 | Weakness 23 | Keys Must Fit In Memory 24 | Bitcask keeps all keys in memory at all times, this means that your system must have enough memory to contain your entire keyspace with room for other operational components and operating system resident filesystem buffer space. 25 | 26 | -------------------------------------------------------------------------------- /spec/fixtures/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basho/riak-ruby-client/ce831c2ba8c17291f6826038f0f4f5549ecf8712/spec/fixtures/cat.jpg -------------------------------------------------------------------------------- /spec/fixtures/multipart-basic-conflict.txt: -------------------------------------------------------------------------------- 1 | --8XZD3w6ttFTHIz6LCmhVxn9Ex0K 2 | Content-Type: text/plain 3 | Link: ; rel="up" 4 | Etag: 2baUwethOoLrVkwnMqzBRW 5 | Last-Modified: Mon, 15 Oct 2012 19:36:06 GMT 6 | 7 | bar 8 | --8XZD3w6ttFTHIz6LCmhVxn9Ex0K 9 | Content-Type: text/plain 10 | Link: ; rel="up" 11 | Etag: 6NtlHf8Lc3TEcCTKOVqEkl 12 | Last-Modified: Mon, 15 Oct 2012 19:35:57 GMT 13 | 14 | foo 15 | --8XZD3w6ttFTHIz6LCmhVxn9Ex0K-- 16 | -------------------------------------------------------------------------------- /spec/fixtures/multipart-blank.txt: -------------------------------------------------------------------------------- 1 | 2 | --73NmmA8dJxSB5nL2dVerpFIi8ze 3 | Content-Type: multipart/mixed; boundary=8fPXq9XfV15txMoV1IbA3hovEij 4 | 5 | --8fPXq9XfV15txMoV1IbA3hovEij-- 6 | 7 | --73NmmA8dJxSB5nL2dVerpFIi8ze-- 8 | -------------------------------------------------------------------------------- /spec/fixtures/multipart-mapreduce.txt: -------------------------------------------------------------------------------- 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-- 11 | -------------------------------------------------------------------------------- /spec/fixtures/multipart-with-body.txt: -------------------------------------------------------------------------------- 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: ; 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-- 17 | -------------------------------------------------------------------------------- /spec/fixtures/multipart-with-marked-tombstones.txt: -------------------------------------------------------------------------------- 1 | 2 | --ADqgQtdmA5iQgyR5UGzX6V3HZtI 3 | Content-Type: multipart/mixed; boundary=Ljz1mP3hZzqPu6DH1Y4L8k7hfxy 4 | 5 | --Ljz1mP3hZzqPu6DH1Y4L8k7hfxy 6 | X-Riak-Vclock: a85hYGBgzGDKBVIcypz/fvrNPcuWwZTIlMfKIOotdIIvCwA= 7 | Location: /buckets/links/keys/target 8 | Content-Type: application/octet-stream 9 | Link: ; rel="up" 10 | Etag: 5bUNdzHJhZDdCr7KlWxXq 11 | Last-Modified: Tue, 18 Oct 2011 19:10:13 GMT 12 | X-Riak-Deleted: true 13 | 14 | 15 | --Ljz1mP3hZzqPu6DH1Y4L8k7hfxy-- 16 | 17 | --ADqgQtdmA5iQgyR5UGzX6V3HZtI-- 18 | -------------------------------------------------------------------------------- /spec/fixtures/multipart-with-unmarked-tombstone.txt: -------------------------------------------------------------------------------- 1 | 2 | --CvfrSTCWwIiwezy0Zt1B2zwKgS7 3 | Content-Type: multipart/mixed; boundary=E9n2ZOKHIazIoPHzXj9XsWYWJjJ 4 | 5 | --E9n2ZOKHIazIoPHzXj9XsWYWJjJ 6 | X-Riak-Vclock: a85hYGBgzGDKBVIcypz/fvpN53+WwZTIlMfKcNVJ6ARfFgA= 7 | Location: /buckets/links/keys/target 8 | Content-Type: application/octet-stream 9 | Link: ; rel="up" 10 | Etag: 50FOyLo7juvEVUO33MRJwP 11 | Last-Modified: Tue, 18 Oct 2011 18:35:01 GMT 12 | 13 | 14 | --E9n2ZOKHIazIoPHzXj9XsWYWJjJ-- 15 | 16 | --CvfrSTCWwIiwezy0Zt1B2zwKgS7-- 17 | -------------------------------------------------------------------------------- /spec/fixtures/server.cert.crt: -------------------------------------------------------------------------------- 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----- 16 | -------------------------------------------------------------------------------- /spec/fixtures/server.cert.key: -------------------------------------------------------------------------------- 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----- 16 | -------------------------------------------------------------------------------- /spec/fixtures/test.pem: -------------------------------------------------------------------------------- 1 | i-am-a-pem 2 | -------------------------------------------------------------------------------- /spec/fixtures/yz_schema_template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | _yz_id 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /spec/integration/riak/counters_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak' 17 | 18 | describe Riak::Counter, test_client: true, integration: true do 19 | before :all do 20 | @bucket = random_bucket 'counter_spec' 21 | @bucket.allow_mult = true 22 | 23 | @counter = Riak::Counter.new @bucket, 'counter_spec' 24 | end 25 | 26 | it 'reads and updates' do 27 | initial = @counter.value 28 | 29 | @counter.increment 30 | @counter.increment 31 | 32 | expect(@counter.value).to eq(initial + 2) 33 | 34 | @counter.decrement 2 35 | 36 | expect(@counter.value).to eq(initial) 37 | 38 | 5.times do 39 | amt = rand(10_000) 40 | 41 | @counter.increment amt 42 | expect(@counter.value).to eq(initial + amt) 43 | 44 | @counter.decrement (amt * 2) 45 | expect(@counter.value).to eq(initial - amt) 46 | 47 | expect(@counter.increment_and_return(amt)).to eq(initial) 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /spec/integration/riak/crdt/configuration_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak' 17 | 18 | describe "CRDT configuration", integration: true, test_client: true do 19 | SETS = Riak::Crdt::DEFAULT_BUCKET_TYPES[:set] 20 | let(:bucket) { random_bucket } 21 | 22 | it "allows default bucket-types to be configured for each data type" do 23 | expect(Riak::Crdt::Set.new(bucket, 'set').bucket_type).to eq SETS 24 | 25 | Riak::Crdt::DEFAULT_BUCKET_TYPES[:set] = 'new_set_default' 26 | expect(Riak::Crdt::Set.new(bucket, 'set').bucket_type).to eq 'new_set_default' 27 | 28 | Riak::Crdt::DEFAULT_BUCKET_TYPES[:set] = SETS 29 | expect(Riak::Crdt::Set.new(bucket, 'set').bucket_type).to eq SETS 30 | end 31 | 32 | describe 'overriding bucket-types' do 33 | let(:name){ 'other_counters' } 34 | let(:type){ test_client.bucket_type name } 35 | let(:typed_bucket){ type.bucket bucket.name } 36 | 37 | it "overrides with a string" do 38 | ctr = Riak::Crdt::Counter.new(bucket, 'ctr', name) 39 | expect(ctr.bucket_type).to eq name 40 | end 41 | 42 | it "overrides with a typed bucket" do 43 | ctr = Riak::Crdt::Counter.new(typed_bucket, 'ctr') 44 | expect(ctr.bucket_type).to eq name 45 | end 46 | 47 | it "overrides with a bucket type object" do 48 | ctr = Riak::Crdt::Counter.new(bucket, 'ctr', type) 49 | expect(ctr.bucket_type).to eq name 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /spec/integration/riak/crdt_validation/grow_only_set_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak' 17 | 18 | describe 'Grow Only CRDT set validation', integration: true, test_client: true do 19 | before(:each) do 20 | ensure_datatype_exists :gset 21 | end 22 | 23 | let(:bucket){ random_bucket 'crdt_validation' } 24 | let(:set){ Riak::Crdt::GrowOnlySet.new bucket, random_key } 25 | 26 | it 'adds duplicate members' do 27 | set.batch do |s| 28 | s.add 'X' 29 | s.add 'Y' 30 | end 31 | 32 | set.reload 33 | 34 | expect{ set.add 'X' }.to_not raise_error 35 | 36 | set2 = Riak::Crdt::GrowOnlySet.new bucket, set.key 37 | expect(set2.members).to eq ::Set.new(%w{X Y}) 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /spec/integration/riak/crdt_validation/map_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak' 17 | 18 | describe 'CRDT map validation', integration: true, test_client: true do 19 | let(:bucket){ random_bucket 'crdt_validation' } 20 | let(:map){ Riak::Crdt::Map.new bucket, random_key } 21 | 22 | it 'deletes sets and re-add entries' do 23 | map.batch do |m| 24 | m.sets['set'].add 'X' 25 | m.sets['set'].add 'Y' 26 | end 27 | 28 | map.reload 29 | expect(map.sets['set'].include? 'Y').to be 30 | 31 | expect do 32 | map.batch do |m| 33 | m.sets.delete 'set' 34 | m.sets['set'].add 'Z' 35 | end 36 | end.to_not raise_error 37 | 38 | map2 = Riak::Crdt::Map.new bucket, map.key 39 | 40 | expect(map2.sets['set'].members).to eq ::Set.new(['Z']) 41 | end 42 | 43 | it 'deletes counters and increments counters' do 44 | map.counters['counter'].increment 5 45 | 46 | map.reload 47 | 48 | expect(map.counters['counter'].value).to eq 5 49 | 50 | map.batch do |m| 51 | m.counters['counter'].increment 2 52 | m.counters.delete 'counter' 53 | end 54 | 55 | map2 = Riak::Crdt::Map.new bucket, map.key 56 | 57 | expect(map2.counters['counter'].value).to eq(7).or eq(2) 58 | end 59 | 60 | it 'deletes maps containing sets and re-adds the contained sets' do 61 | map.batch do |m| 62 | m.maps['map'].sets['set'].add "X" 63 | m.maps['map'].sets['set'].add "Y" 64 | end 65 | 66 | map.reload 67 | expect(map.maps['map'].sets['set'].members).to eq ::Set.new(%w(X Y)) 68 | 69 | map.batch do |m| 70 | m.maps.delete 'map' 71 | m.maps['map'].sets['set'].add "Z" 72 | end 73 | 74 | map2 = Riak::Crdt::Map.new bucket, map.key 75 | expect(map2.maps['map'].sets['set'].members).to eq ::Set.new(['Z']) 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /spec/integration/riak/preflist_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak' 17 | 18 | describe 'Preflist', integration: true, test_client: true do 19 | let(:bucket){ random_bucket } 20 | let(:robject) do 21 | bucket.get_or_new(random_key).tap do |robj| 22 | robj.data = 'asdf' 23 | robj.store 24 | end 25 | end 26 | 27 | matcher :be_a_preflist do 28 | match do |actual| 29 | actual.is_a?(Array) && 30 | actual.first.is_a?(Riak::PreflistItem) 31 | end 32 | end 33 | 34 | it 'is available from RObjects' do 35 | begin 36 | expect(robject.preflist).to be_a_preflist 37 | rescue Riak::ProtobuffsErrorResponse 38 | skip('preflists are not supported') 39 | end 40 | end 41 | 42 | it 'is available from Buckets' do 43 | begin 44 | expect(bucket.get_preflist robject.key).to be_a_preflist 45 | rescue Riak::ProtobuffsErrorResponse 46 | skip('preflists are not supported') 47 | end 48 | end 49 | 50 | it 'is available from the Client' do 51 | begin 52 | expect(test_client.get_preflist bucket.name, robject.key).to be_a_preflist 53 | rescue Riak::ProtobuffsErrorResponse 54 | skip('preflists are not supported') 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/integration/riak/properties_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak/bucket_properties' 17 | 18 | describe Riak::BucketProperties, test_client: true, integration: true do 19 | describe 'Bucket Properties objects' do 20 | let(:bucket){ random_bucket 'props' } 21 | subject{ described_class.new bucket } 22 | 23 | let(:other_bucket) do 24 | random_bucket('props-other').tap do |b| 25 | p = described_class.new b 26 | p['r'] = 1 27 | p.store 28 | end 29 | end 30 | let(:other_props){ described_class.new other_bucket } 31 | 32 | before(:example) do 33 | bucket.clear_props 34 | subject.reload 35 | end 36 | 37 | it 'is initializable with a bucket' do 38 | expect{ described_class.new bucket }.to_not raise_error 39 | end 40 | 41 | it 'works like a hash' do 42 | expect(subject['r']).to eq 'quorum' 43 | expect{ subject['r'] = 1 }.to_not raise_error 44 | subject.store 45 | subject.reload 46 | 47 | expect(subject['r']).to eq 1 48 | end 49 | 50 | it 'can be merged from a hash' do 51 | bulk_props = { r: 1, w: 1, dw: 1 } 52 | expect{ subject.merge! bulk_props }.to_not raise_error 53 | subject.store 54 | subject.reload 55 | 56 | expect(subject['r']).to eq 1 57 | expect(subject['w']).to eq 1 58 | expect(subject['dw']).to eq 1 59 | end 60 | 61 | it 'can be merged from a bucket properties object' do 62 | expect(other_props['r']).to eq 1 63 | expect(subject['r']).to eq 'quorum' 64 | 65 | expect{ subject.merge! other_props }.to_not raise_error 66 | subject.store 67 | subject.reload 68 | 69 | expect(subject['r']).to eq 1 70 | end 71 | 72 | let(:modfun){ { 'mod' => 'validate_json', 'fun' => 'validate' } } 73 | 74 | it 'works with composite/modfun properties' do 75 | expect{ subject['precommit'] = modfun }.to_not raise_error 76 | 77 | subject.store 78 | subject.reload 79 | 80 | expect(subject['precommit']).to eq [modfun] 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /spec/integration/riak/protobuffs/interrupted_request_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'timeout' 17 | 18 | describe 'Protocol Buffers', test_client: true do 19 | describe 'interrupted requests' do 20 | 21 | let(:bucket){ random_bucket 'interrupted_requests' } 22 | 23 | before do 24 | first = bucket.new 'first' 25 | first.data = 'first' 26 | first.content_type = 'text/plain' 27 | first.store 28 | 29 | second = bucket.new 'second' 30 | second.data = 'second' 31 | second.content_type = 'text/plain' 32 | second.store 33 | end 34 | 35 | it 'fails out when a request is interrupted, and never returns the wrong payload' do 36 | expect do 37 | Timeout.timeout 1 do 38 | loop do 39 | expect(bucket.get('first').data).to eq 'first' 40 | end 41 | end 42 | end.to raise_error Timeout::Error 43 | 44 | expect(bucket.get('second').data).to eq 'second' 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /spec/integration/riak/protobuffs_backends_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe "Protocol Buffers", test_client: true do 18 | before do 19 | @client = test_client 20 | @bucket = random_bucket 'protobuf_spec' 21 | end 22 | 23 | [:BeefcakeProtobuffsBackend].each do |klass| 24 | bklass = Riak::Client.const_get(klass) 25 | if bklass.configured? 26 | describe klass.to_s do 27 | before do 28 | @backend = bklass.new(@client, @client.node) 29 | end 30 | 31 | it_should_behave_like "Unified backend API" 32 | 33 | describe "searching yokozuna" do 34 | include_context "search corpus setup" 35 | 36 | it 'returns documents with UTF-8 fields (GH #75)' do 37 | utf8 = Encoding.find('UTF-8') 38 | results = @backend.search( 39 | @search_bucket.name, 40 | 'fearless elephant rushed', 41 | df: 'text' 42 | ) 43 | results['docs'].each do |d| 44 | d.each do |(k, v)| 45 | expect(k.encoding).to eq(utf8) 46 | expect(v.encoding).to eq(utf8) 47 | end 48 | end 49 | end 50 | end 51 | end 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /spec/integration/yokozuna/index_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak' 17 | 18 | describe "Yokozuna", test_client: true, integration: true do 19 | before(:all) do 20 | @client = test_client 21 | 22 | @index = 'yz_spec-' + random_key 23 | @schema = 'yz_spec-' + random_key 24 | end 25 | 26 | context "without any indexes" do 27 | it "allows index creation" do 28 | expect(@client.create_search_index(@index, "_yz_default", 3)).to eq(true) 29 | end 30 | end 31 | 32 | context "with an index" do 33 | before :all do 34 | expect(@client.create_search_index(@index)).to eq(true) 35 | wait_until{ !@client.get_search_index(@index).nil? } 36 | end 37 | 38 | it "allows index inspection" do 39 | expect(@client.get_search_index(@index).name).to eq(@index) 40 | expect{ @client.get_search_index("herp_derp") }.to raise_error(Riak::ProtobuffsFailedRequest) 41 | end 42 | 43 | it "has an index list" do 44 | expect(@client.list_search_indexes.size).to be >= 1 45 | end 46 | 47 | it "associates a bucket with an index" do 48 | @bucket = Riak::Bucket.new(@client, @index) 49 | @bucket.props = {'search_index' => @index} 50 | @bucket = @client.bucket(@index) 51 | expect(@bucket.props).to include('search_index' => @index) 52 | end 53 | 54 | context "associated with a bucket" do 55 | before :all do 56 | @bucket = Riak::Bucket.new(@client, @index) 57 | @bucket.props = {'search_index' => @index} 58 | @bucket = @client.bucket(@index) 59 | expect(@bucket.props).to include('search_index' => @index) 60 | end 61 | 62 | it "indexes on object writes" do 63 | object = @bucket.get_or_new("cat") 64 | object.raw_data = {"cat_s"=>"Lela"}.to_json 65 | object.content_type = 'application/json' 66 | object.store 67 | sleep 2.1 # pause for index commit to trigger 68 | 69 | resp = @client.search(@index, "cat_s:Lela") 70 | expect(resp).to include('docs') 71 | expect(resp['docs'].size).to eq(1) 72 | end 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak/client/beefcake/object_methods' 17 | require 'riak/client/beefcake/messages' 18 | 19 | describe Riak::Client::BeefcakeProtobuffsBackend::ObjectMethods do 20 | before :each do 21 | @client = Riak::Client.new 22 | @backend = Riak::Client::BeefcakeProtobuffsBackend.new(@client, @client.node) 23 | @bucket = Riak::Bucket.new(@client, "bucket") 24 | @object = Riak::RObject.new(@bucket, "bar") 25 | @content = double( 26 | :value => '', 27 | :vtag => nil, 28 | :content_type => nil, 29 | :content_encoding => nil, 30 | :links => nil, 31 | :usermeta => nil, 32 | :last_mod => nil, 33 | :last_mod_usecs => nil, 34 | :indexes => nil, 35 | :charset => nil 36 | ) 37 | end 38 | 39 | describe "loading object data from the response" do 40 | it "loads the key" do 41 | pbuf = double(:vclock => nil, :content => [@content], :value => nil, :key => 'akey') 42 | o = @backend.load_object(pbuf, @object) 43 | expect(o).to eq(@object) 44 | expect(o.key).to eq(pbuf.key) 45 | end 46 | 47 | describe "last_modified" do 48 | before :each do 49 | allow(@content).to receive(:last_mod) { 1271442363 } 50 | end 51 | 52 | it "is set to time of last_mod with microseconds from last_mod_usecs" do 53 | allow(@content).to receive(:last_mod_usecs) { 105696 } 54 | pbuf = double(:vclock => nil, :content => [@content], :value => nil, :key => 'akey') 55 | o = @backend.load_object(pbuf, @object) 56 | expect(o.last_modified).to eq(Time.at(1271442363, 105696)) 57 | end 58 | 59 | it "is set to time of last_mod without microseconds if last_mod_usecs is missing" do 60 | pbuf = double(:vclock => nil, :content => [@content], :value => nil, :key => 'akey') 61 | o = @backend.load_object(pbuf, @object) 62 | expect(o.last_modified).to eq(Time.at(1271442363, 0)) 63 | end 64 | end 65 | end 66 | 67 | end 68 | -------------------------------------------------------------------------------- /spec/riak/bucket_type_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak/bucket_type' 17 | 18 | describe Riak::BucketType do 19 | let(:client){ Riak::Client.allocate } 20 | let(:name){ 'bucket_type_spec' } 21 | let(:backend) do 22 | double('Backend').tap do |backend| 23 | allow(client).to receive(:backend).and_yield(backend) 24 | end 25 | end 26 | 27 | subject{ described_class.new client, name } 28 | 29 | it 'is created with a client and name' do 30 | expect{ described_class.new client, name }.to_not raise_error 31 | end 32 | 33 | it 'returns a typed bucket' do 34 | typed_bucket = subject.bucket 'empanadas' 35 | expect(typed_bucket).to be_a Riak::Bucket 36 | expect(typed_bucket).to be_a Riak::BucketTyped::Bucket 37 | expect(typed_bucket.name).to eq 'empanadas' 38 | expect(typed_bucket.type).to eq subject 39 | end 40 | 41 | describe 'equality' do 42 | let(:same){ described_class.new client, name } 43 | let(:different_client){ described_class.new Riak::Client.allocate, name } 44 | let(:different_name){ described_class.new client, 'different name' } 45 | it { is_expected.to eq same } 46 | it { is_expected.to_not eq different_client } 47 | it { is_expected.to_not eq different_name } 48 | end 49 | 50 | describe 'properties' do 51 | let(:props_expectation){ expect(backend).to receive(:get_bucket_type_props).with(name) } 52 | 53 | it 'is queryable' do 54 | props_expectation.and_return(allow_mult: true) 55 | expect(props = subject.properties).to be_a Hash 56 | expect(props[:allow_mult]).to be 57 | end 58 | 59 | it 'asks for data type' do 60 | props_expectation.and_return(datatype: 'set') 61 | expect(subject.data_type_class).to eq Riak::Crdt::Set 62 | end 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /spec/riak/core_ext/to_param_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | describe Riak do 16 | require 'riak/core_ext/to_param' 17 | 18 | it "converts params correctly" do 19 | expect({ :name => 'David', :nationality => 'Danish' }.to_param).to eq("name=David&nationality=Danish") 20 | end 21 | 22 | # Based on the activesupport implementation. 23 | # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/to_param.rb 24 | it "converts namespaced params correctly" do 25 | expect({ :name => 'David', :nationality => 'Danish' }.to_param('user')).to eq("user%5Bname%5D=David&user%5Bnationality%5D=Danish") 26 | end 27 | 28 | end 29 | -------------------------------------------------------------------------------- /spec/riak/crdt/counter_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require_relative 'shared_examples' 17 | 18 | describe Riak::Crdt::Counter do 19 | let(:bucket) do 20 | double('bucket').tap do |b| 21 | allow(b).to receive(:name).and_return('bucket') 22 | allow(b).to receive(:is_a?).with(Riak::Bucket).and_return(true) 23 | allow(b).to receive(:is_a?).with(Riak::BucketTyped::Bucket).and_return(false) 24 | end 25 | end 26 | it 'initializes with bucket, key, and optional bucket-type' do 27 | expect{ described_class.new bucket, 'key' }.to_not raise_error 28 | expect{ described_class.new bucket, 'key', 'type' }.to_not raise_error 29 | end 30 | 31 | subject{ described_class.new bucket, 'key' } 32 | 33 | describe 'with a client' do 34 | let(:response){ double 'response', key: nil } 35 | let(:operator){ double 'operator' } 36 | let(:loader){ double 'loader', get_loader_for_value: nil } 37 | let(:backend){ double 'backend' } 38 | let(:client){ double 'client' } 39 | 40 | before(:each) do 41 | allow(bucket).to receive(:client).and_return(client) 42 | allow(client).to receive(:backend).and_yield(backend) 43 | allow(backend).to receive(:crdt_operator).and_return(operator) 44 | allow(backend).to receive(:crdt_loader).and_return(loader) 45 | end 46 | 47 | include_examples 'Counter CRDT' 48 | 49 | it 'batches properly' do 50 | expect(operator). 51 | to receive(:operate) { |bucket, key, type, operations| 52 | expect(bucket).to eq bucket 53 | expect(key).to eq 'key' 54 | expect(type).to eq subject.bucket_type 55 | 56 | expect(operations).to be_a Riak::Crdt::Operation::Update 57 | expect(operations.value).to eq 5 58 | }. 59 | and_return(response) 60 | 61 | subject.batch do |s| 62 | s.increment 4 # 4 63 | s.decrement 2 # 2 64 | s.increment 4 # 6 65 | s.decrement # 5 66 | end 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /spec/riak/crdt/grow_only_set_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require_relative 'shared_examples' 17 | 18 | describe Riak::Crdt::GrowOnlySet do 19 | let(:bucket) do 20 | double('bucket').tap do |b| 21 | allow(b).to receive(:name).and_return('bucket') 22 | allow(b).to receive(:is_a?).with(Riak::Bucket).and_return(true) 23 | allow(b).to receive(:is_a?).with(Riak::BucketTyped::Bucket).and_return(false) 24 | end 25 | end 26 | 27 | it 'initializes with bucket, key, and optional bucket-type' do 28 | expect{described_class.new bucket, 'key', 'optional bucket type'}. 29 | to_not raise_error 30 | end 31 | 32 | subject{ described_class.new bucket, 'key' } 33 | 34 | describe 'with a client' do 35 | let(:response){ double 'response', key: nil } 36 | let(:operator){ double 'operator' } 37 | let(:loader){ double 'loader', get_loader_for_value: nil } 38 | let(:backend){ double 'backend' } 39 | let(:client){ double 'client' } 40 | 41 | before(:each) do 42 | allow(bucket).to receive(:client).and_return(client) 43 | allow(client).to receive(:backend).and_yield(backend) 44 | allow(backend).to receive(:crdt_operator).and_return(operator) 45 | allow(backend).to receive(:crdt_loader).and_return(loader) 46 | end 47 | 48 | include_examples 'Grow Only Set CRDT' 49 | 50 | it 'batches properly' do 51 | expect(operator). 52 | to receive(:operate) { |bucket, key, type, operations| 53 | 54 | expect(bucket).to eq bucket 55 | expect(key).to eq 'key' 56 | expect(type).to eq subject.bucket_type 57 | 58 | expect(operations).to be_a Riak::Crdt::Operation::Update 59 | expect(operations.value).to eq({ 60 | add: %w{alpha bravo} 61 | }) 62 | }.and_return(response) 63 | 64 | subject.instance_variable_set :@context, 'placeholder' 65 | 66 | subject.batch do |s| 67 | s.add 'alpha' 68 | s.add 'bravo' 69 | end 70 | end 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /spec/riak/crdt/hyper_log_log_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require_relative 'shared_examples' 17 | 18 | describe Riak::Crdt::HyperLogLog, hll: true do 19 | let(:bucket) do 20 | double('bucket').tap do |b| 21 | allow(b).to receive(:name).and_return('bucket') 22 | allow(b).to receive(:is_a?).with(Riak::Bucket).and_return(true) 23 | allow(b).to receive(:is_a?).with(Riak::BucketTyped::Bucket).and_return(false) 24 | end 25 | end 26 | 27 | it 'initializes with bucket, key, and bucket-type' do 28 | expect{described_class.new bucket, 'key', 'bucket type'}. 29 | to_not raise_error 30 | end 31 | 32 | subject{ described_class.new bucket, 'key' } 33 | 34 | describe 'with a client' do 35 | let(:response){ double 'response', key: nil } 36 | let(:operator){ double 'operator' } 37 | let(:loader){ double 'loader', get_loader_for_value: nil } 38 | let(:backend){ double 'backend' } 39 | let(:client){ double 'client' } 40 | 41 | before(:each) do 42 | allow(bucket).to receive(:client).and_return(client) 43 | allow(client).to receive(:backend).and_yield(backend) 44 | allow(backend).to receive(:crdt_operator).and_return(operator) 45 | allow(backend).to receive(:crdt_loader).and_return(loader) 46 | end 47 | 48 | include_examples 'HyperLogLog CRDT' 49 | 50 | it 'batches properly' do 51 | expect(operator). 52 | to receive(:operate) { |bucket, key, type, operations| 53 | expect(bucket).to eq bucket 54 | expect(key).to eq 'key' 55 | expect(type).to eq subject.bucket_type 56 | 57 | expect(operations).to be_a Riak::Crdt::Operation::Update 58 | expect(operations.value).to eq({add: %w{alpha bravo}}) 59 | }. 60 | and_return(response) 61 | 62 | subject.instance_variable_set :@context, 'placeholder' 63 | 64 | subject.batch do |s| 65 | s.add 'alpha' 66 | s.add 'bravo' 67 | end 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /spec/riak/crdt/inner_counter_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require_relative 'shared_examples' 17 | 18 | describe Riak::Crdt::InnerCounter do 19 | let(:parent){ double 'parent' } 20 | let(:counter_name){ 'counter name' } 21 | subject do 22 | described_class.new(parent, 0).tap do |c| 23 | c.name = counter_name 24 | end 25 | end 26 | 27 | include_examples 'Counter CRDT' 28 | 29 | it 'sends increments to the parent' do 30 | expect(parent).to receive(:increment). 31 | with(counter_name, 1) 32 | 33 | subject.increment 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/riak/crdt/inner_flag_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe Riak::Crdt::InnerFlag do 18 | let(:parent){ double 'parent' } 19 | describe 'a truthy flag' do 20 | subject { described_class.new parent, true } 21 | 22 | it 'feels truthy' do 23 | expect(subject).to be 24 | end 25 | end 26 | 27 | describe 'a falsey flag' do 28 | subject { described_class.new parent, false } 29 | 30 | it 'feels falsey' do 31 | expect(subject).to_not be 32 | end 33 | end 34 | 35 | describe 'updating' do 36 | let(:new_value){ false } 37 | 38 | it 'asks the class for an update operation' do 39 | operation = described_class.update(new_value) 40 | 41 | expect(operation.value).to eq new_value 42 | expect(operation.type).to eq :flag 43 | end 44 | end 45 | 46 | describe 'deleting' do 47 | it 'asks the class for a delete operation' do 48 | operation = described_class.delete 49 | 50 | expect(operation.type).to eq :flag 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /spec/riak/crdt/inner_map_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require_relative 'shared_examples' 17 | 18 | describe Riak::Crdt::InnerMap do 19 | let(:parent){ double 'parent' } 20 | subject{ described_class.new parent, {} } 21 | 22 | include_examples 'Map CRDT' 23 | 24 | let(:populated_contents) do 25 | { 26 | counters: {alpha: 0}, 27 | flags: {bravo: true}, 28 | maps: {}, 29 | registers: {delta: 'the expendables' }, 30 | sets: {echo: %w{stallone statham li lundgren}} 31 | } 32 | end 33 | 34 | it 'is initializable with a nested hash of maps' do 35 | expect{described_class.new parent, populated_contents}. 36 | to_not raise_error 37 | end 38 | 39 | describe 'deleting the inner map' do 40 | it 'asks the class for a delete operation' do 41 | operation = described_class.delete 42 | 43 | expect(operation.type).to eq :map 44 | end 45 | end 46 | 47 | describe 'receiving an operation' do 48 | let(:inner_operation){ double 'inner operation' } 49 | it 'wraps the operation in an update operation and pass it to the parent' do 50 | subject.name = 'name' 51 | 52 | expect(parent).to receive(:operate) do |name, op| 53 | expect(name).to eq 'name' 54 | expect(op.type).to eq :map 55 | expect(op.value).to eq inner_operation 56 | end 57 | 58 | subject.operate inner_operation 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /spec/riak/crdt/inner_register_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe Riak::Crdt::InnerRegister do 18 | let(:parent){ double 'parent' } 19 | subject { described_class.new parent, "espressos" } 20 | 21 | it 'feels like a string' do 22 | expect(subject).to match 'espressos' 23 | expect{ subject.gsub('s', 'x') }.to_not raise_error 24 | expect(subject.gsub('s', 'x')).to eq 'exprexxox' 25 | end 26 | 27 | describe 'immutability' do 28 | it 'is frozen' do 29 | expect(subject.frozen?).to be 30 | end 31 | it "isn't be gsub!-able" do 32 | # "gsub!-able" is awful, open to suggestions 33 | expect{ subject.gsub!('s', 'x') }.to raise_error 34 | end 35 | end 36 | 37 | describe 'updating' do 38 | let(:new_value){ 'new value' } 39 | it "asks the class for an update operation" do 40 | operation = described_class.update(new_value) 41 | 42 | expect(operation.value).to eq new_value 43 | expect(operation.type).to eq :register 44 | end 45 | end 46 | 47 | describe 'deleting' do 48 | it 'asks the class for a delete operation' do 49 | operation = described_class.delete 50 | 51 | expect(operation.type).to eq :register 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /spec/riak/crdt/inner_set_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require_relative 'shared_examples' 17 | 18 | describe Riak::Crdt::InnerSet do 19 | let(:parent){ double 'parent' } 20 | let(:set_name){ 'set name' } 21 | subject do 22 | described_class.new(parent, []).tap do |s| 23 | s.name = set_name 24 | end 25 | end 26 | 27 | include_examples 'Set CRDT' 28 | 29 | it 'sends additions to the parent' do 30 | expect(parent).to receive(:operate) do |name, op| 31 | expect(name).to eq set_name 32 | expect(op.type).to eq :set 33 | expect(op.value).to eq add: 'el' 34 | end 35 | 36 | subject.add 'el' 37 | 38 | expect(parent).to receive(:operate) do |name, op| 39 | expect(name).to eq set_name 40 | expect(op.type).to eq :set 41 | expect(op.value).to eq remove: 'el2' 42 | end 43 | allow(parent).to receive(:context?).and_return(true) 44 | 45 | subject.remove 'el2' 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /spec/riak/crdt/set_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require_relative 'shared_examples' 17 | 18 | describe Riak::Crdt::Set do 19 | let(:bucket) do 20 | double('bucket').tap do |b| 21 | allow(b).to receive(:name).and_return('bucket') 22 | allow(b).to receive(:is_a?).with(Riak::Bucket).and_return(true) 23 | allow(b).to receive(:is_a?).with(Riak::BucketTyped::Bucket).and_return(false) 24 | end 25 | end 26 | 27 | it 'initializes with bucket, key, and optional bucket-type' do 28 | expect{described_class.new bucket, 'key', 'optional bucket type'}. 29 | to_not raise_error 30 | end 31 | 32 | subject{ described_class.new bucket, 'key' } 33 | 34 | describe 'with a client' do 35 | let(:response){ double 'response', key: nil } 36 | let(:operator){ double 'operator' } 37 | let(:loader){ double 'loader', get_loader_for_value: nil } 38 | let(:backend){ double 'backend' } 39 | let(:client){ double 'client' } 40 | 41 | before(:each) do 42 | allow(bucket).to receive(:client).and_return(client) 43 | allow(client).to receive(:backend).and_yield(backend) 44 | allow(backend).to receive(:crdt_operator).and_return(operator) 45 | allow(backend).to receive(:crdt_loader).and_return(loader) 46 | end 47 | 48 | include_examples 'Set CRDT' 49 | 50 | it 'batches properly' do 51 | expect(operator). 52 | to receive(:operate) { |bucket, key, type, operations| 53 | 54 | expect(bucket).to eq bucket 55 | expect(key).to eq 'key' 56 | expect(type).to eq subject.bucket_type 57 | 58 | expect(operations).to be_a Riak::Crdt::Operation::Update 59 | expect(operations.value).to eq({ 60 | add: %w{alpha bravo}, 61 | remove: %w{foxtrot} 62 | }) 63 | }.and_return(response) 64 | 65 | subject.instance_variable_set :@context, 'placeholder' 66 | 67 | subject.batch do |s| 68 | s.add 'alpha' 69 | s.add 'bravo' 70 | s.remove 'foxtrot' 71 | end 72 | end 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /spec/riak/index_collection_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe Riak::IndexCollection do 18 | describe "json initialization" do 19 | it "accepts a list of keys" do 20 | @input = { 21 | 'keys' => %w{first second third} 22 | }.to_json 23 | expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error 24 | expect(%w{first second third}).to eq(@coll) 25 | end 26 | 27 | it "accepts a list of keys and a continuation" do 28 | @input = { 29 | 'keys' => %w{first second third}, 30 | 'continuation' => 'examplecontinuation' 31 | }.to_json 32 | expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error 33 | expect(%w{first second third}).to eq(@coll) 34 | expect(@coll.continuation).to eq('examplecontinuation') 35 | end 36 | 37 | it "accepts a list of results hashes" do 38 | @input = { 39 | 'results' => [ 40 | {'first' => 'first'}, 41 | {'second' => 'second'}, 42 | {'second' => 'other'} 43 | ] 44 | }.to_json 45 | 46 | expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error 47 | expect(%w{first second other}).to eq(@coll) 48 | expect({'first' => %w{first}, 'second' => %w{second other}}).to eq(@coll.with_terms) 49 | end 50 | 51 | it "accepts a list of results hashes and a continuation" do 52 | @input = { 53 | 'results' => [ 54 | {'first' => 'first'}, 55 | {'second' => 'second'}, 56 | {'second' => 'other'} 57 | ], 58 | 'continuation' => 'examplecontinuation' 59 | }.to_json 60 | 61 | expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error 62 | expect(%w{first second other}).to eq(@coll) 63 | expect(@coll.continuation).to eq('examplecontinuation') 64 | expect({'first' => %w{first}, 'second' => %w{second other}}).to eq(@coll.with_terms) 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /spec/riak/list_buckets_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe Riak::ListBuckets do 18 | before :each do 19 | @client = Riak::Client.new 20 | @backend = double 'backend' 21 | @fake_pool = double 'connection pool' 22 | allow(@fake_pool).to receive(:take).and_yield(@backend) 23 | 24 | @expect_list = expect(@backend).to receive(:list_buckets) 25 | 26 | @client.instance_variable_set :@protobuffs_pool, @fake_pool 27 | end 28 | 29 | describe "non-streaming" do 30 | it 'calls the backend without a block' do 31 | @expect_list.with({}).and_return(%w{a b c d}) 32 | 33 | @client.list_buckets 34 | end 35 | end 36 | 37 | describe "streaming" do 38 | it 'calls the backend with a block' do 39 | @expect_list. 40 | and_yield(%w{abc abd abe}). 41 | and_yield(%w{bbb ccc ddd}) 42 | 43 | @yielded = [] 44 | 45 | @client.list_buckets do |bucket| 46 | @yielded << bucket 47 | end 48 | 49 | @yielded.each do |b| 50 | expect(b).to be_a Riak::Bucket 51 | end 52 | expect(@yielded.map(&:name)).to eq(%w{abc abd abe bbb ccc ddd}) 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /spec/riak/map_reduce/filter_builder_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe Riak::MapReduce::FilterBuilder do 18 | subject { Riak::MapReduce::FilterBuilder.new } 19 | it "evaluates the passed block on initialization" do 20 | expect(subject.class.new do 21 | matches "foo" 22 | end.to_a).to eq([[:matches, "foo"]]) 23 | end 24 | 25 | it "adds filters to the list" do 26 | subject.to_lower 27 | subject.similar_to("ripple", 3) 28 | expect(subject.to_a).to eq([[:to_lower], [:similar_to, "ripple", 3]]) 29 | end 30 | 31 | it "adds a logical operation with a block" do 32 | subject.OR do 33 | starts_with "foo" 34 | ends_with "bar" 35 | end 36 | expect(subject.to_a).to eq([[:or, [[:starts_with, "foo"], [:ends_with, "bar"]]]]) 37 | end 38 | 39 | it "raises an error on a filter arity mismatch" do 40 | expect { subject.less_than }.to raise_error(ArgumentError) 41 | end 42 | 43 | it "raises an error when a block is not given to a logical operation" do 44 | expect { subject._or }.to raise_error(ArgumentError) 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /spec/riak/multiexist_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | SingleCov.covered! if defined?(SingleCov) 18 | 19 | describe Riak::Multiexist do 20 | before :each do 21 | @client = Riak::Client.new 22 | @bucket = Riak::Bucket.new(@client, 'foo') 23 | @pairs = [[@bucket, 'key1'], [@bucket, 'key2']] 24 | end 25 | 26 | it "returns state when only some objects are found" do 27 | expect(@bucket).to receive(:exists?). 28 | with('key1'). 29 | and_return(false) 30 | 31 | expect(@bucket).to receive(:exists?). 32 | with('key2'). 33 | and_return(true) 34 | 35 | results = Riak::Multiexist.perform @client, @pairs 36 | 37 | expect(results[[@bucket, 'key1']]).to eq false 38 | expect(results[[@bucket, 'key2']]).to eq true 39 | end 40 | 41 | it "fails when checking the key produces an error" do 42 | expect(@bucket).to receive(:exists?). 43 | with(satisfy { |key| %w(key1 key2).include?(key) }). 44 | and_raise(Riak::ProtobuffsFailedRequest.new(:whoops, "whoops")). 45 | at_least(1) # race condition ... both threads can read at the same time 46 | 47 | expect { Riak::Multiexist.perform @client, @pairs }.to raise_error(Riak::ProtobuffsFailedRequest) 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /spec/riak/multiget_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | SingleCov.covered! uncovered: 3 if defined?(SingleCov) 18 | 19 | describe Riak::Multiget do 20 | before :each do 21 | @client = Riak::Client.new 22 | @bucket = Riak::Bucket.new(@client, 'foo') 23 | @pairs = [[@bucket, 'key1'], [@bucket, 'key2']] 24 | end 25 | 26 | it "returns found objects when only some objects are found" do 27 | expect(@bucket).to receive(:[]). 28 | with('key1'). 29 | and_raise(Riak::ProtobuffsFailedRequest.new(:not_found, "not found")) 30 | 31 | expect(@bucket).to receive(:[]). 32 | with('key2'). 33 | and_return(true) 34 | 35 | results = Riak::Multiget.perform @client, @pairs 36 | 37 | expect(results[[@bucket, 'key1']]).to eq nil 38 | expect(results[[@bucket, 'key2']]).to eq true 39 | end 40 | 41 | it "fails when fetching the key produces an error" do 42 | expect(@bucket).to receive(:[]). 43 | with(satisfy { |key| %w(key1 key2).include?(key) }). 44 | and_raise(Riak::ProtobuffsFailedRequest.new(:whoops, "whoops")). 45 | at_least(1) # race condition ... both threads can read at the same time 46 | 47 | expect { Riak::Multiget.perform @client, @pairs }.to raise_error(Riak::ProtobuffsFailedRequest) 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /spec/riak/node_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe Riak::Client::Node do 18 | before :each do 19 | @client = Riak::Client.new 20 | @node = Riak::Client::Node.new @client 21 | end 22 | 23 | describe 'when initializing' do 24 | it 'defaults to the local interface on port 8087' do 25 | node = Riak::Client::Node.new @client 26 | expect(node.host).to eq('127.0.0.1') 27 | expect(node.pb_port).to eq(8087) 28 | end 29 | 30 | it 'accepts a host' do 31 | node = Riak::Client::Node.new(@client, :host => 'riak.basho.com') 32 | expect(node.host).to eq("riak.basho.com") 33 | end 34 | 35 | it 'accepts a Protobuffs port' do 36 | node = Riak::Client::Node.new @client, :pb_port => 9000 37 | expect(node.pb_port).to eq(9000) 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /spec/riak/search/schema_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | require 'riak/search/schema' 17 | 18 | describe Riak::Search::Schema do 19 | let(:schema_name){ 'schema_name' } 20 | let(:schema_content){ '' } 21 | 22 | let(:schema_exists_expectation) do 23 | expect(backend).to receive(:get_search_schema). 24 | with(schema_name). 25 | and_return(schema_exists_response) 26 | end 27 | 28 | let(:schema_exists_response) do 29 | resp = instance_double 'Riak::Client::BeefcakeProtobuffsBackend::RpbYokozunaSchema' 30 | allow(resp).to receive(:name).and_return(schema_name) 31 | allow(resp).to receive(:content).and_return(schema_content) 32 | 33 | resp 34 | end 35 | 36 | let(:client){ instance_double 'Riak::Client' } 37 | let(:backend) do 38 | be = instance_double 'Riak::Client::BeefcakeProtobuffsBackend' 39 | allow(client).to receive(:backend).and_yield be 40 | be 41 | end 42 | 43 | subject { described_class.new client, schema_name } 44 | 45 | it 'creates schema objects with a client and schema name' do 46 | expect{ described_class.new client, schema_name }.to_not raise_error 47 | end 48 | 49 | it 'tests for schema existence' do 50 | schema_exists_expectation 51 | expect(subject).to be_exists 52 | end 53 | 54 | it 'permits schema creation' do 55 | expect(backend).to receive(:get_search_schema). 56 | with(schema_name). 57 | and_return(nil) 58 | 59 | expect(backend).to receive(:create_search_schema). 60 | with(schema_name, schema_content). 61 | and_return(true) 62 | 63 | expect{ subject.create! schema_content }.to_not raise_error 64 | end 65 | 66 | it 'raises an error when creating a schema that already exists' do 67 | schema_exists_expectation 68 | 69 | expect{ subject.create! schema_content }.to raise_error(Riak::SearchError::SchemaExistsError) 70 | end 71 | 72 | it 'returns data about the schema' do 73 | schema_exists_expectation 74 | 75 | expect(subject.content).to eq schema_content 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /spec/riak/time_series/deletion_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe Riak::TimeSeries::Deletion do 18 | subject{ described_class.new client, table_name } 19 | let(:table_name){ 'GeoCheckin' } 20 | let(:client){ instance_double('Riak::Client') } 21 | let(:key){ double 'key' } 22 | let(:backend) do 23 | instance_double('Riak::Client::BeefcakeProtobuffsBackend').tap do |be| 24 | allow(client).to receive(:backend).and_yield be 25 | end 26 | end 27 | let(:operator) do 28 | Riak::Client::BeefcakeProtobuffsBackend.configured? 29 | instance_double( 30 | 'Riak::Client::BeefcakeProtobuffsBackend::TimeSeriesDeleteOperator' 31 | ).tap do |op| 32 | allow(backend).to receive(:time_series_delete_operator). 33 | and_return(op) 34 | end 35 | end 36 | 37 | it 'initializes with client and table name' do 38 | expect{ described_class.new client, table_name }.to_not raise_error 39 | expect{ described_class.new client }.to raise_error ArgumentError 40 | end 41 | 42 | it 'passes keys to delete to a delete operator' do 43 | expect{ subject.key = key }.to_not raise_error 44 | expect(operator).to receive(:delete).with(table_name, key, Hash.new) 45 | expect{ subject.delete! }.to_not raise_error 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /spec/riak/time_series/listing_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe Riak::TimeSeries::List do 18 | subject { described_class.new client, table_name } 19 | let(:table_name){ 'GeoCheckin' } 20 | let(:client){ instance_double('Riak::Client') } 21 | let(:key){ double 'key' } 22 | let(:backend) do 23 | instance_double('Riak::Client::BeefcakeProtobuffsBackend').tap do |be| 24 | allow(client).to receive(:backend).and_yield be 25 | allow(client).to receive(:convert_timestamp).and_return(true) 26 | end 27 | end 28 | let(:operator) do 29 | Riak::Client::BeefcakeProtobuffsBackend.configured? 30 | instance_double( 31 | 'Riak::Client::BeefcakeProtobuffsBackend::TimeSeriesListOperator' 32 | ).tap do |op| 33 | allow(backend).to receive(:time_series_list_operator). 34 | and_return(op) 35 | end 36 | end 37 | 38 | let(:list_results) do 39 | Riak::TimeSeries::Collection.new.tap do |buf| 40 | %w{family series timestamp} 41 | end 42 | end 43 | 44 | it 'initializes with client and table name' do 45 | expect{ described_class.new client, table_name }.to_not raise_error 46 | expect{ described_class.new client }.to raise_error ArgumentError 47 | end 48 | 49 | it 'passes a block to the operator' do 50 | streamer = proc { double 'block contents' } 51 | 52 | expect(operator).to receive(:list).with(table_name, streamer, timeout: nil) 53 | 54 | subject.issue! &streamer 55 | end 56 | 57 | it 'returns a list of results' do 58 | expect(operator).to receive(:list). 59 | with(table_name, nil, timeout: nil). 60 | and_return(list_results) 61 | 62 | expect(subject.issue!).to eq list_results 63 | expect(subject.results).to eq list_results 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /spec/riak/time_series/submission_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'spec_helper' 16 | 17 | describe Riak::TimeSeries::Submission do 18 | subject{ described_class.new client, table_name } 19 | let(:table_name){ 'GeoCheckin' } 20 | let(:client){ instance_double('Riak::Client') } 21 | let(:measurements){ double 'measurements' } 22 | let(:backend) do 23 | instance_double('Riak::Client::BeefcakeProtobuffsBackend').tap do |be| 24 | allow(client).to receive(:backend).and_yield be 25 | end 26 | end 27 | let(:operator) do 28 | Riak::Client::BeefcakeProtobuffsBackend.configured? 29 | instance_double( 30 | 'Riak::Client::BeefcakeProtobuffsBackend::TimeSeriesPutOperator' 31 | ).tap do |po| 32 | allow(backend).to receive(:time_series_put_operator). 33 | and_return(po) 34 | end 35 | end 36 | 37 | it 'initializes with client and table name' do 38 | expect{ described_class.new client, table_name }.to_not raise_error 39 | expect{ described_class.new client }.to raise_error ArgumentError 40 | end 41 | 42 | it 'passes measurements to a put operator' do 43 | expect{ subject.measurements = measurements }.to_not raise_error 44 | 45 | expect(operator).to receive(:put).with(table_name, measurements) 46 | 47 | expect{ subject.write! }.to_not raise_error 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'bundler/setup' 16 | 17 | # ruby 1.9 and jruby without debug do not support single-cov 18 | if RUBY_VERSION >= "2." && (RUBY_ENGINE != 'jruby' || ENV['JRUBY_OPTS'].to_s.include?('--debug')) 19 | require 'single_cov' 20 | SingleCov.setup :rspec 21 | end 22 | 23 | require 'riak' 24 | require 'stringio' 25 | require 'pp' 26 | require 'instrumentable' 27 | 28 | # Only the tests should really get away with this. 29 | Riak.disable_list_exceptions = true 30 | 31 | %w[integration_setup 32 | version_filter 33 | wait_until 34 | search_corpus_setup 35 | unified_backend_examples 36 | test_client 37 | search_config 38 | crdt_prerequisites 39 | crdt_search_config 40 | crdt_search_fixtures 41 | ].each do |file| 42 | require_relative File.join("support", file) 43 | end 44 | 45 | RSpec.configure do |config| 46 | #config.debug = true 47 | config.mock_with :rspec 48 | 49 | config.before(:each) do 50 | Riak::RObject.on_conflict_hooks.clear 51 | end 52 | 53 | if TestClient.test_client_configuration[:authentication] 54 | config.filter_run_excluding no_security: true 55 | else 56 | config.filter_run_excluding yes_security: true 57 | end 58 | 59 | config.filter_run :focus => true 60 | config.run_all_when_everything_filtered = true 61 | 62 | if defined?(::Java) 63 | config.seed = Time.now.utc 64 | else 65 | config.order = :random 66 | end 67 | 68 | config.raise_errors_for_deprecations! 69 | end 70 | -------------------------------------------------------------------------------- /spec/support/certs/README.md: -------------------------------------------------------------------------------- 1 | **DO NOT USE THESE IN PRODUCTION** 2 | 3 | This directory has certificates and a key for testing Riak authentication. 4 | 5 | * server.key - a private key for a Riak server 6 | * server.crt - the certificate for server.key 7 | * ca.crt - a certificate for the CA that issued server.crt 8 | * empty_ca.crt - a certificate for a CA that has and cannot ever issue a 9 | certificate (I deleted its private key) 10 | 11 | **DO NOT USE THESE IN PRODUCTION** 12 | 13 | These were generated using https://github.com/basho-labs/riak-ruby-ca . -------------------------------------------------------------------------------- /spec/support/certs/ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDjDCCAnQCCQDCaCbuH5N1HjANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMC 3 | VVMxEDAOBgNVBAgMB0Zsb3JpZGExDjAMBgNVBAcMBU1pYW1pMQ4wDAYDVQQKDAVC 4 | YXNobzEZMBcGA1UECwwQUmlhayBSdWJ5IENsaWVudDELMAkGA1UEAwwCQ0ExHjAc 5 | BgkqhkiG9w0BCQEWD2JyeWNlQGJhc2hvLmNvbTAeFw0xNDA5MTgyMjU4MDJaFw0y 6 | NDA5MTUyMjU4MDJaMIGHMQswCQYDVQQGEwJVUzEQMA4GA1UECAwHRmxvcmlkYTEO 7 | MAwGA1UEBwwFTWlhbWkxDjAMBgNVBAoMBUJhc2hvMRkwFwYDVQQLDBBSaWFrIFJ1 8 | YnkgQ2xpZW50MQswCQYDVQQDDAJDQTEeMBwGCSqGSIb3DQEJARYPYnJ5Y2VAYmFz 9 | aG8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApLREjyW0bsMQ 10 | 2xZuZfXrTqndZdtmJrUaUdwLcTYXo/BLJq8mw/UoKBajzDJS1OsVutOT3l1mQZNk 11 | pE15lJbPo301RtkGOeYlTx6ptawutrvlMlACnWtYyuL9U8qqnMJAsdBEjTU3Xxao 12 | /vJTECBVaKtL9D5vEu2fOn4ZWvSuYG14ZXhltBPgon95SrJX+erXgHs0IH6l1ftW 13 | xZL9Uw/Tj/s8XEMK8n6FB+CYuj33fZMjswvdXABzhEAW8bCupJT42V/S9Zj4B0Z8 14 | iv6wgurc1yuU6yl0VDGZ6Ee++7ter3GZZrV4YC5A8UjW0+8sADUYKiZNYWTO6S+N 15 | Pu/sLRdykwIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQBzcs/VIHHeyUWlS+Rx/s/m 16 | m54RK332r2+8Mywtwdz57kA6rsbYBrrlKVmEzjtgCIcpF/3hhEChYcSA4w0Aa+zd 17 | Zd6eNtUyicPFfm/8GycaLM3Ptj3duq4jHha2IzhomfACm8pkBj8IU8Y5q/YBV+3L 18 | hJxderphbz6lqrH6USkt/aaFzu+1onYlxzGZDyiFPOxUbRPXN12y3XCeFSfuHBej 19 | ifFRSHGR8HU++g4VYnOi/1YXSDFh7yRvA2qBlz+kYprBS2GggXIrfCgT+FnMALlg 20 | 6TrfsWQiI3pyGKUsNjdaQckdLMWr8jvutb7vPZ1WdMdgKxbE0Swo1HBbkCAe5JjG 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /spec/support/certs/client.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIB+zCB5AIBATANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMCVVMxEDAOBgNV 3 | BAgMB0Zsb3JpZGExDjAMBgNVBAcMBU1pYW1pMQ4wDAYDVQQKDAVCYXNobzEZMBcG 4 | A1UECwwQUmlhayBSdWJ5IENsaWVudDELMAkGA1UEAwwCQ0ExHjAcBgkqhkiG9w0B 5 | CQEWD2JyeWNlQGJhc2hvLmNvbRcNMTQwOTE4MjI1ODAyWhcNMTQxMDE4MjI1ODAy 6 | WjAWMBQCAzA2BBcNMTQwOTE4MjI1ODAyWqAQMA4wDAYDVR0UBAUCAxgkajANBgkq 7 | hkiG9w0BAQUFAAOCAQEAkPqlW1eWCzJjoj2d2vP/yW2BmHW8AMcn3wSQe3rLFz33 8 | 7/qznQ8Ne5HSaoUW1CFdILQeKrcv+2fXxoEh+QF2Xdf80eL3OaBvaDtedvIrwA5q 9 | 2QWSbvtVKksRx708ngquOS+jx5nYmodPGgCKQLxDTu7yKVxSQSL8m5C+Ki8N+mT2 10 | XR1w72Ds9F/QMyziWCwjgvOKG9oxFG0oO+e+GcXxtkbpWO8w3nQnf+KotjPWq5fa 11 | zOE8Dts9F36awoLlw3SW1aEv2mqPn5CIDsKKx1pQ52Oe0/UKSHOTqqHBzggJ7GFz 12 | OnxmjdZ2YhxFR7QVUX2SlvubvjfIn0NQJbTiswynTQ== 13 | -----END X509 CRL----- 14 | -------------------------------------------------------------------------------- /spec/support/certs/client.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIC0zCCAbsCAQAwgY0xCzAJBgNVBAYTAlVTMRAwDgYDVQQIDAdGbG9yaWRhMQ4w 3 | DAYDVQQHDAVNaWFtaTEOMAwGA1UECgwFQmFzaG8xGTAXBgNVBAsMEFJpYWsgUnVi 4 | eSBjbGllbnQxETAPBgNVBAMMCGNlcnR1c2VyMR4wHAYJKoZIhvcNAQkBFg9icnlj 5 | ZUBiYXNoby5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDU0OCf 6 | hMWM7To3szO9M0KJj7BTm/xG2TrtT6mKXwV1OE6msGIn+f3+/ykY5I25+iXgsCg0 7 | JK7zP9zgMda60H+x01JqZHfrY3Q0mULWKM3oihqMlR5xW6PYQtW3hsnrePORKmtc 8 | hCDyvI5Sh4cC5jzLvlh9omXOd22Ad3kn5bk4BEFLzC1xuBwk0+n86k9UIJUHb+Ga 9 | b4p46bm9cvmmsC1QyrvAm6+a4Up/OnQxvjVsmzMuTkqoKmgNOwRbLvMbxQYwzy/X 10 | S6wP5mY0uMyIV1l51TMnHSeluOIiEcbIu/XBj1RK0ItVkyKBE3/Jub2ZD7924ge4 11 | IkfWCf/HxBBEaHIZAgMBAAGgADANBgkqhkiG9w0BAQUFAAOCAQEAQce8NXpoayV/ 12 | 0eiqAtt1Sk2Rib7/xq4B41rho+Dfsh37PdqPlaB2OPX4aUAghmkOgSub3Q8ZqYJM 13 | eCrnfyCRMiVT7CojqBWQHL6ecdYtozYRWBqXJGZcOTwBa29ulyB+P25P2Acs4b9R 14 | xz2b3uqzZlWo8/53wWdgWKjigCGWe7cVlAhWnBkOpTm6M6frJoNE8xfOgO1/GiWv 15 | ImCVrAuJscsOL9zcZjwkRn+mYOUsccLCPuSvE9J1Nd0aFyQCCg9zJwZ0sINf+VZP 16 | OCsk0aFANrsrIdZLrEZkuTIsmuE3Tsdf0T9CIisLOkPhUF/iy2iAJmsXiHMBR2+9 17 | zXWg4pTHQg== 18 | -----END CERTIFICATE REQUEST----- 19 | -------------------------------------------------------------------------------- /spec/support/certs/client.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAx0GPU6AlCgNiupD0pu5Ol19wpp8jOC9LFrKB65XRDWRWEfvj 3 | B3vNB9hk65+2Sz5Uo+t5jg+upOtTukSi4srYlDR1qWLX2TRBj3yin5CEWtfExXbY 4 | iW/2XkCJNPZW1eZV16ZEUownm3VmtIT2XeldqGynJ/W8KCMa7JTkjyb9IhlE3P+r 5 | x3bFi2lnHVi1VEOcGV72R0qDdIxDu0i9sQNTT6mOvo7fpWnT6S+SnoY/J8piu29P 6 | 8NdiekG1MrfxjaUuwe6eWNOayFz2JtQjkkaJQ4NmuHtQr+sxNg5Nppl5GSJhxIAG 7 | sQkV0+uW1uoJwBB8I5lVA0OlGh4aPQSIUU1bZQIDAQABAoIBAQDHMG/CboZ4cxgA 8 | X6ZjNjnUszEfMFj58rVC1GJyiws4MwSj58V2FrnJTPbeYYPPxljAoUab0GuLLEFA 9 | JRscUyGdTrANC+Wxmb6sXTEJCGR3l9l6eStQgV+tqyA+lMAMBr3r3afRSZDSpNNu 10 | RLkw+niJRUz48nwNN8LTnKi7voMw0IFsK093l5LG4gV+U7LTwhflKG21SXmFexK3 11 | JsgkV3JI+L/tDHHZ6UPsrez0ynubjG+1ex1eFhMg9DTBImznBDLpwpjCTwQs8J+a 12 | xx6LO7ubtvSPGHgqPX8kL1nVgkE5z8IElrpZZ1LzH6uWU0OyHCUUVNuHMDuhyKYN 13 | vZKjdciFAoGBAP1knblpYOp9XY+hzno3A/Mmq6mVoKbAbZdoUqqfCp24KSG1BQ4S 14 | MUaw6qjROzDT6Ew1H8wXdb6ShnGMJgXQ7MHEV1j3RSm3Lq8z+eDZLlNr/8bl7lww 15 | 7h+hgQnc4Vbid6RtSXbjmV2Q05lPf41oRIV6k8ClWjSMIDFbgJf6vYGvAoGBAMlO 16 | W8Q5Zc4+igV09n/XbgMY2BrY2+T/2EpaszZKvMcMg/1ulbynJhHeNKzVk0va5h6Z 17 | DjqlLOpde5a4Cyylmm2ZrpDF1eRxsGUT7D/ggiqxJunxlHjaIuJM/ecCP66ZHdTz 18 | zalCZKP/+92Cy0FCk2HUVjIezoCGSP8z9RM9ZF0rAoGABApXrX4tqm+HT2QAG9jG 19 | uljSgei94ArPdIuYTdotXCh0l3IAe6H0oTDu/PQhIn0uhhCOyj1RhlFlzWezr4IO 20 | VGSiE+wVcT3Xg7mrcVdlMrVVJcHC1Dt/gIedvB+GhFEmITwQ4NFuP5ywkxA+c23H 21 | Me2rb3Xzg0T8umzAFyxLW0cCgYBdPI/AOJ1wgwLGOEAbQhpQEOe2t45RaDYzagLr 22 | OH5q6t8POHLd58T4LaTUEC+iyIYg0d8HRo2hFx8w1ZlHWoRGExIJN7gzkHyUtD+N 23 | 7lwbjeVqIVwVBWN20RYgMqhwI7bvdORiar/WPa/YDsY5Oa6tdv1dRWt7l7ajjNsL 24 | yDl99QKBgHGhV2i5JwX//0gZu+xw4WDml2hQ1XEon8WGOJ+MQbSK68X5Cl6qE+/8 25 | ONbL5tyqYRJjfP0D1EimBXA8BPjBH+ovkk65BK2pf4Ot+4NVtsNtcM2B73MNx0FT 26 | QkWfidG/aDBAk1H9CK9ncg0z6Uh94zbpb0++esREd/RRQ/TLmlGy 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /spec/support/certs/empty_ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDfjCCAuegAwIBAgIJAO0pDelK8iopMA0GCSqGSIb3DQEBBQUAMIGHMQswCQYD 3 | VQQGEwJVUzEQMA4GA1UECBMHRmxvcmlkYTEOMAwGA1UEBxMFTWlhbWkxGzAZBgNV 4 | BAoTEkJhc2hvIFRlY2hub2xvZ2llczEZMBcGA1UECxMQUmlhayBSdWJ5IENsaWVu 5 | dDEeMBwGCSqGSIb3DQEJARYPYnJ5Y2VAYmFzaG8uY29tMB4XDTE0MDIwNDIyNTAw 6 | NFoXDTI0MDIwMjIyNTAwNFowgYcxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdGbG9y 7 | aWRhMQ4wDAYDVQQHEwVNaWFtaTEbMBkGA1UEChMSQmFzaG8gVGVjaG5vbG9naWVz 8 | MRkwFwYDVQQLExBSaWFrIFJ1YnkgQ2xpZW50MR4wHAYJKoZIhvcNAQkBFg9icnlj 9 | ZUBiYXNoby5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAN4yelOGl+MW 10 | FY7Pf9vZjNHDuVQfBkiY9myriNpr3YGGou0xEIJvikkhl4eQAzDsw52qTsESlfwK 11 | +uFmCBvhPBgeWYRd2LnAvRSrD4c7fDp+2eVUL3EKDHKdVNwnobvMiN2GQRZT2E+J 12 | gBX3Wx3VGDtI0+M1Q9QPI7J1iewE0rB/AgMBAAGjge8wgewwHQYDVR0OBBYEFAkx 13 | E0bwW0jX8FhWFW9XMhzGkMkhMIG8BgNVHSMEgbQwgbGAFAkxE0bwW0jX8FhWFW9X 14 | MhzGkMkhoYGNpIGKMIGHMQswCQYDVQQGEwJVUzEQMA4GA1UECBMHRmxvcmlkYTEO 15 | MAwGA1UEBxMFTWlhbWkxGzAZBgNVBAoTEkJhc2hvIFRlY2hub2xvZ2llczEZMBcG 16 | A1UECxMQUmlhayBSdWJ5IENsaWVudDEeMBwGCSqGSIb3DQEJARYPYnJ5Y2VAYmFz 17 | aG8uY29tggkA7SkN6UryKikwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOB 18 | gQCPgOgPnv33+/LrfSSDh/6OdtYAGdrxMkCsuPdwmyZlUl9W7gxFjX7EPxYycUgO 19 | HNGuI10vOipgXrsJZUtQFi9OZ8+2m2Y4JHZR1xqSoHmXL/LoZYggY0BcwfjpSujL 20 | pMhBUfzTLlULaaaBEGCVwxTabP+qzRma/d1FjkMUzbHrmQ== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /spec/support/certs/server.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIB+zCB5AIBATANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMCVVMxEDAOBgNV 3 | BAgMB0Zsb3JpZGExDjAMBgNVBAcMBU1pYW1pMQ4wDAYDVQQKDAVCYXNobzEZMBcG 4 | A1UECwwQUmlhayBSdWJ5IENsaWVudDELMAkGA1UEAwwCQ0ExHjAcBgkqhkiG9w0B 5 | CQEWD2JyeWNlQGJhc2hvLmNvbRcNMTQwOTE4MjI1ODAyWhcNMTQxMDE4MjI1ODAy 6 | WjAWMBQCAzA2AxcNMTQwOTE4MjI1ODAyWqAQMA4wDAYDVR0UBAUCAxgkaDANBgkq 7 | hkiG9w0BAQUFAAOCAQEAF7oEWvw7d79lmQBWw61dUtACJhZ/gHMe6VwuUoQX3pr/ 8 | YmJ2Kj6ac3PuYT26BpdjYbY+TcjMrqoil25kKiC6N1tG7C6Dgc1TNZY63pVSsFfy 9 | fwsKYlrT17Bp9gW53ig73ehfiRpkhbtDT97BxRMJLNmCadeldutVtRrVMXlsGqfU 10 | TR8zhgT1AXqyYxO4SddKGXka9YIp9IVK+7WrnIKHG5Acjap/8TGYSARkIR7kiEtb 11 | 160UI+jptNkZ6Ibs2pb8QrDxXZqBAfhnpinPnqfXqu/m3sjG+XsDLZHii0VzdA/j 12 | scUW02yn/pHQ19z20BR2XN9pswBXqS5ERwc6qJjWMA== 13 | -----END X509 CRL----- 14 | -------------------------------------------------------------------------------- /spec/support/certs/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEAypRqVLZb7lby1uEBe4fvkfVKpVGvEWlu/FMcwnNJcg+Aa0fU 3 | PLkDH/pRhdwd0FKszZc3C4b99zz2nK23BlQU8zyhz/5XshSR3hdZX8GGgS8VisWF 4 | 3svUiJr4BEXcaun1WJbxKspd1+P06h33NK6YwpQFdN7DclFHiuIf4bPXqt1GBPhF 5 | +w2LpTtXdBTfBWrvnfQaneH1jpDK3ON1yazM2vSi9eTUhO76zos1XwUyvjojX3fO 6 | eOaYjtPXcJZxFKeQaT3XGFztzyW3x1YVnyTA1ytZaJSJLFZrtGfjzgnMjhqDMq/9 7 | oM3fsorb1kRrJa9UqHCIAwvGnJrd19FZJrzDQwIDAQABAoIBAQCIwVxux5ST91qE 8 | OO1ZSVEvRVoY9GWs6XIlIK5fjphcSZ61zY23WGaFpeR26zutMMK7H4PnYj/8McmB 9 | x7uwp/5knd/Wm6rz6vL17OlGvUxh1TlDr0hKOWvGtGcN62N7QWmBXpR8AJUNczQZ 10 | ABWsGNnDMU3lsaRbfgc/+JrxMQk8rGK1bm3M80zobJ33mAQVvqV1EL4T30IW/9s1 11 | hvsjUwvt1rfDA+iJZ0bZAu/RuGcb8fQ0V+xiPTCs1BR3oAUD8zP0mVDW8p1ixc4g 12 | qmdHbfFrCzzlCYaPD1O/NHTTpNYDv/PWNQUiwXmlPx128Fhd63VTw/ECR3Yq5aAG 13 | ySoCVkuRAoGBAP0DCCETlpAIZPGwGZ7mgrbXPM8Ij/5lpMrtaa7x0n5XWLgCtOfd 14 | d1U2mV0ub1F149xFWMcw89F79uAUXRdU4GFUuj0u10w8SMUBOiw85VFNzgIdOg1s 15 | 5fZQT5H0TKOGnGiWRnKftBLeCeejvhKxoobaqqAGrMI2F8onCfI8QsP/AoGBAMz4 16 | 556YRyRfkwTXxVi8vj2Xlztyhl3vhYK171/yywAUqF9QrGoqCxrbsU9rbnJs73QM 17 | eeqUbF3pjkafm+9Qp9V/NQaXC+Jfcz/hUDtyZW+B+jiXIQ/aHXRSvw8oCrYEKOtq 18 | ohFjUJst0UmdgQmkQFpnuqctZus0Xl/fEBjiTfC9AoGBAMHQP7ruwWhmNcV6i7XQ 19 | iJM9gARsX7mV7U3R3iI4dnF3wat7z07KtO4e3A6oUnfJYhpLOP2lfzCa0HvIvaLw 20 | zs1gVSYnKp/okinvjbtzjorgmg2+i8jbAbHUxY9d4BNoO4pWi3Kk6hGF63p5UVIK 21 | pyC8gvYBBvfi7ghaLWFVTiPLAoGATMNq+xpMinLAvK+SWQlWtfpvyPO7HrL1bV51 22 | p5lmLUGPTSMJbzkPr59XaEbztibWBsAlaJTtgL5XalucKqQqNurNEQrAiKb2opXf 23 | VmQhWQF0lH0FBMrK/SWAKEz2tfQY3xGwYJKxPWyLVOaHzPSWpUTzwmhegve54G3J 24 | uYgHaIECgYBjLTnXZvihDZfbnIZo9zx65DsperToL1WAWXYBN/RbYWPGNWsIIw9l 25 | /k/dstB8Q3fhRvRq1zWtLFSjVL+t03b0eXN62dLj2hrojgtAInbwAUDVtgtnfqQd 26 | R1Xw38QGYIhQV8hnLGFRUAa+71jlLdQDfogOpwFS96ZL4yFX6rDX+Q== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /spec/support/crdt_prerequisites.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module CrdtPrerequisites 16 | def ensure_datatype_exists(data_type) 17 | type = test_client.bucket_type Riak::Crdt::DEFAULT_BUCKET_TYPES[data_type] 18 | type.properties 19 | rescue Riak::ProtobuffsErrorResponse 20 | skip('#{data_type.to_s} bucket-type not found or active.') 21 | end 22 | end 23 | 24 | RSpec.configure do |config| 25 | config.include CrdtPrerequisites 26 | end 27 | -------------------------------------------------------------------------------- /spec/support/crdt_search_fixtures.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module CrdtSearchFixtures 16 | def map_result_score 17 | 43.21 18 | end 19 | 20 | def maps_type_name 21 | Riak::Crdt::DEFAULT_BUCKET_TYPES[:map] 22 | end 23 | 24 | def maps_bucket_type 25 | return @maps_bucket_type if defined? @maps_bucket_type 26 | 27 | @maps_bucket_type = instance_double('Riak::BucketType').tap do |bt| 28 | allow(bt).to receive(:bucket). 29 | with(bucket_name). 30 | and_return(map_bucket) 31 | allow(bt).to receive(:data_type_class). 32 | and_return(Riak::Crdt::Map) 33 | end 34 | end 35 | 36 | def map_bucket 37 | @map_bucket ||= instance_double('Riak::BucketTyped::Bucket') 38 | end 39 | 40 | def map_raw 41 | @map_raw ||= { 42 | 'score'=>map_result_score, 43 | '_yz_rb'=>bucket_name, 44 | '_yz_rt'=>maps_type_name, 45 | '_yz_rk'=>'map-key' 46 | } 47 | end 48 | 49 | def map_results 50 | @map_results ||= Riak::Search::ResultDocument.new client, map_raw 51 | end 52 | end 53 | 54 | RSpec.configure do |config| 55 | config.include CrdtSearchFixtures, crdt_search_fixtures: true 56 | end 57 | -------------------------------------------------------------------------------- /spec/support/integration_setup.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # auto-tag all integration specs with :integration => true 16 | module IntegrationSpecs 17 | def self.included(klass) 18 | klass.metadata[:integration] = true 19 | end 20 | end 21 | 22 | RSpec.configure do |config| 23 | config.include IntegrationSpecs, file_path: %r{spec/integration} 24 | end 25 | -------------------------------------------------------------------------------- /spec/support/search_corpus_setup.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # 3 | # Copyright 2010-present Basho Technologies, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | shared_context "search corpus setup" do 18 | before do 19 | @search_bucket = random_bucket 'search_test' 20 | @backend.create_search_index @search_bucket.name 21 | 22 | wait_until{ !@backend.get_search_index(@search_bucket.name).nil? } 23 | 24 | @client.set_bucket_props(@search_bucket, 25 | {search_index: @search_bucket.name}, 26 | 'yokozuna') 27 | 28 | wait_until do 29 | p = @client.get_bucket_props(@search_bucket, type: 'yokozuna') 30 | p['search_index'] == @search_bucket.name 31 | end 32 | 33 | idx = 0 34 | old_encoding = Encoding.default_external 35 | Encoding.default_external = Encoding::UTF_8 36 | IO.foreach("spec/fixtures/bitcask.txt") do |para| 37 | next if para =~ /^\s*$|introduction|chapter/ui 38 | idx += 1 39 | Riak::RObject.new(@search_bucket, "bitcask-#{idx}") do |obj| 40 | obj.content_type = 'text/plain' 41 | obj.raw_data = para 42 | @backend.store_object(obj, type: 'yokozuna') 43 | end 44 | end 45 | Encoding.default_external = old_encoding 46 | 47 | wait_until do 48 | results = @backend.search(@search_bucket.name, 49 | 'contain your entire keyspace', 50 | df: 'text') 51 | results['docs'].length > 0 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /spec/support/test_client.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module TestClient 16 | def test_client 17 | if defined? $test_client and $test_client.ping 18 | return $test_client 19 | end 20 | 21 | candidate_client = Riak::Client.new test_client_configuration 22 | 23 | live = candidate_client.ping 24 | 25 | return $test_client = candidate_client if live 26 | end 27 | 28 | def test_client_configuration 29 | TestClient.test_client_configuration 30 | end 31 | 32 | def self.test_client_configuration 33 | if defined? $test_client_configuration 34 | return $test_client_configuration 35 | end 36 | 37 | begin 38 | config_path = File.expand_path '../test_client.yml', __FILE__ 39 | config = YAML.load_file(config_path).symbolize_keys 40 | rescue Errno::ENOENT => ex 41 | $stderr.puts("WARNING: could not find file: #{config_path}, exception: #{ex}") 42 | config = {} 43 | config[:pb_port] = ENV['RIAK_PORT'] || 10017 44 | end 45 | 46 | if config[:nodes] 47 | new_nodes = config[:nodes].map(&:symbolize_keys) 48 | config[:nodes] = new_nodes 49 | end 50 | 51 | $test_client_configuration = config 52 | end 53 | 54 | def random_bucket(name = 'test_client') 55 | bucket_name = [name, Time.now.to_i, random_key].join('-') 56 | test_client.bucket bucket_name 57 | end 58 | 59 | def random_key 60 | rand(36**10).to_s(36) 61 | end 62 | end 63 | 64 | RSpec.configure do |config| 65 | config.include TestClient, test_client: true 66 | end 67 | -------------------------------------------------------------------------------- /spec/support/test_client.yml.example: -------------------------------------------------------------------------------- 1 | # This file is used for configuring test_client used by 2 | # many of the integration tests. 3 | # 4 | # Simply set the arguments you'd normally pass to 5 | # Riak::Client.new in the file. 6 | # 7 | # Don't run multiple nodes, integration tests include 8 | # quorum checks that may result in race conditions. 9 | 10 | pb_port: 8087 11 | -------------------------------------------------------------------------------- /spec/support/version_filter.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require 'rubygems' 16 | 17 | RSpec.configure do |config| 18 | config.before(:each, version: ->(v) { v }) do |example| 19 | required = Gem::Requirement.create(example.metadata[:version]) 20 | actual = Gem::Version.new(test_server.version) 21 | skip( 22 | "SKIP: Tests feature for Riak #{required}, but testing against #{actual}", 23 | unless: required.satisfied_by?(actual) 24 | ) 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /spec/support/wait_until.rb: -------------------------------------------------------------------------------- 1 | # Copyright 2010-present Basho Technologies, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This module is used for search testing, and other testing activities that may 16 | # take time to "settle" in Riak. 17 | module WaitUntil 18 | def wait_until(attempts = 10) 19 | (0..attempts).each do |a| 20 | begin 21 | break if yield 22 | rescue 23 | nil 24 | end 25 | 26 | sleep a 27 | end 28 | end 29 | end 30 | 31 | RSpec.configure do |config| 32 | config.include WaitUntil 33 | config.extend WaitUntil 34 | end 35 | --------------------------------------------------------------------------------