Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

convert numeric const quorum values to strings and vice versa #52

Merged
merged 2 commits into from

1 participant

@nlf
Owner

This makes sure the numerical constants are converted to strings like 'quorum', 'default', 'all', and 'one' for values in bucket properties. Also converts string values to their numerical counterparts when calling setBucket

@nlf nlf merged commit 252828d into from
@nlf nlf deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 15, 2014
  1. bump version

    authored
This page is out of date. Refresh to see the latest.
View
5 index.js
@@ -2,6 +2,7 @@ var Stream = require('stream');
var Protobuf = require('protobuf.js');
var riakproto = require('riakproto');
var _merge = require('./lib/merge');
+var quorum = require('./lib/quorum');
var parseResponse = require('./lib/parse-response');
var ConnectionManager = require('./lib/connection-manager');
@@ -147,6 +148,10 @@ RiakPBC.prototype.getBucket = function (params, callback) {
};
RiakPBC.prototype.setBucket = function (params, callback) {
+ if (params.props) {
+ params.props = quorum.convert(params.props);
+ }
+
return this.makeRequest({
type: 'RpbSetBucketReq',
params: params,
View
3  lib/parse-response.js
@@ -1,8 +1,11 @@
+var quorum = require('./quorum');
var textPattern = /^text\/*/;
module.exports = function parseResponse(response) {
var key, contentType;
+ response = quorum.convert(response);
+
for (key in response) {
if (Buffer.isBuffer(response[key])) {
if (key === 'value') {
View
21 lib/quorum.js
@@ -0,0 +1,21 @@
+var quorums = ['pr', 'r', 'w', 'pw', 'dw', 'rw'];
+var quorumMap = {
+ '4294967294': 'one',
+ one: 4294967294,
+ '4294967293': 'quorum',
+ quorum: 4294967293,
+ '4294967292': 'all',
+ all: 4294967292,
+ '4294967291': 'default',
+ default: 4294967291
+};
+
+exports.convert = function (props) {
+ Object.keys(props).forEach(function (key) {
+ if (~quorums.indexOf(key) && quorumMap[props[key]]) {
+ props[key] = quorumMap[props[key]];
+ }
+ });
+
+ return props;
+};
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "riakpbc",
- "version": "1.2.4",
+ "version": "1.2.5",
"description": "RiakPBC is a low-level Riak 1.4 proto buffer client.",
"main": "index.js",
"dependencies": {
View
23 test/client-test.js
@@ -342,6 +342,29 @@ describe('Client test', function () {
});
});
+ it('setBucket converts quorum values', function (done) {
+ var opts = {
+ bucket: 'test',
+ props: {
+ r: 'quorum',
+ w: 'all'
+ }
+ };
+ client.setBucket(opts, function (err, reply) {
+ expect(err).to.not.exist;
+ done();
+ });
+ });
+
+ it('getBucket converts quorum values', function (done) {
+ client.getBucket({ bucket: 'test' }, function (err, reply) {
+ expect(err).to.not.exist;
+ expect(reply.props.r).to.equal('quorum');
+ expect(reply.props.w).to.equal('all');
+ done();
+ });
+ });
+
it('getKeys', function (done) {
client.getKeys({
bucket: 'test'
Something went wrong with that request. Please try again.