internal static Cell FromTsCell(TsCell tsc) { if (tsc.boolean_valueSpecified) { return(new Cell <bool>(tsc.boolean_value)); } else if (tsc.double_valueSpecified) { return(new Cell <double>(tsc.double_value)); } else if (tsc.sint64_valueSpecified) { return(new Cell <long>(tsc.sint64_value)); } else if (tsc.timestamp_valueSpecified) { return(new Cell <DateTime>( DateTimeUtil.FromUnixTimeMillis(tsc.timestamp_value))); } else if (tsc.varchar_valueSpecified) { return(new Cell <string>(RiakString.FromBytes(tsc.varchar_value))); } return(new Cell()); }
public void Should_Build_Req() { var cmd = new Get.Builder() .WithTable(Table) .WithKey(Key) .Build(); Assert.AreEqual(MessageCode.TsGetResp, cmd.ExpectedCode); TsGetReq pb = (TsGetReq)cmd.ConstructPbRequest(); Assert.AreEqual(Table, RiakString.FromBytes(pb.table)); Assert.IsFalse(pb.timeoutSpecified); Assert.True(pb.key[0].boolean_valueSpecified); Assert.AreEqual(Cells0[0].AsObject, pb.key[0].boolean_value); Assert.True(pb.key[1].double_valueSpecified); Assert.AreEqual(Cells0[1].AsObject, pb.key[1].double_value); Assert.True(pb.key[2].sint64_valueSpecified); Assert.AreEqual(Cells0[2].AsObject, pb.key[2].sint64_value); var dt = (DateTime)Cells0[3].AsObject; Assert.True(pb.key[3].timestamp_valueSpecified); Assert.AreEqual(DateTimeUtil.ToUnixTimeMillis(dt), pb.key[3].timestamp_value); var s = RiakString.ToBytes((string)Cells0[4].AsObject); Assert.True(pb.key[4].varchar_valueSpecified); CollectionAssert.AreEqual(s, pb.key[4].varchar_value); }
public IEnumerable <RiakString> GetValueAsRiakStrings(RiakString key) { IEnumerable <RiakString> valueAsRiakStrings = null; IList <byte[]> value = null; if (TryGetValue(key, out value)) { valueAsRiakStrings = value.Select(v => RiakString.FromBytes(v)); } return(valueAsRiakStrings); }
public void Should_Build_Req() { Store cmd = BuildStoreReq(); Assert.AreEqual(MessageCode.TsPutResp, cmd.ExpectedCode); TsPutReq pb = (TsPutReq)cmd.ConstructPbRequest(); Assert.AreEqual(Table, RiakString.FromBytes(pb.table)); CollectionAssert.AreEqual(TsCols, pb.columns); CollectionAssert.AreEqual(TsRows, pb.rows); }
public void Should_Build_Req_With_Timeout() { Get cmd = BuildGetReqWithTimeout(); Assert.AreEqual(MessageCode.TsGetResp, cmd.ExpectedCode); TsGetReq pb = (TsGetReq)cmd.ConstructRequest(false); Assert.AreEqual(Table, RiakString.FromBytes(pb.table)); Assert.IsTrue(pb.timeoutSpecified); Assert.AreEqual(Timeout.TotalMilliseconds, pb.timeout); }
public void Should_Build_Req() { var cmd = new ListKeys.Builder() .WithTable(Table) .Build(); Assert.AreEqual(MessageCode.TsListKeysResp, cmd.ExpectedCode); TsListKeysReq pb = (TsListKeysReq)cmd.ConstructPbRequest(); Assert.AreEqual(Table, RiakString.FromBytes(pb.table)); Assert.IsFalse(pb.timeoutSpecified); }
public void Should_Build_Req_Correctly() { var fetch = new FetchPreflist.Builder() .WithBucketType(BucketType) .WithBucket(Bucket) .WithKey(Key) .Build(); RpbGetBucketKeyPreflistReq protobuf = (RpbGetBucketKeyPreflistReq)fetch.ConstructPbRequest(); Assert.AreEqual(BucketType, RiakString.FromBytes(protobuf.type)); Assert.AreEqual(Bucket, RiakString.FromBytes(protobuf.bucket)); Assert.AreEqual(Key, RiakString.FromBytes(protobuf.key)); }
public void Should_Build_Req_With_Timeout() { var cmd = new Delete.Builder() .WithTable(Table) .WithKey(Key) .WithTimeout(Timeout) .Build(); Assert.AreEqual(MessageCode.TsDelResp, cmd.ExpectedCode); TsDelReq pb = (TsDelReq)cmd.ConstructPbRequest(); Assert.AreEqual(Table, RiakString.FromBytes(pb.table)); Assert.IsTrue(pb.timeoutSpecified); Assert.AreEqual(Timeout.TotalMilliseconds, pb.timeout); }
public void Should_Build_Req() { var cmd = new Query.Builder() .WithTable(Table) .WithQuery(Query) .Build(); Assert.AreEqual(MessageCode.TsQueryResp, cmd.ExpectedCode); TsQueryReq pb = (TsQueryReq)cmd.ConstructPbRequest(); Assert.AreEqual(QueryRS, RiakString.FromBytes(pb.query.@base)); // NB: Query always streams Assert.IsTrue(pb.streamSpecified); Assert.IsTrue(pb.stream); }
public DecodedResponse Decode() { IEnumerable <Column> cols = Enumerable.Empty <Column>(); if (EnumerableUtil.NotNullOrEmpty(tscols)) { cols = tscols.Select(tsc => new Column(RiakString.FromBytes(tsc.name), (ColumnType)tsc.type)); } IEnumerable <Row> rows = Enumerable.Empty <Row>(); if (EnumerableUtil.NotNullOrEmpty(tsrows)) { rows = tsrows.Select(tsr => new Row(tsr)); } return(new DecodedResponse(cols, rows)); }
public void Should_Build_Req_With_Streaming() { Action <QueryResponse> cb = (QueryResponse qr) => { }; var cmd = new Query.Builder() .WithTable(Table) .WithQuery(Query) .WithCallback(cb) .Build(); Assert.AreEqual(MessageCode.TsQueryResp, cmd.ExpectedCode); TsQueryReq pb = (TsQueryReq)cmd.ConstructRequest(false); Assert.AreEqual(QueryRS, RiakString.FromBytes(pb.query.@base)); // NB: Query always streams Assert.IsTrue(pb.streamSpecified); Assert.IsTrue(pb.stream); }
private ResponseDecoder( IEnumerable <TsColumnDescription> tscols, IEnumerable <TsRow> tsrows) { IEnumerable <Column> cols = Enumerable.Empty <Column>(); if (EnumerableUtil.NotNullOrEmpty(tscols)) { cols = tscols.Select(tsc => new Column(RiakString.FromBytes(tsc.name), (ColumnType)tsc.type)); } IEnumerable <Row> rows = Enumerable.Empty <Row>(); if (EnumerableUtil.NotNullOrEmpty(tsrows)) { rows = tsrows.Select(tsr => new Row(tsr, tscols.ToArray())); } decodedResponse = new DecodedResponse(cols, rows); }
public override void OnSuccess(RpbResp response) { if (response == null) { Response = new PreflistResponse(); } else { RpbGetBucketKeyPreflistResp resp = (RpbGetBucketKeyPreflistResp)response; IEnumerable <PreflistItem> preflistItems = Enumerable.Empty <PreflistItem>(); if (EnumerableUtil.NotNullOrEmpty(resp.preflist)) { preflistItems = resp.preflist.Select(i => new PreflistItem(RiakString.FromBytes(i.node), i.partition, i.primary)); } Response = new PreflistResponse(Options.Key, preflistItems); } }
public void Should_Build_DtFetchReq_Correctly() { var fetch = new FetchCounter.Builder() .WithBucketType(BucketType) .WithBucket(Bucket) .WithKey(Key) .WithR((Quorum)1) .WithPR((Quorum)2) .WithNotFoundOK(true) .WithBasicQuorum(true) .WithTimeout(TimeSpan.FromMilliseconds(20000)) .Build(); DtFetchReq protobuf = (DtFetchReq)fetch.ConstructPbRequest(); Assert.AreEqual(BucketType, RiakString.FromBytes(protobuf.type)); Assert.AreEqual(Bucket, RiakString.FromBytes(protobuf.bucket)); Assert.AreEqual(Key, RiakString.FromBytes(protobuf.key)); Assert.AreEqual(1, protobuf.r); Assert.AreEqual(2, protobuf.pr); Assert.AreEqual(true, protobuf.notfound_ok); Assert.AreEqual(true, protobuf.basic_quorum); Assert.AreEqual(20000, protobuf.timeout); }