├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CONTRIBUTING.md ├── Gruntfile.js ├── LICENSE ├── Makefile ├── NOTICE ├── README.md ├── RELNOTES.md ├── benchmarks └── kv.js ├── build ├── install-deps └── publish ├── index.js ├── lib ├── client.js ├── commands │ ├── commandbase.js │ ├── crdt.js │ ├── crdt │ │ ├── fetchcounter.js │ │ ├── fetchhll.js │ │ ├── fetchmap.js │ │ ├── fetchset.js │ │ ├── updatecounter.js │ │ ├── updategset.js │ │ ├── updatehll.js │ │ ├── updatemap.js │ │ ├── updateset.js │ │ └── updatesetbase.js │ ├── fetchserverinfo.js │ ├── kv.js │ ├── kv │ │ ├── deletevalue.js │ │ ├── fetchbucketprops.js │ │ ├── fetchbuckettypeprops.js │ │ ├── fetchpreflist.js │ │ ├── fetchpropsbase.js │ │ ├── fetchvalue.js │ │ ├── listbuckets.js │ │ ├── listkeys.js │ │ ├── resetbucketprops.js │ │ ├── riakobject.js │ │ ├── secondaryindexquery.js │ │ ├── storebucketprops.js │ │ ├── storebuckettypeprops.js │ │ ├── storepropsbase.js │ │ └── storevalue.js │ ├── mapreduce │ │ └── mapreduce.js │ ├── mr.js │ ├── ping.js │ ├── ts.js │ ├── ts │ │ ├── bykeybase.js │ │ ├── data.js │ │ ├── delete.js │ │ ├── describe.js │ │ ├── get.js │ │ ├── listkeys.js │ │ ├── query.js │ │ ├── store.js │ │ └── utils.js │ ├── yokozuna │ │ ├── deleteindex.js │ │ ├── fetchindex.js │ │ ├── fetchschema.js │ │ ├── search.js │ │ ├── storeindex.js │ │ └── storeschema.js │ └── yz.js ├── core │ ├── authreq.js │ ├── core.js │ ├── leastexecutingnodemanager.js │ ├── nodemanager.js │ ├── riakcluster.js │ ├── riakconnection.js │ ├── riaknode.js │ ├── roundrobinnodemanager.js │ ├── starttls.js │ └── utils.js ├── errors.js ├── protobuf │ └── riakprotobuf.js └── utils.js ├── package.json └── test ├── debug-log.js ├── disable-log.js ├── integration ├── client.js ├── core │ ├── riakcluster.js │ ├── riakconnection.js │ └── riaknode.js ├── crdt │ ├── updateandfetchcounter.js │ ├── updateandfetchgset.js │ ├── updateandfetchhll.js │ ├── updateandfetchmap.js │ └── updateandfetchset.js ├── kv │ ├── fetchandsetbucketprops.js │ ├── fetchandsetbuckettypeprops.js │ ├── fetchpreflist.js │ ├── fetchvalue.js │ ├── listbuckets.js │ ├── listkeys.js │ ├── resetbucketprops.js │ ├── secondaryindexquery.js │ └── storevalue.js ├── mapreduce │ └── mapreduce.js ├── testparams.js ├── ts │ └── timeseries.js └── yokozuna │ ├── search.js │ ├── storeandfetchschema.js │ └── storefetchdeleteindex.js ├── security └── security.js ├── unit ├── client.js ├── commandbase.js ├── core │ ├── authreq.js │ ├── nodemanager.js │ ├── riakcluster.js │ ├── riakconnection.js │ ├── riaknode.js │ └── utils.js ├── crdt │ ├── fetchcounter.js │ ├── fetchhll.js │ ├── fetchmap.js │ ├── fetchset.js │ ├── updatecounter.js │ ├── updategset.js │ ├── updatehll.js │ ├── updatemap.js │ └── updateset.js ├── joi.js ├── kv │ ├── deletevalue.js │ ├── fetchbucketprops.js │ ├── fetchbuckettypeprops.js │ ├── fetchpreflist.js │ ├── fetchvalue.js │ ├── listbuckets.js │ ├── listkeys.js │ ├── riakobject.js │ ├── secondaryindexquery.js │ ├── storebucketprops.js │ ├── storebuckettypeprops.js │ └── storevalue.js ├── mapreduce │ └── mapreduce.js ├── protobuf.js ├── ts │ ├── data.js │ ├── delete.js │ ├── get.js │ ├── listkeys.js │ ├── query.js │ └── store.js └── yokozuna │ ├── deleteindex.js │ ├── fetchindex.js │ ├── fetchschema.js │ ├── search.js │ ├── storeindex.js │ └── storeschema.js └── utils.js /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | Makefile text eol=lf 4 | .travis.yml text eol=lf 5 | .sh text eol=lf 6 | .pl text eol=lf 7 | 8 | *.jpg binary 9 | *.png binary 10 | *.gif binary 11 | *.ico binary 12 | *.bmp binary 13 | *.mdf binary 14 | *.ldf binary 15 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How-to contribute to the Riak Node.js client 2 | 3 | **_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. 4 | 5 | * Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/basho/riak-nodejs-client/issues)** and let us know what you are thinking. 6 | * **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created. 7 | * **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. 8 | 9 | ### Pull Request Process 10 | 11 | Here’s how to get started: 12 | 13 | * Fork the appropriate sub-projects that are affected by your change. 14 | * Create a topic branch for your change and checkout that branch. 15 | `git checkout -b some-topic-branch` 16 | * Make your changes and run the test suite if one is provided. (see below) 17 | * Commit your changes and push them to your fork. 18 | * Open pull-requests for the appropriate projects. 19 | * Contributors will review your pull request, suggest changes, and merge it when it’s ready and/or offer feedback. 20 | * To report a bug or issue, please open a new issue against this repository. 21 | 22 | You can [read the full guidelines for bug reporting and code contributions](http://docs.basho.com/riak/latest/community/bugs/) on the Riak Docs. 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please ensure the following information is supplied for new issues: 2 | 3 | - [ ] Riak Node.js Client version 4 | - [ ] Node.js version 5 | - [ ] Riak version 6 | - [ ] Operating System / Distribution & Version 7 | - [ ] Riak `error.log` file, if applicable 8 | - [ ] What commands were being executed during the error 9 | - [ ] What you *expected* to have happen 10 | 11 | Thank you! 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please ensure the following is present in your Pull Request: 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 | 8 | Thank you! 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /nbproject 2 | node_modules/ 3 | *results.txt 4 | docs/ 5 | out/ 6 | tags 7 | *.tgz 8 | *.log 9 | *.out 10 | *.csv 11 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tools"] 2 | path = tools 3 | url = git://github.com/basho/riak-client-tools 4 | [submodule "lib/protobuf/riak_pb"] 5 | path = lib/protobuf/riak_pb 6 | url = git://github.com/basho/riak_pb 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: node_js 4 | node_js: 5 | - 0.12 6 | - 4 7 | - 6 8 | - stable 9 | env: 10 | - 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 11 | - 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 12 | before_script: 13 | - sudo ./tools/travis-ci/riak-install -i -d "$RIAK_DOWNLOAD_URL" 14 | - sudo ./tools/setup-riak -s 15 | script: 16 | - sudo riak-admin security disable 17 | - make test 18 | - sudo riak-admin security enable 19 | - make security-test 20 | notifications: 21 | slack: 22 | secure: DatOW6e8FqaZmvxcHw+zZ/ku3wMWZ7eoWmqzhu4Wwf4tgC9L//jy4kj2kJx3gktTMPj3rt6eqw9+j7XOjaSFYD8K+BFh/39ORz6G89/Q3WtoK2OsiREtdskLf1qTku7euvXbwhsVno9AWz2AW+idYQj7WxjUKB4TcYn3B4Od3NU= 23 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ##Contributing 2 | 3 | This repo's maintainers are engineers at Basho and we welcome your contribution to the project! 4 | 5 | ### An honest disclaimer 6 | 7 | Due to our obsession with stability and our rich ecosystem of users, community updates on this repo may take a little longer to review. 8 | The most helpful way to contribute is by reporting your experience through issues. Issues may not be updated while we review internally, but they're still incredibly appreciated. 9 | 10 | Thank you for being part of the community. 11 | 12 | ## Helping through sample code 13 | 14 | The most immediately helpful way you can benefit this project is by cloning the [examples repository](https://github.com/basho/riak-nodejs-client-examples/), make some changes and submit a pull request. 15 | 16 | ## How-to contribute to the Node.js client 17 | 18 | **_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. 19 | 20 | * Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/basho/riak-nodejs-client/issues)** and let us know what you are thinking. 21 | * **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created. 22 | * **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. 23 | 24 | ### Pull Request Process 25 | 26 | Here’s how to get started: 27 | 28 | * Fork the appropriate sub-projects that are affected by your change. 29 | * Create a topic branch for your change and checkout that branch. 30 | `git checkout -b some-topic-branch` 31 | * Make your changes and run the test suite if one is provided. (see below) 32 | * Commit your changes and push them to your fork. 33 | * Open pull-requests for the appropriate projects. 34 | * Contributors will review your pull request, suggest changes, and merge it when it’s ready and/or offer feedback. 35 | * To report a bug or issue, please open a new issue against this repository. 36 | 37 | You can [read the full guidelines for bug reporting and code contributions](http://docs.basho.com/riak/latest/community/bugs/) on the Riak Docs. 38 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | module.exports = function(grunt) { 21 | 22 | grunt.initConfig({ 23 | pkg: grunt.file.readJSON('package.json'), 24 | benchmark: { 25 | all: { 26 | src: ['benchmarks/*.js'], 27 | dest: 'benchmarks.csv' 28 | } 29 | }, 30 | yuidoc: { 31 | compile: { 32 | name: '<%= pkg.name %>', 33 | description: '<%= pkg.description %>', 34 | version: '<%= pkg.version %>', 35 | url: '<%= pkg.homepage %>', 36 | options: { 37 | paths: './lib/', 38 | outdir: './docs/', 39 | tabtospace: 4 40 | } 41 | } 42 | }, 43 | jshint: { 44 | files: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js'], 45 | options: { 46 | node: true, 47 | mocha: true 48 | } 49 | }, 50 | mochaTest: { 51 | unit: { 52 | options: { 53 | reporter: 'spec', 54 | captureFile: 'unit-test-results.txt', 55 | quiet: false, 56 | clearRequireCache: false, 57 | colors: false, 58 | useColors: false 59 | }, 60 | src: ['test/unit/**/*.js'] 61 | }, 62 | integration: { 63 | options: { 64 | reporter: 'spec', 65 | captureFile: 'integration-test-results.txt', 66 | quiet: false, 67 | clearRequireCache: false, 68 | colors: false, 69 | useColors: false 70 | }, 71 | src: ['test/integration/**/*.js'] 72 | }, 73 | security: { 74 | options: { 75 | reporter: 'spec', 76 | captureFile: 'security-test-results.txt', 77 | quiet: false, 78 | clearRequireCache: false, 79 | colors: false, 80 | useColors: false 81 | }, 82 | src: ['test/security/**/*.js'] 83 | } 84 | }, 85 | watch: { 86 | files: ['<%= jshint.files %>'], 87 | tasks: ['jshint'] 88 | } 89 | }); 90 | 91 | var enable_debug = process.env.RIAK_NODEJS_CLIENT_DEBUG || 92 | process.env.GRUNT_DEBUG || grunt.option('debug'); 93 | if (enable_debug) { 94 | grunt.log.write('enabling test debugging in Mocha'); 95 | grunt.config.set('mochaTest.unit.options.require', 'test/debug-log'); 96 | grunt.config.set('mochaTest.integration.options.require', 'test/debug-log'); 97 | grunt.config.set('mochaTest.security.options.require', 'test/debug-log'); 98 | } else { 99 | grunt.config.set('mochaTest.options.require', 'test/disable-log'); 100 | } 101 | 102 | grunt.loadNpmTasks('grunt-contrib-jshint'); 103 | grunt.loadNpmTasks('grunt-mocha-test'); 104 | grunt.loadNpmTasks('grunt-contrib-watch'); 105 | grunt.loadNpmTasks('grunt-contrib-yuidoc'); 106 | grunt.loadNpmTasks('grunt-benchmark'); 107 | 108 | grunt.registerTask('lint', 'jshint'); 109 | grunt.registerTask('unit', function (testSuite) { 110 | if (testSuite) { 111 | testSuite = testSuite.trim(); 112 | if (testSuite !== '') { 113 | grunt.config.set('mochaTest.unit.src', ['test/unit/' + testSuite + '/*.js']); 114 | } 115 | } 116 | grunt.task.run(['jshint', 'mochaTest:unit']); 117 | }); 118 | grunt.registerTask('integration', ['jshint', 'mochaTest:integration']); 119 | grunt.registerTask('security', ['jshint', 'mochaTest:security']); 120 | grunt.registerTask('default', ['jshint', 'mochaTest:unit', 'mochaTest:integration']); 121 | grunt.registerTask('docs', 'yuidoc'); 122 | }; 123 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROJDIR = $(realpath $(CURDIR)) 2 | VERBOSITY = normal 3 | GRUNT=$(PROJDIR)/node_modules/grunt-cli/bin/grunt 4 | 5 | .PHONY: all install-deps help test unit-test integration-test integration-test-hll security-test publish 6 | 7 | all: test 8 | 9 | install-deps: 10 | $(PROJDIR)/build/install-deps $(PROJDIR) 11 | 12 | lint: 13 | $(GRUNT) lint 14 | 15 | unit-test: 16 | $(GRUNT) unit:$(SUITE) 17 | 18 | integration-test: 19 | $(GRUNT) integration 20 | 21 | security-test: 22 | $(GRUNT) security 23 | 24 | test: 25 | $(GRUNT) 26 | 27 | publish: 28 | $(PROJDIR)/build/publish $(VERSION) 29 | 30 | help: 31 | @echo '' 32 | @echo ' Targets:' 33 | @echo '-----------------------------------------------------------------' 34 | @echo ' all - Run everything ' 35 | @echo ' lint - Run jshint ' 36 | @echo ' install-deps - Install required dependencies ' 37 | @echo ' test - Run unit & integration tests ' 38 | @echo ' unit-test [SUITE=suite_name] - Run unit tests ' 39 | @echo ' integration-test - Run integration tests ' 40 | @echo ' security-test - Run security tests ' 41 | @echo '-----------------------------------------------------------------' 42 | @echo '' 43 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Riak Node.js Client 2 | Copyright 2014-present Basho Technologies, Inc. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Riak Node.js Client 2 | 3 | **Riak Node.js Client** is a client which makes it easy to communicate with [Riak](http://basho.com/riak/), an open source, distributed database that focuses on high availability, horizontal scalability, and *predictable* latency. Both Riak and this code is maintained by [Basho](http://www.basho.com/). 4 | 5 | ## Build Status 6 | 7 | * Master: [![Build Status](https://travis-ci.org/basho/riak-nodejs-client.svg?branch=master)](https://travis-ci.org/basho/riak-nodejs-client) 8 | 9 | # Installation 10 | 11 | `npm install basho-riak-client --save` 12 | 13 | # Documentation 14 | 15 | Most documentation is living in the [wiki](https://github.com/basho/riak-nodejs-client/wiki). For specifics on our progress here, see the [release notes](https://github.com/basho/riak-nodejs-client/blob/master/RELNOTES.md). 16 | 17 | # Testing / Contributing 18 | 19 | This repository's maintainers are engineers at Basho and we welcome your contribution to the project! Review the details in [CONTRIBUTING.md](CONTRIBUTING.md) in order to give back to this project. 20 | 21 | *Note:* Please clone this repository in such a manner that submodules are also cloned: 22 | 23 | ``` 24 | git clone --recursive https://github.com/basho/riak-nodejs-client 25 | 26 | OR: 27 | 28 | git clone https://github.com/basho/riak-nodejs-client 29 | git submodule update --init --recursive 30 | ``` 31 | 32 | ## Unit Tests 33 | 34 | ```sh 35 | make unit-test 36 | ``` 37 | 38 | ## Integration Tests 39 | 40 | You have two options to run Riak locally - either build from source, or use a pre-installed Riak package. 41 | 42 | ### Source 43 | 44 | To setup the default test configuration, build a Riak node from a clone of `github.com/basho/riak`: 45 | 46 | ```sh 47 | # check out latest release tag 48 | git checkout riak-2.1.4 49 | make locked-deps 50 | make rel 51 | ``` 52 | 53 | [Source build documentation](http://docs.basho.com/riak/kv/latest/setup/installing/source/). 54 | 55 | When building from source, the protocol buffers port will be `8087` and HTTP will be `8098`. 56 | 57 | ### Package 58 | 59 | Install using your platform's package manager ([docs](http://docs.basho.com/riak/kv/latest/setup/installing/)) 60 | 61 | When installing from a package, the protocol buffers port will be `8087` and HTTP will be `8098`. 62 | 63 | ### Running Integration Tests 64 | 65 | * Ensure you've initialized this repo's submodules: 66 | 67 | ```sh 68 | git submodule update --init 69 | ``` 70 | 71 | * Run the following: 72 | 73 | ```sh 74 | ./tools/setup-riak 75 | make integration-test 76 | ``` 77 | 78 | # Roadmap 79 | 80 | The **Riak Node.js Client** will support Node.js releases according to the [LTS schedule](https://github.com/nodejs/LTS#lts-schedule). 81 | 82 | ## License and Authors 83 | **The Riak Node.js** Client is Open Source software released under the Apache 2.0 License. Please see the [LICENSE](LICENSE) file for full license details. 84 | 85 | * Author: [Brian Roach](https://github.com/broach) 86 | * Author: [Luke Bakken](http://bakken.io/) 87 | * Author: [Bryce Kerley](https://github.com/bkerley) 88 | 89 | ## Contributors 90 | 91 | Thank you to all of our contributors! 92 | 93 | * [Tim Kennedy](https://github.com/stretchkennedy) 94 | * [Doug Luce](https://github.com/dougluce) 95 | * [Charlie Zhang](https://github.com/charliezhang) 96 | * [Colin Hemmings](https://github.com/gonzohunter) 97 | * [Timothy Stonis](https://github.com/tstonis) 98 | * [Aleksandr Popov](https://github.com/mogadanez) 99 | * [Josh Yudaken](https://github.com/qix) 100 | * [Gabriel Nicolas Avellaneda](https://github.com/GabrielNicolasAvellaneda) 101 | * [Iain Proctor](https://github.com/iproctor) 102 | * [Brian Edgerton](https://github.com/brianedgerton) 103 | * [Samuel](https://github.com/faust64) 104 | * [Bryan Burgers](https://github.com/bryanburgers) 105 | -------------------------------------------------------------------------------- /benchmarks/kv.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var Riak = require('../lib/client'); 21 | 22 | var logger = require('winston'); 23 | var rs = require('randomstring'); 24 | 25 | var bucketType = 'no_siblings'; 26 | var bucket = 'kv_benchmarks'; 27 | 28 | var strings = []; 29 | var i = 0; 30 | for (i = 0; i < 32; ++i) { 31 | strings[i] = rs.generate((i + 1) * 1024); 32 | } 33 | 34 | var corkNodes = []; 35 | var noCorkNodes = []; 36 | for (var i = 17; i <= 47; i += 10) { 37 | var port = 10000 + i; 38 | corkNodes.push(new Riak.Node({ remoteAddress: 'riak-test', remotePort: port.toString(), cork: true })); 39 | noCorkNodes.push(new Riak.Node({ remoteAddress: 'riak-test', remotePort: port.toString(), cork: false })); 40 | } 41 | 42 | var corkCluster = new Riak.Cluster.Builder().withRiakNodes(corkNodes).build(); 43 | var corkClient = new Riak.Client(corkCluster); 44 | 45 | var noCorkCluster = new Riak.Cluster.Builder().withRiakNodes(noCorkNodes).build(); 46 | var noCorkClient = new Riak.Client(noCorkCluster); 47 | 48 | i = 0; 49 | 50 | function getContent() { 51 | 52 | ++i; 53 | if (i >= 32 ) { 54 | i = 0; 55 | } 56 | 57 | var string = strings[i]; 58 | 59 | var robj = new Riak.Commands.KV.RiakObject() 60 | .setBucketType(bucketType) 61 | .setBucket(bucket) 62 | .setKey(i.toString()) 63 | .setContentType('text/plain') 64 | .setValue(string); 65 | 66 | return robj; 67 | } 68 | 69 | function kv(deferred, useCork) { 70 | 71 | var client = useCork ? corkClient : noCorkClient; 72 | 73 | var f_callback = function(err, resp) { 74 | if (err) { 75 | logger.error('[benchmarks/kv]', err); 76 | throw new Error(err); 77 | } else { 78 | var robj = resp.values.shift(); 79 | var length = robj.getValue().toString('utf8').length; 80 | logger.debug("[benchmarks/kv] %d value length: %d", i, length); 81 | } 82 | deferred.resolve(); 83 | }; 84 | 85 | var s_callback = function(err, resp) { 86 | if (err) { 87 | logger.error('[benchmarks/kv]', err); 88 | throw new Error(err); 89 | } else { 90 | var fetch = new Riak.Commands.KV.FetchValue.Builder() 91 | .withBucketType(bucketType) 92 | .withBucket(bucket) 93 | .withKey(i.toString()) 94 | .withCallback(f_callback) 95 | .build(); 96 | 97 | client.execute(fetch); 98 | } 99 | }; 100 | 101 | var robj = getContent(); 102 | 103 | logger.debug("[benchmarks/kv] storing: %s", JSON.stringify(robj)); 104 | 105 | var store = new Riak.Commands.KV.StoreValue.Builder() 106 | .withContent(robj) 107 | .withCallback(s_callback) 108 | .build(); 109 | 110 | client.execute(store); 111 | } 112 | 113 | module.exports = { 114 | name: 'KV Benchmarks', 115 | tests: [ 116 | { 117 | name: 'KV with cork()', 118 | defer: true, 119 | fn: function (deferred) { 120 | kv(deferred, true); 121 | } 122 | }, 123 | { 124 | name: 'KV without cork()', 125 | defer: true, 126 | fn: function (deferred) { 127 | kv(deferred, false); 128 | } 129 | } 130 | ] 131 | }; 132 | -------------------------------------------------------------------------------- /build/install-deps: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | PLATFORM=$(uname -s) 4 | 5 | if [[ $PLATFORM != 'Linux' ]] 6 | then 7 | echo '[error] must be run on Linux platforms' 2>&1 8 | exit 1 9 | fi 10 | 11 | set -o nounset 12 | 13 | apt_get=$(which apt-get 2>/dev/null) 14 | if [[ ! -x $apt_get ]] 15 | then 16 | echo '[error] must be run on Linux platform that uses deb packaging' 2>&1 17 | exit 1 18 | fi 19 | 20 | if [[ -f /etc/lsb-release ]] 21 | then 22 | source /etc/lsb-release 23 | if [[ $DISTRIB_CODENAME != 'precise' ]] && [[ $DISTRIB_CODENAME != 'trusty' ]] 24 | then 25 | echo '[error] Only tested on Ubuntu 12 precise and Ubuntu 14 trusty' 2>&1 26 | exit 1 27 | fi 28 | else 29 | echo '[error] /etc/lsb-release does not exist' 2>&1 30 | exit 1 31 | fi 32 | 33 | declare -r projdir="$1" 34 | 35 | curl=$(which curl 2>/dev/null) 36 | node=$(which node 2>/dev/null) 37 | npm=$(which npm 2>/dev/null) 38 | 39 | set -o errexit 40 | 41 | if [[ ! -x $curl ]] 42 | then 43 | export DEBIAN_FRONTEND=noninteractive 44 | sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' update 45 | sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install curl 46 | fi 47 | echo '[info] curl dependency is installed' 48 | 49 | if [[ ! -x $node || ! -x $npm ]] 50 | then 51 | # https://nodesource.com/blog/nodejs-v012-iojs-and-the-nodesource-linux-repositories 52 | curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash - 53 | sudo apt-get install -y nodejs 54 | fi 55 | echo '[info] node dependencies are installed' 56 | 57 | echo '[info] running "npm install" to install node modules...' 58 | (cd $projdir && npm install) 59 | 60 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | if (process.env.RIAK_NODEJS_CLIENT_DEBUG) { 21 | var logger = require('winston'); 22 | logger.remove(logger.transports.Console); 23 | logger.add(logger.transports.Console, { 24 | level : 'debug', 25 | colorize: true, 26 | timestamp: true 27 | }); 28 | } 29 | 30 | module.exports = require('./lib/client'); 31 | -------------------------------------------------------------------------------- /lib/commands/crdt.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | /** 21 | * Provides all the commands for Riak CRDTs (Conflict-Free Replicated Data Type) 22 | * @module CRDT 23 | * @main CRDT 24 | */ 25 | function CRDT() { } 26 | 27 | // CRDT exports 28 | module.exports = CRDT; 29 | module.exports.FetchCounter = require('./crdt/fetchcounter'); 30 | module.exports.UpdateCounter = require('./crdt/updatecounter'); 31 | module.exports.FetchMap = require('./crdt/fetchmap'); 32 | module.exports.UpdateMap = require('./crdt/updatemap'); 33 | module.exports.FetchSet = require('./crdt/fetchset'); 34 | module.exports.UpdateSet = require('./crdt/updateset'); 35 | module.exports.UpdateGSet = require('./crdt/updategset'); 36 | module.exports.FetchHll = require('./crdt/fetchhll'); 37 | module.exports.UpdateHll = require('./crdt/updatehll'); 38 | -------------------------------------------------------------------------------- /lib/commands/crdt/updategset.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var UpdateSetBase = require('./updatesetbase'); 21 | var inherits = require('util').inherits; 22 | var Joi = require('joi'); 23 | var ByteBuffer = require('bytebuffer'); 24 | 25 | var utils = require('../../utils'); 26 | var rpb = require('../../protobuf/riakprotobuf'); 27 | var DtOp = rpb.getProtoFor('DtOp'); 28 | var GSetOp = rpb.getProtoFor('GSetOp'); 29 | 30 | /** 31 | * Provides the Update GSet class, its builder, and its response. 32 | * @module CRDT 33 | */ 34 | 35 | /** 36 | * Command used tp update a gset in Riak 37 | * 38 | * As a convenience, a builder class is provided: 39 | * 40 | * var update = new UpdateGSet.Builder() 41 | * .withBucketType('gsets') 42 | * .withBucket('myBucket') 43 | * .withKey('set_1') 44 | * .withAdditions(['this', 'that', 'other']) 45 | * .withCallback(callback) 46 | * .build(); 47 | * 48 | * See {{#crossLink "UpdateSet.Builder"}}UpdateSet.Builder{{/crossLink}} 49 | * @class UpdateGSet 50 | * @constructor 51 | * @param {String[]|Buffer[]} [options.additions] The values to be added to the set. 52 | * @extends UpdateSetBase 53 | */ 54 | function UpdateGSet(options, callback) { 55 | var gset_opts = { 56 | additions: options.additions 57 | }; 58 | delete options.additions; 59 | 60 | UpdateSetBase.call(this, options, callback); 61 | 62 | var self = this; 63 | Joi.validate(gset_opts, schema, function(err, opts) { 64 | if (err) { 65 | throw err; 66 | } 67 | self.additions = opts.additions; 68 | }); 69 | } 70 | 71 | inherits(UpdateGSet, UpdateSetBase); 72 | 73 | UpdateGSet.prototype.constructDtOp = function() { 74 | var dt_op = new DtOp(); 75 | var gset_op = new GSetOp(); 76 | dt_op.setGsetOp(gset_op); 77 | gset_op.adds = UpdateSetBase.buflist(this.additions); 78 | return dt_op; 79 | }; 80 | 81 | UpdateGSet.prototype.getUpdateRespValues = function(dtUpdateResp) { 82 | return dtUpdateResp.gset_value; 83 | }; 84 | 85 | var schema = Joi.object().keys({ 86 | additions: Joi.array().default([]).optional(), 87 | }); 88 | 89 | /** 90 | * A builder for constructing UpdateGSet instances. 91 | * 92 | * Rather than having to manually construct the __options__ and instantiating 93 | * a UpdateGSet directly, this builder may be used. 94 | * 95 | * var update = new UpdateGSet.Builder() 96 | * .withBucketType('myBucketType') 97 | * .withBucket('myBucket') 98 | * .withKey('myKey') 99 | * .withAdditions(['this', 'that', 'other']) 100 | * .withCallback(myCallback) 101 | * .build(); 102 | * 103 | * @class UpdateGSet.Builder 104 | * @extends UpdateSetBase.Builder 105 | */ 106 | function Builder() { 107 | UpdateSetBase.Builder.call(this); 108 | } 109 | 110 | inherits(Builder, UpdateSetBase.Builder); 111 | 112 | /** 113 | * Construct an UpdateGSet instance. 114 | * @method build 115 | * @return {UpdateGSet} 116 | */ 117 | Builder.prototype.build = function() { 118 | var cb = this.callback; 119 | delete this.callback; 120 | return new UpdateGSet(this, cb); 121 | }; 122 | 123 | /** 124 | * The values you wish to add to this gset. 125 | * @method withAdditions 126 | * @param {String[]|Buffer[]} additions The values to add. 127 | * @chainable 128 | */ 129 | utils.bb(Builder, 'additions'); 130 | 131 | module.exports = UpdateGSet; 132 | module.exports.Builder = Builder; 133 | -------------------------------------------------------------------------------- /lib/commands/crdt/updateset.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var UpdateSetBase = require('./updatesetbase'); 21 | var inherits = require('util').inherits; 22 | var Joi = require('joi'); 23 | var ByteBuffer = require('bytebuffer'); 24 | 25 | var utils = require('../../utils'); 26 | var rpb = require('../../protobuf/riakprotobuf'); 27 | var DtOp = rpb.getProtoFor('DtOp'); 28 | var SetOp = rpb.getProtoFor('SetOp'); 29 | 30 | /** 31 | * Provides the Update Set class, its builder, and its response. 32 | * @module CRDT 33 | */ 34 | 35 | /** 36 | * Command used tp update a set in Riak 37 | * 38 | * As a convenience, a builder class is provided: 39 | * 40 | * var update = new UpdateSet.Builder() 41 | * .withBucketType('sets') 42 | * .withBucket('myBucket') 43 | * .withKey('set_1') 44 | * .withAdditions(['this', 'that', 'other']) 45 | * .withCallback(callback) 46 | * .build(); 47 | * 48 | * See {{#crossLink "UpdateSet.Builder"}}UpdateSet.Builder{{/crossLink}} 49 | * @class UpdateSet 50 | * @constructor 51 | * @param {String[]|Buffer[]} [options.additions] The values to be added to the set. 52 | * @param {String[]|Buffer[]} [options.removals] The values to remove from the set. Note that a context is required. 53 | * @extends UpdateSetBase 54 | */ 55 | function UpdateSet(options, callback) { 56 | var set_opts = { 57 | additions: options.additions, 58 | removals: options.removals 59 | }; 60 | delete options.additions; 61 | delete options.removals; 62 | 63 | UpdateSetBase.call(this, options, callback); 64 | 65 | var self = this; 66 | Joi.validate(set_opts, schema, function(err, opts) { 67 | if (err) { 68 | throw err; 69 | } 70 | self.additions = opts.additions; 71 | self.removals = opts.removals; 72 | }); 73 | } 74 | 75 | inherits(UpdateSet, UpdateSetBase); 76 | 77 | UpdateSet.prototype.constructDtOp = function() { 78 | var dt_op = new DtOp(); 79 | var setOp = new SetOp(); 80 | dt_op.setSetOp(setOp); 81 | setOp.adds = UpdateSetBase.buflist(this.additions); 82 | setOp.removes = UpdateSetBase.buflist(this.removals); 83 | return dt_op; 84 | }; 85 | 86 | UpdateSet.prototype.getUpdateRespValues = function(dtUpdateResp) { 87 | return dtUpdateResp.set_value; 88 | }; 89 | 90 | var schema = Joi.object().keys({ 91 | additions: Joi.array().default([]).optional(), 92 | removals: Joi.array().default([]).optional() 93 | }); 94 | 95 | /** 96 | * A builder for constructing UpdateSet instances. 97 | * 98 | * Rather than having to manually construct the __options__ and instantiating 99 | * a UpdateSet directly, this builder may be used. 100 | * 101 | * var update = new UpdateSet.Builder() 102 | * .withBucketType('myBucketType') 103 | * .withBucket('myBucket') 104 | * .withKey('myKey') 105 | * .withAdditions(['this', 'that', 'other']) 106 | * .withCallback(myCallback) 107 | * .build(); 108 | * 109 | * @class UpdateSet.Builder 110 | * @extends UpdateSetBase.Builder 111 | */ 112 | function Builder() { 113 | UpdateSetBase.Builder.call(this); 114 | } 115 | 116 | inherits(Builder, UpdateSetBase.Builder); 117 | 118 | /** 119 | * Construct an UpdateSet instance. 120 | * @method build 121 | * @return {UpdateSet} 122 | */ 123 | Builder.prototype.build = function() { 124 | var cb = this.callback; 125 | delete this.callback; 126 | return new UpdateSet(this, cb); 127 | }; 128 | 129 | /** 130 | * The values you wish to add to this set. 131 | * @method withAdditions 132 | * @param {String[]|Buffer[]} additions The values to add. 133 | * @chainable 134 | */ 135 | utils.bb(Builder, 'additions'); 136 | 137 | /** 138 | * The values you wish to remove from this set. 139 | * __Note:__ when performing removals a context must be provided. 140 | * @method withRemovals 141 | * @param {String[]|Buffer[]} removals The values to remove. 142 | * @chainable 143 | */ 144 | utils.bb(Builder, 'removals'); 145 | 146 | module.exports = UpdateSet; 147 | module.exports.Builder = Builder; 148 | -------------------------------------------------------------------------------- /lib/commands/fetchserverinfo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var CommandBase = require('../commands/commandbase'); 21 | var inherits = require('util').inherits; 22 | 23 | /** 24 | * Provides the FetchServerInfo class 25 | * @module Core 26 | */ 27 | 28 | /** 29 | * Command used to ping Riak. 30 | * @class FetchServerInfo 31 | * @constructor 32 | * @param {Function} callback the callback to be executed when the operation completes. 33 | * @param {String} callback.err An error message. Will be null if no error. 34 | * @param {Boolean} callback.response the response from Riak. Will be true unless there was an error. 35 | * @param {Object} callback.data additional error data. Will be null if no error. 36 | * @extends CommandBase 37 | */ 38 | function FetchServerInfo(callback) { 39 | CommandBase.call(this, 'RpbGetServerInfoReq', 'RpbGetServerInfoResp', callback); 40 | } 41 | 42 | inherits(FetchServerInfo, CommandBase); 43 | 44 | FetchServerInfo.prototype.constructPbRequest = function() { 45 | /* 46 | * NB: since this is just a message code there is nothing to return 47 | */ 48 | return; 49 | }; 50 | 51 | FetchServerInfo.prototype.onSuccess = function(rpbFetchServerInfoResp) { 52 | var response = { node: '', server_version: '' }; 53 | if (rpbFetchServerInfoResp) { 54 | var node = rpbFetchServerInfoResp.getNode().toString('utf8'); 55 | var server_version = rpbFetchServerInfoResp.getServerVersion().toString('utf8'); 56 | response.node = node; 57 | response.server_version = server_version; 58 | } 59 | this._callback(null, response); 60 | return true; 61 | }; 62 | 63 | module.exports = FetchServerInfo; 64 | 65 | -------------------------------------------------------------------------------- /lib/commands/kv.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | /** 21 | * Provides all the commands for Riak Key-Value operations. 22 | * @module KV 23 | * @main KV 24 | */ 25 | function KV() { } 26 | 27 | // KV exports 28 | module.exports = KV; 29 | module.exports.DeleteValue = require('./kv/deletevalue'); 30 | module.exports.FetchBucketProps = require('./kv/fetchbucketprops'); 31 | module.exports.FetchBucketTypeProps = require('./kv/fetchbuckettypeprops'); 32 | module.exports.FetchPreflist = require('./kv/fetchpreflist'); 33 | module.exports.FetchValue = require('./kv/fetchvalue'); 34 | module.exports.ListBuckets = require('./kv/listbuckets'); 35 | module.exports.ListKeys = require('./kv/listkeys'); 36 | module.exports.RiakObject = require('./kv/riakobject'); 37 | module.exports.SecondaryIndexQuery = require('./kv/secondaryindexquery'); 38 | module.exports.StoreBucketProps = require('./kv/storebucketprops'); 39 | module.exports.StoreBucketTypeProps = require('./kv/storebuckettypeprops'); 40 | module.exports.ResetBucketProps = require('./kv/resetbucketprops'); 41 | module.exports.StoreValue = require('./kv/storevalue'); 42 | 43 | -------------------------------------------------------------------------------- /lib/commands/kv/fetchbucketprops.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var FetchPropsBase = require('./fetchpropsbase'); 21 | var inherits = require('util').inherits; 22 | var Joi = require('joi'); 23 | 24 | /** 25 | * Provides the FetchBucketProps class, its builder, and its response. 26 | * @module KV 27 | */ 28 | 29 | /** 30 | * Command used to fetch a bucket's properties from Riak. 31 | * 32 | * As a convenience, a builder class is provided: 33 | * 34 | * var fetch = new FetchBucketProps.Builder() 35 | * .withBucketType('my_type') 36 | * .withBucket('myBucket') 37 | * .withCallback(myCallback) 38 | * .build(); 39 | * 40 | * See {{#crossLink "FetchBucketProps.Builder"}}FetchBucketProps.Builder{{/crossLink}} 41 | * @class FetchBucketProps 42 | * @constructor 43 | * @param {Object} options The options for this command 44 | * @param {String} [options.bucketType=default] The bucket type in riak. 45 | * @param {String} options.bucket The bucket in riak. 46 | * @param {Function} callback The callback to be executed when the operation completes. 47 | * @param {String} callback.err An error message. Will ne null if no error. 48 | * @param {Object} callback.response The response from Riak. This is an oject with all the bucket properties. 49 | * @param {Object} callback.data additional error data. Will be null if no error. 50 | * @extends FetchPropsBase 51 | */ 52 | function FetchBucketProps(options, callback) { 53 | FetchPropsBase.call(this, 'RpbGetBucketReq','RpbGetBucketResp', callback); 54 | this.validateOptions(options, schema); 55 | } 56 | 57 | inherits(FetchBucketProps, FetchPropsBase); 58 | 59 | FetchBucketProps.prototype.constructPbRequest = function() { 60 | var protobuf = this.getPbReqBuilder(); 61 | protobuf.setType(new Buffer(this.options.bucketType)); 62 | protobuf.setBucket(new Buffer(this.options.bucket)); 63 | return protobuf; 64 | }; 65 | 66 | var schema = Joi.object().keys({ 67 | bucket: Joi.string().required(), 68 | bucketType: Joi.string().default('default') 69 | }); 70 | 71 | /** 72 | * A builder for constructing FetchBucketProps instances 73 | * 74 | * Rather than having to manually construct the __options__ and instantiating 75 | * a FetchBucketProps directly, this builder may be used. 76 | * 77 | * var fetch = new FetchBucketProps.Builder() 78 | * .withBucketType('my_type') 79 | * .withBucket('myBucket') 80 | * .withCallback(myCallback) 81 | * .build(); 82 | * 83 | * @class FetchBucketProps.Builder 84 | * @constructor 85 | */ 86 | function Builder() { 87 | FetchPropsBase.Builder.call(this); 88 | } 89 | 90 | inherits(Builder, FetchPropsBase.Builder); 91 | 92 | /** 93 | * Set the bucket. 94 | * @method withBucket 95 | * @param {String} bucket the bucket in Riak 96 | * @chainable 97 | */ 98 | Builder.prototype.withBucket = function(bucket) { 99 | this.bucket = bucket; 100 | return this; 101 | }; 102 | 103 | /** 104 | * Construct a FetchBucketProps instance. 105 | * @method build 106 | * @return {FetchBucketProps} 107 | */ 108 | Builder.prototype.build = function() { 109 | var cb = this.callback; 110 | delete this.callback; 111 | return new FetchBucketProps(this, cb); 112 | }; 113 | 114 | module.exports = FetchBucketProps; 115 | module.exports.Builder = Builder; 116 | 117 | -------------------------------------------------------------------------------- /lib/commands/kv/fetchbuckettypeprops.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var FetchPropsBase = require('./fetchpropsbase'); 21 | var inherits = require('util').inherits; 22 | var Joi = require('joi'); 23 | 24 | /** 25 | * Provides the FetchBucketTypeProps class, its builder, and its response. 26 | * @module KV 27 | */ 28 | 29 | /** 30 | * Command used to fetch a bucket's properties from Riak. 31 | * 32 | * As a convenience, a builder class is provided: 33 | * 34 | * var fetch = new FetchBucketTypeProps.Builder() 35 | * .withBucketType('my_type') 36 | * .withCallback(myCallback) 37 | * .build(); 38 | * 39 | * See {{#crossLink "FetchBucketTypeProps.Builder"}}FetchBucketTypeProps.Builder{{/crossLink}} 40 | * @class FetchBucketTypeProps 41 | * @constructor 42 | * @param {Object} options The options for this command 43 | * @param {String} [options.bucketType=default] The bucket type in riak. 44 | * @param {Function} callback The callback to be executed when the operation completes. 45 | * @param {String} callback.err An error message. Will ne null if no error. 46 | * @param {Object} callback.response The response from Riak. This is an oject with all the bucket type properties. 47 | * @param {Object} callback.data additional error data. Will be null if no error. 48 | * @extends FetchPropsBase 49 | */ 50 | function FetchBucketTypeProps(options, callback) { 51 | FetchPropsBase.call(this, 'RpbGetBucketTypeReq','RpbGetBucketResp', callback); 52 | this.validateOptions(options, schema); 53 | } 54 | 55 | inherits(FetchBucketTypeProps, FetchPropsBase); 56 | 57 | FetchBucketTypeProps.prototype.constructPbRequest = function() { 58 | var protobuf = this.getPbReqBuilder(); 59 | protobuf.setType(new Buffer(this.options.bucketType)); 60 | return protobuf; 61 | }; 62 | 63 | var schema = Joi.object().keys({ 64 | bucketType: Joi.string().default('default') 65 | }); 66 | 67 | /** 68 | * A builder for constructing FetchBucketTypeProps instances 69 | * 70 | * Rather than having to manually construct the __options__ and instantiating 71 | * a FetchBucketTypeProps directly, this builder may be used. 72 | * 73 | * var fetch = new FetchBucketTypeProps.Builder() 74 | * .withBucketType('my_type') 75 | * .withCallback(myCallback) 76 | * .build(); 77 | * 78 | * @class FetchBucketTypeProps.Builder 79 | * @constructor 80 | */ 81 | function Builder() { 82 | FetchPropsBase.Builder.call(this); 83 | } 84 | 85 | inherits(Builder, FetchPropsBase.Builder); 86 | 87 | /** 88 | * Construct a FetchBucketTypeProps instance. 89 | * @method build 90 | * @return {FetchBucketTypeProps} 91 | */ 92 | Builder.prototype.build = function() { 93 | var cb = this.callback; 94 | delete this.callback; 95 | return new FetchBucketTypeProps(this, cb); 96 | }; 97 | 98 | module.exports = FetchBucketTypeProps; 99 | module.exports.Builder = Builder; 100 | 101 | -------------------------------------------------------------------------------- /lib/commands/kv/storebucketprops.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var inherits = require('util').inherits; 21 | var Joi = require('joi'); 22 | 23 | var StorePropsBase = require('./storepropsbase'); 24 | 25 | /** 26 | * Provides the StoreBucketProps class, its builder, and its response. 27 | * @module KV 28 | */ 29 | 30 | /** 31 | * Command used to set the properties on a bucket in Riak. 32 | * 33 | * As a convenience, a builder class is provided: 34 | * 35 | * var storeProps = new StoreBucketProps.Builder() 36 | * .withBucket('my-bucket') 37 | * .withAllowMult(true) 38 | * .build(); 39 | * 40 | * See {{#crossLink "StoreBucketProps.Builder"}}StoreBucketProps.Builder{{/crossLink}} 41 | * 42 | * @class StoreBucketProps 43 | * @constructor 44 | * @param {Object} options The properties to store 45 | * @param {String} options.bucket The bucket in riak. 46 | * @param {String} [options.bucketType] The bucket type in riak. If not supplied 'default is used' 47 | * @param {Function} callback The callback to be executed when the operation completes. 48 | * @param {String} callback.err An error message. Will be null if no error. 49 | * @param {Boolean} callback.response the response from Riak. This will be true. 50 | * @param {Function} callback The callback to be executed when the operation completes. 51 | * @param {String} callback.err An error message. Will ne null if no error. 52 | * @param {Object} callback.response The response from Riak. This is an oject with all the bucket properties. 53 | * @param {Object} callback.data additional error data. Will be null if no error. 54 | * @extends StorePropsBase 55 | */ 56 | function StoreBucketProps(options, callback) { 57 | StorePropsBase.call(this, options, 'RpbSetBucketReq', 'RpbSetBucketResp', callback); 58 | this.validateOptions(options, schema, { allowUnknown: true }); 59 | } 60 | 61 | inherits(StoreBucketProps, StorePropsBase); 62 | 63 | StoreBucketProps.prototype.constructPbRequest = function() { 64 | var protobuf = StoreBucketProps.super_.prototype.constructPbRequest.call(this); 65 | protobuf.setBucket(new Buffer(this.options.bucket)); 66 | protobuf.setType(new Buffer(this.options.bucketType)); 67 | return protobuf; 68 | }; 69 | 70 | var schema = Joi.object().keys({ 71 | bucket: Joi.string().required(), 72 | bucketType: Joi.string().default('default') 73 | }); 74 | 75 | /** 76 | * A builder for constructing StoreBucketProps instances 77 | * 78 | * Rather than having to manually construct the __options__ and instantiating 79 | * a StoreBucketProps directly, this builder may be used. 80 | * 81 | * var storeProps = new StoreBucketProps.Builder() 82 | * .withAllowMult(true) 83 | * .build(); 84 | * 85 | * @class StoreBucketProps.Builder 86 | * @constructor 87 | * @extends StorePropsBase.Builder 88 | */ 89 | function Builder() { 90 | StorePropsBase.Builder.call(this); 91 | this.precommit = []; 92 | this.postcommit = []; 93 | } 94 | 95 | inherits(Builder, StorePropsBase.Builder); 96 | 97 | /** 98 | * Set the bucket. 99 | * @method withBucket 100 | * @param {String} bucket the bucket in Riak 101 | * @chainable 102 | */ 103 | Builder.prototype.withBucket = function(bucket) { 104 | this.bucket = bucket; 105 | return this; 106 | }; 107 | 108 | /** 109 | * Construct a StoreBucketProps instance. 110 | * @method build 111 | * @return {StoreBucketProps} 112 | */ 113 | Builder.prototype.build = function() { 114 | var cb = this.callback; 115 | delete this.callback; 116 | return new StoreBucketProps(this, cb); 117 | }; 118 | 119 | module.exports = StoreBucketProps; 120 | module.exports.Builder = Builder; 121 | -------------------------------------------------------------------------------- /lib/commands/kv/storebuckettypeprops.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var inherits = require('util').inherits; 21 | var Joi = require('joi'); 22 | 23 | var StorePropsBase = require('./storepropsbase'); 24 | 25 | /** 26 | * Provides the StoreBucketTypeProps class, its builder, and its response. 27 | * @module KV 28 | */ 29 | 30 | /** 31 | * Command used to set the properties on a bucket type in Riak. 32 | * 33 | * As a convenience, a builder class is provided: 34 | * 35 | * var storeProps = new StoreBucketTypeProps.Builder() 36 | * .withBucketType('my-type') 37 | * .withAllowMult(true) 38 | * .build(); 39 | * 40 | * See {{#crossLink "StoreBucketTypeProps.Builder"}}StoreBucketTypeProps.Builder{{/crossLink}} 41 | * 42 | * @class StoreBucketTypeProps 43 | * @constructor 44 | * @param {Object} options The properties to store 45 | * @param {String} [options.bucketType] The bucket type in riak. If not supplied 'default is used' 46 | * @param {Function} callback The callback to be executed when the operation completes. 47 | * @param {String} callback.err An error message. Will be null if no error. 48 | * @param {Boolean} callback.response the response from Riak. This will be true. 49 | * @param {Function} callback The callback to be executed when the operation completes. 50 | * @param {String} callback.err An error message. Will ne null if no error. 51 | * @param {Object} callback.response The response from Riak. This is an oject with all the bucket properties. 52 | * @param {Object} callback.data additional error data. Will be null if no error. 53 | * @extends StorePropsBase 54 | */ 55 | function StoreBucketTypeProps(options, callback) { 56 | StorePropsBase.call(this, options, 'RpbSetBucketTypeReq', 'RpbSetBucketResp', callback); 57 | this.validateOptions(options, schema, { allowUnknown: true }); 58 | } 59 | 60 | inherits(StoreBucketTypeProps, StorePropsBase); 61 | 62 | StoreBucketTypeProps.prototype.constructPbRequest = function() { 63 | var protobuf = StoreBucketTypeProps.super_.prototype.constructPbRequest.call(this); 64 | protobuf.setType(new Buffer(this.options.bucketType)); 65 | return protobuf; 66 | }; 67 | 68 | /** 69 | * A builder for constructing StoreBucketTypeProps instances 70 | * 71 | * Rather than having to manually construct the __options__ and instantiating 72 | * a StoreBucketTypeProps directly, this builder may be used. 73 | * 74 | * var storeProps = new StoreBucketTypeProps.Builder() 75 | * .withAllowMult(true) 76 | * .build(); 77 | * 78 | * @class StoreBucketTypeProps.Builder 79 | * @constructor 80 | * @extends StorePropsBase.Builder 81 | */ 82 | function Builder() { 83 | StorePropsBase.Builder.call(this); 84 | this.precommit = []; 85 | this.postcommit = []; 86 | } 87 | 88 | inherits(Builder, StorePropsBase.Builder); 89 | 90 | var schema = Joi.object().keys({ 91 | bucketType: Joi.string().default('default') 92 | }); 93 | 94 | /** 95 | * Construct a StoreBucketTypeProps instance. 96 | * @method build 97 | * @return {StoreBucketTypeProps} 98 | */ 99 | Builder.prototype.build = function() { 100 | var cb = this.callback; 101 | delete this.callback; 102 | return new StoreBucketTypeProps(this, cb); 103 | }; 104 | 105 | module.exports = StoreBucketTypeProps; 106 | module.exports.Builder = Builder; 107 | -------------------------------------------------------------------------------- /lib/commands/mr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | /** 21 | * Provides the commands for Riak Map-Reduce 22 | * @module MR 23 | * @main MR 24 | */ 25 | function MR() { } 26 | 27 | // MR exports 28 | module.exports = MR; 29 | module.exports.MapReduce = require('./mapreduce/mapreduce'); 30 | 31 | -------------------------------------------------------------------------------- /lib/commands/ping.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var CommandBase = require('../commands/commandbase'); 21 | var inherits = require('util').inherits; 22 | 23 | /** 24 | * Provides the Ping class 25 | * @module Core 26 | */ 27 | 28 | /** 29 | * Command used to ping Riak. 30 | * @class Ping 31 | * @constructor 32 | * @param {Function} callback the callback to be executed when the operation completes. 33 | * @param {String} callback.err An error message. Will be null if no error. 34 | * @param {Boolean} callback.response the response from Riak. Will be true unless there was an error. 35 | * @param {Object} callback.data additional error data. Will be null if no error. 36 | * @extends CommandBase 37 | */ 38 | function Ping(callback) { 39 | CommandBase.call(this, 'RpbPingReq', 'RpbPingResp', callback); 40 | } 41 | 42 | inherits(Ping, CommandBase); 43 | 44 | Ping.prototype.constructPbRequest = function() { 45 | /* 46 | * NB: since this is just a message code there is nothing to return 47 | */ 48 | return; 49 | }; 50 | 51 | Ping.prototype.onSuccess = function(rpbPingResp) { 52 | this._callback(null, true); 53 | return true; 54 | }; 55 | 56 | module.exports = Ping; 57 | 58 | -------------------------------------------------------------------------------- /lib/commands/ts.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var tsdata = require('./ts/data'); 21 | 22 | /** 23 | * Provides all the commands for Riak Timeseries operations. 24 | * @module TS 25 | * @main TS 26 | */ 27 | function TS() { } 28 | 29 | // TS exports 30 | module.exports = TS; 31 | module.exports.Describe = require('./ts/describe'); 32 | module.exports.Store = require('./ts/store'); 33 | module.exports.Query = require('./ts/query'); 34 | module.exports.Get = require('./ts/get'); 35 | module.exports.Delete = require('./ts/delete'); 36 | module.exports.ListKeys = require('./ts/listkeys'); 37 | module.exports.ColumnType = tsdata.ColumnType; 38 | -------------------------------------------------------------------------------- /lib/commands/ts/bykeybase.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var inherits = require('util').inherits; 21 | var Joi = require('joi'); 22 | var logger = require('winston'); 23 | 24 | var CommandBase = require('../commandbase'); 25 | var tsdata = require('./data'); 26 | var tsutils = require('./utils'); 27 | 28 | /** 29 | * Base class for Get and Delete classes. 30 | * @module TS 31 | */ 32 | 33 | /** 34 | * @class ByKeyBase 35 | * @constructor 36 | * @param {Object} options The options for this command. 37 | * @param {String} options.table The timeseries table from which retrieve a key from Riak. 38 | * @param {Object[]} options.key The timeseries composite key to retrieve from Riak. 39 | * @param {Function} callback The allback to be executed when the operation completes. 40 | * @param {String} callback.err An error message. Will be null if no error. 41 | * @param {Object} callback.response Object containing timeseries data. 42 | * @param {Object} callback.response.columns Timeseries column data 43 | * @param {Object} callback.response.rows Timeseries row data 44 | * @param {Object} callback.data additional error data. Will be null if no error. 45 | * @extends CommandBase 46 | */ 47 | function ByKeyBase(options, pbRequestName, pbResponseName, callback) { 48 | CommandBase.call(this, pbRequestName, pbResponseName, callback); 49 | this.validateOptions(options, schema); 50 | } 51 | 52 | inherits(ByKeyBase, CommandBase); 53 | 54 | ByKeyBase.prototype.constructPbRequest = function() { 55 | var protobuf = this.getPbReqBuilder(); 56 | protobuf.setTable(new Buffer(this.options.table)); 57 | var cells = tsutils.convertToTsCells(this.options.key); 58 | Array.prototype.push.apply(protobuf.key, cells); 59 | return protobuf; 60 | }; 61 | 62 | var schema = Joi.object().keys({ 63 | table: Joi.string().required(), 64 | key: Joi.array().required() 65 | }); 66 | 67 | /** 68 | * A builder for constructing Get / Delete command instances. 69 | * 70 | * Rather than having to manually construct the __options__ and instantiating 71 | * a ByKeyBase directly, this builder may be used. 72 | * 73 | * var get = new Get.Builder() 74 | * .withKey(key) 75 | * .build(); 76 | * 77 | * @class ByKeyBase.Builder 78 | * @constructor 79 | */ 80 | function Builder() {} 81 | 82 | /** 83 | * Set the table. 84 | * @method withTable 85 | * @param {String} table the table in Riak 86 | * @chainable 87 | */ 88 | Builder.prototype.withTable = function(table) { 89 | this.table = table; 90 | return this; 91 | }; 92 | 93 | /** 94 | * Set the key 95 | * @method withKey 96 | * @param {Object[]} key the timeseries key value 97 | * @chainable 98 | */ 99 | Builder.prototype.withKey = function(key) { 100 | this.key = key; 101 | return this; 102 | }; 103 | 104 | /** 105 | * Set the callback to be executed when the operation completes. 106 | * @method withCallback 107 | * @param {Function} callback The allback to be executed when the operation completes. 108 | * @param {String} callback.err An error message. Will be null if no error. 109 | * @param {Object} callback.response The response from Riak 110 | * @chainable 111 | */ 112 | Builder.prototype.withCallback = function(callback) { 113 | this.callback = callback; 114 | return this; 115 | }; 116 | 117 | module.exports = ByKeyBase; 118 | module.exports.Builder = Builder; 119 | -------------------------------------------------------------------------------- /lib/commands/ts/data.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var rpb = require('../../protobuf/riakprotobuf'); 21 | var TsColumnType = rpb.getProtoFor('TsColumnType'); 22 | 23 | var validColumnTypes = Object.freeze([0, 1, 2, 3, 4, 5]); 24 | 25 | var ColumnType = Object.freeze({ 26 | Varchar: TsColumnType.VARCHAR, 27 | Int64: TsColumnType.SINT64, 28 | Double: TsColumnType.DOUBLE, 29 | Timestamp: TsColumnType.TIMESTAMP, 30 | Boolean: TsColumnType.BOOLEAN, 31 | Blob: TsColumnType.BLOB 32 | }); 33 | 34 | module.exports.ColumnType = ColumnType; 35 | module.exports.validColumnTypes = validColumnTypes; 36 | -------------------------------------------------------------------------------- /lib/commands/ts/delete.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var inherits = require('util').inherits; 21 | var Joi = require('joi'); 22 | var logger = require('winston'); 23 | 24 | var ByKeyBase = require('./bykeybase'); 25 | 26 | /** 27 | * Provides the Delete class, its builder, and its response. 28 | * @module TS 29 | */ 30 | 31 | /** 32 | * Command used to delete timeseries data from Riak. 33 | * 34 | * As a convenience, a builder class is provided: 35 | * 36 | * var get = new Delete.Builder() 37 | * .withKey(key) 38 | * .withCallback(callback) 39 | * .build(); 40 | * 41 | * See {{#crossLink "Delete.Builder"}}Delete.Builder{{/crossLink}} 42 | * 43 | * @class Delete 44 | * @constructor 45 | * @param {Function} callback The allback to be executed when the operation completes. 46 | * @param {String} callback.err An error message. Will be null if no error. 47 | * @param {Object} callback.response true or false to indicate success / failure. 48 | * @param {Object} callback.data additional error data. Will be null if no error. 49 | * @extends ByKeyBase 50 | */ 51 | function Delete(options, callback) { 52 | ByKeyBase.call(this, options, 'TsDelReq', 'TsDelResp', callback); 53 | } 54 | 55 | inherits(Delete, ByKeyBase); 56 | 57 | Delete.prototype.onSuccess = function(rpbDelResp) { 58 | this._callback(null, true); 59 | return true; 60 | }; 61 | 62 | /** 63 | * A builder for constructing Delete instances. 64 | * 65 | * Rather than having to manually construct the __options__ and instantiating 66 | * a Delete directly, this builder may be used. 67 | * 68 | * var get = new Delete.Builder() 69 | * .withKey(key) 70 | * .build(); 71 | * 72 | * @class Delete.Builder 73 | * @constructor 74 | * @extends ByKeyBase.Builder 75 | */ 76 | function Builder() { 77 | ByKeyBase.Builder.call(this); 78 | } 79 | 80 | inherits(Builder, ByKeyBase.Builder); 81 | 82 | /** 83 | * Construct a Delete instance. 84 | * @method build 85 | * @return {Delete} a Delete instance 86 | */ 87 | Builder.prototype.build = function() { 88 | var cb = this.callback; 89 | delete this.callback; 90 | return new Delete(this, cb); 91 | }; 92 | 93 | module.exports = Delete; 94 | module.exports.Builder = Builder; 95 | -------------------------------------------------------------------------------- /lib/commands/ts/describe.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var inherits = require('util').inherits; 21 | var Joi = require('joi'); 22 | var logger = require('winston'); 23 | 24 | var Query = require('./query'); 25 | 26 | /** 27 | * Provides the Describe class, its builder, and its response. 28 | * @module TS 29 | */ 30 | 31 | /** 32 | * Command used to get a timeseries table's description. 33 | * 34 | * As a convenience, a builder class is provided: 35 | * 36 | * var storeValue = new Describe.Builder() 37 | * .withTable('GeoCheckin') 38 | * .withCallback(callback) 39 | * .build(); 40 | * 41 | * See {{#crossLink "Describe.Builder"}}Describe.Builder{{/crossLink}} 42 | * 43 | * @class Describe 44 | * @constructor 45 | * @param {Object} options The options for this command. 46 | * @param {String} options.table The timeseries table in Riak. 47 | * @param {Function} callback The allback to be executed when the operation completes. 48 | * @param {String} callback.err An error message. Will be null if no error. 49 | * @param {Object} callback.response Object containing timeseries table metadata. 50 | * @param {Object} callback.response.columns Timeseries table metadata columns. 51 | * @param {Object} callback.response.rows Timeseries table metadata rows. 52 | * @param {Object} callback.data additional error data. Will be null if no error. 53 | * @extends Query 54 | */ 55 | function Describe(options, callback) { 56 | var self = this; 57 | Joi.validate(options, schema, function(err, options) { 58 | if (err) { 59 | throw err; 60 | } 61 | self.options = options; 62 | }); 63 | 64 | var queryOptions = { 65 | query : 'DESCRIBE ' + self.options.table 66 | }; 67 | 68 | Query.call(this, queryOptions, callback); 69 | } 70 | 71 | inherits(Describe, Query); 72 | 73 | var schema = Joi.object().keys({ 74 | table: Joi.string().required() 75 | }); 76 | 77 | /** 78 | * A builder for constructing Describe instances. 79 | * 80 | * Rather than having to manually construct the __options__ and instantiating 81 | * a Describe directly, this builder may be used. 82 | * 83 | * var storeValue = new Describe.Builder() 84 | * .withTable('table') 85 | * .build(); 86 | * 87 | * @class Describe.Builder 88 | * @constructor 89 | */ 90 | function Builder() {} 91 | 92 | Builder.prototype = { 93 | /** 94 | * Set the timeseries table. 95 | * @method withDescribe 96 | * @param {String} table the timeseries table 97 | * @chainable 98 | */ 99 | withTable : function(table) { 100 | this.table = table; 101 | return this; 102 | }, 103 | /** 104 | * Set the callback to be executed when the operation completes. 105 | * @method withCallback 106 | * @param {Function} callback The allback to be executed when the operation completes. 107 | * @param {String} callback.err An error message. Will be null if no error. 108 | * @param {Object} callback.response The response from Riak 109 | * @chainable 110 | */ 111 | withCallback : function(callback) { 112 | this.callback = callback; 113 | return this; 114 | }, 115 | /** 116 | * Construct a Describe instance. 117 | * @method build 118 | * @return {Describe} a Describe instance 119 | */ 120 | build : function() { 121 | var cb = this.callback; 122 | delete this.callback; 123 | return new Describe(this, cb); 124 | } 125 | }; 126 | 127 | module.exports = Describe; 128 | module.exports.Builder = Builder; 129 | -------------------------------------------------------------------------------- /lib/commands/ts/get.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var inherits = require('util').inherits; 21 | var Joi = require('joi'); 22 | var logger = require('winston'); 23 | 24 | var ByKeyBase = require('./bykeybase'); 25 | var tsutils = require('./utils'); 26 | 27 | /** 28 | * Provides the Get class, its builder, and its response. 29 | * @module TS 30 | */ 31 | 32 | /** 33 | * Command used to get timeseries data in Riak. 34 | * 35 | * As a convenience, a builder class is provided: 36 | * 37 | * var get = new Get.Builder() 38 | * .withKey(key) 39 | * .withCallback(callback) 40 | * .build(); 41 | * 42 | * See {{#crossLink "Get.Builder"}}Get.Builder{{/crossLink}} 43 | * 44 | * @class Get 45 | * @constructor 46 | * @param {Function} callback The allback to be executed when the operation completes. 47 | * @param {String} callback.err An error message. Will be null if no error. 48 | * @param {Object} callback.response.columns Timeseries column data 49 | * @param {Object} callback.response.rows Timeseries row data 50 | * @param {Object} callback.data additional error data. Will be null if no error. 51 | * @extends ByKeyBase 52 | */ 53 | function Get(options, callback) { 54 | ByKeyBase.call(this, options, 'TsGetReq', 'TsGetResp', callback); 55 | } 56 | 57 | inherits(Get, ByKeyBase); 58 | 59 | Get.prototype.onSuccess = function(rpbGetResp) { 60 | // NB: rpbGetResp is TsGetResp, same as TsQueryResp 61 | // columns, rows 62 | var response = tsutils.convertToResponse(rpbGetResp); 63 | this._callback(null, response); 64 | return true; 65 | }; 66 | 67 | /** 68 | * A builder for constructing Get instances. 69 | * 70 | * Rather than having to manually construct the __options__ and instantiating 71 | * a Get directly, this builder may be used. 72 | * 73 | * var get = new Get.Builder() 74 | * .withKey(key) 75 | * .build(); 76 | * 77 | * @class Get.Builder 78 | * @constructor 79 | * @extends ByKeyBase.Builder 80 | */ 81 | function Builder() { 82 | ByKeyBase.Builder.call(this); 83 | } 84 | 85 | inherits(Builder, ByKeyBase.Builder); 86 | 87 | /** 88 | * Construct a Get instance. 89 | * @method build 90 | * @return {Get} a Get instance 91 | */ 92 | Builder.prototype.build = function() { 93 | var cb = this.callback; 94 | delete this.callback; 95 | return new Get(this, cb); 96 | }; 97 | 98 | module.exports = Get; 99 | module.exports.Builder = Builder; 100 | -------------------------------------------------------------------------------- /lib/commands/ts/query.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var inherits = require('util').inherits; 21 | var Joi = require('joi'); 22 | var logger = require('winston'); 23 | 24 | var CommandBase = require('../commandbase'); 25 | var tsdata = require('./data'); 26 | var tsutils = require('./utils'); 27 | 28 | var rpb = require('../../../lib/protobuf/riakprotobuf'); 29 | var TsInterpolation = rpb.getProtoFor('TsInterpolation'); 30 | 31 | /** 32 | * Provides the Query class, its builder, and its response. 33 | * @module TS 34 | */ 35 | 36 | /** 37 | * Command used to query timeseries data in Riak. 38 | * 39 | * As a convenience, a builder class is provided: 40 | * 41 | * var storeValue = new Query.Builder() 42 | * .withQuery('select * from timeseries') 43 | * .withCallback(callback) 44 | * .build(); 45 | * 46 | * See {{#crossLink "Query.Builder"}}Query.Builder{{/crossLink}} 47 | * 48 | * @class Query 49 | * @constructor 50 | * @param {Object} options The options for this command. 51 | * @param {String} options.query The timeseries query for Riak. 52 | * @param {Function} callback The allback to be executed when the operation completes. 53 | * @param {String} callback.err An error message. Will be null if no error. 54 | * @param {Object} callback.response Object containing timeseries data. 55 | * @param {Object} callback.response.columns Timeseries column data 56 | * @param {Object} callback.response.rows Timeseries row data 57 | * @param {Object} callback.data additional error data. Will be null if no error. 58 | * @extends CommandBase 59 | */ 60 | function Query(options, callback) { 61 | CommandBase.call(this, 'TsQueryReq', 'TsQueryResp', callback); 62 | this.validateOptions(options, schema); 63 | } 64 | 65 | inherits(Query, CommandBase); 66 | 67 | Query.prototype.constructPbRequest = function() { 68 | var protobuf = this.getPbReqBuilder(); 69 | 70 | if (this.options.query) { 71 | var tsi = new TsInterpolation(); 72 | tsi.setBase(new Buffer(this.options.query)); 73 | protobuf.setQuery(tsi); 74 | } 75 | 76 | return protobuf; 77 | }; 78 | 79 | Query.prototype.onSuccess = function(rpbQueryResp) { 80 | var response = tsutils.convertToResponse(rpbQueryResp); 81 | this._callback(null, response); 82 | return true; 83 | }; 84 | 85 | var schema = Joi.object().keys({ 86 | query: Joi.string().optional() // TODO RTS-311 why is this optional? 87 | }); 88 | 89 | /** 90 | * A builder for constructing Query instances. 91 | * 92 | * Rather than having to manually construct the __options__ and instantiating 93 | * a Query directly, this builder may be used. 94 | * 95 | * var storeValue = new Query.Builder() 96 | * .withTable('table') 97 | * .withColumns(columns) 98 | * .withRows(rows) 99 | * .build(); 100 | * 101 | * @class Query.Builder 102 | * @constructor 103 | */ 104 | function Builder() {} 105 | 106 | Builder.prototype = { 107 | /** 108 | * Set the query text. 109 | * @method withQuery 110 | * @param {String} query the timeseries query 111 | * @chainable 112 | */ 113 | withQuery : function(query) { 114 | this.query = query; 115 | return this; 116 | }, 117 | /** 118 | * Set the callback to be executed when the operation completes. 119 | * @method withCallback 120 | * @param {Function} callback The allback to be executed when the operation completes. 121 | * @param {String} callback.err An error message. Will be null if no error. 122 | * @param {Object} callback.response The response from Riak 123 | * @chainable 124 | */ 125 | withCallback : function(callback) { 126 | this.callback = callback; 127 | return this; 128 | }, 129 | /** 130 | * Construct a Query instance. 131 | * @method build 132 | * @return {Query} a Query instance 133 | */ 134 | build : function() { 135 | var cb = this.callback; 136 | delete this.callback; 137 | return new Query(this, cb); 138 | } 139 | }; 140 | 141 | module.exports = Query; 142 | module.exports.Builder = Builder; 143 | -------------------------------------------------------------------------------- /lib/commands/yokozuna/deleteindex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var CommandBase = require('../commandbase'); 21 | var inherits = require('util').inherits; 22 | var Joi = require('joi'); 23 | 24 | /** 25 | * Provides the (Yokozuna) DeleteIndex command and its builder. 26 | * @module YZ 27 | */ 28 | 29 | /** 30 | * Command used to Delete a Yokozuna index. 31 | * 32 | * As a convenience, a builder class is provided: 33 | * 34 | * var del = DeleteIndex.Builder() 35 | * .withIndexName('index_name') 36 | * .withCallback(callback) 37 | * .build(); 38 | * 39 | * See {{#crossLink "DeleteIndex.Builder"}}DeleteIndex.Builder{{/crossLink}} 40 | * 41 | * @class DeleteIndex 42 | * @constructor 43 | * @param {Object} options The options for this command 44 | * @param {String} [options.indexName] The name of the index to delete. 45 | * @param {Function} callback The callback to be executed when the operation completes. 46 | * @param {String} callback.err An error message. Will be null if no error. 47 | * @param {Boolean} callback.response operation either succeeds or returns error. This will be true. 48 | * @param {Object} callback.data additional error data. Will be null if no error. 49 | * @extends CommandBase 50 | */ 51 | function DeleteIndex(options, callback) { 52 | CommandBase.call(this, 'RpbYokozunaIndexDeleteReq' , 'RpbDelResp', callback); 53 | this.validateOptions(options, schema); 54 | } 55 | 56 | inherits(DeleteIndex, CommandBase); 57 | 58 | DeleteIndex.prototype.constructPbRequest = function() { 59 | 60 | var protobuf = this.getPbReqBuilder(); 61 | 62 | protobuf.setName(new Buffer(this.options.indexName)); 63 | 64 | return protobuf; 65 | 66 | }; 67 | 68 | DeleteIndex.prototype.onSuccess = function(RpbDelResp) { 69 | // RpbDelResp is simply null (no body) 70 | this._callback(null, true); 71 | return true; 72 | }; 73 | 74 | var schema = Joi.object().keys({ 75 | indexName: Joi.string().required() 76 | }); 77 | 78 | /** 79 | * A builder for constructing DeleteIndex instances. 80 | * 81 | * Rather than having to manually construct the __options__ and instantiating 82 | * a DeleteIndex directly, this builder may be used. 83 | * 84 | * var del = DeleteIndex.Builder() 85 | * .withIndexName('index_name') 86 | * .withCallback(callback) 87 | * .build(); 88 | * 89 | * @class DeleteIndex.Builder 90 | * @constructor 91 | */ 92 | function Builder(){} 93 | 94 | Builder.prototype = { 95 | 96 | /** 97 | * The name of the index to delete. 98 | * If one is not supplied, all indexes are returned. 99 | * @method withIndexName 100 | * @param {String} indexName the name of the index 101 | * @chainable 102 | */ 103 | withIndexName : function(indexName) { 104 | this.indexName = indexName; 105 | return this; 106 | }, 107 | /** 108 | * Set the callback to be executed when the operation completes. 109 | * @method withCallback 110 | * @param {Function} callback the callback to execute 111 | * @param {String} callback.err An error message 112 | * @param {Boolean} callback.response will always be true. 113 | * @chainable 114 | */ 115 | withCallback : function(callback) { 116 | this.callback = callback; 117 | return this; 118 | }, 119 | /** 120 | * Construct a DeleteIndex instance. 121 | * @method build 122 | * @return {DeleteIndex} 123 | */ 124 | build : function() { 125 | var cb = this.callback; 126 | delete this.callback; 127 | return new DeleteIndex(this, cb); 128 | } 129 | }; 130 | 131 | module.exports = DeleteIndex; 132 | module.exports.Builder = Builder; 133 | -------------------------------------------------------------------------------- /lib/commands/yokozuna/fetchschema.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var CommandBase = require('../commandbase'); 21 | var inherits = require('util').inherits; 22 | var Joi = require('joi'); 23 | 24 | /** 25 | * Provides the (Yokozuna) FetchSchema command. 26 | * @module YZ 27 | */ 28 | 29 | /** 30 | * Command used to fetch a Yokozuna schema. 31 | * 32 | * As a convenience, a builder class is provided: 33 | * 34 | * var fetch = FetchSchema.Builder() 35 | * .withSchemaName('schema_name') 36 | * .withCallback(callback) 37 | * .build(); 38 | * 39 | * See {{#crossLink "FetchSchema.Builder"}}FetchSchema.Builder{{/crossLink}} 40 | * 41 | * @class FetchSchema 42 | * @constructor 43 | * @param {Object} options The options for this command 44 | * @param {String} options.schemaName The name of the schema to fetch. 45 | * @param {Function} callback The callback to be executed when the operation completes. 46 | * @param {String} callback.err An error message. Will be null if no error. 47 | * @param {Object} callback.response The response from Riak. 48 | * @param {String} callback.response.name The schema name. 49 | * @param {String} callback.response.content The schema XML. 50 | * @param {Object} callback.data additional error data. Will be null if no error. 51 | * @extends CommandBase 52 | */ 53 | function FetchSchema(options, callback) { 54 | CommandBase.call(this, 'RpbYokozunaSchemaGetReq' , 'RpbYokozunaSchemaGetResp', callback); 55 | this.validateOptions(options, schema); 56 | } 57 | 58 | inherits(FetchSchema, CommandBase); 59 | 60 | FetchSchema.prototype.constructPbRequest = function() { 61 | 62 | var protobuf = this.getPbReqBuilder(); 63 | 64 | protobuf.setName(new Buffer(this.options.schemaName)); 65 | 66 | return protobuf; 67 | 68 | }; 69 | 70 | FetchSchema.prototype.onSuccess = function(rpbYokozunaSchemaGetResp) { 71 | 72 | var pbSchema = rpbYokozunaSchemaGetResp.schema; 73 | var schema = { name: pbSchema.name.toString('utf8') }; 74 | if (pbSchema.content) { 75 | schema.content = pbSchema.content.toString('utf8'); 76 | } 77 | 78 | this._callback(null, schema); 79 | return true; 80 | }; 81 | 82 | var schema = Joi.object().keys({ 83 | schemaName: Joi.string().default(null).optional() 84 | }); 85 | 86 | /** 87 | * A builder for constructing FetchSchema instances. 88 | * 89 | * Rather than having to manually construct the __options__ and instantiating 90 | * a FetchSchema directly, this builder may be used. 91 | * 92 | * var fetch = FetchSchema.Builder() 93 | * .withSchemaName('schema_name') 94 | * .withCallback(callback) 95 | * .build(); 96 | * 97 | * @class FetchSchema.Builder 98 | * @constructor 99 | */ 100 | function Builder(){} 101 | 102 | Builder.prototype = { 103 | 104 | /** 105 | * The name of the schema to fetch. 106 | * @method withSchemaName 107 | * @param {String} schemaName the name of the schema 108 | * @chainable 109 | */ 110 | withSchemaName : function(schemaName) { 111 | this.schemaName = schemaName; 112 | return this; 113 | }, 114 | /** 115 | * Set the callback to be executed when the operation completes. 116 | * @method withCallback 117 | * @param {Function} callback The callback to be executed when the operation completes. 118 | * @param {String} callback.err An error message. Will be null if no error. 119 | * @param {Object} callback.response The response from Riak. 120 | * @param {String} callback.response.name The schema name. 121 | * @param {String} callback.response.content The schema XML. 122 | * @chainable 123 | */ 124 | withCallback : function(callback) { 125 | this.callback = callback; 126 | return this; 127 | }, 128 | /** 129 | * Construct a FetchSchema instance. 130 | * @method build 131 | * @return {FetchSchema} 132 | */ 133 | build : function() { 134 | var cb = this.callback; 135 | delete this.callback; 136 | return new FetchSchema(this, cb); 137 | } 138 | }; 139 | 140 | module.exports = FetchSchema; 141 | module.exports.Builder = Builder; 142 | -------------------------------------------------------------------------------- /lib/commands/yz.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | /** 21 | * Provides all the commands for Riak Search 2.0 (Yokozuna/Solr) 22 | * @module YZ 23 | * @main YZ 24 | */ 25 | function YZ() { } 26 | 27 | // YZ exports 28 | module.exports = YZ; 29 | module.exports.DeleteIndex = require('./yokozuna/deleteindex'); 30 | module.exports.FetchIndex = require('./yokozuna/fetchindex'); 31 | module.exports.FetchSchema = require('./yokozuna/fetchschema'); 32 | module.exports.Search = require('./yokozuna/search'); 33 | module.exports.StoreIndex = require('./yokozuna/storeindex'); 34 | module.exports.StoreSchema = require('./yokozuna/storeschema'); 35 | -------------------------------------------------------------------------------- /lib/core/authreq.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var CommandBase = require('../commands/commandbase'); 21 | var inherits = require('util').inherits; 22 | var Joi = require('joi'); 23 | var logger = require('winston'); 24 | 25 | /** 26 | * 27 | * @module Core 28 | */ 29 | 30 | /** 31 | * Provides the AuthReq class 32 | * Command used to authenticate with Riak. 33 | * 34 | * @class AuthReq 35 | * @constructor 36 | * @param {Object} options 37 | * @param {String} options.user the user with which to authenticate (required) 38 | * @param {String} options.password the password with which to authenticate (optional) 39 | * @extends CommandBase 40 | */ 41 | function AuthReq(options) { 42 | CommandBase.call(this, 'RpbAuthReq', 'RpbAuthResp', function () { 43 | logger.debug('[AuthReq] callback'); 44 | }); 45 | this.validateOptions(options, schema); 46 | this.user = this.options.user; 47 | this.password = this.options.password; 48 | } 49 | 50 | inherits(AuthReq, CommandBase); 51 | 52 | AuthReq.prototype.constructPbRequest = function() { 53 | var protobuf = this.getPbReqBuilder(); 54 | protobuf.setUser(new Buffer(this.user)); 55 | protobuf.setPassword(new Buffer(this.password)); 56 | return protobuf; 57 | }; 58 | 59 | AuthReq.prototype.onSuccess = function(rpbAuthResp) { 60 | this._callback(null, true); 61 | return true; 62 | }; 63 | 64 | var schema = Joi.object().keys({ 65 | user: Joi.string().required(), 66 | password: Joi.string().optional().allow('').default('') 67 | }); 68 | 69 | module.exports = AuthReq; 70 | -------------------------------------------------------------------------------- /lib/core/core.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | /** 21 | * Provides the classes that make up the core of the client. 22 | * @module Core 23 | * @main Core 24 | */ 25 | function Core() { } 26 | 27 | // Core exports 28 | module.exports = Core; 29 | module.exports.RiakNode = require('./riaknode'); 30 | module.exports.RiakCluster = require('./riakcluster'); 31 | 32 | var RoundRobinNodeManager = require('./roundrobinnodemanager'); 33 | module.exports.RoundRobinNodeManager = RoundRobinNodeManager; 34 | module.exports.DefaultNodeManager = RoundRobinNodeManager; 35 | 36 | module.exports.LeastExecutingNodeManager = require('./leastexecutingnodemanager'); 37 | -------------------------------------------------------------------------------- /lib/core/leastexecutingnodemanager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | var inherits = require('util').inherits; 19 | var logger = require('winston'); 20 | 21 | var NodeManager = require('./nodemanager'); 22 | 23 | /** 24 | * @module Core 25 | */ 26 | 27 | /** 28 | * A NodeManager that can be used by RiakCluster. 29 | * 30 | * This NodeManager does a least-commands-executing selection of RiakNodes. 31 | * 32 | * @class LeastExecutingNodeManager 33 | * @param {Boolean} shuffle Shuffle nodes that have same execution count. 34 | * @constructor 35 | * @extends NodeManager 36 | */ 37 | function LeastExecutingNodeManager(shuffle) { 38 | NodeManager.call(this, 'LeastExecutingNodeManager'); 39 | this._shuffle = shuffle; 40 | } 41 | 42 | inherits(LeastExecutingNodeManager, NodeManager); 43 | 44 | LeastExecutingNodeManager.prototype.executeOnNode = function(nodes, command, previous) { 45 | if (nodes.length === 0) { 46 | logger.error("[LeastExecutingNodeManager] zero nodes for execution of command %s", command.name); 47 | return false; 48 | } 49 | 50 | var n = []; 51 | Array.prototype.push.apply(n, nodes); 52 | n.sort(function (a, b) { 53 | return a.executeCount - b.executeCount; 54 | }); 55 | 56 | var i = 0; 57 | if (this._shuffle) { 58 | var j = 0; 59 | for (i = 0; i < n.length - 1; i++) { 60 | j = i + 1; 61 | if (n[j].executeCount > n[i].executeCount) { 62 | break; 63 | } 64 | } 65 | if (j > 1) { 66 | var s = shuffleArray(n.slice(0, j)); 67 | n = Array.prototype.concat(s, n.slice(j)); 68 | } 69 | } 70 | 71 | var executing = false; 72 | for (i = 0; i < n.length; i++) { 73 | executing = this.tryExecute(n[i], command); 74 | if (executing) { 75 | break; 76 | } 77 | } 78 | return executing; 79 | }; 80 | 81 | /** 82 | * Randomize array element order in-place. 83 | * Using Durstenfeld shuffle algorithm. 84 | * http://stackoverflow.com/a/12646864 85 | */ 86 | function shuffleArray(array) { 87 | for (var i = array.length - 1; i > 0; i--) { 88 | var j = Math.floor(Math.random() * (i + 1)); 89 | var temp = array[i]; 90 | array[i] = array[j]; 91 | array[j] = temp; 92 | } 93 | return array; 94 | } 95 | 96 | module.exports = LeastExecutingNodeManager; 97 | -------------------------------------------------------------------------------- /lib/core/nodemanager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var logger = require('winston'); 21 | 22 | var RiakNode = require('./riaknode'); 23 | 24 | /** 25 | * @module Core 26 | */ 27 | 28 | /** 29 | * Abstract class that defines a NodeManager 30 | * 31 | * Every time a command is executed on the {{#crossLink "RiakCluster"}}{{/crossLink}} 32 | * a {{#crossLink "RiakNode"}}{{/crossLink}} is selected. The default procedure for 33 | * doing so is a simple round-robin provided via {{#crossLink "DefaultNodeManager"}}{{/crossLink}}. 34 | * 35 | * If you wish to alter this behavior you should extend this class and implement 36 | * your own executeOnNode(). This function should pick a node from the list and 37 | * execute the command via {{#crossLink "RiakNode/execute:method"}}{{/crossLink}}. 38 | * 39 | * @class NodeManager 40 | * @param {String} name The name of the node manager 41 | * @constructor 42 | */ 43 | function NodeManager(name) { 44 | this._name = name; 45 | } 46 | 47 | /** 48 | * Receives the array or RiakNode objects from the RiakCluster, chooses one, and executes the command on it. 49 | * @param {RiakNode[]} nodes The array of nodes contained in the RiakCluster 50 | * @param {Object} command The command to execute on a node. 51 | * @param {RiakNode} [previous] if a command is being retried due to a failure, this will be the previous node on which it was attempted. 52 | * @returns {Boolean} True if a node was chosen and accepted the command, false otherwise. 53 | */ 54 | NodeManager.prototype.executeOnNode = function(nodes, command, previous) { 55 | throw 'Not supported yet!'; 56 | }; 57 | 58 | /** 59 | * @param {RiakNode} node The node on which to try to execute the command 60 | * @param {Object} command The command to execute on a node. 61 | * @returns {Boolean} True if a node was chosen and accepted the command, false otherwise. 62 | */ 63 | NodeManager.prototype.tryExecute = function(node, command) { 64 | var executing = false; 65 | if (node.state === RiakNode.State.RUNNING) { 66 | logger.debug("[%s] executing command '%s' on node (%s:%d)", 67 | this._name, command.name, node.remoteAddress, node.remotePort); 68 | if (node.execute(command)) { 69 | executing = true; 70 | } else { 71 | logger.debug("[%s] command '%s' did NOT execute", 72 | this._name, command.name); 73 | } 74 | } 75 | return executing; 76 | }; 77 | 78 | module.exports = NodeManager; 79 | -------------------------------------------------------------------------------- /lib/core/roundrobinnodemanager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | var inherits = require('util').inherits; 19 | var logger = require('winston'); 20 | 21 | var NodeManager = require('./nodemanager'); 22 | var RiakNode = require('./riaknode'); 23 | 24 | /** 25 | * @module Core 26 | */ 27 | 28 | /** 29 | * A NodeManager that can be used by RiakCluster. 30 | * 31 | * This NodeManager does a round-robin selection of RiakNodes. 32 | * 33 | * @class RoundRobinNodeManager 34 | * @constructor 35 | * @extends NodeManager 36 | */ 37 | function RoundRobinNodeManager() { 38 | NodeManager.call(this, 'RoundRobinNodeManager'); 39 | this._nodeIndex = 0; 40 | } 41 | 42 | inherits(RoundRobinNodeManager, NodeManager); 43 | 44 | RoundRobinNodeManager.prototype.executeOnNode = function(nodes, command, previous) { 45 | if (nodes.length === 0) { 46 | logger.error('[RoundRobinNodeManager] zero nodes for execution of command %s', command.name); 47 | return false; 48 | } 49 | 50 | var executing = false; 51 | var first = true; 52 | 53 | var startingIndex = this._nodeIndex; 54 | if (startingIndex >= nodes.length) { 55 | startingIndex = 0; 56 | } 57 | 58 | for (;;) { 59 | // Check index before accessing {nodes} because elements can be removed from {nodes}. 60 | if (this._nodeIndex >= nodes.length) { 61 | this._nodeIndex = 0; 62 | } 63 | 64 | if (!first && (this._nodeIndex === startingIndex || nodes.length === 1)) { 65 | break; 66 | } 67 | 68 | first = false; 69 | 70 | var node = nodes[this._nodeIndex]; 71 | this._nodeIndex++; 72 | 73 | // don't try the same node twice in a row if we have multiple nodes 74 | if (nodes.length > 1 && previous && previous === node) { 75 | continue; 76 | } 77 | 78 | if (node.state !== RiakNode.State.RUNNING) { 79 | continue; 80 | } 81 | 82 | executing = this.tryExecute(node, command); 83 | if (executing) { 84 | break; 85 | } 86 | } 87 | 88 | return executing; 89 | 90 | }; 91 | 92 | module.exports = RoundRobinNodeManager; 93 | -------------------------------------------------------------------------------- /lib/core/starttls.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var CommandBase = require('../commands/commandbase'); 21 | var inherits = require('util').inherits; 22 | var Joi = require('joi'); 23 | var logger = require('winston'); 24 | 25 | /** 26 | * @module Core 27 | */ 28 | 29 | /** 30 | * Provides the StartTls command used to start a TLS session with Riak. 31 | * @class StartTls 32 | * @constructor 33 | * @param {Function} callback the function to call when the command completes or errors 34 | * @extends CommandBase 35 | */ 36 | function StartTls() { 37 | CommandBase.call(this, 'RpbStartTls', 'RpbStartTls', function () { 38 | logger.debug('[StartTls] callback'); 39 | }); 40 | } 41 | 42 | inherits(StartTls, CommandBase); 43 | 44 | StartTls.prototype.constructPbRequest = function() { 45 | /* 46 | * NB: since this is just a message code there is nothing to return 47 | */ 48 | return; 49 | }; 50 | 51 | StartTls.prototype.onSuccess = function(rpbStartTlsResp) { 52 | this._callback(null, true); 53 | return true; 54 | }; 55 | 56 | module.exports = StartTls; 57 | -------------------------------------------------------------------------------- /lib/core/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var logger = require('winston'); 21 | var util = require('util'); 22 | 23 | var rpb = require('../protobuf/riakprotobuf'); 24 | var rpbErrorRespCode = rpb.getCodeFor('RpbErrorResp'); 25 | 26 | function checkRiakError(d) { 27 | var msg = null; 28 | var error = false; 29 | if (d.code === rpbErrorRespCode) { 30 | error = true; 31 | var errmsg = d.decoded.getErrmsg().toString('utf8'); 32 | var errcode = d.decoded.getErrcode(); 33 | msg = util.format("%s command '%s' received RpbErrorResp (%d) %s", 34 | d.conn.name, d.command.name, errcode, errmsg); 35 | logger.debug(msg); 36 | if (d.shouldCallback) { 37 | d.command.onRiakError(d.decoded); 38 | } 39 | } 40 | return { error: error, riakError: error, msg: msg }; 41 | } 42 | 43 | function checkRespCode(d) { 44 | var msg = null; 45 | var error = false; 46 | var expectedCode = d.command.getExpectedResponseCode(); 47 | if (d.code !== expectedCode) { 48 | error = true; 49 | msg = util.format("%s command '%s' received incorrect response; expected %d, got %d", 50 | d.conn.name, d.command.name, expectedCode, d.code); 51 | logger.debug(msg); 52 | if (d.shouldCallback) { 53 | d.command.onError(msg); 54 | } 55 | } 56 | return { error: error, riakError: false, msg: msg }; 57 | } 58 | 59 | function handleRiakResponse(d, onError, onSuccess) { 60 | var err = checkRiakError(d); 61 | if (err.error === false) { 62 | err = checkRespCode(d); 63 | } 64 | if (err.error === true) { 65 | onError(err); 66 | } else { 67 | if (d.shouldCallback) { 68 | d.command.onSuccess(d.decoded); 69 | } 70 | onSuccess(); 71 | } 72 | } 73 | 74 | function stateCheck(name, state, allowedStates, stateNames) { 75 | if (allowedStates.indexOf(state) === -1) { 76 | var sn = allowedStates.map(function (val, idx, ary) { 77 | return stateNames[val]; 78 | }); 79 | var msg = util.format('%s illegal state! required: %s current: %s', 80 | name, sn, stateNames[state]); 81 | throw new Error(msg); 82 | } 83 | } 84 | 85 | module.exports.handleRiakResponse = handleRiakResponse; 86 | module.exports.stateCheck = stateCheck; 87 | -------------------------------------------------------------------------------- /lib/errors.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | function ListError() { 21 | return new Error('Bucket and key list operations are expensive and should not be used in production.'); 22 | } 23 | 24 | module.exports.ListError = ListError; 25 | -------------------------------------------------------------------------------- /lib/protobuf/riakprotobuf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var ProtoBuf = require('protobufjs'); 21 | var HashMap = require('hashmap').HashMap; 22 | var fs = require('fs'); 23 | var path = require('path'); 24 | 25 | var riakPbSrc = path.join(__dirname, 'riak_pb', 'src'); 26 | 27 | var builder = ProtoBuf.newBuilder(); 28 | ProtoBuf.loadProtoFile(path.join(riakPbSrc, 'riak.proto'), builder); 29 | ProtoBuf.loadProtoFile(path.join(riakPbSrc, 'riak_dt.proto'), builder); 30 | ProtoBuf.loadProtoFile(path.join(riakPbSrc, 'riak_kv.proto'), builder); 31 | ProtoBuf.loadProtoFile(path.join(riakPbSrc, 'riak_ts.proto'), builder); 32 | ProtoBuf.loadProtoFile(path.join(riakPbSrc, 'riak_search.proto'), builder); 33 | ProtoBuf.loadProtoFile(path.join(riakPbSrc, 'riak_yokozuna.proto'), builder); 34 | 35 | var codeMap = new HashMap(); 36 | fs.readFileSync(path.join(riakPbSrc, 'riak_pb_messages.csv')).toString().split('\n').forEach(function(line) { 37 | if (line === '') return; 38 | var array = line.split(','); 39 | codeMap.set(parseInt(array[0]), array[1]); 40 | codeMap.set(array[1], parseInt(array[0])); 41 | }); 42 | 43 | module.exports = { 44 | getProtoFor : function(nameOrNumber) { 45 | if (typeof nameOrNumber === 'number') { 46 | nameOrNumber = codeMap.get(nameOrNumber); 47 | } 48 | return builder.build(nameOrNumber); 49 | }, 50 | getCodeFor : function(name) { 51 | return codeMap.get(name); 52 | } 53 | }; 54 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var Long = require('long'); 21 | 22 | function isString(v) { 23 | return (typeof v === 'string' || v instanceof String); 24 | } 25 | 26 | function isNullOrUndefined(v) { 27 | return (v === null || typeof v === 'undefined'); 28 | } 29 | 30 | function maybeIsNumber(n) { 31 | if (n instanceof Long) { 32 | return n; 33 | } 34 | var asNum = parseFloat(n); 35 | if (isNaN(asNum)) { 36 | return undefined; 37 | } 38 | return asNum; 39 | } 40 | 41 | function isInteger(n) { 42 | if (n instanceof Long) { 43 | return true; 44 | } else { 45 | return typeof n === 'number' && n % 1 === 0; 46 | } 47 | } 48 | 49 | function isFloat(n) { 50 | return typeof n === 'number' && n % 1 !== 0; 51 | } 52 | 53 | function firstUc(str) { 54 | return str.charAt(0).toUpperCase() + str.slice(1); 55 | } 56 | 57 | function bb(obj, prop) { 58 | obj.prototype['with' + firstUc(prop)] = function(pv) { 59 | this[prop] = pv; 60 | return this; 61 | }; 62 | } 63 | 64 | function ListError() { 65 | return new Error('Bucket and key list operations are expensive and should not be used in production.'); 66 | } 67 | 68 | module.exports.isString = isString; 69 | module.exports.isNullOrUndefined = isNullOrUndefined; 70 | module.exports.maybeIsNumber = maybeIsNumber; 71 | module.exports.isInteger = isInteger; 72 | module.exports.isFloat = isFloat; 73 | module.exports.bb = bb; 74 | module.exports.ListError = ListError; 75 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "basho-riak-client", 3 | "description": "Basho's officially supported NodeJS client for Riak", 4 | "version": "2.4.0", 5 | "author": "Brian Roach ", 6 | "contributors": [ 7 | "Luke Bakken ", 8 | "Bryce Kerley " 9 | ], 10 | "license": "Apache-2.0", 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/basho/riak-nodejs-client.git" 14 | }, 15 | "homepage": "https://github.com/basho/riak-nodejs-client/wiki", 16 | "keywords": [ 17 | "riak", 18 | "node", 19 | "nodejs", 20 | "distributed", 21 | "nosql", 22 | "driver", 23 | "riak-nodejs-client", 24 | "client", 25 | "basho" 26 | ], 27 | "dependencies": { 28 | "async": "~2.0", 29 | "backoff": "~2.5", 30 | "bytebuffer": "~5.0", 31 | "hashmap": "~2.0", 32 | "joi": "~6.0", 33 | "long": "~3.2", 34 | "protobufjs": "~5.0", 35 | "winston": "~2.2" 36 | }, 37 | "devDependencies": { 38 | "benchmark": "latest", 39 | "grunt": "latest", 40 | "grunt-benchmark": "latest", 41 | "grunt-cli": "latest", 42 | "grunt-contrib-jshint": "latest", 43 | "grunt-contrib-watch": "latest", 44 | "grunt-contrib-yuidoc": "latest", 45 | "grunt-mocha-test": "latest", 46 | "jshint": "latest", 47 | "mocha": "~3.1", 48 | "randomstring": "~1.1", 49 | "yuidocjs": "latest" 50 | }, 51 | "engines": { 52 | "node": "~0.12" 53 | }, 54 | "files": [ 55 | "LICENSE", 56 | "README.md", 57 | "index.js", 58 | "lib/*.js", 59 | "lib/commands/", 60 | "lib/core/", 61 | "lib/protobuf/*.js", 62 | "lib/protobuf/riak_pb/src/*.proto", 63 | "lib/protobuf/riak_pb/src/*.csv" 64 | ], 65 | "bugs": { 66 | "url": "https://github.com/basho/riak-nodejs-client/issues" 67 | }, 68 | "main": "index.js", 69 | "directories": { 70 | "lib": "./lib" 71 | }, 72 | "scripts": {} 73 | } 74 | -------------------------------------------------------------------------------- /test/debug-log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var logger = require('winston'); 21 | logger.remove(logger.transports.Console); 22 | logger.add(logger.transports.Console, { 23 | level : 'debug', 24 | colorize: true, 25 | timestamp: true 26 | }); 27 | -------------------------------------------------------------------------------- /test/disable-log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var logger = require('winston'); 21 | logger.remove(logger.transports.Console); 22 | -------------------------------------------------------------------------------- /test/integration/client.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | var logger = require('winston'); 22 | var net = require('net'); 23 | 24 | var Test = require('./testparams'); 25 | var Riak = require('../../index.js'); 26 | 27 | var host = '127.0.0.1'; 28 | var header = new Buffer(5); 29 | header.writeUInt8(2, 4); 30 | header.writeInt32BE(1, 0); 31 | 32 | function startServer(cb) { 33 | var server = net.createServer(function(socket) { 34 | socket.on('data', function(data) { 35 | socket.write(header); 36 | }); 37 | }); 38 | 39 | var port = Test.getPort(); 40 | var sopts = { host: host, port: port }; 41 | server.listen(sopts, function() { 42 | logger.debug('listener started'); 43 | cb(port, server); 44 | }); 45 | } 46 | 47 | describe('integration-client', function() { 48 | it('array-of-addrs-without-callback', function(done) { 49 | startServer(function (port, server) { 50 | var addr = host + ':' + port; 51 | var c = new Riak.Client([addr]); 52 | setTimeout(function () { 53 | c.shutdown(function (state) { 54 | if (state === Riak.Cluster.State.SHUTDOWN) { 55 | server.close(function () { 56 | done(); 57 | }); 58 | } 59 | }); 60 | }, 250); 61 | }); 62 | }); 63 | 64 | it('array-of-addrs-with-callback', function(done) { 65 | startServer(function (port, server) { 66 | var addr = host + ':' + port; 67 | var c = new Riak.Client([addr, addr], function (err, client) { 68 | assert(Object.is(c, client)); 69 | c.stop(function (err, rslt) { 70 | assert(!err, err); 71 | server.close(function () { 72 | done(); 73 | }); 74 | }); 75 | }); 76 | }); 77 | }); 78 | 79 | it('RiakCluster-without-callback', function(done) { 80 | startServer(function (port, server) { 81 | var nopts = { 82 | remoteAddress: host, 83 | remotePort: port 84 | }; 85 | var node = new Riak.Node(nopts); 86 | var copts = { 87 | nodes: [ node ] 88 | }; 89 | var cl = new Riak.Cluster(copts); 90 | var c = new Riak.Client(cl); 91 | setTimeout(function () { 92 | c.shutdown(function (state) { 93 | if (state === Riak.Cluster.State.SHUTDOWN) { 94 | server.close(function () { 95 | done(); 96 | }); 97 | } 98 | }); 99 | }, 250); 100 | }); 101 | }); 102 | 103 | it('RiakCluster-with-callback', function(done) { 104 | startServer(function (port, server) { 105 | var nopts = { 106 | remoteAddress: host, 107 | remotePort: port 108 | }; 109 | var node = new Riak.Node(nopts); 110 | var copts = { 111 | nodes: [ node ] 112 | }; 113 | var cl = new Riak.Cluster(copts); 114 | var c = new Riak.Client(cl, function (err, client) { 115 | assert(Object.is(c, client)); 116 | assert(!err, err); 117 | client.stop(function (err, rslt) { 118 | assert(!err); 119 | assert.equal(rslt, Riak.Cluster.State.SHUTDOWN); 120 | server.close(function () { 121 | done(); 122 | }); 123 | }); 124 | }); 125 | }); 126 | }); 127 | }); 128 | -------------------------------------------------------------------------------- /test/integration/crdt/updateandfetchcounter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var UpdateCounter = require('../../../lib/commands/crdt/updatecounter'); 24 | var FetchCounter = require('../../../lib/commands/crdt/fetchcounter'); 25 | 26 | describe('integration-crdt-counter', function() { 27 | var cluster; 28 | before(function(done) { 29 | cluster = Test.buildCluster(function (err, rslt) { 30 | assert(!err, err); 31 | var callback = function(err, resp) { 32 | assert(!err, err); 33 | done(); 34 | }; 35 | var update = new UpdateCounter.Builder() 36 | .withBucketType(Test.counterBucketType) 37 | .withBucket(Test.bucketName) 38 | .withKey('counter_1') 39 | .withIncrement(10) 40 | .withCallback(callback) 41 | .build(); 42 | cluster.execute(update); 43 | }); 44 | }); 45 | 46 | after(function(done) { 47 | Test.cleanBucket(cluster, Test.counterBucketType, Test.bucketName, function() { 48 | cluster.stop(function (err, rslt) { 49 | assert(!err, err); 50 | done(); 51 | }); 52 | }); 53 | }); 54 | 55 | it('fetches-counter', function(done) { 56 | var callback = function(err, resp) { 57 | assert(!err, err); 58 | assert.equal(resp.counterValue, 10); 59 | done(); 60 | }; 61 | var fetch = new FetchCounter.Builder() 62 | .withKey('counter_1') 63 | .withBucketType(Test.counterBucketType) 64 | .withBucket(Test.bucketName) 65 | .withCallback(callback) 66 | .build(); 67 | cluster.execute(fetch); 68 | }); 69 | 70 | it('returns-isNotFound', function(done) { 71 | var callback = function(err, resp) { 72 | assert(!err, err); 73 | assert(resp.notFound); 74 | assert(resp.isNotFound); 75 | done(); 76 | }; 77 | var fetch = new FetchCounter.Builder() 78 | .withKey('counter_notFound') 79 | .withBucketType(Test.counterBucketType) 80 | .withBucket(Test.bucketName) 81 | .withCallback(callback) 82 | .build(); 83 | cluster.execute(fetch); 84 | }); 85 | 86 | it('updates-counter', function(done) { 87 | var callback = function(err, resp) { 88 | assert(!err, err); 89 | assert.equal(resp.counterValue, 20); 90 | done(); 91 | }; 92 | var update = new UpdateCounter.Builder() 93 | .withKey('counter_1') 94 | .withBucketType(Test.counterBucketType) 95 | .withBucket(Test.bucketName) 96 | .withIncrement(10) 97 | .withCallback(callback) 98 | .build(); 99 | 100 | cluster.execute(update); 101 | }); 102 | 103 | it('generates-key', function(done) { 104 | var callback = function(err, resp) { 105 | assert(!err, err); 106 | assert.equal(resp.counterValue, 10); 107 | assert(resp.generatedKey); 108 | done(); 109 | }; 110 | var update = new UpdateCounter.Builder() 111 | .withBucketType(Test.counterBucketType) 112 | .withBucket(Test.bucketName) 113 | .withIncrement(10) 114 | .withCallback(callback) 115 | .build(); 116 | cluster.execute(update); 117 | }); 118 | }); 119 | -------------------------------------------------------------------------------- /test/integration/crdt/updateandfetchgset.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var UpdateGSet = require('../../../lib/commands/crdt/updategset'); 24 | var FetchSet = require('../../../lib/commands/crdt/fetchset'); 25 | var RiakCluster = require('../../../lib/core/riakcluster'); 26 | 27 | var gset_supported = true; 28 | 29 | describe('Update and Fetch GSet - Integration', function() { 30 | var context; 31 | var cluster; 32 | before(function(done) { 33 | var suite = this; 34 | cluster = Test.buildCluster(function (err, rslt) { 35 | assert(!err, err); 36 | var callback = function(err, resp) { 37 | if (err) { 38 | gset_supported = false; 39 | suite.skip(); 40 | } else { 41 | assert.equal(resp.values.length, 2); 42 | assert.equal(resp.context, null); 43 | context = resp.context; 44 | } 45 | done(); 46 | }; 47 | var update = new UpdateGSet.Builder() 48 | .withBucketType(Test.gsetBucketType) 49 | .withBucket(Test.bucketName) 50 | .withKey('gset_1') 51 | .withAdditions(['this', 'that']) 52 | .withCallback(callback) 53 | .build(); 54 | cluster.execute(update); 55 | }); 56 | }); 57 | 58 | after(function(done) { 59 | if (gset_supported) { 60 | Test.cleanBucket(cluster, Test.gsetBucketType, Test.bucketName, function() { 61 | cluster.stop(function (err, state) { 62 | done(); 63 | }); 64 | }); 65 | } else { 66 | done(); 67 | } 68 | }); 69 | 70 | it('Should fetch a gset', function(done) { 71 | var callback = function(err, resp) { 72 | assert(!err, err); 73 | assert.equal(resp.values.length, 2); 74 | assert.equal(resp.context, null); 75 | done(); 76 | }; 77 | var fetch = new FetchSet.Builder() 78 | .withBucketType(Test.gsetBucketType) 79 | .withBucket(Test.bucketName) 80 | .withKey('gset_1') 81 | .withCallback(callback) 82 | .build(); 83 | cluster.execute(fetch); 84 | }); 85 | 86 | it('Should report isNotFound if a gset does not exist', function(done) { 87 | var callback = function(err, resp) { 88 | assert(!err, err); 89 | assert(resp.notFound); 90 | assert(resp.isNotFound); 91 | done(); 92 | }; 93 | var fetch = new FetchSet.Builder() 94 | .withBucketType(Test.gsetBucketType) 95 | .withBucket(Test.bucketName) 96 | .withKey('gset_notFound') 97 | .withCallback(callback) 98 | .build(); 99 | cluster.execute(fetch); 100 | }); 101 | 102 | it('Should add to a gset', function(done) { 103 | var callback = function(err, resp) { 104 | assert(!err, err); 105 | assert.equal(resp.values.length, 3); 106 | done(); 107 | }; 108 | 109 | var update = new UpdateGSet.Builder() 110 | .withBucketType(Test.gsetBucketType) 111 | .withBucket(Test.bucketName) 112 | .withKey('gset_1') 113 | .withAdditions(['those']) 114 | .withContext(context) 115 | .withCallback(callback) 116 | .build(); 117 | 118 | cluster.execute(update); 119 | }); 120 | }); 121 | -------------------------------------------------------------------------------- /test/integration/crdt/updateandfetchhll.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var UpdateHll = require('../../../lib/commands/crdt/updatehll'); 24 | var FetchHll = require('../../../lib/commands/crdt/fetchhll'); 25 | var RiakCluster = require('../../../lib/core/riakcluster'); 26 | 27 | var hll_supported = true; 28 | 29 | describe('Update and Fetch Hyperloglog - Integration', function() { 30 | var context; 31 | var cluster; 32 | before(function(done) { 33 | var suite = this; 34 | cluster = Test.buildCluster(function (err, rslt) { 35 | assert(!err, err); 36 | var callback = function(err, resp) { 37 | if (err) { 38 | hll_supported = false; 39 | suite.skip(); 40 | } else { 41 | assert.equal(resp.cardinality, 4); 42 | } 43 | done(); 44 | }; 45 | var update = new UpdateHll.Builder() 46 | .withBucketType(Test.hllBucketType) 47 | .withBucket(Test.bucketName) 48 | .withKey('hll_1') 49 | .withAdditions(['Jokes', 'are', 'better', 'explained', 'Jokes']) 50 | .withCallback(callback) 51 | .build(); 52 | cluster.execute(update); 53 | }); 54 | }); 55 | 56 | after(function(done) { 57 | if (hll_supported) { 58 | Test.cleanBucket(cluster, Test.hllBucketType, Test.bucketName, function() { 59 | cluster.stop(function (err, state) { 60 | done(); 61 | }); 62 | }); 63 | } else { 64 | done(); 65 | } 66 | }); 67 | 68 | it('Should fetch a hyperloglog', function(done) { 69 | var callback = function(err, resp) { 70 | assert(!err, err); 71 | assert(!resp.notFound); 72 | assert(!resp.isNotFound); 73 | assert.equal(resp.cardinality, 4); 74 | done(); 75 | }; 76 | var fetch = new FetchHll.Builder() 77 | .withBucketType(Test.hllBucketType) 78 | .withBucket(Test.bucketName) 79 | .withKey('hll_1') 80 | .withCallback(callback) 81 | .build(); 82 | cluster.execute(fetch); 83 | }); 84 | 85 | it('Should report isNotFound if a hyperloglog does not exist', function(done) { 86 | var callback = function(err, resp) { 87 | assert(!err, err); 88 | assert(resp.isNotFound); 89 | assert.equal(resp.cardinality, null); 90 | done(); 91 | }; 92 | var fetch = new FetchHll.Builder() 93 | .withBucketType(Test.hllBucketType) 94 | .withBucket(Test.bucketName) 95 | .withKey('empty_hll') 96 | .withCallback(callback) 97 | .build(); 98 | cluster.execute(fetch); 99 | }); 100 | }); 101 | -------------------------------------------------------------------------------- /test/integration/crdt/updateandfetchset.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var UpdateSet = require('../../../lib/commands/crdt/updateset'); 24 | var FetchSet = require('../../../lib/commands/crdt/fetchset'); 25 | var RiakCluster = require('../../../lib/core/riakcluster'); 26 | 27 | describe('Update and Fetch Set - Integration', function() { 28 | var context; 29 | var cluster; 30 | before(function(done) { 31 | cluster = Test.buildCluster(function (err, rslt) { 32 | assert(!err, err); 33 | var callback = function(err, resp) { 34 | assert(!err, err); 35 | assert.equal(resp.values.length, 2); 36 | assert(resp.context); 37 | context = resp.context; 38 | done(); 39 | }; 40 | var update = new UpdateSet.Builder() 41 | .withBucketType(Test.setBucketType) 42 | .withBucket(Test.bucketName) 43 | .withKey('set_1') 44 | .withAdditions(['this', 'that']) 45 | .withCallback(callback) 46 | .build(); 47 | cluster.execute(update); 48 | }); 49 | }); 50 | 51 | after(function(done) { 52 | Test.cleanBucket(cluster, Test.setBucketType, Test.bucketName, function() { 53 | cluster.stop(function (err, state) { 54 | done(); 55 | }); 56 | }); 57 | }); 58 | 59 | it('Should fetch a set', function(done) { 60 | var callback = function(err, resp) { 61 | assert(!err, err); 62 | assert.equal(resp.values.length, 2); 63 | assert(resp.context); 64 | done(); 65 | }; 66 | var fetch = new FetchSet.Builder() 67 | .withBucketType(Test.setBucketType) 68 | .withBucket(Test.bucketName) 69 | .withKey('set_1') 70 | .withCallback(callback) 71 | .build(); 72 | cluster.execute(fetch); 73 | }); 74 | 75 | it('Should report isNotFound if a set does not exist', function(done) { 76 | var callback = function(err, resp) { 77 | assert(!err, err); 78 | assert(resp.notFound); 79 | assert(resp.isNotFound); 80 | done(); 81 | }; 82 | var fetch = new FetchSet.Builder() 83 | .withBucketType(Test.setBucketType) 84 | .withBucket(Test.bucketName) 85 | .withKey('set_notFound') 86 | .withCallback(callback) 87 | .build(); 88 | cluster.execute(fetch); 89 | }); 90 | 91 | it('Should remove from a set', function(done) { 92 | 93 | var callback = function(err, resp) { 94 | assert(!err, err); 95 | assert.equal(resp.values.length, 1); 96 | done(); 97 | }; 98 | 99 | // This ... tests updating a new set 100 | var update = new UpdateSet.Builder() 101 | .withBucketType(Test.setBucketType) 102 | .withBucket(Test.bucketName) 103 | .withKey('set_1') 104 | .withRemovals(['this']) 105 | .withContext(context) 106 | .withCallback(callback) 107 | .build(); 108 | 109 | cluster.execute(update); 110 | 111 | }); 112 | 113 | }); 114 | -------------------------------------------------------------------------------- /test/integration/kv/fetchandsetbucketprops.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var StoreProps = require('../../../lib/commands/kv/storebucketprops'); 24 | var FetchProps = require('../../../lib/commands/kv/fetchbucketprops'); 25 | 26 | describe('Store and Fetch Bucket props - Integration', function() { 27 | var cluster; 28 | before(function(done) { 29 | cluster = Test.buildCluster(function (err, rslt) { 30 | assert(!err, err); 31 | done(); 32 | }); 33 | }); 34 | 35 | after(function(done) { 36 | cluster.stop(function (err, rslt) { 37 | assert(!err, err); 38 | done(); 39 | }); 40 | }); 41 | 42 | describe('StoreBucketProps', function() { 43 | it('Should store props for a bucket in the default type', function(done) { 44 | var callback = function(err, resp) { 45 | assert(!err, err); 46 | done(); 47 | }; 48 | var store = new StoreProps.Builder() 49 | .withBucket(Test.bucketName + '_sp') 50 | .withAllowMult(true) 51 | .withCallback(callback) 52 | .build(); 53 | cluster.execute(store); 54 | }); 55 | 56 | it('Should store bucket props for a bucket in a non-default type', function(done) { 57 | var callback = function(err, resp) { 58 | assert(!err, err); 59 | done(); 60 | }; 61 | var store = new StoreProps.Builder() 62 | .withBucketType(Test.bucketType) 63 | .withBucket(Test.bucketName + '_sp') 64 | .withAllowMult(false) 65 | .withCallback(callback) 66 | .build(); 67 | cluster.execute(store); 68 | 69 | }); 70 | }); 71 | 72 | describe('FetchBucketProps', function() { 73 | it('Should fetch props for a bucket in the default Type', function(done) { 74 | var callback = function(err, resp) { 75 | assert(!err, err); 76 | assert(resp.nVal); 77 | done(); 78 | }; 79 | var fetch = new FetchProps.Builder() 80 | .withBucket(Test.bucketName + '_sp') 81 | .withCallback(callback) 82 | .build(); 83 | cluster.execute(fetch); 84 | }); 85 | 86 | it('Should fetch props for a bucket in a non-default Type', function(done) { 87 | var callback = function(err, resp) { 88 | assert(!err, err); 89 | assert(resp.nVal); 90 | done(); 91 | }; 92 | var fetch = new FetchProps.Builder() 93 | .withBucketType(Test.bucketType) 94 | .withCallback(callback) 95 | .withBucket(Test.bucketName + '_sp') 96 | .build(); 97 | cluster.execute(fetch); 98 | }); 99 | }); 100 | }); 101 | -------------------------------------------------------------------------------- /test/integration/kv/fetchandsetbuckettypeprops.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var Test = require('../testparams'); 21 | var StoreBucketTypeProps = require('../../../lib/commands/kv/storebuckettypeprops'); 22 | var FetchBucketTypeProps = require('../../../lib/commands/kv/fetchbuckettypeprops'); 23 | var RiakNode = require('../../../lib/core/riaknode'); 24 | var RiakCluster = require('../../../lib/core/riakcluster'); 25 | var assert = require('assert'); 26 | 27 | var bucketName = Test.bucketName + '_sp'; 28 | 29 | describe('integration-core-bucket-type-props', function() { 30 | var cluster; 31 | before(function(done) { 32 | cluster = Test.buildCluster(function (err, rslt) { 33 | done(); 34 | }); 35 | }); 36 | 37 | after(function(done) { 38 | var sc = function (state) { 39 | if (state === RiakCluster.State.SHUTDOWN) { 40 | done(); 41 | } 42 | }; 43 | cluster.on('stateChange', sc); 44 | cluster.stop(); 45 | }); 46 | 47 | describe('store', function() { 48 | it('should-not-store-for-default', function(done) { 49 | var callback = function(err, resp) { 50 | assert(err, err); 51 | done(); 52 | }; 53 | var store = new StoreBucketTypeProps.Builder() 54 | .withAllowMult(true) 55 | .withCallback(callback) 56 | .build(); 57 | cluster.execute(store); 58 | }); 59 | 60 | it('should-store-for-non-default', function(done) { 61 | var cb3 = function(err, resp) { 62 | assert(!err, err); 63 | done(); 64 | }; 65 | var cb2 = function(err, resp) { 66 | assert(!err, err); 67 | assert.strictEqual(resp.allowMult, false); 68 | assert.strictEqual(resp.nVal, 4); 69 | var store = new StoreBucketTypeProps.Builder() 70 | .withBucketType(Test.bucketType) 71 | .withAllowMult(true) 72 | .withNVal(3) 73 | .withCallback(cb3) 74 | .build(); 75 | cluster.execute(store); 76 | }; 77 | var cb1 = function(err, resp) { 78 | assert(!err, err); 79 | var fetch = new FetchBucketTypeProps.Builder() 80 | .withBucketType(Test.bucketType) 81 | .withCallback(cb2) 82 | .build(); 83 | cluster.execute(fetch); 84 | }; 85 | var store = new StoreBucketTypeProps.Builder() 86 | .withBucketType(Test.bucketType) 87 | .withAllowMult(false) 88 | .withNVal(4) 89 | .withCallback(cb1) 90 | .build(); 91 | cluster.execute(store); 92 | }); 93 | }); 94 | 95 | describe('fetch', function() { 96 | it('default', function(done) { 97 | var callback = function(err, resp) { 98 | assert(!err, err); 99 | assert(resp.nVal); 100 | done(); 101 | }; 102 | var fetch = new FetchBucketTypeProps.Builder() 103 | .withCallback(callback) 104 | .build(); 105 | cluster.execute(fetch); 106 | }); 107 | 108 | it('non-default', function(done) { 109 | var callback = function(err, resp) { 110 | assert(!err, err); 111 | assert(resp.nVal); 112 | done(); 113 | }; 114 | var fetch = new FetchBucketTypeProps.Builder() 115 | .withBucketType(Test.bucketType) 116 | .withCallback(callback) 117 | .build(); 118 | cluster.execute(fetch); 119 | }); 120 | }); 121 | }); 122 | -------------------------------------------------------------------------------- /test/integration/kv/fetchpreflist.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var FetchServerInfo = require('../../../lib/commands/fetchserverinfo'); 24 | var FetchPreflist = require('../../../lib/commands/kv/fetchpreflist'); 25 | 26 | var cb = function (err, resp) { 27 | assert(!err, err); 28 | assert.equal(resp.preflist.length, 3); // NB: since nval is 3 29 | }; 30 | 31 | describe('FetchPreflist - Integration', function() { 32 | var cluster; 33 | before(function(done) { 34 | var self = this; 35 | cluster = Test.buildCluster(function (err, rslt) { 36 | assert(!err, err); 37 | 38 | function info_cb(err, resp) { 39 | if (resp.server_version < '2.1') { 40 | self.skip(); 41 | } 42 | done(); 43 | } 44 | 45 | var fetch = new FetchServerInfo(info_cb); 46 | cluster.execute(fetch); 47 | }); 48 | }); 49 | 50 | after(function(done) { 51 | cluster.stop(function (err, rslt) { 52 | assert(!err, err); 53 | done(); 54 | }); 55 | }); 56 | 57 | it('fetch-default-type-preflist', function(done) { 58 | var fetch = new FetchPreflist.Builder() 59 | .withBucket(Test.bucketName) 60 | .withKey('my_key1') 61 | .withCallback(function (err, resp) { cb(err, resp); done(); }) 62 | .build(); 63 | cluster.execute(fetch); 64 | }); 65 | 66 | it('fetch-non-default-type-preflist', function(done) { 67 | var fetch = new FetchPreflist.Builder() 68 | .withBucket(Test.bucketName) 69 | .withBucketType(Test.bucketType) 70 | .withKey('my_key1') 71 | .withCallback(function (err, resp) { cb(err, resp); done(); }) 72 | .build(); 73 | cluster.execute(fetch); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/integration/kv/listbuckets.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var ListBuckets = require('../../../lib/commands/kv/listbuckets'); 24 | var StoreValue = require('../../../lib/commands/kv/storevalue'); 25 | 26 | describe('ListBuckets - Integration', function() { 27 | var cluster; 28 | before(function(done) { 29 | cluster = Test.buildCluster(function (err, rslt) { 30 | assert(!err, err); 31 | 32 | var count = 0; 33 | var cb = function(err, resp) { 34 | assert(!err, err); 35 | count++; 36 | if (count === 10) { 37 | done(); 38 | } 39 | }; 40 | 41 | for (var i = 0; i < 5; i++) { 42 | // Will create buckets 43 | var bucket = Test.bucketName + '_lb' + i; 44 | var store = new StoreValue.Builder() 45 | .withBucket(bucket) 46 | .withContent('value') 47 | .withCallback(cb) 48 | .build(); 49 | cluster.execute(store); 50 | store = new StoreValue.Builder() 51 | .withBucketType(Test.bucketType) 52 | .withBucket(bucket) 53 | .withContent('value') 54 | .withCallback(cb) 55 | .build(); 56 | cluster.execute(store); 57 | } 58 | }); 59 | }); 60 | 61 | after(function(done) { 62 | var num = 0; 63 | var type = 'default'; 64 | var nukeBucket = function() { 65 | num++; 66 | if (num === 6) { 67 | if(type === 'default') { 68 | type = Test.bucketType; 69 | num = 1; 70 | Test.cleanBucket(cluster, type, Test.bucketName + '_lb' + (num - 1), nukeBucket); 71 | } else { 72 | cluster.stop(function (err, rslt) { 73 | assert(!err, err); 74 | done(); 75 | }); 76 | } 77 | } else { 78 | Test.cleanBucket(cluster, type, Test.bucketName + '_lb' + (num - 1), nukeBucket); 79 | } 80 | }; 81 | nukeBucket(); 82 | }); 83 | 84 | it('should list buckets in the default type', function(done) { 85 | var callback = function(err, resp) { 86 | assert(!err, err); 87 | if (!resp.done) { 88 | assert(resp.buckets.length); 89 | } else { 90 | done(); 91 | } 92 | }; 93 | var list = new ListBuckets.Builder() 94 | .withAllowListing() 95 | .withCallback(callback) 96 | .build(); 97 | cluster.execute(list); 98 | }); 99 | 100 | it('should list buckets in a non-default type', function(done) { 101 | var callback = function(err, resp) { 102 | assert(!err, err); 103 | if (!resp.done) { 104 | assert(resp.buckets.length); 105 | } else { 106 | done(); 107 | } 108 | }; 109 | var list = new ListBuckets.Builder() 110 | .withAllowListing() 111 | .withCallback(callback) 112 | .withBucketType(Test.bucketType) 113 | .build(); 114 | cluster.execute(list); 115 | }); 116 | }); 117 | -------------------------------------------------------------------------------- /test/integration/kv/listkeys.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var ListKeys = require('../../../lib/commands/kv/listkeys'); 24 | var StoreValue = require('../../../lib/commands/kv/storevalue'); 25 | 26 | describe('ListKeys - Integration', function() { 27 | var totalKeyCount = 50; 28 | var listKeysPrefix = 'listKeysPrefix_'; 29 | 30 | var cluster; 31 | before(function(done) { 32 | cluster = Test.buildCluster(function (err, rslt) { 33 | assert(!err, err); 34 | 35 | var count = 0; 36 | var cb = function(err, resp) { 37 | assert(!err, err); 38 | count++; 39 | if (count === totalKeyCount) { 40 | done(); 41 | } 42 | }; 43 | 44 | for (var i = 0; i < totalKeyCount; i++) { 45 | // Will create keys 46 | var key = listKeysPrefix + i; 47 | var store = new StoreValue.Builder() 48 | .withBucket(Test.bucketName) 49 | .withKey(key) 50 | .withContent('value') 51 | .withCallback(cb) 52 | .build(); 53 | cluster.execute(store); 54 | } 55 | }); 56 | }); 57 | 58 | after(function(done) { 59 | Test.cleanBucket(cluster, 'default', Test.bucketName, done); 60 | }); 61 | 62 | it('should list keys in the default type', function(done) { 63 | var keyCount = 0; 64 | var callback = function(err, resp) { 65 | assert(!err, err); 66 | if (!resp.done) { 67 | resp.keys.forEach(function (k) { 68 | if (k.indexOf(listKeysPrefix) === 0) { 69 | keyCount++; 70 | } 71 | }); 72 | } else { 73 | assert.equal(keyCount, totalKeyCount); 74 | done(); 75 | } 76 | }; 77 | var list = new ListKeys.Builder() 78 | .withAllowListing() 79 | .withBucketType('default') 80 | .withBucket(Test.bucketName) 81 | .withCallback(callback) 82 | .withStreaming(true) 83 | .build(); 84 | cluster.execute(list); 85 | }); 86 | }); 87 | -------------------------------------------------------------------------------- /test/integration/yokozuna/storeandfetchschema.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var StoreSchema = require('../../../lib/commands/yokozuna/storeschema'); 24 | var FetchSchema = require('../../../lib/commands/yokozuna/fetchschema'); 25 | 26 | describe('Update and Fetch Yokozuna schema - Integration', function() { 27 | var defaultSchema; 28 | var cluster; 29 | before(function(done) { 30 | cluster = Test.buildCluster(function (err, rslt) { 31 | assert(!err, err); 32 | var callback = function(err, resp) { 33 | assert(!err, err); 34 | assert(resp.content); 35 | defaultSchema = resp.content; 36 | done(); 37 | }; 38 | var fetch = new FetchSchema.Builder() 39 | .withSchemaName('_yz_default') 40 | .withCallback(callback) 41 | .build(); 42 | cluster.execute(fetch); 43 | }); 44 | }); 45 | 46 | after(function(done) { 47 | cluster.stop(function (err, rslt) { 48 | assert(!err, err); 49 | done(); 50 | }); 51 | }); 52 | 53 | it('Should store a schema', function(done) { 54 | var callback = function(err, resp) { 55 | assert(!err, err); 56 | assert(resp); 57 | done(); 58 | }; 59 | 60 | var store = new StoreSchema.Builder() 61 | .withSchemaName('mySchema') 62 | .withSchema(defaultSchema) 63 | .withCallback(callback) 64 | .build(); 65 | cluster.execute(store); 66 | 67 | }); 68 | 69 | it('Should fetch a schema', function(done) { 70 | var callback = function(err, resp) { 71 | assert(!err, err); 72 | assert(resp); 73 | done(); 74 | }; 75 | var fetch = new FetchSchema.Builder() 76 | .withSchemaName('mySchema') 77 | .withCallback(callback) 78 | .build(); 79 | cluster.execute(fetch); 80 | }); 81 | }); 82 | -------------------------------------------------------------------------------- /test/integration/yokozuna/storefetchdeleteindex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | 22 | var Test = require('../testparams'); 23 | var StoreIndex = require('../../../lib/commands/yokozuna/storeindex'); 24 | var FetchIndex = require('../../../lib/commands/yokozuna/fetchindex'); 25 | var DeleteIndex = require('../../../lib/commands/yokozuna/deleteindex'); 26 | var rs = require('randomstring'); 27 | 28 | describe('yokozuna-store-and-fetch', function() { 29 | var cluster; 30 | var fetch_attempts = 10; 31 | var fetch_timeout = 1000; 32 | var total_timeout = (fetch_attempts * fetch_timeout) + 1000; 33 | var tmp = 'idx_' + rs.generate(8); 34 | 35 | this.timeout(total_timeout); 36 | 37 | before(function(done) { 38 | cluster = Test.buildCluster(function (err, rslt) { 39 | assert(!err, err); 40 | var callback = function(err, resp) { 41 | assert(!err, err); 42 | assert(resp); 43 | done(); 44 | }; 45 | var store = new StoreIndex.Builder() 46 | .withIndexName(tmp) 47 | .withCallback(callback) 48 | .build(); 49 | cluster.execute(store); 50 | }); 51 | }); 52 | 53 | after(function(done) { 54 | var callback = function(err, resp) { 55 | assert(!err, err); 56 | assert(resp); 57 | cluster.stop(function (err, rslt) { 58 | assert(!err, err); 59 | done(); 60 | }); 61 | }; 62 | var del = new DeleteIndex.Builder() 63 | .withIndexName(tmp) 64 | .withCallback(callback) 65 | .build(); 66 | cluster.execute(del); 67 | }); 68 | 69 | it('fetches', function(done) { 70 | var count = 0; 71 | var callback = function(err, resp) { 72 | count++; 73 | if (err && err === 'notfound') { 74 | if (count < fetch_attempts) { 75 | setTimeout(fetchme, fetch_timeout); 76 | } else { 77 | assert(!err, err); 78 | } 79 | } else { 80 | assert(resp); 81 | done(); 82 | } 83 | }; 84 | var fetchme = function() { 85 | var fetch = new FetchIndex.Builder() 86 | .withIndexName(tmp) 87 | .withCallback(callback) 88 | .build(); 89 | cluster.execute(fetch); 90 | }; 91 | fetchme(); 92 | }); 93 | }); 94 | -------------------------------------------------------------------------------- /test/security/security.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | var logger = require('winston'); 22 | 23 | var Ping = require('../../lib/commands/ping'); 24 | var Test = require('../integration/testparams'); 25 | var RiakConnection = require('../../lib/core/riakconnection'); 26 | 27 | function cleanup(conn, done) { 28 | conn.removeAllListeners(); 29 | conn.close(); 30 | done(); 31 | } 32 | 33 | function ping(conn, done) { 34 | var p = new Ping(function () {}); 35 | conn.on('responseReceived', function (c, cmd, mc, pb) { 36 | assert.strictEqual(mc, cmd.getExpectedResponseCode()); 37 | cleanup(c, done); 38 | }); 39 | conn.execute(p); 40 | } 41 | 42 | function setup_events(conn, done) { 43 | conn.on('connectFailed', function (c, err) { 44 | assert(!err, err); 45 | cleanup(c, done); 46 | }); 47 | conn.on('connected', function (c) { 48 | ping(c, done); 49 | }); 50 | } 51 | 52 | describe('security', function() { 53 | describe('connect-tls-clientcert', function() { 54 | it('emits-connected-then-ping', function(done) { 55 | var conn = new RiakConnection({ 56 | remoteAddress : Test.riakHost, 57 | remotePort : Test.riakPort, 58 | auth: Test.certAuth 59 | }); 60 | setup_events(conn, done); 61 | conn.connect(); 62 | }); 63 | }); 64 | 65 | describe('connect-tls-password', function() { 66 | it('emits-connected-then-ping', function(done) { 67 | var conn = new RiakConnection({ 68 | remoteAddress : Test.riakHost, 69 | remotePort : Test.riakPort, 70 | auth: Test.passAuth 71 | }); 72 | setup_events(conn, done); 73 | conn.connect(); 74 | }); 75 | }); 76 | }); 77 | -------------------------------------------------------------------------------- /test/unit/core/authreq.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | var assert = require('assert'); 19 | var AuthReq = require('../../../lib/core/authreq'); 20 | 21 | describe('AuthReq', function() { 22 | it('sets user and password from options', function(done) { 23 | var user = 'user'; 24 | var password = 'password'; 25 | var opts = { 26 | user: user, 27 | password: password 28 | }; 29 | var cb = function (e, r) { }; 30 | var r = new AuthReq(opts, cb); 31 | assert.strictEqual(r.user, user); 32 | assert.strictEqual(r.password, password); 33 | done(); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /test/unit/core/nodemanager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | var assert = require('assert'); 19 | var logging = require('winston'); 20 | var joi = require('joi'); 21 | 22 | var LeastExecutingNodeManager = require('../../../lib/core/leastexecutingnodemanager.js'); 23 | 24 | function getManager(shuffle) { 25 | var m = new LeastExecutingNodeManager(shuffle); 26 | m.tryExecute = function (node, command) { 27 | logging.debug('[LeastExecutingNodeManager-TEST] executing %s on node (%d:%d)', 28 | command.name, node.id, node.executeCount); 29 | node.executed = true; 30 | return true; 31 | }; 32 | return m; 33 | } 34 | 35 | describe('NodeManager', function() { 36 | describe('LeastExecutingNodeManager', function() { 37 | it('sorts by executeCount to choose a node', function(done) { 38 | var n = [ 39 | { executeCount: 3, id: 0 }, 40 | { executeCount: 2, id: 1 }, 41 | { executeCount: 1, id: 2 } 42 | ]; 43 | var m = getManager(false); 44 | assert(m.executeOnNode(n, { name: 'TEST COMMAND' })); 45 | assert(n[2].executed); 46 | assert.equal(n[2].id, 2); 47 | done(); 48 | }); 49 | 50 | it('sorts by executeCount and shuffles to choose a node', function(done) { 51 | var n = [ 52 | { executeCount: 3, id: 0 }, 53 | { executeCount: 2, id: 1 }, 54 | { executeCount: 1, id: 2 }, 55 | { executeCount: 1, id: 3 }, 56 | { executeCount: 1, id: 4 } 57 | ]; 58 | var m = getManager(true); 59 | 60 | for (var k = 0; k < n.length * 10; k++) { 61 | assert(m.executeOnNode(n, { name: 'TEST COMMAND' })); 62 | var found = false; 63 | for (var i = 2; i <= 4; i++) { 64 | if (n[i].executed) { 65 | assert(n[i].id === 2 || n[i].id === 3 || n[i].id === 4); 66 | found = true; 67 | break; 68 | } 69 | } 70 | assert(found); 71 | } 72 | 73 | done(); 74 | }); 75 | }); 76 | }); 77 | -------------------------------------------------------------------------------- /test/unit/core/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var assert = require('assert'); 21 | var logger = require('winston'); 22 | 23 | var utils = require('../../../lib/core/utils'); 24 | 25 | var state = Object.freeze({ 26 | CREATED : 0, 27 | RUNNING : 1, 28 | HEALTH_CHECKING : 2, 29 | SHUTTING_DOWN : 3, 30 | SHUTDOWN : 4 31 | }); 32 | 33 | var stateNames = Object.freeze({ 34 | 0 : 'CREATED', 35 | 1 : 'RUNNING', 36 | 2 : 'HEALTH_CHECKING', 37 | 3 : 'SHUTTING_DOWN', 38 | 4 : 'SHUTDOWN' 39 | }); 40 | 41 | describe('core-utils', function() { 42 | it('state-check-failure', function(done) { 43 | assert.throws( 44 | function () { 45 | utils.stateCheck('FRAZZLE', 46 | state.RUNNING, [state.CREATED, state.SHUTDOWN], stateNames); 47 | }, 48 | function (err) { 49 | logger.debug('[t/u/c/utils] saw err:', err.message); 50 | return err instanceof Error && 51 | /RUNNING/.test(err) && 52 | /CREATED/.test(err) && 53 | /SHUTDOWN/.test(err); 54 | }, 55 | 'unexpected error!' 56 | ); 57 | done(); 58 | }); 59 | }); 60 | -------------------------------------------------------------------------------- /test/unit/crdt/fetchcounter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var FetchCounter = require('../../../lib/commands/crdt/fetchcounter'); 21 | var DtFetchResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('DtFetchResp'); 22 | var DtValue = require('../../../lib/protobuf/riakprotobuf').getProtoFor('DtValue'); 23 | var RpbErrorResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbErrorResp'); 24 | 25 | var assert = require('assert'); 26 | 27 | describe('FetchCounter', function() { 28 | describe('Build', function() { 29 | it('should build a DtFetchReq correctly', function(done) { 30 | var fetch = new FetchCounter.Builder() 31 | .withBucketType('counters') 32 | .withBucket('myBucket') 33 | .withKey('counter_1') 34 | .withCallback(function(){}) 35 | .withR(1) 36 | .withPr(2) 37 | .withNotFoundOk(true) 38 | .withBasicQuorum(true) 39 | .withTimeout(20000) 40 | .build(); 41 | 42 | var protobuf = fetch.constructPbRequest(); 43 | 44 | assert.equal(protobuf.getType().toString('utf8'), 'counters'); 45 | assert.equal(protobuf.getBucket().toString('utf8'), 'myBucket'); 46 | assert.equal(protobuf.getKey().toString('utf8'), 'counter_1'); 47 | assert.equal(protobuf.getR(), 1); 48 | assert.equal(protobuf.getPr(), 2); 49 | assert.equal(protobuf.getNotfoundOk(), true); 50 | assert.equal(protobuf.getBasicQuorum(), true); 51 | assert.equal(protobuf.getTimeout(), 20000); 52 | done(); 53 | }); 54 | 55 | it('should take a DtFetchResp and call the users callback with the response', function(done) { 56 | var dtFetchResp = new DtFetchResp(); 57 | var dtValue = new DtValue(); 58 | dtValue.setCounterValue(42); 59 | dtFetchResp.value = dtValue; 60 | 61 | var callback = function(err, response) { 62 | if (response) { 63 | assert.equal(response.counterValue, 42); 64 | done(); 65 | } 66 | }; 67 | 68 | var fetch = new FetchCounter.Builder() 69 | .withBucketType('counters') 70 | .withBucket('myBucket') 71 | .withKey('counter_1') 72 | .withCallback(callback) 73 | .build(); 74 | 75 | fetch.onSuccess(dtFetchResp); 76 | }); 77 | 78 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 79 | var rpbErrorResp = new RpbErrorResp(); 80 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 81 | 82 | var callback = function(err, response) { 83 | if (err) { 84 | assert.equal(err,'this is an error'); 85 | done(); 86 | } 87 | }; 88 | 89 | var fetch = new FetchCounter.Builder() 90 | .withBucketType('counters') 91 | .withBucket('myBucket') 92 | .withKey('counter_1') 93 | .withCallback(callback) 94 | .build(); 95 | 96 | fetch.onRiakError(rpbErrorResp); 97 | }); 98 | }); 99 | }); 100 | -------------------------------------------------------------------------------- /test/unit/crdt/fetchhll.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var FetchHll = require('../../../lib/commands/crdt/fetchhll'); 21 | var DtFetchResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('DtFetchResp'); 22 | var DtValue = require('../../../lib/protobuf/riakprotobuf').getProtoFor('DtValue'); 23 | var RpbErrorResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbErrorResp'); 24 | 25 | var assert = require('assert'); 26 | 27 | describe('FetchHll', function() { 28 | describe('Build', function() { 29 | it('should build a DtFetchReq correctly', function(done) { 30 | var fetch = new FetchHll.Builder() 31 | .withBucketType('hlls') 32 | .withBucket('myBucket') 33 | .withKey('hll_1') 34 | .withCallback(function(){}) 35 | .withR(1) 36 | .withPr(2) 37 | .withNotFoundOk(true) 38 | .withBasicQuorum(true) 39 | .withTimeout(20000) 40 | .build(); 41 | 42 | var protobuf = fetch.constructPbRequest(); 43 | 44 | assert.equal(protobuf.getType().toString('utf8'), 'hlls'); 45 | assert.equal(protobuf.getBucket().toString('utf8'), 'myBucket'); 46 | assert.equal(protobuf.getKey().toString('utf8'), 'hll_1'); 47 | assert.equal(protobuf.getR(), 1); 48 | assert.equal(protobuf.getPr(), 2); 49 | assert.equal(protobuf.getNotfoundOk(), true); 50 | assert.equal(protobuf.getBasicQuorum(), true); 51 | assert.equal(protobuf.getTimeout(), 20000); 52 | done(); 53 | }); 54 | 55 | it('should take a DtFetchResp and call the users callback with the response', function(done) { 56 | var dtFetchResp = new DtFetchResp(); 57 | var dtValue = new DtValue(); 58 | dtValue.setHllValue(42); 59 | dtFetchResp.value = dtValue; 60 | 61 | var callback = function(err, response) { 62 | if (response) { 63 | assert.equal(response.cardinality, 42); 64 | done(); 65 | } 66 | }; 67 | 68 | var fetch = new FetchHll.Builder() 69 | .withBucketType('hlls') 70 | .withBucket('myBucket') 71 | .withKey('hll_1') 72 | .withCallback(callback) 73 | .build(); 74 | 75 | fetch.onSuccess(dtFetchResp); 76 | }); 77 | 78 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 79 | var rpbErrorResp = new RpbErrorResp(); 80 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 81 | 82 | var callback = function(err, response) { 83 | if (err) { 84 | assert.equal(err,'this is an error'); 85 | done(); 86 | } 87 | }; 88 | 89 | var fetch = new FetchHll.Builder() 90 | .withBucketType('hlls') 91 | .withBucket('myBucket') 92 | .withKey('hll_1') 93 | .withCallback(callback) 94 | .build(); 95 | 96 | fetch.onRiakError(rpbErrorResp); 97 | }); 98 | }); 99 | }); 100 | -------------------------------------------------------------------------------- /test/unit/crdt/updatecounter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var UpdateCounter = require('../../../lib/commands/crdt/updatecounter'); 21 | var DtUpdateResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('DtUpdateResp'); 22 | var DtValue = require('../../../lib/protobuf/riakprotobuf').getProtoFor('DtValue'); 23 | var RpbErrorResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbErrorResp'); 24 | 25 | var assert = require('assert'); 26 | 27 | describe('UpdateCounter', function() { 28 | describe('Build', function() { 29 | it('should build a DtUpdateReq correctly', function(done) { 30 | var update = new UpdateCounter.Builder() 31 | .withBucketType('counters') 32 | .withBucket('myBucket') 33 | .withKey('counter_1') 34 | .withIncrement(100) 35 | .withCallback(function(){}) 36 | .withW(3) 37 | .withPw(1) 38 | .withDw(2) 39 | .withReturnBody(true) 40 | .withTimeout(20000) 41 | .build(); 42 | 43 | var protobuf = update.constructPbRequest(); 44 | 45 | assert.equal(protobuf.getType().toString('utf8'), 'counters'); 46 | assert.equal(protobuf.getBucket().toString('utf8'), 'myBucket'); 47 | assert.equal(protobuf.getKey().toString('utf8'), 'counter_1'); 48 | assert.equal(protobuf.getW(), 3); 49 | assert.equal(protobuf.getPw(), 1); 50 | assert.equal(protobuf.getDw(), 2); 51 | assert.equal(protobuf.getReturnBody(), true); 52 | assert.equal(protobuf.op.counter_op.increment, 100); 53 | assert.equal(protobuf.getTimeout(), 20000); 54 | done(); 55 | }); 56 | 57 | it('should take a DtUpdateResp and call the users callback with the response', function(done) { 58 | var dtUpdateResp = new DtUpdateResp(); 59 | dtUpdateResp.setCounterValue(42); 60 | dtUpdateResp.setKey(new Buffer('NewGeneratedKey')); 61 | 62 | var callback = function(err, response) { 63 | if (response) { 64 | assert.equal(response.counterValue, 42); 65 | assert.equal(response.generatedKey, 'NewGeneratedKey'); 66 | done(); 67 | } 68 | }; 69 | 70 | var update = new UpdateCounter.Builder() 71 | .withBucketType('counters') 72 | .withBucket('myBucket') 73 | .withKey('counter_1') 74 | .withIncrement(100) 75 | .withCallback(callback) 76 | .build(); 77 | update.onSuccess(dtUpdateResp); 78 | }); 79 | 80 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 81 | var rpbErrorResp = new RpbErrorResp(); 82 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 83 | 84 | var callback = function(err, response) { 85 | if (err) { 86 | assert.equal(err,'this is an error'); 87 | done(); 88 | } 89 | }; 90 | 91 | var update = new UpdateCounter.Builder() 92 | .withBucketType('counters') 93 | .withBucket('myBucket') 94 | .withKey('counter_1') 95 | .withIncrement(100) 96 | .withCallback(callback) 97 | .build(); 98 | 99 | update.onRiakError(rpbErrorResp); 100 | }); 101 | }); 102 | }); 103 | -------------------------------------------------------------------------------- /test/unit/joi.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var Joi = require('joi'); 21 | var assert = require('assert'); 22 | 23 | describe('Joi', function() { 24 | it('returns object being validated on success', function(done) { 25 | var cb = function (err, rslt) { }; 26 | var schema = Joi.func().required(); 27 | var self = this; 28 | Joi.validate(cb, schema, function(err, value) { 29 | if (err) { 30 | throw new Error('callback is required and must be a function.'); 31 | } 32 | assert.strictEqual(value, cb); 33 | done(); 34 | }); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /test/unit/kv/deletevalue.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var rpb = require('../../../lib/protobuf/riakprotobuf'); 21 | var DeleteValue = require('../../../lib/commands/kv/deletevalue'); 22 | var RpbDelResp = rpb.getProtoFor('RpbDelResp'); 23 | var RpbErrorResp = rpb.getProtoFor('RpbErrorResp'); 24 | 25 | var assert = require('assert'); 26 | var crypto = require('crypto'); 27 | 28 | describe('DeleteValue', function() { 29 | describe('Build', function() { 30 | it('should build a RpbDelReq correctly', function(done) { 31 | var deleteValue = new DeleteValue.Builder() 32 | .withBucketType('bucket_type') 33 | .withBucket('bucket_name') 34 | .withKey('key') 35 | .withR(1) 36 | .withPr(2) 37 | .withW(3) 38 | .withPw(4) 39 | .withDw(5) 40 | .withRw(6) 41 | .withVClock(new Buffer('1234')) 42 | .withTimeout(20000) 43 | .withCallback(function(){}) 44 | .build(); 45 | 46 | var protobuf = deleteValue.constructPbRequest(); 47 | 48 | assert.equal(protobuf.getType().toString('utf8'), 'bucket_type'); 49 | assert.equal(protobuf.getBucket().toString('utf8'), 'bucket_name'); 50 | assert.equal(protobuf.getKey().toString('utf8'), 'key'); 51 | assert.equal(protobuf.getR(), 1); 52 | assert.equal(protobuf.getPr(), 2); 53 | assert.equal(protobuf.getW(), 3); 54 | assert.equal(protobuf.getPw(), 4); 55 | assert.equal(protobuf.getDw(), 5); 56 | assert.equal(protobuf.getRw(), 6); 57 | assert(protobuf.getVclock().toString('utf8'), '1234'); 58 | assert.equal(protobuf.getTimeout(), 20000); 59 | done(); 60 | }); 61 | 62 | it('should build a RpbDelReq correctly with a binary key', function(done) { 63 | var binaryKey = crypto.randomBytes(128); 64 | var deleteValue = new DeleteValue.Builder() 65 | .withBucketType('bucket_type') 66 | .withBucket('bucket_name') 67 | .withKey(binaryKey) 68 | .withCallback(function(){}) 69 | .build(); 70 | var protobuf = deleteValue.constructPbRequest(); 71 | var keyBuf = protobuf.getKey().toBuffer(); 72 | assert(binaryKey.equals(keyBuf)); 73 | done(); 74 | }); 75 | 76 | it('should take a RpbDelResp and call the users callback with the response', function(done) { 77 | // Riak doesn't actually return a RpbDelResp message - just the code. The core 78 | // will send null to the command onSuccess and the response sent to the user 79 | // is simply a boolean true. 80 | var callback = function(err, resp) { 81 | assert(resp === true); 82 | done(); 83 | }; 84 | 85 | var deleteValue = new DeleteValue.Builder() 86 | .withBucketType('bucket_type') 87 | .withBucket('bucket_name') 88 | .withKey('key') 89 | .withCallback(callback) 90 | .build(); 91 | 92 | deleteValue.onSuccess(null); 93 | }); 94 | 95 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 96 | var rpbErrorResp = new RpbErrorResp(); 97 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 98 | 99 | var callback = function(err, response) { 100 | if (err) { 101 | assert.equal(err,'this is an error'); 102 | done(); 103 | } 104 | }; 105 | 106 | var deleteValue = new DeleteValue.Builder() 107 | .withBucketType('bucket_type') 108 | .withBucket('bucket_name') 109 | .withKey('key') 110 | .withCallback(callback) 111 | .build(); 112 | 113 | deleteValue.onRiakError(rpbErrorResp); 114 | }); 115 | }); 116 | }); 117 | -------------------------------------------------------------------------------- /test/unit/kv/riakobject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var rpb = require('../../../lib/protobuf/riakprotobuf'); 21 | var RiakObject = require('../../../lib/commands/kv/riakobject'); 22 | var RpbContent = rpb.getProtoFor('RpbContent'); 23 | 24 | var assert = require('assert'); 25 | 26 | describe('RiakObject', function() { 27 | it('should build correctly when convertToJs is true and isTombstone is true', function(done) { 28 | var value = 'this is a value'; 29 | 30 | var rpbContent = new RpbContent(); 31 | rpbContent.setValue(new Buffer(value)); 32 | rpbContent.setDeleted(true); 33 | 34 | var ro = RiakObject.createFromRpbContent(rpbContent, true); 35 | assert(ro.isTombstone); 36 | assert(JSON.stringify(ro.value) === '{}'); 37 | done(); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /test/unit/mapreduce/mapreduce.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var MapReduce = require('../../../lib/commands/mapreduce/mapreduce'); 21 | var RpbErrorResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbErrorResp'); 22 | var RpbMapRedResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbMapRedResp'); 23 | 24 | var assert = require('assert'); 25 | 26 | describe('MapReduce', function() { 27 | describe('Build', function() { 28 | it('should build a RpbMapRedReq correctly', function(done) { 29 | 30 | var query = '{"inputs":"goog","query":[{"map":{"language":"javascript",' + 31 | '"source":"function(value, keyData, arg) { ' + 32 | 'var data = Riak.mapValuesJson(value)[0]; if(data.High ' + 33 | '&& parseFloat(data.High) > 600.00) return [value.key];' + 34 | 'else return [];}","keep":true}}]}'; 35 | 36 | var mr = new MapReduce(query, function(){}); 37 | 38 | var protobuf = mr.constructPbRequest(); 39 | 40 | assert.equal(protobuf.getRequest().toString('utf8'), query); 41 | assert.equal(protobuf.getContentType().toString('utf8'), 'application/json'); 42 | done(); 43 | 44 | }); 45 | 46 | it('should take a RpbMapRedResp and call the users callback with the response', function(done) { 47 | 48 | var resp = new RpbMapRedResp(); 49 | resp.phase = 1; 50 | // Riak returns JSON 51 | resp.response = new Buffer('[{ "the": 8}]'); 52 | resp.done = true; 53 | 54 | var callback = function(err, resp) { 55 | assert(resp.phase_1); 56 | // returned JSON is parsed and returned as JS 57 | assert.equal(resp.phase_1.constructor, Array); 58 | assert.equal(resp.phase_1.length, 1); 59 | assert.equal(resp.phase_1[0].the, 8); 60 | assert.equal(resp.done, true); 61 | done(); 62 | }; 63 | 64 | var mr = new MapReduce('some query', callback, false); 65 | mr.onSuccess(resp); 66 | 67 | 68 | }); 69 | 70 | it('should take a RpbMapRedResp and stream the response', function(done) { 71 | 72 | var resp = new RpbMapRedResp(); 73 | resp.phase = 1; 74 | // Riak returns JSON 75 | resp.response = new Buffer('[{ "the": 8}]'); 76 | resp.done = true; 77 | 78 | var callback = function(err, resp) { 79 | assert.equal(resp.phase, 1); 80 | // returned JSON is parsed and returned as JS 81 | assert.equal(resp.response.constructor, Array); 82 | assert.equal(resp.response.length, 1); 83 | assert.equal(resp.response[0].the, 8); 84 | assert.equal(resp.done, true); 85 | done(); 86 | }; 87 | 88 | var mr = new MapReduce('some query', callback); 89 | mr.onSuccess(resp); 90 | 91 | 92 | }); 93 | 94 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 95 | var rpbErrorResp = new RpbErrorResp(); 96 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 97 | 98 | var callback = function(err, response) { 99 | if (err) { 100 | assert.equal(err,'this is an error'); 101 | done(); 102 | } 103 | }; 104 | 105 | var mr = new MapReduce('some query', callback); 106 | mr.onRiakError(rpbErrorResp); 107 | }); 108 | 109 | }); 110 | }); 111 | -------------------------------------------------------------------------------- /test/unit/protobuf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var rpb = require('../../lib/protobuf/riakprotobuf'); 21 | var TsCell = rpb.getProtoFor('TsCell'); 22 | 23 | var assert = require('assert'); 24 | 25 | describe('Protobuf', function() { 26 | it('uses null to mean "value not set"', function(done) { 27 | var tsc = new TsCell(); 28 | assert.strictEqual(tsc.getVarcharValue(), null); 29 | assert.strictEqual(tsc.getSint64Value(), null); 30 | assert.strictEqual(tsc.getTimestampValue(), null); 31 | assert.strictEqual(tsc.getBooleanValue(), null); 32 | assert.strictEqual(tsc.getDoubleValue(), null); 33 | done(); 34 | }); 35 | }); 36 | 37 | -------------------------------------------------------------------------------- /test/unit/ts/delete.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var d = require('./data'); 21 | var TS = require('../../../lib/commands/ts'); 22 | 23 | var rpb = require('../../../lib/protobuf/riakprotobuf'); 24 | var RpbErrorResp = rpb.getProtoFor('RpbErrorResp'); 25 | 26 | var assert = require('assert'); 27 | if (!assert.deepStrictEqual) { 28 | assert.deepStrictEqual = assert.deepEqual; 29 | } 30 | 31 | var logger = require('winston'); 32 | var Long = require('long'); 33 | 34 | var table = 'test-table'; 35 | var key = [ 'foo', 'bar', 'baz' ]; 36 | 37 | describe('Delete', function() { 38 | describe('Build', function() { 39 | it('should build a TsDelReq correctly', function(done) { 40 | var cmd = new TS.Delete.Builder() 41 | .withTable(table) 42 | .withKey(key) 43 | .withCallback(function(){}) 44 | .build(); 45 | var protobuf = cmd.constructPbRequest(); 46 | assert.strictEqual(protobuf.getTable().toString('utf8'), table); 47 | 48 | var tscells = protobuf.getKey(); 49 | for (var i = 0; i < key.length; i++) { 50 | var tsc = tscells[i]; 51 | assert.strictEqual(tsc.varchar_value.toString('utf8'), key[i]); 52 | } 53 | 54 | done(); 55 | }); 56 | 57 | it('should take a TsDelResp and call the users callback with the response', function(done) { 58 | var cb = function(err, response) { 59 | assert(!err, err); 60 | assert(response); 61 | done(); 62 | }; 63 | var cmd = new TS.Delete.Builder() 64 | .withTable(table) 65 | .withKey(key) 66 | .withCallback(cb) 67 | .build(); 68 | cmd.onSuccess(d.tsDeleteResp); 69 | }); 70 | 71 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 72 | var rpbErrorResp = new RpbErrorResp(); 73 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 74 | var cb = function(err, response) { 75 | assert(err, !err); 76 | assert.strictEqual(err, 'this is an error'); 77 | done(); 78 | }; 79 | var cmd = new TS.Delete.Builder() 80 | .withTable(table) 81 | .withKey(key) 82 | .withCallback(cb) 83 | .build(); 84 | cmd.onRiakError(rpbErrorResp); 85 | }); 86 | }); 87 | }); 88 | -------------------------------------------------------------------------------- /test/unit/ts/get.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var d = require('./data'); 21 | var TS = require('../../../lib/commands/ts'); 22 | 23 | var rpb = require('../../../lib/protobuf/riakprotobuf'); 24 | var RpbErrorResp = rpb.getProtoFor('RpbErrorResp'); 25 | 26 | var assert = require('assert'); 27 | if (!assert.deepStrictEqual) { 28 | assert.deepStrictEqual = assert.deepEqual; 29 | } 30 | 31 | var logger = require('winston'); 32 | var Long = require('long'); 33 | 34 | var table = 'test-table'; 35 | var key = [ 'foo', 'bar', 'baz' ]; 36 | 37 | describe('Get', function() { 38 | describe('Build', function() { 39 | it('should build a TsGetReq correctly', function(done) { 40 | var cmd = new TS.Get.Builder() 41 | .withTable(table) 42 | .withKey(key) 43 | .withCallback(function(){}) 44 | .build(); 45 | var protobuf = cmd.constructPbRequest(); 46 | assert.strictEqual(protobuf.getTable().toString('utf8'), table); 47 | 48 | var tscells = protobuf.getKey(); 49 | for (var i = 0; i < key.length; i++) { 50 | var tsc = tscells[i]; 51 | assert.strictEqual(tsc.varchar_value.toString('utf8'), key[i]); 52 | } 53 | 54 | done(); 55 | }); 56 | 57 | it('should take a TsGetResp and call the users callback with the response', function(done) { 58 | var cb = function(err, response) { 59 | assert(!err, err); 60 | d.validateResponse(response, d.tsGetResp); 61 | done(); 62 | }; 63 | var cmd = new TS.Get.Builder() 64 | .withTable(table) 65 | .withKey(key) 66 | .withCallback(cb) 67 | .build(); 68 | cmd.onSuccess(d.tsGetResp); 69 | }); 70 | 71 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 72 | var rpbErrorResp = new RpbErrorResp(); 73 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 74 | rpbErrorResp.setErrcode(11); 75 | var cb = function(err, response, errdata) { 76 | assert(err, !err); 77 | assert(!response); 78 | assert(errdata, !errdata); 79 | assert.strictEqual(errdata.msg, 'this is an error'); 80 | assert.strictEqual(errdata.code, 11); 81 | done(); 82 | }; 83 | var cmd = new TS.Get.Builder() 84 | .withTable(table) 85 | .withKey(key) 86 | .withCallback(cb) 87 | .build(); 88 | cmd.onRiakError(rpbErrorResp); 89 | }); 90 | }); 91 | }); 92 | -------------------------------------------------------------------------------- /test/unit/ts/query.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var d = require('./data'); 21 | var TS = require('../../../lib/commands/ts'); 22 | 23 | var rpb = require('../../../lib/protobuf/riakprotobuf'); 24 | var RpbErrorResp = rpb.getProtoFor('RpbErrorResp'); 25 | 26 | var assert = require('assert'); 27 | if (!assert.deepStrictEqual) { 28 | assert.deepStrictEqual = assert.deepEqual; 29 | } 30 | 31 | var logger = require('winston'); 32 | var Long = require('long'); 33 | 34 | var queryText = 'select * from foo where baz = "bat"'; 35 | 36 | describe('Query', function() { 37 | describe('Build', function() { 38 | it('should build a TsQueryReq correctly', function(done) { 39 | var queryCommand = new TS.Query.Builder() 40 | .withQuery(queryText) 41 | .withCallback(function(){}) 42 | .build(); 43 | var protobuf = queryCommand.constructPbRequest(); 44 | 45 | var tsi = protobuf.getQuery(); 46 | assert(tsi, 'expected Tsinterpolation'); 47 | 48 | var base = tsi.getBase().toString('utf8'); 49 | assert.strictEqual(base, queryText); 50 | 51 | var i = tsi.getInterpolations(); 52 | assert(Array.isArray(i)); 53 | assert.strictEqual(i.length, 0); 54 | 55 | done(); 56 | }); 57 | 58 | it('should take a TsQueryResp and call the users callback with the response', function(done) { 59 | var cb = function(err, response) { 60 | assert(!err, err); 61 | d.validateResponse(response, d.tsQueryResp); 62 | done(); 63 | }; 64 | var queryCommand = new TS.Query.Builder() 65 | .withQuery(queryText) 66 | .withCallback(cb) 67 | .build(); 68 | queryCommand.onSuccess(d.tsQueryResp); 69 | }); 70 | 71 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 72 | var rpbErrorResp = new RpbErrorResp(); 73 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 74 | 75 | var cb = function(err, response) { 76 | assert(err, !err); 77 | assert.strictEqual(err, 'this is an error'); 78 | done(); 79 | }; 80 | 81 | var queryCommand = new TS.Query.Builder() 82 | .withQuery(queryText) 83 | .withCallback(cb) 84 | .build(); 85 | 86 | queryCommand.onRiakError(rpbErrorResp); 87 | }); 88 | }); 89 | }); 90 | -------------------------------------------------------------------------------- /test/unit/yokozuna/deleteindex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var DeleteIndex = require('../../../lib/commands/yokozuna/deleteindex'); 21 | var RpbErrorResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbErrorResp'); 22 | 23 | var assert = require('assert'); 24 | 25 | describe('DeleteIndex', function() { 26 | describe('Build', function() { 27 | it('should build a RpbYokozunaIndexDeleteReq correctly', function(done) { 28 | 29 | var del = new DeleteIndex.Builder() 30 | .withIndexName('indexName') 31 | .withCallback(function(){}) 32 | .build(); 33 | 34 | var protobuf = del.constructPbRequest(); 35 | 36 | assert.equal(protobuf.getName().toString('utf8'), 'indexName'); 37 | done(); 38 | 39 | }); 40 | 41 | it('should take a RpbDelResp and call the users callback with the response', function(done) { 42 | 43 | 44 | var callback = function(err, response) { 45 | 46 | assert.equal(response, true); 47 | done(); 48 | }; 49 | 50 | var del = new DeleteIndex.Builder() 51 | .withIndexName('indexName') 52 | .withCallback(callback) 53 | .build(); 54 | 55 | // a RpbDelResp is a null message (no body) from riak 56 | del.onSuccess(null); 57 | 58 | }); 59 | 60 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 61 | var rpbErrorResp = new RpbErrorResp(); 62 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 63 | 64 | var callback = function(err, response) { 65 | if (err) { 66 | assert.equal(err,'this is an error'); 67 | done(); 68 | } 69 | }; 70 | 71 | var del = new DeleteIndex.Builder() 72 | .withIndexName('indexName') 73 | .withCallback(callback) 74 | .build(); 75 | 76 | del.onRiakError(rpbErrorResp); 77 | 78 | }); 79 | 80 | 81 | 82 | }); 83 | }); 84 | -------------------------------------------------------------------------------- /test/unit/yokozuna/fetchindex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var FetchIndex = require('../../../lib/commands/yokozuna/fetchindex'); 21 | var RpbYokozunaIndexGetResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbYokozunaIndexGetResp'); 22 | var RpbYokozunaIndex = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbYokozunaIndex'); 23 | var RpbErrorResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbErrorResp'); 24 | 25 | var assert = require('assert'); 26 | 27 | describe('FetchIndex', function() { 28 | describe('Build', function() { 29 | it('should build a RpbYokozunaIndexGetReq correctly', function(done) { 30 | 31 | var fetch = new FetchIndex.Builder() 32 | .withIndexName('indexName') 33 | .withCallback(function(){}) 34 | .build(); 35 | 36 | var protobuf = fetch.constructPbRequest(); 37 | 38 | assert.equal(protobuf.getName().toString('utf8'), 'indexName'); 39 | done(); 40 | 41 | }); 42 | 43 | it('should take a RpbYokozunaIndexGetResp and call the users callback with the response', function(done) { 44 | 45 | var resp = new RpbYokozunaIndexGetResp(); 46 | 47 | for (var i =0; i < 3; i++) { 48 | var index = new RpbYokozunaIndex(); 49 | 50 | index.name = new Buffer('myIndex_' + i); 51 | index.schema = new Buffer('mySchema_' + i); 52 | index.n_val = i; 53 | 54 | resp.index.push(index); 55 | } 56 | 57 | var callback = function(err, response) { 58 | 59 | assert.equal(response.length, 3); 60 | assert.equal(response[1].indexName, 'myIndex_1'); 61 | assert.equal(response[1].schemaName, 'mySchema_1'); 62 | assert.equal(response[1].nVal, 1); 63 | done(); 64 | }; 65 | 66 | var fetch = new FetchIndex.Builder() 67 | .withIndexName('indexName') 68 | .withCallback(callback) 69 | .build(); 70 | 71 | fetch.onSuccess(resp); 72 | 73 | }); 74 | 75 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 76 | var rpbErrorResp = new RpbErrorResp(); 77 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 78 | 79 | var callback = function(err, response) { 80 | if (err) { 81 | assert.equal(err,'this is an error'); 82 | done(); 83 | } 84 | }; 85 | 86 | var fetch = new FetchIndex.Builder() 87 | .withIndexName('indexName') 88 | .withCallback(callback) 89 | .build(); 90 | 91 | fetch.onRiakError(rpbErrorResp); 92 | 93 | }); 94 | 95 | }); 96 | }); 97 | -------------------------------------------------------------------------------- /test/unit/yokozuna/fetchschema.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var FetchSchema = require('../../../lib/commands/yokozuna/fetchschema'); 21 | var RpbYokozunaSchemaGetResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbYokozunaSchemaGetResp'); 22 | var RpbYokozunaSchema = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbYokozunaSchema'); 23 | var RpbErrorResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbErrorResp'); 24 | var assert = require('assert'); 25 | 26 | describe('FetchSchema', function() { 27 | describe('Build', function() { 28 | it('should build a RpbYokozunaSchemaGetReq correctly', function(done) { 29 | 30 | var fetch = new FetchSchema.Builder() 31 | .withSchemaName('schema_name') 32 | .withCallback(function(){}) 33 | .build(); 34 | 35 | var protobuf = fetch.constructPbRequest(); 36 | 37 | assert.equal(protobuf.name.toString('utf8'), 'schema_name'); 38 | done(); 39 | }); 40 | 41 | it('should take a RpbYokozunaSchemaGetResp and call the users callback with the response', function(done) { 42 | 43 | var resp = new RpbYokozunaSchemaGetResp(); 44 | var schema = new RpbYokozunaSchema(); 45 | schema.name = new Buffer('mySchemaName'); 46 | schema.content = new Buffer('some XML'); 47 | resp.schema = schema; 48 | 49 | var callback = function(err, response) { 50 | 51 | assert.equal(response.name, 'mySchemaName'); 52 | assert.equal(response.content, 'some XML'); 53 | done(); 54 | }; 55 | 56 | var fetch = new FetchSchema.Builder() 57 | .withSchemaName('schema_name') 58 | .withCallback(callback) 59 | .build(); 60 | 61 | fetch.onSuccess(resp); 62 | 63 | }); 64 | 65 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 66 | var rpbErrorResp = new RpbErrorResp(); 67 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 68 | 69 | var callback = function(err, response) { 70 | if (err) { 71 | assert.equal(err,'this is an error'); 72 | done(); 73 | } 74 | }; 75 | 76 | var fetch = new FetchSchema.Builder() 77 | .withSchemaName('schema_name') 78 | .withCallback(callback) 79 | .build(); 80 | 81 | fetch.onRiakError(rpbErrorResp); 82 | 83 | 84 | }); 85 | }); 86 | }); 87 | -------------------------------------------------------------------------------- /test/unit/yokozuna/storeindex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var StoreIndex = require('../../../lib/commands/yokozuna/storeindex'); 21 | var RpbYokozunaIndex = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbYokozunaIndex'); 22 | var RpbErrorResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbErrorResp'); 23 | 24 | var assert = require('assert'); 25 | 26 | describe('StoreIndex', function() { 27 | describe('Build', function() { 28 | it('should build a RpbYokozunaIndexPutReq correctly', function(done) { 29 | 30 | var store = new StoreIndex.Builder() 31 | .withIndexName('indexName') 32 | .withSchemaName('schemaName') 33 | .withNVal(5) 34 | .withTimeout(60000) 35 | .withCallback(function(){}) 36 | .build(); 37 | 38 | var protobuf = store.constructPbRequest(); 39 | assert.equal(protobuf.getTimeout(), 60000); 40 | 41 | var index = protobuf.index; 42 | assert.equal(index.getName().toString('utf8'), 'indexName'); 43 | assert.equal(index.getSchema().toString('utf8'), 'schemaName'); 44 | assert.equal(index.getNVal(), 5); 45 | done(); 46 | }); 47 | 48 | it('should only require name and callback', function(done) { 49 | 50 | assert.throws(function () { 51 | new StoreIndex.Builder().build(); 52 | }); 53 | 54 | assert.throws(function () { 55 | new StoreIndex.Builder() 56 | .withIndexName('indexName') 57 | .build(); 58 | }); 59 | 60 | assert.throws(function () { 61 | new StoreIndex.Builder() 62 | .withCallback(function () {}) 63 | .build(); 64 | }); 65 | 66 | assert.doesNotThrow(function () { 67 | new StoreIndex.Builder() 68 | .withIndexName('indexName') 69 | .withCallback(function () {}) 70 | .build(); 71 | }); 72 | 73 | done(); 74 | }); 75 | }); 76 | 77 | it('should take a RpbPutResp and call the users callback with the response', function(done) { 78 | 79 | var callback = function(err, response) { 80 | assert.equal(response, true); 81 | done(); 82 | }; 83 | 84 | var store = new StoreIndex.Builder() 85 | .withIndexName('indexName') 86 | .withCallback(callback) 87 | .build(); 88 | 89 | // the RpbPutResp is a null message (no body) from riak 90 | store.onSuccess(null); 91 | 92 | }); 93 | 94 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 95 | var rpbErrorResp = new RpbErrorResp(); 96 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 97 | 98 | var callback = function(err, response) { 99 | if (err) { 100 | assert.equal(err,'this is an error'); 101 | done(); 102 | } 103 | }; 104 | 105 | var store = new StoreIndex.Builder() 106 | .withIndexName('indexName') 107 | .withCallback(callback) 108 | .build(); 109 | 110 | store.onRiakError(rpbErrorResp); 111 | 112 | }); 113 | 114 | }); 115 | -------------------------------------------------------------------------------- /test/unit/yokozuna/storeschema.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | var StoreSchema = require('../../../lib/commands/yokozuna/storeschema'); 21 | var RpbYokozunaIndex = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbYokozunaIndex'); 22 | var RpbErrorResp = require('../../../lib/protobuf/riakprotobuf').getProtoFor('RpbErrorResp'); 23 | 24 | var assert = require('assert'); 25 | 26 | describe('StoreSchema', function() { 27 | describe('Build', function() { 28 | it('should build a RpbYokozunaSchemaPutReq correctly', function(done) { 29 | 30 | var store = new StoreSchema.Builder() 31 | .withSchemaName('schemaName') 32 | .withSchema('some XML') 33 | .withCallback(function(){}) 34 | .build(); 35 | 36 | var protobuf = store.constructPbRequest(); 37 | var schema = protobuf.schema; 38 | assert.equal(schema.getName().toString('utf8'), 'schemaName'); 39 | assert.equal(schema.getContent().toString('utf8'), 'some XML'); 40 | done(); 41 | }); 42 | 43 | it('should take a RpbPutResp and call the users callback with the response', function(done) { 44 | 45 | 46 | var callback = function(err, response) { 47 | 48 | assert.equal(response, true); 49 | done(); 50 | }; 51 | 52 | var store = new StoreSchema.Builder() 53 | .withSchemaName('schemaName') 54 | .withSchema('some XML') 55 | .withCallback(callback) 56 | .build(); 57 | 58 | // the RpbPutResp is a null message (no body) from riak 59 | store.onSuccess(null); 60 | 61 | }); 62 | 63 | it ('should take a RpbErrorResp and call the users callback with the error message', function(done) { 64 | var rpbErrorResp = new RpbErrorResp(); 65 | rpbErrorResp.setErrmsg(new Buffer('this is an error')); 66 | 67 | var callback = function(err, response) { 68 | if (err) { 69 | assert.equal(err,'this is an error'); 70 | done(); 71 | } 72 | }; 73 | 74 | var store = new StoreSchema.Builder() 75 | .withSchemaName('schemaName') 76 | .withSchema('some XML') 77 | .withCallback(callback) 78 | .build(); 79 | 80 | store.onRiakError(rpbErrorResp); 81 | 82 | }); 83 | 84 | }); 85 | }); 86 | -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright 2014-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 | 18 | 'use strict'; 19 | 20 | function includesBuffer(haystack, needle) { 21 | var needleBuf = new Buffer(needle); 22 | var len = haystack.length; 23 | for (var i = 0; i < len; i++) { 24 | if (haystack[i].equals(needleBuf)) return true; 25 | } 26 | 27 | return false; 28 | } 29 | 30 | function includes(haystack, needle) { 31 | var len = haystack.length; 32 | for (var i = 0; i < len; i++) { 33 | if (haystack[i] === needle) return true; 34 | } 35 | 36 | return false; 37 | } 38 | 39 | module.exports.includesBuffer = includesBuffer; 40 | module.exports.includes = includes; 41 | --------------------------------------------------------------------------------