def test_encode_data_for_put(self):
        c = PbufCodec()
        tsobj = TsObject(None, self.table, self.rows, None)
        msg = c.encode_timeseries_put(tsobj)
        req = riak.pb.riak_ts_pb2.TsPutReq()
        req.ParseFromString(msg.data)

        # NB: expected, actual
        self.assertEqual(self.table.name, bytes_to_str(req.table))
        self.assertEqual(len(self.rows), len(req.rows))

        r0 = req.rows[0]
        self.assertEqual(bytes_to_str(r0.cells[0].varchar_value),
                         self.rows[0][0])
        self.assertEqual(r0.cells[1].sint64_value, self.rows[0][1])
        self.assertEqual(r0.cells[2].double_value, self.rows[0][2])
        self.assertEqual(r0.cells[3].timestamp_value, self.ts0ms)
        self.assertEqual(r0.cells[4].boolean_value, self.rows[0][4])
        self.assertFalse(r0.cells[5].HasField('varchar_value'))

        r1 = req.rows[1]
        self.assertEqual(bytes_to_str(r1.cells[0].varchar_value),
                         self.rows[1][0])
        self.assertEqual(r1.cells[1].sint64_value, self.rows[1][1])
        self.assertEqual(r1.cells[2].double_value, self.rows[1][2])
        self.assertEqual(r1.cells[3].timestamp_value, self.ts1ms)
        self.assertEqual(r1.cells[4].boolean_value, self.rows[1][4])
        self.assertEqual(r1.cells[5].varchar_value, self.rows[1][5])
 def test_encode_data_for_listkeys(self):
     c = PbufCodec(client_timeouts=True)
     msg = c.encode_timeseries_listkeysreq(self.table, 1234)
     req = riak.pb.riak_ts_pb2.TsListKeysReq()
     req.ParseFromString(msg.data)
     self.assertEqual(self.table.name, bytes_to_str(req.table))
     self.assertEqual(1234, req.timeout)
示例#3
0
    def test_encode_data_for_put(self):
        c = PbufCodec()
        tsobj = TsObject(None, self.table, self.rows, None)
        msg = c.encode_timeseries_put(tsobj)
        req = riak.pb.riak_ts_pb2.TsPutReq()
        req.ParseFromString(msg.data)

        # NB: expected, actual
        self.assertEqual(self.table.name, bytes_to_str(req.table))
        self.assertEqual(len(self.rows), len(req.rows))

        r0 = req.rows[0]
        self.assertEqual(bytes_to_str(r0.cells[0].varchar_value),
                         self.rows[0][0])
        self.assertEqual(r0.cells[1].sint64_value, self.rows[0][1])
        self.assertEqual(r0.cells[2].double_value, self.rows[0][2])
        self.assertEqual(r0.cells[3].timestamp_value, self.ts0ms)
        self.assertEqual(r0.cells[4].boolean_value, self.rows[0][4])
        self.assertFalse(r0.cells[5].HasField('varchar_value'))

        r1 = req.rows[1]
        self.assertEqual(bytes_to_str(r1.cells[0].varchar_value),
                         self.rows[1][0])
        self.assertEqual(r1.cells[1].sint64_value, self.rows[1][1])
        self.assertEqual(r1.cells[2].double_value, self.rows[1][2])
        self.assertEqual(r1.cells[3].timestamp_value, self.ts1ms)
        self.assertEqual(r1.cells[4].boolean_value, self.rows[1][4])
        self.assertEqual(r1.cells[5].varchar_value, self.rows[1][5])
示例#4
0
 def test_encode_data_for_delete(self):
     c = PbufCodec()
     msg = c.encode_timeseries_keyreq(
             self.table, self.test_key, is_delete=True)
     req = riak.pb.riak_ts_pb2.TsDelReq()
     req.ParseFromString(msg.data)
     self.validate_keyreq(req)
示例#5
0
 def test_encode_data_for_listkeys(self):
     c = PbufCodec(client_timeouts=True)
     msg = c.encode_timeseries_listkeysreq(self.table, 1234)
     req = riak.pb.riak_ts_pb2.TsListKeysReq()
     req.ParseFromString(msg.data)
     self.assertEqual(self.table.name, bytes_to_str(req.table))
     self.assertEqual(1234, req.timeout)
示例#6
0
 def test_encode_data_for_delete(self):
     c = PbufCodec()
     msg = c.encode_timeseries_keyreq(
             self.table, self.test_key, is_delete=True)
     req = riak.pb.riak_ts_pb2.TsDelReq()
     req.ParseFromString(msg.data)
     self.validate_keyreq(req)
示例#7
0
 def get_server_info(self):
     """
     Get information about the server
     """
     # NB: can't do it this way due to recursion
     # codec = self._get_codec(ttb_supported=False)
     codec = PbufCodec()
     msg = Msg(riak.pb.messages.MSG_CODE_GET_SERVER_INFO_REQ, None,
               riak.pb.messages.MSG_CODE_GET_SERVER_INFO_RESP)
     resp_code, resp = self._request(msg, codec)
     return codec.decode_get_server_info(resp)
