From ed6aba47202a3816608500efc62c74669438c87c Mon Sep 17 00:00:00 2001 From: Tiago Peczenyj Date: Fri, 5 Jan 2024 12:10:25 +0100 Subject: [PATCH 1/2] fix issue with old protocol buffer generated code --- lib/Riak/Light/PBC.pm | 735 +++++++++++++++++++----------------------- pbc/generate.pl | 3 +- 2 files changed, 338 insertions(+), 400 deletions(-) diff --git a/lib/Riak/Light/PBC.pm b/lib/Riak/Light/PBC.pm index 10680a3..f586659 100644 --- a/lib/Riak/Light/PBC.pm +++ b/lib/Riak/Light/PBC.pm @@ -1,578 +1,515 @@ -## no critic (RequireUseStrict, RequireUseWarnings) +# Generated by the protocol buffer compiler (protoc-perl) DO NOT EDIT! +# source: /home/weborama.office/tiago/work/perl/Riak-Light/pbc/riak.proto + package Riak::Light::PBC; -## use critic -# ABSTRACT: ProtocolBuffers helper to access the Riak API -## -## This file was generated by Google::ProtocolBuffers (0.08) -## on Fri Feb 28 12:59:39 2014 -## + use strict; use warnings; + use Google::ProtocolBuffers; -{ - unless (RpbIndexReq::IndexQueryType->can('_pb_fields_list')) { +{ + unless ( RpbIndexReq::IndexQueryType->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_enum( 'RpbIndexReq::IndexQueryType', - [ - ['eq', 0], - ['range', 1], + [ [ 'eq', 0 ], + [ 'range', 1 ], ] ); } - - unless (RpbSetClientIdReq->can('_pb_fields_list')) { - Google::ProtocolBuffers->create_message( - 'RpbSetClientIdReq', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'client_id', 1, undef - ], - ], - { 'create_accessors' => 1, } - ); - } - - unless (RpbPutReq->can('_pb_fields_list')) { + unless ( RpbContent->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbPutReq', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'bucket', 1, undef + 'RpbContent', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'value', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'key', 2, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'content_type', 2, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'vclock', 3, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'charset', 3, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - 'RpbContent', - 'content', 4, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'content_encoding', 4, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'w', 5, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'vtag', 5, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'dw', 6, undef + [ Google::ProtocolBuffers::Constants::LABEL_REPEATED(), + 'RpbLink', + 'links', 6, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'return_body', 7, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'last_mod', 7, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'pw', 8, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'last_mod_usecs', 8, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'if_not_modified', 9, undef + [ Google::ProtocolBuffers::Constants::LABEL_REPEATED(), + 'RpbPair', + 'usermeta', 9, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'if_none_match', 10, undef + [ Google::ProtocolBuffers::Constants::LABEL_REPEATED(), + 'RpbPair', + 'indexes', 10, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'return_head', 11, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'deleted', 11, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbGetReq->can('_pb_fields_list')) { + unless ( RpbDelReq->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbGetReq', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'RpbDelReq', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'bucket', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'key', 2, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'r', 3, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'rw', 3, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'pr', 4, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'vclock', 4, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'basic_quorum', 5, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'r', 5, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'notfound_ok', 6, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'w', 6, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'if_modified', 7, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'pr', 7, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'head', 8, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'pw', 8, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'deletedvclock', 9, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'dw', 9, undef ], ], - { 'create_accessors' => 1, } - ); - } + undef, - unless (RpbLink->can('_pb_fields_list')) { - Google::ProtocolBuffers->create_message( - 'RpbLink', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'bucket', 1, undef - ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'key', 2, undef - ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'tag', 3, undef - ], - - ], - { 'create_accessors' => 1, } + { 'create_accessors' => 1, } ); } - unless (RpbGetResp->can('_pb_fields_list')) { + unless ( RpbErrorResp->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbGetResp', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REPEATED(), - 'RpbContent', - 'content', 1, undef - ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'vclock', 2, undef + 'RpbErrorResp', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'errmsg', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'unchanged', 3, undef + [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'errcode', 2, undef ], ], - { 'create_accessors' => 1, } - ); - } - - unless (RpbPair->can('_pb_fields_list')) { - Google::ProtocolBuffers->create_message( - 'RpbPair', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'key', 1, undef - ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'value', 2, undef - ], + undef, - ], - { 'create_accessors' => 1, } + { 'create_accessors' => 1, } ); } - unless (RpbPutResp->can('_pb_fields_list')) { + unless ( RpbGetClientIdResp->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbPutResp', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REPEATED(), - 'RpbContent', - 'contents', 1, undef - ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'vclock', 2, undef - ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'key', 3, undef + 'RpbGetClientIdResp', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'client_id', 1, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbDelReq->can('_pb_fields_list')) { + unless ( RpbGetReq->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbDelReq', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'RpbGetReq', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'bucket', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'key', 2, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'rw', 3, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'r', 3, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'vclock', 4, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'pr', 4, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'r', 5, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'basic_quorum', 5, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'w', 6, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'notfound_ok', 6, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'pr', 7, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'if_modified', 7, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'pw', 8, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'head', 8, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'dw', 9, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'deletedvclock', 9, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbMapRedReq->can('_pb_fields_list')) { + unless ( RpbGetResp->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbMapRedReq', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'request', 1, undef + 'RpbGetResp', + [ [ Google::ProtocolBuffers::Constants::LABEL_REPEATED(), + 'RpbContent', + 'content', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'content_type', 2, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'vclock', 2, undef + ], + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'unchanged', 3, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbIndexReq->can('_pb_fields_list')) { + unless ( RpbIndexReq->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( 'RpbIndexReq', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'bucket', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'index', 2, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - 'RpbIndexReq::IndexQueryType', + [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + 'RpbIndexReq::IndexQueryType', 'qtype', 3, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'key', 4, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'range_min', 5, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'range_max', 6, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), 'return_terms', 7, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), 'stream', 8, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), 'max_results', 9, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), 'continuation', 10, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbGetClientIdResp->can('_pb_fields_list')) { + unless ( RpbIndexResp->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbGetClientIdResp', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'client_id', 1, undef + 'RpbIndexResp', + [ [ Google::ProtocolBuffers::Constants::LABEL_REPEATED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'keys', 1, undef + ], + [ Google::ProtocolBuffers::Constants::LABEL_REPEATED(), + 'RpbPair', + 'results', 2, undef + ], + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'continuation', 3, undef + ], + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'done', 4, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbMapRedResp->can('_pb_fields_list')) { + unless ( RpbLink->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbMapRedResp', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'phase', 1, undef + 'RpbLink', + [ [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'bucket', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'response', 2, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'key', 2, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'done', 3, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'tag', 3, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbIndexResp->can('_pb_fields_list')) { + unless ( RpbListKeysReq->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbIndexResp', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REPEATED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'keys', 1, undef - ], - [ - Google::ProtocolBuffers::Constants::LABEL_REPEATED(), - 'RpbPair', - 'results', 2, undef + 'RpbListKeysReq', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'bucket', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'continuation', 3, undef + + ], + undef, + + { 'create_accessors' => 1, } + ); + } + + unless ( RpbListKeysResp->can('_pb_fields_list') ) { + Google::ProtocolBuffers->create_message( + 'RpbListKeysResp', + [ [ Google::ProtocolBuffers::Constants::LABEL_REPEATED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'keys', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'done', 4, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'done', 2, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbErrorResp->can('_pb_fields_list')) { + unless ( RpbMapRedReq->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbErrorResp', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'errmsg', 1, undef + 'RpbMapRedReq', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'request', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'errcode', 2, undef + [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'content_type', 2, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbListKeysReq->can('_pb_fields_list')) { + unless ( RpbMapRedResp->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbListKeysReq', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'bucket', 1, undef + 'RpbMapRedResp', + [ [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'phase', 1, undef + ], + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'response', 2, undef + ], + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'done', 3, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbListKeysResp->can('_pb_fields_list')) { + unless ( RpbPair->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbListKeysResp', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REPEATED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'keys', 1, undef + 'RpbPair', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'key', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'done', 2, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'value', 2, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } - unless (RpbContent->can('_pb_fields_list')) { + unless ( RpbPutReq->can('_pb_fields_list') ) { Google::ProtocolBuffers->create_message( - 'RpbContent', - [ - [ - Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'value', 1, undef + 'RpbPutReq', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'bucket', 1, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'content_type', 2, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'key', 2, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'charset', 3, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'vclock', 3, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'content_encoding', 4, undef + [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + 'RpbContent', + 'content', 4, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BYTES(), - 'vtag', 5, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'w', 5, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REPEATED(), - 'RpbLink', - 'links', 6, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'dw', 6, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'last_mod', 7, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'return_body', 7, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_UINT32(), - 'last_mod_usecs', 8, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_UINT32(), + 'pw', 8, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REPEATED(), - 'RpbPair', - 'usermeta', 9, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'if_not_modified', 9, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_REPEATED(), - 'RpbPair', - 'indexes', 10, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'if_none_match', 10, undef ], - [ - Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), - Google::ProtocolBuffers::Constants::TYPE_BOOL(), - 'deleted', 11, undef + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BOOL(), + 'return_head', 11, undef + ], + + ], + undef, + + { 'create_accessors' => 1, } + ); + } + + unless ( RpbPutResp->can('_pb_fields_list') ) { + Google::ProtocolBuffers->create_message( + 'RpbPutResp', + [ [ Google::ProtocolBuffers::Constants::LABEL_REPEATED(), + 'RpbContent', + 'contents', 1, undef + ], + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'vclock', 2, undef + ], + [ Google::ProtocolBuffers::Constants::LABEL_OPTIONAL(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'key', 3, undef + ], + + ], + undef, + + { 'create_accessors' => 1, } + ); + } + + unless ( RpbSetClientIdReq->can('_pb_fields_list') ) { + Google::ProtocolBuffers->create_message( + 'RpbSetClientIdReq', + [ [ Google::ProtocolBuffers::Constants::LABEL_REQUIRED(), + Google::ProtocolBuffers::Constants::TYPE_BYTES(), + 'client_id', 1, undef ], ], - { 'create_accessors' => 1, } + undef, + + { 'create_accessors' => 1, } ); } diff --git a/pbc/generate.pl b/pbc/generate.pl index 7eeac79..5e86f26 100644 --- a/pbc/generate.pl +++ b/pbc/generate.pl @@ -6,6 +6,7 @@ Google::ProtocolBuffers->parsefile( "$Bin/riak.proto", { generate_code => "$Bin/../lib/Riak/Light/PBC.pm", - create_accessors => 1 + create_accessors => 1, + package_name => 'Riak::Light::PBC', } ); From 54d1d698e5e59cec174006c9e543b1844a3ca16b Mon Sep 17 00:00:00 2001 From: Tiago Peczenyj Date: Fri, 5 Jan 2024 12:10:37 +0100 Subject: [PATCH 2/2] apply perltidy --- benchmarks/compare_all_only_get.pl | 7 +- benchmarks/compare_all_only_put.pl | 9 +- lib/Riak/Light.pm | 567 +++++++++++---------- lib/Riak/Light/Connector.pm | 4 +- lib/Riak/Light/Driver.pm | 4 +- lib/Riak/Light/Timeout/Alarm.pm | 8 +- lib/Riak/Light/Timeout/Select.pm | 6 +- lib/Riak/Light/Timeout/SelectOnRead.pm | 4 +- lib/Riak/Light/Timeout/SetSockOpt.pm | 15 +- lib/Riak/Light/Timeout/TimeOut.pm | 10 +- lib/Riak/Light/Util.pm | 7 +- t/01_load.t | 2 +- t/02_class_test.t | 14 +- t/03_real_riak_test.t | 13 +- t/04_client_tests.t | 672 +++++++++++++------------ t/07_socket_test.t | 22 +- t/08_autodie.t | 25 +- t/12_timeout_setsockopt.t | 4 +- t/15_secondary_indexes.t | 205 +++++--- t/16_map_reduce.t | 98 ++-- t/17_2i_map_reduce.t | 75 +-- t/20_pid_test.t | 18 +- t/21_fix_issue_with_pid.pl | 10 +- t/80_extra_parameters.t | 172 ++++--- t/90_client_id.t | 4 +- t/99_memory_lead.t | 53 +- t/99_no_namespace_autoclean.t | 3 +- t/99_test_util.t | 2 +- t/tlib/TestTimeout.pm | 2 +- 29 files changed, 1088 insertions(+), 947 deletions(-) diff --git a/benchmarks/compare_all_only_get.pl b/benchmarks/compare_all_only_get.pl index 7ad6bbe..31638a6 100644 --- a/benchmarks/compare_all_only_get.pl +++ b/benchmarks/compare_all_only_get.pl @@ -19,9 +19,10 @@ my $http_host = "http://127.0.0.1:8098"; -my $riak_light_client1 = - Riak::Light->new( host => $host_pbc, port => $port_pbc, - timeout_provider => undef ); +my $riak_light_client1 = Riak::Light->new( + host => $host_pbc, port => $port_pbc, + timeout_provider => undef +); $riak_light_client1->put( foo_riak_light1 => key => $hash ); diff --git a/benchmarks/compare_all_only_put.pl b/benchmarks/compare_all_only_put.pl index 8488fc6..71ace1f 100644 --- a/benchmarks/compare_all_only_put.pl +++ b/benchmarks/compare_all_only_put.pl @@ -22,13 +22,14 @@ my ( $host_pbc, $port_pbc ) = split ':', $ENV{RIAK_PBC_HOST}; my $http_host = $ENV{RIAK_REST_HOST}; -my $hash = { baz => 1024, boom => [ 1, 2, 3, 4, 5, 1000, rand(1024) ] }; +my $hash = { baz => 1024, boom => [ 1, 2, 3, 4, 5, 1000, rand(1024) ] }; #clients -my $riak_light_client1 = - Riak::Light->new( host => $host_pbc, port => $port_pbc, - timeout_provider => undef ); +my $riak_light_client1 = Riak::Light->new( + host => $host_pbc, port => $port_pbc, + timeout_provider => undef +); $riak_light_client1->put( foo_riak_light1 => key => $hash ); diff --git a/lib/Riak/Light.pm b/lib/Riak/Light.pm index 1473e98..ceb1b18 100644 --- a/lib/Riak/Light.pm +++ b/lib/Riak/Light.pm @@ -8,7 +8,7 @@ use Riak::Light::Driver; use MIME::Base64 qw(encode_base64); use Type::Params qw(compile); use Types::Standard -types; -use English qw(-no_match_vars ); +use English qw(-no_match_vars ); use Scalar::Util qw(blessed); use IO::Socket; use Socket qw(TCP_NODELAY IPPROTO_TCP); @@ -20,43 +20,45 @@ use Moo; # ABSTRACT: Fast and lightweight Perl client for Riak -has pid => ( is => 'lazy', isa => Int, clearer => 1, predicate => 1 ); -has port => ( is => 'ro', isa => Int, required => 1 ); -has host => ( is => 'ro', isa => Str, required => 1 ); -has r => ( is => 'ro', isa => Int, default => sub {2} ); -has w => ( is => 'ro', isa => Int, default => sub {2} ); -has dw => ( is => 'ro', isa => Int, default => sub {2} ); +has pid => ( is => 'lazy', isa => Int, clearer => 1, predicate => 1 ); +has port => ( is => 'ro', isa => Int, required => 1 ); +has host => ( is => 'ro', isa => Str, required => 1 ); +has r => ( is => 'ro', isa => Int, default => sub {2} ); +has w => ( is => 'ro', isa => Int, default => sub {2} ); +has dw => ( is => 'ro', isa => Int, default => sub {2} ); -has pr => ( is => 'ro', isa => Int, predicate => 1); -has pw => ( is => 'ro', isa => Int, predicate => 1); -has rw => ( is => 'ro', isa => Int, predicate => 1); +has pr => ( is => 'ro', isa => Int, predicate => 1 ); +has pw => ( is => 'ro', isa => Int, predicate => 1 ); +has rw => ( is => 'ro', isa => Int, predicate => 1 ); -has autodie => ( is => 'ro', isa => Bool, default => sub {1}, trigger => 1 ); -has timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); -has tcp_nodelay => ( is => 'ro', isa => Bool, default => sub {1} ); +has autodie => ( is => 'ro', isa => Bool, default => sub {1}, trigger => 1 ); +has timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); +has tcp_nodelay => ( is => 'ro', isa => Bool, default => sub {1} ); has in_timeout => ( is => 'lazy', trigger => 1 ); has out_timeout => ( is => 'lazy', trigger => 1 ); -has client_id => ( is => 'lazy', isa => Str ); - +has client_id => ( is => 'lazy', isa => Str ); + sub _build_pid { - $$ + $$; } sub _build_client_id { - "perl_riak_light" . encode_base64(int(rand(10737411824)), ''); + "perl_riak_light" . encode_base64( int( rand(10737411824) ), '' ); } sub _trigger_autodie { - my ($self, $value) = @_; - carp "autodie will be disable in the next version" unless $value; + my ( $self, $value ) = @_; + carp "autodie will be disable in the next version" unless $value; } sub _trigger_in_timeout { - carp "this feature will be disabled in the next version, you should use just timeout instead"; + carp + "this feature will be disabled in the next version, you should use just timeout instead"; } sub _trigger_out_timeout { - carp "this feature will be disabled in the next version, you should use just timeout instead"; + carp + "this feature will be disabled in the next version, you should use just timeout instead"; } sub _build_in_timeout { @@ -68,8 +70,8 @@ sub _build_out_timeout { } has timeout_provider => ( - is => 'ro', - isa => Maybe [Str], + is => 'ro', + isa => Maybe [Str], default => sub {'Riak::Light::Timeout::Select'} ); @@ -82,7 +84,7 @@ sub _build_driver { sub _build_socket { my ($self) = @_; - $self->pid; # force associate the pid with the current socket + $self->pid; # force associate the pid with the current socket my $host = $self->host; my $port = $self->port; @@ -96,13 +98,13 @@ sub _build_socket { croak "Error ($!), can't connect to $host:$port" unless defined $socket; - if($self->tcp_nodelay){ - $socket->setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) - or croak "Cannot set tcp nodelay $! ($^E)"; + if ( $self->tcp_nodelay ) { + $socket->setsockopt( IPPROTO_TCP, TCP_NODELAY, 1 ) + or croak "Cannot set tcp nodelay $! ($^E)"; } - + return $socket unless defined $self->timeout_provider; - + use Module::Load qw(load); load $self->timeout_provider; @@ -118,34 +120,34 @@ sub BUILD { $_[0]->driver; } -const my $PING => 'ping'; -const my $GET => 'get'; -const my $PUT => 'put'; -const my $DEL => 'del'; -const my $GET_KEYS => 'get_keys'; -const my $QUERY_INDEX => 'query_index'; -const my $MAP_REDUCE => 'map_reduce'; +const my $PING => 'ping'; +const my $GET => 'get'; +const my $PUT => 'put'; +const my $DEL => 'del'; +const my $GET_KEYS => 'get_keys'; +const my $QUERY_INDEX => 'query_index'; +const my $MAP_REDUCE => 'map_reduce'; const my $SET_CLIENT_ID => 'set_client_id'; const my $GET_CLIENT_ID => 'get_client_id'; -const my $ERROR_RESPONSE_CODE => 0; -const my $GET_RESPONSE_CODE => 10; -const my $GET_KEYS_RESPONSE_CODE => 18; -const my $MAP_REDUCE_RESPONSE_CODE => 24; -const my $QUERY_INDEX_RESPONSE_CODE => 26; +const my $ERROR_RESPONSE_CODE => 0; +const my $GET_RESPONSE_CODE => 10; +const my $GET_KEYS_RESPONSE_CODE => 18; +const my $MAP_REDUCE_RESPONSE_CODE => 24; +const my $QUERY_INDEX_RESPONSE_CODE => 26; const my $GET_CLIENT_ID_RESPONSE_CODE => 4; const my $CODES => { - $PING => { request_code => 1, response_code => 2 }, - $GET => { request_code => 9, response_code => 10 }, - $PUT => { request_code => 11, response_code => 12 }, - $DEL => { request_code => 13, response_code => 14 }, - $GET_KEYS => { request_code => 17, response_code => 18 }, - $MAP_REDUCE => { request_code => 23, response_code => 24 }, - $QUERY_INDEX => { request_code => 25, response_code => 26 }, - $GET_CLIENT_ID => { request_code => 3, response_code => 4}, - $SET_CLIENT_ID => { request_code => 5, response_code => 6}, - }; + $PING => { request_code => 1, response_code => 2 }, + $GET => { request_code => 9, response_code => 10 }, + $PUT => { request_code => 11, response_code => 12 }, + $DEL => { request_code => 13, response_code => 14 }, + $GET_KEYS => { request_code => 17, response_code => 18 }, + $MAP_REDUCE => { request_code => 23, response_code => 24 }, + $QUERY_INDEX => { request_code => 25, response_code => 26 }, + $GET_CLIENT_ID => { request_code => 3, response_code => 4 }, + $SET_CLIENT_ID => { request_code => 5, response_code => 6 }, +}; const my $DEFAULT_MAX_RESULTS => 100; @@ -161,7 +163,7 @@ sub is_alive { } sub get_keys { - state $check = compile(Any, Str, Optional[CodeRef]); + state $check = compile( Any, Str, Optional [CodeRef] ); my ( $self, $bucket, $callback ) = $check->(@_); my $body = RpbListKeysReq->encode( { bucket => $bucket } ); @@ -170,90 +172,89 @@ sub get_keys { bucket => $bucket, operation => $GET_KEYS, body => $body, - callback => $callback, + callback => $callback, ); } sub get_raw { - state $check = compile(Any, Str, Str, Optional[Bool]); - my ( $self, $bucket, $key, $return_all) = $check->(@_); + state $check = compile( Any, Str, Str, Optional [Bool] ); + my ( $self, $bucket, $key, $return_all ) = $check->(@_); my $response = $self->_fetch( $bucket, $key, 0 ); - + my $result; - if(defined $response) { - $result = ($return_all)? $response : $response->{value}; + if ( defined $response ) { + $result = ($return_all) ? $response : $response->{value}; } - $result + $result; } sub get_full_raw { - state $check = compile(Any, Str, Str); - my ( $self, $bucket, $key) = $check->(@_); - - $self->get_raw($bucket, $key, 1) + state $check = compile( Any, Str, Str ); + my ( $self, $bucket, $key ) = $check->(@_); + + $self->get_raw( $bucket, $key, 1 ); } sub get { - state $check = compile(Any, Str, Str, Optional[Bool]); - my ( $self, $bucket, $key, $return_all) = $check->(@_); + state $check = compile( Any, Str, Str, Optional [Bool] ); + my ( $self, $bucket, $key, $return_all ) = $check->(@_); my $response = $self->_fetch( $bucket, $key, 1 ); my $result; - if(defined $response) { - $result = ($return_all)? $response : $response->{value}; + if ( defined $response ) { + $result = ($return_all) ? $response : $response->{value}; } - $result + $result; } sub get_full { - state $check = compile(Any, Str, Str); - my ( $self, $bucket, $key) = $check->(@_); + state $check = compile( Any, Str, Str ); + my ( $self, $bucket, $key ) = $check->(@_); - $self->get($bucket, $key, 1) + $self->get( $bucket, $key, 1 ); } sub get_all_indexes { - state $check = compile(Any, Str, Str); + state $check = compile( Any, Str, Str ); my ( $self, $bucket, $key ) = $check->(@_); - my $response = $self->_fetch( $bucket, $key, 0, 1); - - return (! defined $response ) ? [] : [ - map { - +{ value => $_->value, key => $_->key } - } @{ $response->{indexes} // [] } - ]; + my $response = $self->_fetch( $bucket, $key, 0, 1 ); + + return ( !defined $response ) + ? [] + : [ map { +{ value => $_->value, key => $_->key } } + @{ $response->{indexes} // [] } ]; } sub get_index_value { - state $check = compile(Any, Str, Str, Str); + state $check = compile( Any, Str, Str, Str ); my ( $self, $bucket, $key, $index_name ) = $check->(@_); - - $self->get_all_index_values($bucket,$key)->{$index_name}; + + $self->get_all_index_values( $bucket, $key )->{$index_name}; } sub get_all_index_values { - state $check = compile(Any, Str, Str); - my ( $self, $bucket, $key) = $check->(@_); - + state $check = compile( Any, Str, Str ); + my ( $self, $bucket, $key ) = $check->(@_); + my %values; - foreach my $index (@{ $self->get_all_indexes($bucket, $key) }){ - my $key = $index->{key}; - $values{$key} //= []; - push @{ $values{$key} }, $index->{value}; + foreach my $index ( @{ $self->get_all_indexes( $bucket, $key ) } ) { + my $key = $index->{key}; + $values{$key} //= []; + push @{ $values{$key} }, $index->{value}; } - \%values + \%values; } sub get_vclock { - state $check = compile(Any, Str, Str); + state $check = compile( Any, Str, Str ); my ( $self, $bucket, $key ) = $check->(@_); - my $response = $self->_fetch( $bucket, $key, 0, 1); - + my $response = $self->_fetch( $bucket, $key, 0, 1 ); + defined $response and $response->{vclock}; } sub exists { - state $check = compile(Any, Str, Str); + state $check = compile( Any, Str, Str ); my ( $self, $bucket, $key ) = $check->(@_); defined $self->_fetch( $bucket, $key, 0, 1 ); } @@ -283,31 +284,40 @@ sub _fetch { } sub put_raw { - state $check = compile(Any, Str, Str, Any, Optional[Str], Optional[HashRef[Str|ArrayRef[Str]]], Optional[Str]); - my ( $self, $bucket, $key, $value, $content_type, $indexes, $vclock ) = $check->(@_); + state $check = compile( + Any, Str, Str, Any, Optional [Str], + Optional [ HashRef [ Str | ArrayRef [Str] ] ], Optional [Str] + ); + my ( $self, $bucket, $key, $value, $content_type, $indexes, $vclock ) = + $check->(@_); $content_type ||= 'plain/text'; - $self->_store( $bucket, $key, $value, $content_type, $indexes, $vclock); + $self->_store( $bucket, $key, $value, $content_type, $indexes, $vclock ); } sub put { - state $check = compile(Any, Str, Str, Any, Optional[Str], Optional[HashRef[Str|ArrayRef[Str]]], Optional[Str]); - my ( $self, $bucket, $key, $value, $content_type, $indexes, $vclock ) = $check->(@_); + state $check = compile( + Any, Str, Str, Any, Optional [Str], + Optional [ HashRef [ Str | ArrayRef [Str] ] ], Optional [Str] + ); + my ( $self, $bucket, $key, $value, $content_type, $indexes, $vclock ) = + $check->(@_); - ($content_type ||= 'application/json') - eq 'application/json' - and $value = encode_json($value); + ( $content_type ||= 'application/json' ) eq 'application/json' + and $value = encode_json($value); - $self->_store( $bucket, $key, $value, $content_type, $indexes, $vclock); + $self->_store( $bucket, $key, $value, $content_type, $indexes, $vclock ); } sub _store { - my ( $self, $bucket, $key, $encoded_value, $content_type, $indexes, $vclock ) = @_; + my ($self, $bucket, $key, $encoded_value, $content_type, $indexes, + $vclock + ) = @_; my %extra_parameters = (); $extra_parameters{vclock} = $vclock if $vclock; - $extra_parameters{dw} = $self->dw; - $extra_parameters{pw} = $self->pw if $self->has_pw; + $extra_parameters{dw} = $self->dw; + $extra_parameters{pw} = $self->pw if $self->has_pw; my $body = RpbPutReq->encode( { key => $key, @@ -315,17 +325,19 @@ sub _store { content => { value => $encoded_value, content_type => $content_type, - ( $indexes ? - (indexes => [ - map { - my $k = $_; - my $v = $indexes->{$_}; - ref $v eq 'ARRAY' - ? map { { key => $k , value => $_ }; } @$v - : { key => $k , value => $v }; - } keys %$indexes - ]) - : () ), + ( $indexes + ? ( indexes => [ + map { + my $k = $_; + my $v = $indexes->{$_}; + ref $v eq 'ARRAY' + ? map { { key => $k, value => $_ }; } @$v + : { key => $k, value => $v }; + } keys %$indexes + ] + ) + : () + ), }, w => $self->w, %extra_parameters, @@ -341,7 +353,7 @@ sub _store { } sub del { - state $check = compile(Any, Str, Str); + state $check = compile( Any, Str, Str ); my ( $self, $bucket, $key ) = $check->(@_); my %extra_parameters; @@ -369,110 +381,118 @@ sub del { } sub query_index_loop { - state $check = compile(Any, Str, Str, Str|ArrayRef, Optional[HashRef]); - my ( $self, $bucket, $index, $value_to_match, $extra_parameters ) = $check->(@_); + state $check = + compile( Any, Str, Str, Str | ArrayRef, Optional [HashRef] ); + my ( $self, $bucket, $index, $value_to_match, $extra_parameters ) = + $check->(@_); - $extra_parameters //= {}; - $extra_parameters->{max_results} //= $DEFAULT_MAX_RESULTS; - - my @keys; - do { - - my ($temp_keys, $continuation, undef) = $self->query_index($bucket, $index, $value_to_match, $extra_parameters); - - $extra_parameters->{continuation} = $continuation; + $extra_parameters //= {}; + $extra_parameters->{max_results} //= $DEFAULT_MAX_RESULTS; + + my @keys; + do { - push @keys, @{$temp_keys}; + my ( $temp_keys, $continuation, undef ) = $self->query_index( + $bucket, $index, $value_to_match, + $extra_parameters + ); - } while(defined $extra_parameters->{continuation}); + $extra_parameters->{continuation} = $continuation; - return \@keys; + push @keys, @{$temp_keys}; + + } while ( defined $extra_parameters->{continuation} ); + + return \@keys; } sub query_index { - state $check = compile(Any, Str, Str, Str|ArrayRef, Optional[HashRef]); - my ( $self, $bucket, $index, $value_to_match, $extra_parameters ) = $check->(@_); + state $check = + compile( Any, Str, Str, Str | ArrayRef, Optional [HashRef] ); + my ( $self, $bucket, $index, $value_to_match, $extra_parameters ) = + $check->(@_); - my $query_type = 0; # eq - ref $value_to_match - and $query_type = 1; # range + my $query_type = 0; # eq + ref $value_to_match + and $query_type = 1; # range - croak "query index in stream mode not supported" + croak "query index in stream mode not supported" if defined $extra_parameters && $extra_parameters->{stream}; - my $body = RpbIndexReq->encode( - { index => $index, - bucket => $bucket, - qtype => $query_type, - $query_type ? - ( range_min => $value_to_match->[0], - range_max => $value_to_match->[1] ) - : (key => $value_to_match ), - %{$extra_parameters // {}}, - } - ); - - $self->_parse_response( - $query_type ? - (key => "2i query on index='$index' => " . $value_to_match->[0] . '...' . $value_to_match->[1]) - : (key => "2i query on index='$index' => " . $value_to_match ), - bucket => $bucket, - operation => $QUERY_INDEX, - body => $body, - paginate => defined $extra_parameters && exists $extra_parameters->{max_results}, - ); - } - + my $body = RpbIndexReq->encode( + { index => $index, + bucket => $bucket, + qtype => $query_type, + $query_type + ? ( range_min => $value_to_match->[0], + range_max => $value_to_match->[1] + ) + : ( key => $value_to_match ), + %{ $extra_parameters // {} }, + } + ); + + $self->_parse_response( + $query_type + ? ( key => "2i query on index='$index' => " + . $value_to_match->[0] . '...' + . $value_to_match->[1] ) + : ( key => "2i query on index='$index' => " . $value_to_match ), + bucket => $bucket, + operation => $QUERY_INDEX, + body => $body, + paginate => defined $extra_parameters + && exists $extra_parameters->{max_results}, + ); +} + sub map_reduce { - state $check = compile(Any, Any, Optional[CodeRef]); - my ( $self, $request, $callback) = $check->(@_); + state $check = compile( Any, Any, Optional [CodeRef] ); + my ( $self, $request, $callback ) = $check->(@_); - my @args; - - push @args, ref($request) ? encode_json($request): $request; - push @args, 'application/json'; - push @args, $callback if $callback; - - $self->map_reduce_raw(@args); -} + my @args; + + push @args, ref($request) ? encode_json($request) : $request; + push @args, 'application/json'; + push @args, $callback if $callback; + + $self->map_reduce_raw(@args); +} sub map_reduce_raw { - state $check = compile(Any, Str, Str, Optional[CodeRef]); - my ( $self, $request, $content_type, $callback) = $check->(@_); - - my $body = RpbMapRedReq->encode( - { - request => $request, - content_type => $content_type, - } - ); + state $check = compile( Any, Str, Str, Optional [CodeRef] ); + my ( $self, $request, $content_type, $callback ) = $check->(@_); - $self->_parse_response( - key => 'no-key', - bucket => 'no-bucket', - operation => $MAP_REDUCE, - body => $body, - callback => $callback, - decode => ($content_type eq 'application/json'), - ); -} + my $body = RpbMapRedReq->encode( + { request => $request, + content_type => $content_type, + } + ); + + $self->_parse_response( + key => 'no-key', + bucket => 'no-bucket', + operation => $MAP_REDUCE, + body => $body, + callback => $callback, + decode => ( $content_type eq 'application/json' ), + ); +} sub get_client_id { - my $self = shift; + my $self = shift; - $self->_parse_response( - operation => $GET_CLIENT_ID, - body => q(), - ); + $self->_parse_response( + operation => $GET_CLIENT_ID, + body => q(), + ); } sub set_client_id { - state $check = compile(Any, Str); + state $check = compile( Any, Str ); my ( $self, $client_id ) = $check->(@_); - my $body = RpbSetClientIdReq->encode( - { client_id => $client_id } - ); + my $body = RpbSetClientIdReq->encode( { client_id => $client_id } ); $self->_parse_response( operation => $SET_CLIENT_ID, @@ -481,12 +501,12 @@ sub set_client_id { } sub _pid_change { - $_[0]->pid != $$ + $_[0]->pid != $$; } sub _parse_response { my ( $self, %args ) = @_; - + my $operation = $args{operation}; my $request_code = $CODES->{$operation}->{request_code}; @@ -498,14 +518,14 @@ sub _parse_response { my $key = $args{key}; my $callback = $args{callback}; my $paginate = $args{paginate}; - + $self->autodie or undef $@; ## no critic (RequireLocalizedPunctuationVars) if ( $self->_pid_change ) { - $self->clear_pid; - $self->clear_driver; - } + $self->clear_pid; + $self->clear_driver; + } $self->driver->perform_request( code => $request_code, @@ -522,83 +542,94 @@ sub _parse_response { my $response; my @results; while (1) { + # get and check response $response = $self->driver->read_response() // { code => -1, body => undef, error => $ERRNO }; - my ($response_code, $response_body, $response_error) = @{$response}{qw(code body error)}; + my ( $response_code, $response_body, $response_error ) = + @{$response}{qw(code body error)}; # in case of internal error message defined $response_error and return $self->_process_generic_error( - $response_error, $operation, $bucket, - $key + $response_error, $operation, $bucket, + $key ); - + # in case of error msg $response_code == $ERROR_RESPONSE_CODE and return $self->_process_riak_error( - $response_body, $operation, $bucket, - $key + $response_body, $operation, $bucket, + $key ); - + # in case of default message $response_code != $expected_code and return $self->_process_generic_error( - "Unexpected Response Code in (got: $response_code, expected: $expected_code)", - $operation, $bucket, $key + "Unexpected Response Code in (got: $response_code, expected: $expected_code)", + $operation, $bucket, $key ); - + $response_code == $GET_CLIENT_ID_RESPONSE_CODE and return $self->_process_get_client_id_response($response_body); # we have a 'get' response $response_code == $GET_RESPONSE_CODE - and return $self->_process_get_response( $response_body, $bucket, $key, $decode ); + and return $self->_process_get_response( + $response_body, $bucket, $key, + $decode + ); - # we have a 'get_keys' response - # TODO: support for 1.4 (which provides 'stream', 'return_terms', and 'stream') - if ($response_code == $GET_KEYS_RESPONSE_CODE) { - my $obj = RpbListKeysResp->decode( $response_body ); - my @keys = @{$obj->keys // []}; +# we have a 'get_keys' response +# TODO: support for 1.4 (which provides 'stream', 'return_terms', and 'stream') + if ( $response_code == $GET_KEYS_RESPONSE_CODE ) { + my $obj = RpbListKeysResp->decode($response_body); + my @keys = @{ $obj->keys // [] }; if ($callback) { $callback->($_) foreach @keys; $obj->done and return; - } else { + } + else { push @results, @keys; $obj->done and return \@results; } next; - } # in case of a 'query_index' response - elsif ($response_code == $QUERY_INDEX_RESPONSE_CODE) { - my $obj = RpbIndexResp->decode( $response_body ); - + } # in case of a 'query_index' response + elsif ( $response_code == $QUERY_INDEX_RESPONSE_CODE ) { + my $obj = RpbIndexResp->decode($response_body); + my $keys = $obj->keys // []; - if($paginate and wantarray) { - return ($keys, $obj->continuation, $obj->done); - } else { - return $keys; + if ( $paginate and wantarray ) { + return ( $keys, $obj->continuation, $obj->done ); + } + else { + return $keys; } } - elsif ($response_code == $MAP_REDUCE_RESPONSE_CODE) { - my $obj = RpbMapRedResp->decode( $response_body ); - - my $phase = $obj->phase; - my $response = ($decode) ? decode_json($obj->response // '[]') : $obj->response; - - if ($callback){ - $obj->done - and return; - $callback->( $response, $phase); - } else { - $obj->done - and return \@results; - push @results, { phase => $phase, response => $response }; - } - next; + elsif ( $response_code == $MAP_REDUCE_RESPONSE_CODE ) { + my $obj = RpbMapRedResp->decode($response_body); + + my $phase = $obj->phase; + my $response = + ($decode) + ? decode_json( $obj->response // '[]' ) + : $obj->response; + + if ($callback) { + $obj->done + and return; + $callback->( $response, $phase ); + } + else { + $obj->done + and return \@results; + push @results, { phase => $phase, response => $response }; + } + next; } # in case of no return value, signify success @@ -608,13 +639,15 @@ sub _parse_response { } sub _process_get_client_id_response { - my ( $self, $encoded_message ) = @_; + my ( $self, $encoded_message ) = @_; - $self->_process_generic_error( "Undefined Message", 'get client id', '-', '-' ) - unless ( defined $encoded_message ); + $self->_process_generic_error( + "Undefined Message", 'get client id', '-', + '-' + ) unless ( defined $encoded_message ); my $decoded_message = RpbGetClientIdResp->decode($encoded_message); - $decoded_message->client_id; + $decoded_message->client_id; } sub _process_get_response { @@ -627,13 +660,16 @@ sub _process_get_response { my $contents = $decoded_message->content; if ( ref($contents) eq 'ARRAY' ) { - my $content = $contents->[0]; - - my $decode = $should_decode && ($content->content_type eq 'application/json'); - return { - value => ( $decode ) ? decode_json($content->value) : $content->value, - indexes => $content->indexes, - vclock => $decoded_message->vclock, + my $content = $contents->[0]; + + my $decode = + $should_decode && ( $content->content_type eq 'application/json' ); + return { + value => ($decode) + ? decode_json( $content->value ) + : $content->value, + indexes => $content->indexes, + vclock => $decoded_message->vclock, }; } @@ -659,14 +695,17 @@ sub _process_generic_error { my $extra = ''; - if( $operation eq $PING ) { - $extra = ''; - } elsif ( $operation eq $QUERY_INDEX) { - $extra = "(bucket: $bucket, $key)"; - } elsif ( $operation eq $MAP_REDUCE) { - $extra = ''; # maybe add the sha1 of the request? - } else { - $extra = "(bucket: $bucket, key: $key)"; + if ( $operation eq $PING ) { + $extra = ''; + } + elsif ( $operation eq $QUERY_INDEX ) { + $extra = "(bucket: $bucket, $key)"; + } + elsif ( $operation eq $MAP_REDUCE ) { + $extra = ''; # maybe add the sha1 of the request? + } + else { + $extra = "(bucket: $bucket, key: $key)"; } my $error_message = "Error in '$operation' $extra: $error"; diff --git a/lib/Riak/Light/Connector.pm b/lib/Riak/Light/Connector.pm index cdd01d8..b143b90 100644 --- a/lib/Riak/Light/Connector.pm +++ b/lib/Riak/Light/Connector.pm @@ -18,14 +18,14 @@ sub perform_request { } sub read_response { - my ($self) = @_; + my ($self) = @_; my $length = $self->_read_length(); # read first four bytes return unless ($length); $self->_read_all($length); # read the message } sub _read_length { - my ($self) = @_; + my ($self) = @_; my $first_four_bytes = $self->_read_all(4); diff --git a/lib/Riak/Light/Driver.pm b/lib/Riak/Light/Driver.pm index b2fef8b..3684359 100644 --- a/lib/Riak/Light/Driver.pm +++ b/lib/Riak/Light/Driver.pm @@ -35,7 +35,7 @@ sub perform_request { } sub read_response { - my ($self) = @_; + my ($self) = @_; my $response = $self->connector->read_response() or return $self->_parse_error(); $self->_parse_response($response); @@ -43,7 +43,7 @@ sub read_response { sub _parse_response { my ( $self, $response ) = @_; - my ( $code, $body ) = unpack( 'c a*', $response ); + my ( $code, $body ) = unpack( 'c a*', $response ); { code => $code, body => $body, error => undef }; } diff --git a/lib/Riak/Light/Timeout/Alarm.pm b/lib/Riak/Light/Timeout/Alarm.pm index cf1af86..ae2bb87 100644 --- a/lib/Riak/Light/Timeout/Alarm.pm +++ b/lib/Riak/Light/Timeout/Alarm.pm @@ -2,8 +2,8 @@ package Riak::Light::Timeout::Alarm; ## use critic -use POSIX qw(ETIMEDOUT ECONNRESET); -use Time::HiRes qw(alarm); +use POSIX qw(ETIMEDOUT ECONNRESET); +use Time::HiRes qw(alarm); use Riak::Light::Util qw(is_windows); use Carp; use Moo; @@ -13,8 +13,8 @@ with 'Riak::Light::Timeout'; # ABSTRACT: proxy to read/write using Alarm as a timeout provider ( Not Safe: can clobber previous alarm ) has socket => ( is => 'ro', required => 1 ); -has in_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); -has out_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); +has in_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); +has out_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); has is_valid => ( is => 'rw', isa => Bool, default => sub {1} ); sub BUILD { diff --git a/lib/Riak/Light/Timeout/Select.pm b/lib/Riak/Light/Timeout/Select.pm index 17ab4d7..bbe452d 100644 --- a/lib/Riak/Light/Timeout/Select.pm +++ b/lib/Riak/Light/Timeout/Select.pm @@ -16,7 +16,7 @@ with 'Riak::Light::Timeout'; has socket => ( is => 'ro', required => 1 ); has in_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); has out_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); -has select => ( is => 'ro', default => sub { IO::Select->new } ); +has select => ( is => 'ro', default => sub { IO::Select->new } ); sub BUILD { $_[0]->select->add( $_[0]->socket ); @@ -44,7 +44,7 @@ sub sysread { if $self->select->can_read( $self->in_timeout ); $self->clean(); - $! = ETIMEDOUT; ## no critic (RequireLocalizedPunctuationVars) + $! = ETIMEDOUT; ## no critic (RequireLocalizedPunctuationVars) undef; } @@ -58,7 +58,7 @@ sub syswrite { if $self->select->can_write( $self->out_timeout ); $self->clean(); - $! = ETIMEDOUT; ## no critic (RequireLocalizedPunctuationVars) + $! = ETIMEDOUT; ## no critic (RequireLocalizedPunctuationVars) undef; } diff --git a/lib/Riak/Light/Timeout/SelectOnRead.pm b/lib/Riak/Light/Timeout/SelectOnRead.pm index 22f657c..9fe5d6a 100644 --- a/lib/Riak/Light/Timeout/SelectOnRead.pm +++ b/lib/Riak/Light/Timeout/SelectOnRead.pm @@ -17,9 +17,10 @@ with 'Riak::Light::Timeout'; has socket => ( is => 'ro', required => 1 ); has in_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); has out_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); -has select => ( is => 'ro', default => sub { IO::Select->new } ); +has select => ( is => 'ro', default => sub { IO::Select->new } ); sub BUILD { + #carp "Should block in Write Operations, be careful"; $_[0]->select->add( $_[0]->socket ); @@ -59,6 +60,7 @@ sub syswrite { 1; +__END__ =head1 NAME Riak::Light::Timeout::SelectOnRead -IO Timeout based on IO::Select (only in read operations) for Riak::Light diff --git a/lib/Riak/Light/Timeout/SetSockOpt.pm b/lib/Riak/Light/Timeout/SetSockOpt.pm index 992108a..51e720b 100644 --- a/lib/Riak/Light/Timeout/SetSockOpt.pm +++ b/lib/Riak/Light/Timeout/SetSockOpt.pm @@ -16,26 +16,27 @@ with 'Riak::Light::Timeout'; # ABSTRACT: proxy to read/write using IO::Select as a timeout provider only for READ operations. has socket => ( is => 'ro', required => 1 ); -has in_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); -has out_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); +has in_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); +has out_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); has is_valid => ( is => 'rw', isa => Bool, default => sub {1} ); sub BUILD { + # carp "This Timeout Provider is EXPERIMENTAL!"; croak "NetBSD no supported yet" if is_netbsd(); ## TODO: see https://metacpan.org/source/ZWON/RedisDB-2.12/lib/RedisDB.pm#L235 - + croak "Solaris is not supported" if is_solaris(); - + $_[0]->_set_so_rcvtimeo(); $_[0]->_set_so_sndtimeo(); } sub _set_so_rcvtimeo { - my ($self) = @_; + my ($self) = @_; my $seconds = int( $self->in_timeout ); my $useconds = int( 1_000_000 * ( $self->in_timeout - $seconds ) ); my $timeout = pack( 'l!l!', $seconds, $useconds ); @@ -45,7 +46,7 @@ sub _set_so_rcvtimeo { } sub _set_so_sndtimeo { - my ($self) = @_; + my ($self) = @_; my $seconds = int( $self->out_timeout ); my $useconds = int( 1_000_000 * ( $self->out_timeout - $seconds ) ); my $timeout = pack( 'l!l!', $seconds, $useconds ); @@ -57,7 +58,7 @@ sub _set_so_sndtimeo { sub clean { $_[0]->socket->close(); $_[0]->is_valid(0); - $! = ETIMEDOUT; ## no critic (RequireLocalizedPunctuationVars) + $! = ETIMEDOUT; ## no critic (RequireLocalizedPunctuationVars) } sub sysread { diff --git a/lib/Riak/Light/Timeout/TimeOut.pm b/lib/Riak/Light/Timeout/TimeOut.pm index f4c4fa8..d95ed3a 100644 --- a/lib/Riak/Light/Timeout/TimeOut.pm +++ b/lib/Riak/Light/Timeout/TimeOut.pm @@ -2,7 +2,7 @@ package Riak::Light::Timeout::TimeOut; ## use critic -use POSIX qw(ETIMEDOUT ECONNRESET); +use POSIX qw(ETIMEDOUT ECONNRESET); use Time::Out qw(timeout); use Time::HiRes; use Riak::Light::Util qw(is_windows); @@ -15,8 +15,8 @@ with 'Riak::Light::Timeout'; # ABSTRACT: proxy to read/write using Time::Out as a timeout provider has socket => ( is => 'ro', required => 1 ); -has in_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); -has out_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); +has in_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); +has out_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); has is_valid => ( is => 'rw', isa => Bool, default => sub {1} ); sub BUILD { @@ -41,7 +41,7 @@ sub sysread { my $buffer; my $seconds = $self->in_timeout; - my $result = timeout $seconds, @_ => sub { + my $result = timeout $seconds, @_ => sub { my $readed = $self->socket->sysread(@_); $buffer = $_[0]; # NECESSARY, timeout does not map the alias @_ !! $readed; @@ -62,7 +62,7 @@ sub syswrite { $self->is_valid or $! = ECONNRESET, return; ## no critic (RequireLocalizedPunctuationVars) my $seconds = $self->out_timeout; - my $result = timeout $seconds, @_ => sub { + my $result = timeout $seconds, @_ => sub { $self->socket->syswrite(@_); }; if ($@) { diff --git a/lib/Riak/Light/Util.pm b/lib/Riak/Light/Util.pm index 90684bb..3be3cfd 100644 --- a/lib/Riak/Light/Util.pm +++ b/lib/Riak/Light/Util.pm @@ -1,10 +1,13 @@ ## no critic (RequireUseStrict, RequireUseWarnings) package Riak::Light::Util; ## use critic +use strict; +use warnings; use Config; use Exporter 'import'; -@EXPORT_OK = qw(is_windows is_netbsd is_solaris); +our @EXPORT_OK = qw(is_windows is_netbsd is_solaris); + #ABSTRACT: util class, provides is_windows, is_solaris, etc sub is_windows { @@ -20,7 +23,7 @@ sub is_solaris { } 1; - +__END__ =head1 DESCRIPTION Internal class diff --git a/t/01_load.t b/t/01_load.t index 1e470bd..a3a27ea 100644 --- a/t/01_load.t +++ b/t/01_load.t @@ -14,4 +14,4 @@ use Riak::Light::Timeout::TimeOut; use Riak::Light::Util; ok 1, 'All modules loaded successfully'; -$ok = 1; \ No newline at end of file +$ok = 1; diff --git a/t/02_class_test.t b/t/02_class_test.t index c00a2c0..480c7a3 100644 --- a/t/02_class_test.t +++ b/t/02_class_test.t @@ -23,9 +23,9 @@ subtest "new and default attrs values" => sub { ok( !$client->autodie, "default autodie shoudl be false" ); ok( $client->timeout_provider, 'Riak::Light::Timeout::Select' ); - ok( !$client->has_rw, "should have no rw"); - ok( !$client->has_pr, "should have no pr"); - ok( !$client->has_pw, "should have no pw"); + ok( !$client->has_rw, "should have no rw" ); + ok( !$client->has_pr, "should have no pr" ); + ok( !$client->has_pw, "should have no pw" ); }; subtest "new and other attrs values" => sub { @@ -43,7 +43,7 @@ subtest "new and other attrs values" => sub { out_timeout => 4, rw => 1, pr => 2, - pw => 3, + pw => 3, timeout_provider => 'Riak::Light::Timeout::TimeOut' ], "a new client" @@ -54,11 +54,11 @@ subtest "new and other attrs values" => sub { is( $client->dw, 1, "dw should be 1" ); is( $client->rw, 1, "rw should be 1" ); is( $client->pr, 2, "pr should be 2" ); - is( $client->pw, 3, "pw should be 3" ); + is( $client->pw, 3, "pw should be 3" ); ok( $client->autodie, "autodie should be true" ); ok( $client->timeout_provider, 'Riak::Light::Timeout::TimeOut' ); - is( $client->in_timeout, 2, "in timeout should be 2"); - is( $client->out_timeout, 4, "out timeout should be 4"); + is( $client->in_timeout, 2, "in timeout should be 2" ); + is( $client->out_timeout, 4, "out timeout should be 4" ); }; subtest "should be a riak::light instance" => sub { diff --git a/t/03_real_riak_test.t b/t/03_real_riak_test.t index 5381601..c39bfde 100644 --- a/t/03_real_riak_test.t +++ b/t/03_real_riak_test.t @@ -22,7 +22,7 @@ subtest "simple get/set/delete test" => sub { ); my $scalar = '3.14159'; - my $hash = { baz => 1024 }; + my $hash = { baz => 1024 }; ok( $client->ping(), "should can ping" ); ok( $client->is_alive(), "should can ping" ); @@ -41,9 +41,9 @@ subtest "simple get/set/delete test" => sub { "should fetch the raw scalar from Riak" ); - ok( $client->exists( foo => 'bar' ), "should exists" ); - ok( $client->del( foo => 'bar' ), "should delete the hashref" ); - ok( !$client->get( foo => 'bar' ), "should fetch UNDEF from Riak" ); + ok( $client->exists( foo => 'bar' ), "should exists" ); + ok( $client->del( foo => 'bar' ), "should delete the hashref" ); + ok( !$client->get( foo => 'bar' ), "should fetch UNDEF from Riak" ); ok( !$client->exists( foo => 'bar' ), "should not exists" ); ok( $client->put( foo => "baz", 'TEXT', 'plain/text' ), @@ -53,9 +53,10 @@ subtest "simple get/set/delete test" => sub { "should fetch the text from Riak" ); - my $vclock = $client->get_vclock(foo => "baz"); + my $vclock = $client->get_vclock( foo => "baz" ); ok $vclock, "should return vclock=$vclock"; + #ok(!$@, "should has no error - foo => bar is undefined"); }; @@ -87,7 +88,7 @@ subtest "get keys" => sub { $client->get_keys( $bucket => sub { push @keys, $_[0] } ); @keys = sort @keys; - is( scalar @keys, 3, 'should return 3 items' ); + is( scalar @keys, 3, 'should return 3 items' ); is( $keys[0], 'bam', '..bam' ); is( $keys[1], 'bar', '..bar' ); is( $keys[2], 'baz', '..baz' ); diff --git a/t/04_client_tests.t b/t/04_client_tests.t index acbae7e..ef97e94 100644 --- a/t/04_client_tests.t +++ b/t/04_client_tests.t @@ -175,183 +175,180 @@ subtest "ping" => sub { }; subtest "vclock" => sub { - plan tests => 3; - subtest "should return the vclock" => sub { - plan tests => 1; - my $mock = Test::MockObject->new; - - my $mock_response = { - error => undef, - code => 10, - body => RpbGetResp->encode( - { content => { - value => encode_json({ foo => 1}), - content_type => 'application/json', - }, - vclock => 12345, - } - ) - }; - - $mock->set_true('perform_request'); - $mock->set_always( read_response => $mock_response ); - - my $client = Riak::Light->new( - host => 'host', port => 1234, autodie => 1, - driver => $mock - ); - - is( - $client->get_vclock( foo => "bar" ), 12345, - "should return the same vclock" - ); - }; - - subtest "should return the vclock in get_full" => sub { - plan tests => 1; - my $mock = Test::MockObject->new; - - my $mock_response = { - error => undef, - code => 10, - body => RpbGetResp->encode( - { content => { - value => encode_json({ foo => 1}), - content_type => 'application/json', - indexes => [{key => 'foo_int', value => 1}] - }, - vclock => 12345, - } - ) - }; - - $mock->set_true('perform_request'); - $mock->set_always( read_response => $mock_response ); - - my $client = Riak::Light->new( - host => 'host', port => 1234, autodie => 1, - driver => $mock - ); - - is_deeply( - $client->get_full( foo => "bar" ), - { - value => { foo => 1}, - indexes => [{key => 'foo_int', value => 1}], - vclock => 12345 - }, - "should return the same vclock" - ); - }; - - subtest "should return the vclock in get_full_raw" => sub { - plan tests => 1; - my $mock = Test::MockObject->new; - - my $mock_response = { - error => undef, - code => 10, - body => RpbGetResp->encode( - { content => { - value => encode_json({ foo => 1}), - content_type => 'application/json', - indexes => [{key => 'foo_int', value => 1}] - }, - vclock => 12345, - } - ) - }; - - $mock->set_true('perform_request'); - $mock->set_always( read_response => $mock_response ); - - my $client = Riak::Light->new( - host => 'host', port => 1234, autodie => 1, - driver => $mock - ); - - is_deeply( - $client->get_full_raw( foo => "bar" ), - { - value => encode_json{ foo => 1}, - indexes => [{key => 'foo_int', value => 1}], - vclock => 12345 - }, - "should return the same vclock" - ); - }; + plan tests => 3; + subtest "should return the vclock" => sub { + plan tests => 1; + my $mock = Test::MockObject->new; + + my $mock_response = { + error => undef, + code => 10, + body => RpbGetResp->encode( + { content => { + value => encode_json( { foo => 1 } ), + content_type => 'application/json', + }, + vclock => 12345, + } + ) + }; + + $mock->set_true('perform_request'); + $mock->set_always( read_response => $mock_response ); + + my $client = Riak::Light->new( + host => 'host', port => 1234, autodie => 1, + driver => $mock + ); + + is( $client->get_vclock( foo => "bar" ), 12345, + "should return the same vclock" + ); + }; + + subtest "should return the vclock in get_full" => sub { + plan tests => 1; + my $mock = Test::MockObject->new; + + my $mock_response = { + error => undef, + code => 10, + body => RpbGetResp->encode( + { content => { + value => encode_json( { foo => 1 } ), + content_type => 'application/json', + indexes => [ { key => 'foo_int', value => 1 } ] + }, + vclock => 12345, + } + ) + }; + + $mock->set_true('perform_request'); + $mock->set_always( read_response => $mock_response ); + + my $client = Riak::Light->new( + host => 'host', port => 1234, autodie => 1, + driver => $mock + ); + + is_deeply( + $client->get_full( foo => "bar" ), + { value => { foo => 1 }, + indexes => [ { key => 'foo_int', value => 1 } ], + vclock => 12345 + }, + "should return the same vclock" + ); + }; + + subtest "should return the vclock in get_full_raw" => sub { + plan tests => 1; + my $mock = Test::MockObject->new; + + my $mock_response = { + error => undef, + code => 10, + body => RpbGetResp->encode( + { content => { + value => encode_json( { foo => 1 } ), + content_type => 'application/json', + indexes => [ { key => 'foo_int', value => 1 } ] + }, + vclock => 12345, + } + ) + }; + + $mock->set_true('perform_request'); + $mock->set_always( read_response => $mock_response ); + + my $client = Riak::Light->new( + host => 'host', port => 1234, autodie => 1, + driver => $mock + ); + + is_deeply( + $client->get_full_raw( foo => "bar" ), + { value => encode_json { foo => 1 }, + indexes => [ { key => 'foo_int', value => 1 } ], + vclock => 12345 + }, + "should return the same vclock" + ); + }; }; subtest 'get_all_indexes' => sub { - plan tests => 2; - subtest 'should list indexes' => sub { - plan tests => 1; - my $mock = Test::MockObject->new; - - my $mock_response = { - error => undef, - code => 10, - body => RpbGetResp->encode( - { content => { - value => encode_json({ foo => 1}), - content_type => 'application/json', - indexes => [ - {key => 'foo_int', value => 1}, - {key => 'foo_int', value => 2}, - {key => 'foo_bin', value => 'bar'}, - ], - } - } - ) - }; - - $mock->set_true('perform_request'); - $mock->set_always( read_response => $mock_response ); - - my $client = Riak::Light->new( - host => 'host', port => 1234, autodie => 1, - driver => $mock - ); - - is_deeply( - $client->get_all_indexes( foo => "bar" ), [ - {key => 'foo_int', value => 1}, - {key => 'foo_int', value => 2}, - {key => 'foo_bin', value => 'bar'}, - ], - "should return the same structure" - ); - }; - - subtest 'should not list indexes if it is missing' => sub { - plan tests => 1; - my $mock = Test::MockObject->new; - - my $mock_response = { - error => undef, - code => 10, - body => RpbGetResp->encode( - { content => { - value => encode_json({ foo => 1 }), - content_type => 'application/json', + plan tests => 2; + subtest 'should list indexes' => sub { + plan tests => 1; + my $mock = Test::MockObject->new; + + my $mock_response = { + error => undef, + code => 10, + body => RpbGetResp->encode( + { content => { + value => encode_json( { foo => 1 } ), + content_type => 'application/json', + indexes => [ + { key => 'foo_int', value => 1 }, + { key => 'foo_int', value => 2 }, + { key => 'foo_bin', value => 'bar' }, + ], + } } - } - ) + ) + }; + + $mock->set_true('perform_request'); + $mock->set_always( read_response => $mock_response ); + + my $client = Riak::Light->new( + host => 'host', port => 1234, autodie => 1, + driver => $mock + ); + + is_deeply( + $client->get_all_indexes( foo => "bar" ), + [ { key => 'foo_int', value => 1 }, + { key => 'foo_int', value => 2 }, + { key => 'foo_bin', value => 'bar' }, + ], + "should return the same structure" + ); }; - $mock->set_true('perform_request'); - $mock->set_always( read_response => $mock_response ); + subtest 'should not list indexes if it is missing' => sub { + plan tests => 1; + my $mock = Test::MockObject->new; + + my $mock_response = { + error => undef, + code => 10, + body => RpbGetResp->encode( + { content => { + value => encode_json( { foo => 1 } ), + content_type => 'application/json', + } + } + ) + }; + + $mock->set_true('perform_request'); + $mock->set_always( read_response => $mock_response ); - my $client = Riak::Light->new( - host => 'host', port => 1234, autodie => 1, - driver => $mock - ); + my $client = Riak::Light->new( + host => 'host', port => 1234, autodie => 1, + driver => $mock + ); - is_deeply( - $client->get_all_indexes( foo => "bar" ), [], - "should return the empty structure" - ); - }; + is_deeply( + $client->get_all_indexes( foo => "bar" ), [], + "should return the empty structure" + ); + }; }; subtest "get" => sub { @@ -512,8 +509,8 @@ subtest "put" => sub { ); my $scalar = '3.14159'; - my $hash = { foo => 123 }; - ok( $client->put( foo => "bar", $hash ), "should store data" ); + my $hash = { foo => 123 }; + ok( $client->put( foo => "bar", $hash ), "should store data" ); ok( $client->put_raw( foo => "bar", $scalar ), "should store data" ); }; @@ -536,7 +533,7 @@ subtest "put" => sub { ); my $scalar = '3.14159'; - my $hash = { foo => 123 }; + my $hash = { foo => 123 }; ok( $client->put( foo => "bar", $scalar, 'text/plain' ), "should store data" ); @@ -730,9 +727,7 @@ subtest "query_index" => sub { ); throws_ok { - $client->query_index( - foo => bar => 1 - ); + $client->query_index( foo => bar => 1 ); } qr/Error in 'query_index' \(bucket: foo, 2i query on index='bar' => 1\): ops/; }; @@ -745,7 +740,9 @@ subtest "query_index" => sub { my $mock_response = { error => undef, code => 26, - body => RpbIndexResp->encode( { keys => [], done => undef, continuation => undef } ) + body => RpbIndexResp->encode( + { keys => [], done => undef, continuation => undef } + ) }; $mock->set_true('perform_request'); @@ -756,9 +753,7 @@ subtest "query_index" => sub { driver => $mock ); - my $keys = $client->query_index( - foo => bar => 1 - ); + my $keys = $client->query_index( foo => bar => 1 ); is( scalar @{$keys}, 0 ); }; @@ -770,7 +765,9 @@ subtest "query_index" => sub { my $mock_response = { error => undef, code => 26, - body => RpbIndexResp->encode( { keys => [ 1, 2 , 3], done => undef, continuation => undef } ) + body => RpbIndexResp->encode( + { keys => [ 1, 2, 3 ], done => undef, continuation => undef } + ) }; $mock->set_true('perform_request'); @@ -781,12 +778,10 @@ subtest "query_index" => sub { driver => $mock ); - my $keys = $client->query_index( - foo => bar => 1 - ); + my $keys = $client->query_index( foo => bar => 1 ); is scalar @{$keys}, 3; - is_deeply [ sort @{$keys} ], [ 1, 2 ,3]; + is_deeply [ sort @{$keys} ], [ 1, 2, 3 ]; }; subtest "simple retrieve (wantarray)" => sub { @@ -796,7 +791,9 @@ subtest "query_index" => sub { my $mock_response = { error => undef, code => 26, - body => RpbIndexResp->encode( { keys => [ 1, 2 , 3], done => 0, continuation => 'foo' } ) + body => RpbIndexResp->encode( + { keys => [ 1, 2, 3 ], done => 0, continuation => 'foo' } + ) }; $mock->set_true('perform_request'); @@ -807,25 +804,24 @@ subtest "query_index" => sub { driver => $mock ); - my ($keys, $continuation, $done) = $client->query_index( - foo => bar => 1, { max_results => 1024} - ); + my ( $keys, $continuation, $done ) = + $client->query_index( foo => bar => 1, { max_results => 1024 } ); - is_deeply [ sort @{$keys} ], [ 1, 2 ,3]; + is_deeply [ sort @{$keys} ], [ 1, 2, 3 ]; is $continuation, 'foo'; - is $done, 0; - my ($name, $args) = $mock->next_call(); + is $done, 0; + my ( $name, $args ) = $mock->next_call(); is $name, 'perform_request', 'call perform_request'; - my (undef, %hash) = @{$args}; + my ( undef, %hash ) = @{$args}; my $request = RpbIndexReq->decode( $hash{body} ); - is $request->index, 'bar'; - is $request->bucket, 'foo'; - is $request->key, 1; - is $request->qtype, 0; - is $request->max_results, 1024; + is $request->index, 'bar'; + is $request->bucket, 'foo'; + is $request->key, 1; + is $request->qtype, 0; + is $request->max_results, 1024; is $request->continuation, undef; $mock->called_ok('read_response'); @@ -838,13 +834,17 @@ subtest "query_index" => sub { my $mock_response1 = { error => undef, code => 26, - body => RpbIndexResp->encode( { keys => [ 1, 2 ], done => 0, continuation => 'foo' } ) + body => RpbIndexResp->encode( + { keys => [ 1, 2 ], done => 0, continuation => 'foo' } + ) }; my $mock_response2 = { error => undef, code => 26, - body => RpbIndexResp->encode( { keys => [ 3, 4], done => 1, continuation => undef } ) + body => RpbIndexResp->encode( + { keys => [ 3, 4 ], done => 1, continuation => undef } + ) }; $mock->set_true('perform_request'); @@ -855,161 +855,165 @@ subtest "query_index" => sub { driver => $mock ); - my $keys = $client->query_index_loop( - foo => bar => 1 - ); + my $keys = $client->query_index_loop( foo => bar => 1 ); is scalar @{$keys}, 4; - is_deeply [ sort @{$keys} ], [ 1, 2 ,3, 4]; + is_deeply [ sort @{$keys} ], [ 1, 2, 3, 4 ]; - my ($name, $args) = $mock->next_call(); + my ( $name, $args ) = $mock->next_call(); is $name, 'perform_request', 'call perform_request'; - my (undef, %hash) = @{$args}; + my ( undef, %hash ) = @{$args}; my $request = RpbIndexReq->decode( $hash{body} ); - is $request->index, 'bar'; - is $request->bucket, 'foo'; - is $request->key, 1; - is $request->qtype, 0; - is $request->max_results, 100; + is $request->index, 'bar'; + is $request->bucket, 'foo'; + is $request->key, 1; + is $request->qtype, 0; + is $request->max_results, 100; is $request->continuation, undef; - ($name, $args) = $mock->next_call(); + ( $name, $args ) = $mock->next_call(); is $name, 'read_response', 'call perform_request'; - - ($name, $args) = $mock->next_call(); + + ( $name, $args ) = $mock->next_call(); is $name, 'perform_request', 'call perform_request again'; - (undef, %hash) = @{$args}; + ( undef, %hash ) = @{$args}; $request = RpbIndexReq->decode( $hash{body} ); - is $request->index, 'bar'; - is $request->bucket, 'foo'; - is $request->key, 1; - is $request->qtype, 0; - is $request->max_results, 100; + is $request->index, 'bar'; + is $request->bucket, 'foo'; + is $request->key, 1; + is $request->qtype, 0; + is $request->max_results, 100; is $request->continuation, 'foo'; - ($name, $args) = $mock->next_call(); + ( $name, $args ) = $mock->next_call(); is $name, 'read_response', 'call perform_request again'; }; }; subtest "map_reduce" => sub { - plan tests => 3; - - subtest "should throw error" => sub { - plan tests => 1; - my $mock = Test::MockObject->new; - - my $mock_response = { - error => "ops", - code => -1, - body => undef - }; - - $mock->set_true('perform_request'); - $mock->set_always( 'read_response', $mock_response ); - - my $client = Riak::Light->new( - host => 'host', port => 1234, autodie => 1, - driver => $mock - ); - - throws_ok { - $client->map_reduce('some-js-map-reduce...'); - } - qr/Error in 'map_reduce' : ops/, - 'should die with the correct message'; - }; - - subtest "should return arrayref" => sub { - plan tests => 2; - my $mock = Test::MockObject->new; - - my $mock_response1 = { - error => undef, - code => 24, - body => RpbMapRedResp->encode({ - done => undef, - phase => 0, - response => '[["foo",1]]', - }) - }; - my $mock_response2 = { - error => undef, - code => 24, - body => RpbMapRedResp->encode({ - done => 1, - phase => undef, - response => undef, - }) - }; - - $mock->set_true('perform_request'); - $mock->set_series( 'read_response', $mock_response1, $mock_response2); - - - my $client = Riak::Light->new( - host => 'host', port => 1234, autodie => 1, - driver => $mock - ); - - my $arrayref; - lives_ok { - $arrayref = $client->map_reduce('some-js-map-reduce...'); - } - 'should not die'; - - is_deeply [{ - phase => 0, - response => [["foo",1]], - }], $arrayref, 'should return'; - }; - subtest "should call the callback" => sub { - plan tests => 3; - my $mock = Test::MockObject->new; - - my $mock_response1 = { - error => undef, - code => 24, - body => RpbMapRedResp->encode({ - done => undef, - phase => 0, - response => '[["foo",1]]', - }) - }; - my $mock_response2 = { - error => undef, - code => 24, - body => RpbMapRedResp->encode({ - done => 1, - phase => undef, - response => undef, - }) - }; - - $mock->set_true('perform_request'); - $mock->set_series( 'read_response', $mock_response1, $mock_response2); - - my $client = Riak::Light->new( - host => 'host', port => 1234, autodie => 1, - driver => $mock - ); - - my ($phase, $response); - my $callback = sub { - ($response, $phase) = @_; - }; - lives_ok { - $client->map_reduce('some-js-map-reduce...', $callback); - } - 'should not die'; - - is $phase, 0, 'phase should be 1'; - is_deeply [["foo",1]], $response, 'should return'; - }; -}; \ No newline at end of file + plan tests => 3; + + subtest "should throw error" => sub { + plan tests => 1; + my $mock = Test::MockObject->new; + + my $mock_response = { + error => "ops", + code => -1, + body => undef + }; + + $mock->set_true('perform_request'); + $mock->set_always( 'read_response', $mock_response ); + + my $client = Riak::Light->new( + host => 'host', port => 1234, autodie => 1, + driver => $mock + ); + + throws_ok { + $client->map_reduce('some-js-map-reduce...'); + } + qr/Error in 'map_reduce' : ops/, + 'should die with the correct message'; + }; + + subtest "should return arrayref" => sub { + plan tests => 2; + my $mock = Test::MockObject->new; + + my $mock_response1 = { + error => undef, + code => 24, + body => RpbMapRedResp->encode( + { done => undef, + phase => 0, + response => '[["foo",1]]', + } + ) + }; + my $mock_response2 = { + error => undef, + code => 24, + body => RpbMapRedResp->encode( + { done => 1, + phase => undef, + response => undef, + } + ) + }; + + $mock->set_true('perform_request'); + $mock->set_series( 'read_response', $mock_response1, $mock_response2 ); + + + my $client = Riak::Light->new( + host => 'host', port => 1234, autodie => 1, + driver => $mock + ); + + my $arrayref; + lives_ok { + $arrayref = $client->map_reduce('some-js-map-reduce...'); + } + 'should not die'; + + is_deeply [ + { phase => 0, + response => [ [ "foo", 1 ] ], + } + ], + $arrayref, 'should return'; + }; + subtest "should call the callback" => sub { + plan tests => 3; + my $mock = Test::MockObject->new; + + my $mock_response1 = { + error => undef, + code => 24, + body => RpbMapRedResp->encode( + { done => undef, + phase => 0, + response => '[["foo",1]]', + } + ) + }; + my $mock_response2 = { + error => undef, + code => 24, + body => RpbMapRedResp->encode( + { done => 1, + phase => undef, + response => undef, + } + ) + }; + + $mock->set_true('perform_request'); + $mock->set_series( 'read_response', $mock_response1, $mock_response2 ); + + my $client = Riak::Light->new( + host => 'host', port => 1234, autodie => 1, + driver => $mock + ); + + my ( $phase, $response ); + my $callback = sub { + ( $response, $phase ) = @_; + }; + lives_ok { + $client->map_reduce( 'some-js-map-reduce...', $callback ); + } + 'should not die'; + + is $phase, 0, 'phase should be 1'; + is_deeply [ [ "foo", 1 ] ], $response, 'should return'; + }; +}; diff --git a/t/07_socket_test.t b/t/07_socket_test.t index be8239c..65df42c 100644 --- a/t/07_socket_test.t +++ b/t/07_socket_test.t @@ -29,14 +29,18 @@ subtest "should not die if can connect" => sub { my $client; lives_ok { $client = Riak::Light->new( - host => '127.0.0.1', - port => $server->port, + host => '127.0.0.1', + port => $server->port, timeout_provider => undef, ); }; is $client->tcp_nodelay, 1, 'default, should be enable'; - ok $client->driver->connector->socket->getsockopt(IPPROTO_TCP, TCP_NODELAY), "should set TCP_NODELAY to 1"; + ok $client->driver->connector->socket->getsockopt( + IPPROTO_TCP, + TCP_NODELAY + ), + "should set TCP_NODELAY to 1"; }; subtest "should not die if can connect wihout TCP_NODELAY" => sub { @@ -61,14 +65,18 @@ subtest "should not die if can connect wihout TCP_NODELAY" => sub { my $client; lives_ok { $client = Riak::Light->new( - host => '127.0.0.1', - port => $server->port, + host => '127.0.0.1', + port => $server->port, timeout_provider => undef, - tcp_nodelay => 0, + tcp_nodelay => 0, ); }; - is $client->driver->connector->socket->getsockopt(IPPROTO_TCP, TCP_NODELAY), 0, "should NOT set TCP_NODELAY to 1"; + is $client->driver->connector->socket->getsockopt( + IPPROTO_TCP, + TCP_NODELAY + ), + 0, "should NOT set TCP_NODELAY to 1"; }; subtest "should die if cant connect" => sub { diff --git a/t/08_autodie.t b/t/08_autodie.t index 48ab8eb..c1a7ad9 100644 --- a/t/08_autodie.t +++ b/t/08_autodie.t @@ -67,14 +67,23 @@ subtest "should clear \$\@ between calls (exists)" => sub { $mock->set_true('perform_request'); $mock->set_series( 'read_response', { error => "ops" }, - { error => undef, code => 10, body => RpbGetResp->encode({content => { - value => q(), - content_type => 'application/json' - } }) } + { error => undef, + code => 10, + body => RpbGetResp->encode( + { content => { + value => q(), + content_type => 'application/json' + } + } + ) + } ); - ok( !$client->exists(foo => "bar"), "should not die" ); - like( $@, qr/Error in 'get' \(bucket: foo, key: bar\): ops/, "should set \$\@ to the error" ); - ok( $client->exists(foo => "bar"), "should return true" ); - ok( !$@, " \$\@ should be clean" ); + ok( !$client->exists( foo => "bar" ), "should not die" ); + like( + $@, qr/Error in 'get' \(bucket: foo, key: bar\): ops/, + "should set \$\@ to the error" + ); + ok( $client->exists( foo => "bar" ), "should return true" ); + ok( !$@, " \$\@ should be clean" ); }; diff --git a/t/12_timeout_setsockopt.t b/t/12_timeout_setsockopt.t index 2a3c5c1..98c800a 100644 --- a/t/12_timeout_setsockopt.t +++ b/t/12_timeout_setsockopt.t @@ -1,6 +1,6 @@ BEGIN { use Config; - if ( $Config{osname} eq 'netbsd' || $Config{osname} eq 'solaris') { + if ( $Config{osname} eq 'netbsd' || $Config{osname} eq 'solaris' ) { require Test::More; Test::More::plan( skip_all => 'should not test Riak::Light::Timeout::SetSockOpt under Solaris OR Netbsd 6.0 (or superior) and longsize 4' @@ -21,7 +21,7 @@ subtest "test die under solaris" => sub { use Riak::Light::Timeout::SetSockOpt; my $module = Test::MockModule->new('Riak::Light::Timeout::SetSockOpt'); - $module->mock( is_netbsd => 0 ); + $module->mock( is_netbsd => 0 ); $module->mock( is_solaris => 1 ); throws_ok { diff --git a/t/15_secondary_indexes.t b/t/15_secondary_indexes.t index 16b1f68..17f0e60 100644 --- a/t/15_secondary_indexes.t +++ b/t/15_secondary_indexes.t @@ -26,128 +26,169 @@ subtest "query 2i" => sub { my $bucket_name = "test_bucket_$$"; - foreach (1..50) { + foreach ( 1 .. 50 ) { ok( $client->del( $bucket_name => "key$_" ), "should cleanup the key in Riak" - ); + ); } - foreach (1..50) { - ok( ! $client->exists( $bucket_name => "key$_" ), + foreach ( 1 .. 50 ) { + ok( !$client->exists( $bucket_name => "key$_" ), "key shouldn't exist anymore" - ); + ); } - foreach (1..50) { - ok( $client->del( $bucket_name => "other_key$_"), + foreach ( 1 .. 50 ) { + ok( $client->del( $bucket_name => "other_key$_" ), "should cleanup the key in Riak" - ); + ); } - foreach (1..50) { - ok( ! $client->exists( $bucket_name => "other_key$_" ), + foreach ( 1 .. 50 ) { + ok( !$client->exists( $bucket_name => "other_key$_" ), "key shouldn't exist anymore" - ); + ); } - foreach (1..50) { - ok( $client->put( $bucket_name => "key$_", $hash, undef, { index_test_field_bin => 'plop', - index_test_field2_bin => [ 'plop2', 'plop3' ] } ), + foreach ( 1 .. 50 ) { + ok( $client->put( + $bucket_name => "key$_", + $hash, undef, + { index_test_field_bin => 'plop', + index_test_field2_bin => [ 'plop2', 'plop3' ] + } + ), "should store the hashref in Riak with indexes" - ); + ); } - foreach (1..50) { - ok( $client->put( $bucket_name => "other_key$_", $hash, undef, { index_test_field3_int => $_ } ), + foreach ( 1 .. 50 ) { + ok( $client->put( + $bucket_name => "other_key$_", $hash, undef, + { index_test_field3_int => $_ } + ), "should store the hashref in Riak with other index" - ); + ); } - is_deeply( [ sort @{ $client->query_index( $bucket_name => 'index_test_field_bin', 'plop' ) } ], - [ sort map { "key$_" }(1..50)], - "querying the index should return the keys" - ); - is_deeply( [ sort @{ $client->query_index( $bucket_name => 'index_test_field2_bin', 'plop2' ) } ], - [ sort map { "key$_" }(1..50)], - "querying the index should return the keys" - ); - is_deeply( [ sort @{ $client->query_index( $bucket_name => 'index_test_field2_bin', 'plop3' ) } ], - [ sort map { "key$_" }(1..50)], - "querying the index should return the keys" - ); - is_deeply( [ sort @{ $client->query_index( $bucket_name => 'index_test_field3_int', [ 30, 45] ) } ], - [ sort map { "other_key$_" }(30..45)], - "querying the index with range should return the keys" - ); - - foreach (1..50){ - is_deeply( [ - sort { - $a->{value} cmp $b->{value} - } @{ $client->get_all_indexes($bucket_name => "key$_") } - ], - [ - { key => 'index_test_field_bin', value => 'plop' }, - { key => 'index_test_field2_bin', value => 'plop2' }, - { key => 'index_test_field2_bin', value => 'plop3' }, - ], - "querying all indexes from key$_" + is_deeply( + [ sort @{ + $client->query_index( + $bucket_name => 'index_test_field_bin', 'plop' + ) + } + ], + [ sort map {"key$_"} ( 1 .. 50 ) ], + "querying the index should return the keys" + ); + is_deeply( + [ sort @{ + $client->query_index( + $bucket_name => 'index_test_field2_bin', 'plop2' + ) + } + ], + [ sort map {"key$_"} ( 1 .. 50 ) ], + "querying the index should return the keys" + ); + is_deeply( + [ sort @{ + $client->query_index( + $bucket_name => 'index_test_field2_bin', 'plop3' + ) + } + ], + [ sort map {"key$_"} ( 1 .. 50 ) ], + "querying the index should return the keys" + ); + is_deeply( + [ sort @{ + $client->query_index( + $bucket_name => 'index_test_field3_int', [ 30, 45 ] + ) + } + ], + [ sort map {"other_key$_"} ( 30 .. 45 ) ], + "querying the index with range should return the keys" + ); + + foreach ( 1 .. 50 ) { + is_deeply( + [ sort { $a->{value} cmp $b->{value} } + @{ $client->get_all_indexes( $bucket_name => "key$_" ) } + ], + [ { key => 'index_test_field_bin', value => 'plop' }, + { key => 'index_test_field2_bin', value => 'plop2' }, + { key => 'index_test_field2_bin', value => 'plop3' }, + ], + "querying all indexes from key$_" ); - - is_deeply( $client->get_all_indexes($bucket_name => "other_key$_"), - [ - { key => 'index_test_field3_int', value => $_ }, - ], "querying all indexes from other_key$_" + + is_deeply( + $client->get_all_indexes( $bucket_name => "other_key$_" ), + [ { key => 'index_test_field3_int', value => $_ }, + ], + "querying all indexes from other_key$_" + ); + + is_deeply( + $client->get_index_value( + $bucket_name => "key$_" => 'index_test_field_bin' + ), + ['plop'], + 'should return the value of index_test_field_bin index "plop"' ); - is_deeply($client->get_index_value($bucket_name => "key$_" => 'index_test_field_bin'), - ['plop'], - 'should return the value of index_test_field_bin index "plop"'); - - my $data = $client->get_all_index_values($bucket_name => "key$_"); - - $data->{index_test_field2_bin} = [ sort @{ $data->{index_test_field2_bin} } ]; - + my $data = $client->get_all_index_values( $bucket_name => "key$_" ); + + $data->{index_test_field2_bin} = + [ sort @{ $data->{index_test_field2_bin} } ]; + is_deeply $data, { - index_test_field_bin => ['plop'], - index_test_field2_bin => ['plop2', 'plop3'] - }, 'should return two indexes'; + index_test_field_bin => ['plop'], + index_test_field2_bin => [ 'plop2', 'plop3' ] + }, + 'should return two indexes'; } - foreach (1..50) { + foreach ( 1 .. 50 ) { ok( $client->del( $bucket_name => "key$_" ), "should cleanup the key in Riak" - ); + ); } - foreach (1..50) { - ok( ! $client->exists( $bucket_name => "key$_" ), + foreach ( 1 .. 50 ) { + ok( !$client->exists( $bucket_name => "key$_" ), "key shouldn't exist anymore" - ); + ); } - foreach (1..50) { - ok( $client->del( $bucket_name => "other_key$_"), + foreach ( 1 .. 50 ) { + ok( $client->del( $bucket_name => "other_key$_" ), "should cleanup the key in Riak" - ); + ); } - foreach (1..50) { - ok( ! $client->exists( $bucket_name => "other_key$_" ), + foreach ( 1 .. 50 ) { + ok( !$client->exists( $bucket_name => "other_key$_" ), "key shouldn't exist anymore" - ); + ); } - is_deeply( $client->query_index( $bucket_name => 'index_test_field_bin', 'plop' ), - [ ], - "querying the index should return nothing" - ); + is_deeply( + $client->query_index( $bucket_name => 'index_test_field_bin', 'plop' ), + [], + "querying the index should return nothing" + ); - is_deeply( $client->query_index( $bucket_name => 'index_test_field2_bin', 'plop2' ), - [ ], - "querying the index should return nothing" - ); + is_deeply( + $client->query_index( + $bucket_name => 'index_test_field2_bin', 'plop2' + ), + [], + "querying the index should return nothing" + ); }; diff --git a/t/16_map_reduce.t b/t/16_map_reduce.t index 8665504..cd44241 100644 --- a/t/16_map_reduce.t +++ b/t/16_map_reduce.t @@ -14,7 +14,7 @@ use JSON; subtest "map reduce" => sub { plan tests => 6; - + my ( $host, $port ) = split ':', $ENV{RIAK_PBC_HOST}; my $client = Riak::Light->new( @@ -23,71 +23,73 @@ subtest "map reduce" => sub { ); ok( $client->ping(), "should can ping" ); - ok( $client->is_alive(), "should be alive" ); - - foreach my $key ( @{ $client->get_keys('training') }){ - $client->del( training => $key ); + ok( $client->is_alive(), "should be alive" ); + + foreach my $key ( @{ $client->get_keys('training') } ) { + $client->del( training => $key ); } # FORCE DELETE! $client->del( training => 'foo' ); $client->del( training => 'bar' ); $client->del( training => 'baz' ); - $client->del( training => 'bam' ); - - $client->put( training => foo => 'pizza data goes here' ,'text/plain'); - $client->put( training => bar => 'pizza pizza pizza pizza' ,'text/plain'); - $client->put( training => baz => 'nothing to see here' ,'text/plain'); - $client->put( training => bam => 'pizza pizza pizza' ,'text/plain'); - + $client->del( training => 'bam' ); + + $client->put( training => foo => 'pizza data goes here', 'text/plain' ); + $client->put( training => bar => 'pizza pizza pizza pizza', 'text/plain' ); + $client->put( training => baz => 'nothing to see here', 'text/plain' ); + $client->put( training => bam => 'pizza pizza pizza', 'text/plain' ); + my %expected = ( - 'bar' => 4, - #'baz' => 0, - 'bam' => 3, - 'foo' => 1, + 'bar' => 4, + + #'baz' => 0, + 'bam' => 3, + 'foo' => 1, ); - - + + my $json_hash = { inputs => "training", - query => [{ - map => { - language =>"javascript", - source =>"function(riakObject) { + query => [ + { map => { + language => "javascript", + source => "function(riakObject) { var val = riakObject.values[0].data.match(/pizza/g); return [[riakObject.key, (val ? val.length : 0 )]]; }" - } - }] - }; - + } + } + ] + }; + my $json_string = '{ "inputs":"training", "query":[{"map":{"language":"javascript", "source":"function(riakObject) { var val = riakObject.values[0].data.match(/pizza/g); return [[riakObject.key, (val ? val.length : 0 )]]; - }"}}]}'; - - foreach my $json_query ( $json_string, $json_hash ){ - my $response = $client->map_reduce($json_query); - - # will return something like - #[ - # {'response' => [['foo',1]],'phase' => 0}, - # {'response' => [['bam',3]],'phase' => 0}, - # {'response' => [['bar',4]],'phase' => 0}, - # {'response' => [['baz',0]],'phase' => 0} - #] - # now map the key => value - - my %got = map { - $_->{response}->[0]->[0] => $_->{response}->[0]->[1] - } @{ $response }; - - my $zero = delete $got{baz}; - ok(! $zero, 'should return zero for baz'); - eq_or_diff \%got , \%expected, "should return the proper data structure for query as: " - . ((ref $json_query) ? "reference" : "string") ; + }"}}]}'; + + foreach my $json_query ( $json_string, $json_hash ) { + my $response = $client->map_reduce($json_query); + + # will return something like + #[ + # {'response' => [['foo',1]],'phase' => 0}, + # {'response' => [['bam',3]],'phase' => 0}, + # {'response' => [['bar',4]],'phase' => 0}, + # {'response' => [['baz',0]],'phase' => 0} + #] + # now map the key => value + + my %got = map { $_->{response}->[0]->[0] => $_->{response}->[0]->[1] } + @{$response}; + + my $zero = delete $got{baz}; + ok( !$zero, 'should return zero for baz' ); + eq_or_diff \%got, \%expected, + "should return the proper data structure for query as: " + . ( ( ref $json_query ) ? "reference" : "string" ); } }; diff --git a/t/17_2i_map_reduce.t b/t/17_2i_map_reduce.t index 5349347..d87bfc4 100644 --- a/t/17_2i_map_reduce.t +++ b/t/17_2i_map_reduce.t @@ -14,7 +14,7 @@ use JSON; subtest "map reduce" => sub { plan tests => 2; - + my ( $host, $port ) = split ':', $ENV{RIAK_PBC_HOST}; my $client = Riak::Light->new( @@ -22,30 +22,42 @@ subtest "map reduce" => sub { timeout_provider => undef ); - ok( $client->ping(), "should can ping" ); - + ok( $client->ping(), "should can ping" ); + my $keys = $client->get_keys('training'); - - foreach my $key ( @{ $keys }){ - $client->del( training => $key); + + foreach my $key ( @{$keys} ) { + $client->del( training => $key ); } - - $client->put( training => foo => '...' ,'text/plain', { last_modify_int => 1, tag_bin => ['even', 'odd'] }); - $client->put( training => bar => '...' ,'text/plain', { last_modify_int => 2 }); - $client->put( training => baz => '...' ,'text/plain', { last_modify_int => 3, tag_bin => ['even'] }); - $client->put( training => bam => '...' ,'text/plain', { last_modify_int => 4, tag_bin => ['odd'] }); - + + $client->put( + training => foo => '...', 'text/plain', + { last_modify_int => 1, tag_bin => [ 'even', 'odd' ] } + ); + $client->put( + training => bar => '...', 'text/plain', + { last_modify_int => 2 } + ); + $client->put( + training => baz => '...', 'text/plain', + { last_modify_int => 3, tag_bin => ['even'] } + ); + $client->put( + training => bam => '...', 'text/plain', + { last_modify_int => 4, tag_bin => ['odd'] } + ); + my $json_hash = { inputs => { - bucket => 'training', - index => 'last_modify_int', - start => 2, - end => 3, + bucket => 'training', + index => 'last_modify_int', + start => 2, + end => 3, }, - query => [{ - map => { - language =>"javascript", - source =>"function(riakObject) { + query => [ + { map => { + language => "javascript", + source => "function(riakObject) { var indexes = riakObject.values[0].metadata.index; var tag_bin = indexes.tag_bin; @@ -55,14 +67,19 @@ subtest "map reduce" => sub { ] ] : []; }" - } - }] - }; - + } + } + ] + }; + my $data = []; - $client->map_reduce($json_hash, sub { - ($data, undef) = @_; - }) ; - - eq_or_diff $data, [['baz', 'even' ]], 'should return the map_reduce result'; + $client->map_reduce( + $json_hash, + sub { + ( $data, undef ) = @_; + } + ); + + eq_or_diff $data, [ [ 'baz', 'even' ] ], + 'should return the map_reduce result'; }; diff --git a/t/20_pid_test.t b/t/20_pid_test.t index 95ad5cc..6f36f9b 100644 --- a/t/20_pid_test.t +++ b/t/20_pid_test.t @@ -26,20 +26,20 @@ subtest "should reconnect if PID changes" => sub { ); my $client = Riak::Light->new( - pid => $pid - 1, - host => '127.0.0.1', - port => $server->port, - timeout_provider => undef, - ); + pid => $pid - 1, + host => '127.0.0.1', + port => $server->port, + timeout_provider => undef, + ); my $old_socket = $client->driver->connector->socket; - my $old_pid = $client->pid; + my $old_pid = $client->pid; eval { $client->ping() }; my $new_socket = $client->driver->connector->socket; - my $new_pid = $client->pid; + my $new_pid = $client->pid; isnt $old_socket, $new_socket, 'should not be the same socket'; - isnt $old_pid, $new_pid, 'pid must be updated'; - is $new_pid, $pid, 'must actualize pid with current pid'; + isnt $old_pid, $new_pid, 'pid must be updated'; + is $new_pid, $pid, 'must actualize pid with current pid'; }; diff --git a/t/21_fix_issue_with_pid.pl b/t/21_fix_issue_with_pid.pl index 63e9407..995df8d 100644 --- a/t/21_fix_issue_with_pid.pl +++ b/t/21_fix_issue_with_pid.pl @@ -24,13 +24,13 @@ ); my $client = Riak::Light->new( - host => '127.0.0.1', - port => $server->port, - timeout_provider => undef, - ); + host => '127.0.0.1', + port => $server->port, + timeout_provider => undef, + ); ok $client->has_pid, 'client should has pid'; - + my $client_pid = $client->pid; is $client_pid, $$, 'should create pid with the current pid'; diff --git a/t/80_extra_parameters.t b/t/80_extra_parameters.t index 8eb4fb5..00dac3c 100644 --- a/t/80_extra_parameters.t +++ b/t/80_extra_parameters.t @@ -35,23 +35,24 @@ subtest "fetch" => sub { driver => $mock ); - $client->get( foo => "bar" ); + $client->get( foo => "bar" ); - my ($name, $args) = $mock->next_call; + my ( $name, $args ) = $mock->next_call; - my %params; + my %params; - ( undef, %params )= @$args; - my $request = RpbGetReq->decode($params{body}); + ( undef, %params ) = @$args; + my $request = RpbGetReq->decode( $params{body} ); - is $name, "perform_request", 'should call perform_request'; - is $request->r, 2 , 'should create the request with r = 2'; - is $request->bucket, "foo", 'should create the request with bucket = foo'; - is $request->key, "bar", 'should create the request with key = bar'; - ok !$request->pr, 'pr should not be used'; + is $name, "perform_request", 'should call perform_request'; + is $request->r, 2, 'should create the request with r = 2'; + is $request->bucket, "foo", + 'should create the request with bucket = foo'; + is $request->key, "bar", 'should create the request with key = bar'; + ok !$request->pr, 'pr should not be used'; }; - subtest "fetch simple value with extra parameters" => sub { + subtest "fetch simple value with extra parameters" => sub { plan tests => 5; my $mock = Test::MockObject->new; @@ -77,27 +78,28 @@ subtest "fetch" => sub { driver => $mock ); - $client->get( foo => "bar" ); + $client->get( foo => "bar" ); - my ($name, $args) = $mock->next_call; + my ( $name, $args ) = $mock->next_call; - my %params; + my %params; - ( undef, %params )= @$args; - my $request = RpbGetReq->decode($params{body}); + ( undef, %params ) = @$args; + my $request = RpbGetReq->decode( $params{body} ); - is $name, "perform_request", 'should call perform_request'; - is $request->r, 2 , 'should create the request with r = 2'; - is $request->bucket, "foo", 'should create the request with bucket = foo'; - is $request->key, "bar", 'should create the request with key = bar'; - is $request->pr, 3, 'should create the request with pr = 3'; - }; + is $name, "perform_request", 'should call perform_request'; + is $request->r, 2, 'should create the request with r = 2'; + is $request->bucket, "foo", + 'should create the request with bucket = foo'; + is $request->key, "bar", 'should create the request with key = bar'; + is $request->pr, 3, 'should create the request with pr = 3'; + }; }; subtest "store" => sub { - plan tests => 2; + plan tests => 2; - subtest "store simple data " => sub { + subtest "store simple data " => sub { plan tests => 8; my $mock = Test::MockObject->new; @@ -115,27 +117,29 @@ subtest "store" => sub { driver => $mock ); - $client->put_raw( foo => "bar", "1" ); + $client->put_raw( foo => "bar", "1" ); - my ($name, $args) = $mock->next_call; + my ( $name, $args ) = $mock->next_call; - my %params; + my %params; - ( undef, %params )= @$args; - my $request = RpbPutReq->decode($params{body}); + ( undef, %params ) = @$args; + my $request = RpbPutReq->decode( $params{body} ); - is $name, "perform_request", 'should call perform_request'; - is $request->w, 2 , 'should create the request with w = 2'; - is $request->bucket, "foo", 'should create the request with bucket = foo'; - is $request->key, "bar", 'should create the request with key = bar'; - is $request->dw, 2, 'should create the request with dw = 2'; - ok !$request->pw, 'should has no pw'; - is $request->content->content_type, "plain/text", "content_type should be plain/text"; - is $request->content->value, "1", "value should be 1"; + is $name, "perform_request", 'should call perform_request'; + is $request->w, 2, 'should create the request with w = 2'; + is $request->bucket, "foo", + 'should create the request with bucket = foo'; + is $request->key, "bar", 'should create the request with key = bar'; + is $request->dw, 2, 'should create the request with dw = 2'; + ok !$request->pw, 'should has no pw'; + is $request->content->content_type, "plain/text", + "content_type should be plain/text"; + is $request->content->value, "1", "value should be 1"; }; - subtest "store simple data with extra parameters" => sub { + subtest "store simple data with extra parameters" => sub { plan tests => 8; my $mock = Test::MockObject->new; @@ -153,28 +157,30 @@ subtest "store" => sub { driver => $mock ); - $client->put_raw( foo => "bar", "1" ); + $client->put_raw( foo => "bar", "1" ); - my ($name, $args) = $mock->next_call; + my ( $name, $args ) = $mock->next_call; - my %params; + my %params; - ( undef, %params )= @$args; - my $request = RpbPutReq->decode($params{body}); + ( undef, %params ) = @$args; + my $request = RpbPutReq->decode( $params{body} ); - is $name, "perform_request", 'should call perform_request'; - is $request->w, 2 , 'should create the request with w = 2'; - is $request->bucket, "foo", 'should create the request with bucket = foo'; - is $request->key, "bar", 'should create the request with key = bar'; - is $request->dw, 2, 'should create the request with dw = 2'; - is $request->pw, 1, 'should create the request with pw = 1'; - is $request->content->content_type, "plain/text", "content_type should be plain/text"; - is $request->content->value, "1", "value should be 1"; + is $name, "perform_request", 'should call perform_request'; + is $request->w, 2, 'should create the request with w = 2'; + is $request->bucket, "foo", + 'should create the request with bucket = foo'; + is $request->key, "bar", 'should create the request with key = bar'; + is $request->dw, 2, 'should create the request with dw = 2'; + is $request->pw, 1, 'should create the request with pw = 1'; + is $request->content->content_type, "plain/text", + "content_type should be plain/text"; + is $request->content->value, "1", "value should be 1"; }; }; subtest "delete" => sub { - plan tests => 2; + plan tests => 2; subtest "del simple data " => sub { plan tests => 9; @@ -196,24 +202,25 @@ subtest "delete" => sub { $client->del( foo => "bar" ); - my ($name, $args) = $mock->next_call; + my ( $name, $args ) = $mock->next_call; - my %params; + my %params; - ( undef, %params )= @$args; - my $request = RpbDelReq->decode($params{body}); + ( undef, %params ) = @$args; + my $request = RpbDelReq->decode( $params{body} ); - is $name, "perform_request", 'should call perform_request'; - is $request->w, 2 , 'should create the request with w = 2'; - is $request->r, 2 , 'should create the request with r = 2'; - is $request->dw, 2, 'should create the request with dw = 2'; - - is $request->bucket, "foo", 'should create the request with bucket = foo'; - is $request->key, "bar", 'should create the request with key = bar'; + is $name, "perform_request", 'should call perform_request'; + is $request->w, 2, 'should create the request with w = 2'; + is $request->r, 2, 'should create the request with r = 2'; + is $request->dw, 2, 'should create the request with dw = 2'; - ok !$request->rw, 'should has no rw'; - ok !$request->pr, 'should has no pr'; - ok !$request->pw, 'should has no pw'; + is $request->bucket, "foo", + 'should create the request with bucket = foo'; + is $request->key, "bar", 'should create the request with key = bar'; + + ok !$request->rw, 'should has no rw'; + ok !$request->pr, 'should has no pr'; + ok !$request->pw, 'should has no pw'; }; subtest "del simple data with extra parameters" => sub { @@ -231,30 +238,31 @@ subtest "delete" => sub { my $client = Riak::Light->new( host => 'host', port => 1234, autodie => 1, - rw => 1, pr => 2, pw => 3, + rw => 1, pr => 2, pw => 3, driver => $mock ); $client->del( foo => "bar" ); - my ($name, $args) = $mock->next_call; + my ( $name, $args ) = $mock->next_call; + + my %params; - my %params; + ( undef, %params ) = @$args; + my $request = RpbDelReq->decode( $params{body} ); - ( undef, %params )= @$args; - my $request = RpbDelReq->decode($params{body}); + is $name, "perform_request", 'should call perform_request'; + is $request->w, 2, 'should create the request with w = 2'; + is $request->r, 2, 'should create the request with r = 2'; + is $request->dw, 2, 'should create the request with dw = 2'; - is $name, "perform_request", 'should call perform_request'; - is $request->w, 2 , 'should create the request with w = 2'; - is $request->r, 2 , 'should create the request with r = 2'; - is $request->dw, 2, 'should create the request with dw = 2'; - - is $request->bucket, "foo", 'should create the request with bucket = foo'; - is $request->key, "bar", 'should create the request with key = bar'; + is $request->bucket, "foo", + 'should create the request with bucket = foo'; + is $request->key, "bar", 'should create the request with key = bar'; - is $request->rw, 1, 'should create the request with rw = 1'; - is $request->pr, 2, 'should create the request with pr = 2'; - is $request->pw, 3, 'should create the request with pw = 3'; + is $request->rw, 1, 'should create the request with rw = 1'; + is $request->pr, 2, 'should create the request with pr = 2'; + is $request->pw, 3, 'should create the request with pw = 3'; }; -}; \ No newline at end of file +}; diff --git a/t/90_client_id.t b/t/90_client_id.t index a312ecd..ced41a8 100644 --- a/t/90_client_id.t +++ b/t/90_client_id.t @@ -18,6 +18,6 @@ my $client = Riak::Light->new( timeout_provider => undef ); -is $client->set_client_id('ID'), 1, 'can set' ; +is $client->set_client_id('ID'), 1, 'can set'; -is $client->get_client_id, 'ID', 'should return the client id'; \ No newline at end of file +is $client->get_client_id, 'ID', 'should return the client id'; diff --git a/t/99_memory_lead.t b/t/99_memory_lead.t index 56b3185..5484943 100644 --- a/t/99_memory_lead.t +++ b/t/99_memory_lead.t @@ -13,47 +13,50 @@ use Test::LeakTrace; use Riak::Light; no_leaks_ok { - - my ( $host, $port ) = split ':', $ENV{RIAK_PBC_HOST}; + + my ( $host, $port ) = split ':', $ENV{RIAK_PBC_HOST}; my $client = Riak::Light->new( host => $host, port => $port, timeout_provider => undef ); - $client->put(foo => bar => { my => 666}); - $client->get(foo => 'bar'); - $client->del(foo => 'bar'); -} ' should be ok for no timeout_provider'; + $client->put( foo => bar => { my => 666 } ); + $client->get( foo => 'bar' ); + $client->del( foo => 'bar' ); +} +' should be ok for no timeout_provider'; my ( $host, $port ) = split ':', $ENV{RIAK_PBC_HOST}; my $client = Riak::Light->new( - host => $host, port => $port, - timeout_provider => 'Riak::Light::Timeout::Select' + host => $host, port => $port, + timeout_provider => 'Riak::Light::Timeout::Select' ); no_leaks_ok { - for(1..2){ - $client->put(foo => bar => { my => 666}); - $client->get(foo => 'bar'); - $client->del(foo => 'bar'); - } -} ' should be ok for setsockopt timeout_provider'; + for ( 1 .. 2 ) { + $client->put( foo => bar => { my => 666 } ); + $client->get( foo => 'bar' ); + $client->del( foo => 'bar' ); + } +} +' should be ok for setsockopt timeout_provider'; leaktrace { - - $client->put(foo => bar => { my => 666}); - $client->get(foo => 'bar'); - $client->del(foo => 'bar'); -} ; + + $client->put( foo => bar => { my => 666 } ); + $client->get( foo => 'bar' ); + $client->del( foo => 'bar' ); +}; no_leaks_ok { -my $client2 = Riak::Light->new( + my $client2 = Riak::Light->new( host => $host, port => $port, timeout_provider => 'Riak::Light::Timeout::Select' -); - $client2->put(foo => bar => { my => 666}); - $client2->get(foo => 'bar'); - $client2->del(foo => 'bar'); -} ' should be ok for setsockopt timeout_provider'; + ); + $client2->put( foo => bar => { my => 666 } ); + $client2->get( foo => 'bar' ); + $client2->del( foo => 'bar' ); +} +' should be ok for setsockopt timeout_provider'; diff --git a/t/99_no_namespace_autoclean.t b/t/99_no_namespace_autoclean.t index f222b3a..1e16874 100644 --- a/t/99_no_namespace_autoclean.t +++ b/t/99_no_namespace_autoclean.t @@ -3,5 +3,6 @@ use Test::More tests => 2; use Riak::Light; ok( !defined $namespace::autoclean::VERSION, - "should not load namespace::autoclean" ); + "should not load namespace::autoclean" +); ok( !defined $Class::MOP::VERSION, "should not load Class::MOP" ); diff --git a/t/99_test_util.t b/t/99_test_util.t index 42e7a2c..01b16b2 100644 --- a/t/99_test_util.t +++ b/t/99_test_util.t @@ -18,4 +18,4 @@ subtest "is solaris" => sub { require Riak::Light::Util; is( Riak::Light::Util::is_solaris(), $Config{osname} eq 'solaris' ); -}; \ No newline at end of file +}; diff --git a/t/tlib/TestTimeout.pm b/t/tlib/TestTimeout.pm index 9f8f533..21ebfda 100644 --- a/t/tlib/TestTimeout.pm +++ b/t/tlib/TestTimeout.pm @@ -49,7 +49,7 @@ sub create_server_with_timeout { } sub test_timeout { - my $provider = shift; + my $provider = shift; my $provider_name = $provider // "undef"; subtest