Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

convert numeric const quorum values to strings and vice versa

  • Loading branch information...
commit 882ecfcb8c902f28da7670949c6a097cb6b5290a 1 parent 637cea6
@nlf authored
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
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'
Please sign in to comment.
Something went wrong with that request. Please try again.