示例#8
0
 def get_server_info(self):
     """
     Get information about the server
     """
     # NB: can't do it this way due to recursion
     # codec = self._get_codec(ttb_supported=False)
     codec = PbufCodec()
     msg = Msg(riak.pb.messages.MSG_CODE_GET_SERVER_INFO_REQ, None,
               riak.pb.messages.MSG_CODE_GET_SERVER_INFO_RESP)
     resp_code, resp = self._request(msg, codec)
     return codec.decode_get_server_info(resp)
示例#9
0
 def _get_pbuf_codec(self):
     if not self._pbuf_c:
         self._pbuf_c = PbufCodec(self.client_timeouts(),
                                  self.quorum_controls(),
                                  self.tombstone_vclocks(),
                                  self.bucket_types())
     return self._pbuf_c
示例#10
0
 def _auth(self):
     """
     Perform an authorization request against Riak
     returns True upon success, False otherwise
     Note: Riak will sleep for a short period of time upon a failed
           auth request/response to prevent denial of service attacks
     """
     codec = PbufCodec()
     username = self._client._credentials.username
     password = self._client._credentials.password
     if not password:
         password = ''
     msg = codec.encode_auth(username, password)
     resp_code, _ = self._non_connect_send_recv_msg(msg)
     if resp_code == riak.pb.messages.MSG_CODE_AUTH_RESP:
         return True
     else:
         return False
示例#11
0
 def _auth(self):
     """
     Perform an authorization request against Riak
     returns True upon success, False otherwise
     Note: Riak will sleep for a short period of time upon a failed
           auth request/response to prevent denial of service attacks
     """
     codec = PbufCodec()
     username = self._client._credentials.username
     password = self._client._credentials.password
     if not password:
         password = ''
     msg = codec.encode_auth(username, password)
     resp_code, _ = self._non_connect_send_recv_msg(msg)
     if resp_code == riak.pb.messages.MSG_CODE_AUTH_RESP:
         return True
     else:
         return False
    def test_decode_data_from_query(self):
        tqr = riak.pb.riak_ts_pb2.TsQueryResp()

        c0 = tqr.columns.add()
        c0.name = str_to_bytes('col_varchar')
        c0.type = TsColumnType.Value('VARCHAR')
        c1 = tqr.columns.add()
        c1.name = str_to_bytes('col_integer')
        c1.type = TsColumnType.Value('SINT64')
        c2 = tqr.columns.add()
        c2.name = str_to_bytes('col_double')
        c2.type = TsColumnType.Value('DOUBLE')
        c3 = tqr.columns.add()
        c3.name = str_to_bytes('col_timestamp')
        c3.type = TsColumnType.Value('TIMESTAMP')
        c4 = tqr.columns.add()
        c4.name = str_to_bytes('col_boolean')
        c4.type = TsColumnType.Value('BOOLEAN')
        c5 = tqr.columns.add()
        c5.name = str_to_bytes('col_blob')
        c5.type = TsColumnType.Value('BLOB')

        r0 = tqr.rows.add()
        r0c0 = r0.cells.add()
        r0c0.varchar_value = str_to_bytes(self.rows[0][0])
        r0c1 = r0.cells.add()
        r0c1.sint64_value = self.rows[0][1]
        r0c2 = r0.cells.add()
        r0c2.double_value = self.rows[0][2]
        r0c3 = r0.cells.add()
        r0c3.timestamp_value = self.ts0ms
        r0c4 = r0.cells.add()
        r0c4.boolean_value = self.rows[0][4]
        r0.cells.add()

        r1 = tqr.rows.add()
        r1c0 = r1.cells.add()
        r1c0.varchar_value = str_to_bytes(self.rows[1][0])
        r1c1 = r1.cells.add()
        r1c1.sint64_value = self.rows[1][1]
        r1c2 = r1.cells.add()
        r1c2.double_value = self.rows[1][2]
        r1c3 = r1.cells.add()
        r1c3.timestamp_value = self.ts1ms
        r1c4 = r1.cells.add()
        r1c4.boolean_value = self.rows[1][4]
        r1c5 = r1.cells.add()
        r1c5.varchar_value = self.rows[1][5]

        tsobj = TsObject(None, self.table)
        c = PbufCodec()
        c.decode_timeseries(tqr, tsobj, True)

        self.assertEqual(len(tsobj.rows), len(self.rows))
        self.assertEqual(len(tsobj.columns.names), len(tqr.columns))
        self.assertEqual(len(tsobj.columns.types), len(tqr.columns))

        cn, ct = tsobj.columns
        self.assertEqual(cn[0], 'col_varchar')
        self.assertEqual(ct[0], 'varchar')
        self.assertEqual(cn[1], 'col_integer')
        self.assertEqual(ct[1], 'sint64')
        self.assertEqual(cn[2], 'col_double')
        self.assertEqual(ct[2], 'double')
        self.assertEqual(cn[3], 'col_timestamp')
        self.assertEqual(ct[3], 'timestamp')
        self.assertEqual(cn[4], 'col_boolean')
        self.assertEqual(ct[4], 'boolean')
        self.assertEqual(cn[5], 'col_blob')
        self.assertEqual(ct[5], 'blob')

        r0 = tsobj.rows[0]
        self.assertEqual(bytes_to_str(r0[0]), self.rows[0][0])
        self.assertEqual(r0[1], self.rows[0][1])
        self.assertEqual(r0[2], self.rows[0][2])
        self.assertEqual(r0[3], ts0)
        self.assertEqual(r0[4], self.rows[0][4])
        self.assertEqual(r0[5], self.rows[0][5])

        r1 = tsobj.rows[1]
        self.assertEqual(bytes_to_str(r1[0]), self.rows[1][0])
        self.assertEqual(r1[1], self.rows[1][1])
        self.assertEqual(r1[2], self.rows[1][2])
        self.assertEqual(r1[3], ts1)
        self.assertEqual(r1[4], self.rows[1][4])
        self.assertEqual(r1[5], self.rows[1][5])
示例#13
0
    def test_decode_data_from_query(self):
        tqr = riak.pb.riak_ts_pb2.TsQueryResp()

        c0 = tqr.columns.add()
        c0.name = str_to_bytes('col_varchar')
        c0.type = TsColumnType.Value('VARCHAR')
        c1 = tqr.columns.add()
        c1.name = str_to_bytes('col_integer')
        c1.type = TsColumnType.Value('SINT64')
        c2 = tqr.columns.add()
        c2.name = str_to_bytes('col_double')
        c2.type = TsColumnType.Value('DOUBLE')
        c3 = tqr.columns.add()
        c3.name = str_to_bytes('col_timestamp')
        c3.type = TsColumnType.Value('TIMESTAMP')
        c4 = tqr.columns.add()
        c4.name = str_to_bytes('col_boolean')
        c4.type = TsColumnType.Value('BOOLEAN')
        c5 = tqr.columns.add()
        c5.name = str_to_bytes('col_blob')
        c5.type = TsColumnType.Value('BLOB')

        r0 = tqr.rows.add()
        r0c0 = r0.cells.add()
        r0c0.varchar_value = str_to_bytes(self.rows[0][0])
        r0c1 = r0.cells.add()
        r0c1.sint64_value = self.rows[0][1]
        r0c2 = r0.cells.add()
        r0c2.double_value = self.rows[0][2]
        r0c3 = r0.cells.add()
        r0c3.timestamp_value = self.ts0ms
        r0c4 = r0.cells.add()
        r0c4.boolean_value = self.rows[0][4]
        r0.cells.add()

        r1 = tqr.rows.add()
        r1c0 = r1.cells.add()
        r1c0.varchar_value = str_to_bytes(self.rows[1][0])
        r1c1 = r1.cells.add()
        r1c1.sint64_value = self.rows[1][1]
        r1c2 = r1.cells.add()
        r1c2.double_value = self.rows[1][2]
        r1c3 = r1.cells.add()
        r1c3.timestamp_value = self.ts1ms
        r1c4 = r1.cells.add()
        r1c4.boolean_value = self.rows[1][4]
        r1c5 = r1.cells.add()
        r1c5.varchar_value = self.rows[1][5]

        tsobj = TsObject(None, self.table)
        c = PbufCodec()
        c.decode_timeseries(tqr, tsobj, True)

        self.assertEqual(len(tsobj.rows), len(self.rows))
        self.assertEqual(len(tsobj.columns.names), len(tqr.columns))
        self.assertEqual(len(tsobj.columns.types), len(tqr.columns))

        cn, ct = tsobj.columns
        self.assertEqual(cn[0], 'col_varchar')
        self.assertEqual(ct[0], 'varchar')
        self.assertEqual(cn[1], 'col_integer')
        self.assertEqual(ct[1], 'sint64')
        self.assertEqual(cn[2], 'col_double')
        self.assertEqual(ct[2], 'double')
        self.assertEqual(cn[3], 'col_timestamp')
        self.assertEqual(ct[3], 'timestamp')
        self.assertEqual(cn[4], 'col_boolean')
        self.assertEqual(ct[4], 'boolean')
        self.assertEqual(cn[5], 'col_blob')
        self.assertEqual(ct[5], 'blob')

        r0 = tsobj.rows[0]
        self.assertEqual(bytes_to_str(r0[0]), self.rows[0][0])
        self.assertEqual(r0[1], self.rows[0][1])
        self.assertEqual(r0[2], self.rows[0][2])
        self.assertEqual(r0[3], ts0)
        self.assertEqual(r0[4], self.rows[0][4])
        self.assertEqual(r0[5], self.rows[0][5])

        r1 = tsobj.rows[1]
        self.assertEqual(bytes_to_str(r1[0]), self.rows[1][0])
        self.assertEqual(r1[1], self.rows[1][1])
        self.assertEqual(r1[2], self.rows[1][2])
        self.assertEqual(r1[3], ts1)
        self.assertEqual(r1[4], self.rows[1][4])
        self.assertEqual(r1[5], self.rows[1][5])