Esempio n. 1
0
        public override RiakReq ConstructRequest(bool useTtb)
        {
            if (useTtb)
            {
                expectedCode = MessageCode.TsTtbMsg;
                usingTtb     = true;

                using (var os = new OtpOutputStream())
                {
                    os.WriteByte(OtpExternal.VersionTag);

                    // TsQueryReq is a 4-tuple: {'tsqueryreq', TsInterpolation, boolIsStreaming, bytesCoverContext}
                    os.WriteTupleHead(4);
                    os.WriteAtom(TsQueryReqAtom);

                    // TsInterpolation is a 3-tuple
                    // {'tsinterpolation', query, []} empty list is interpolations
                    os.WriteTupleHead(3);
                    os.WriteAtom(TsInterpolationAtom);
                    os.WriteStringAsBinary(CommandOptions.Query);
                    os.WriteNil();

                    os.WriteBoolean(false);
                    os.WriteAtom(UndefinedAtom);
                    os.Flush();

                    return(new TsTtbMsg(os.ToArray()));
                }
            }
            else
            {
                var req = new TsQueryReq();

                req.query = new TsInterpolation
                {
                    @base = CommandOptions.Query
                };

                // NB: always stream, collect results unless callback is passed.
                req.stream = true;

                return(req);
            }
        }
        public void Write_Atom()
        {
            byte[] want = { 131, 100, 0, 18, 102, 114, 97, 122, 122, 108, 101, 100, 97, 122, 122, 108, 101, 45, 49, 50, 51, 52 };
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.Write(OtpExternal.VersionTag);
                os.WriteAtom("frazzledazzle-1234");
                Assert.AreEqual(want.Length, os.Position);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }
        public void Can_Parse_Bare_RpbErrorResp()
        {
            byte[] b = null;
            using (var os = new OtpOutputStream())
            {
                os.WriteAtom(TtbErrorDecoder.RpbErrorRespAtom);
                os.Flush();
                b = os.ToArray();
            }

            var ex = Assert.Throws <RiakException>(() => new TsTtbResp(b));

            Assert.IsTrue(ex.Message.Contains(TtbErrorDecoder.RpbErrorRespEmpty));
        }
        public void Can_Parse_RpbErrorResp_In_2_Tuple_With_Code()
        {
            byte[] b = null;
            using (var os = new OtpOutputStream())
            {
                os.WriteTupleHead(2);
                os.WriteAtom(TtbErrorDecoder.RpbErrorRespAtom);
                os.WriteLong(ErrCode);
                os.Flush();
                b = os.ToArray();
            }

            var ex = Assert.Throws <RiakException>(() => new TsTtbResp(b));

            Assert.IsTrue(ex.Message.Contains(ErrCode.ToString()));
        }
Esempio n. 5
0
        // TODO FUTURE this all really should be in a codec
        public override RiakReq ConstructRequest(bool useTtb)
        {
            RiakReq rv;

            if (useTtb)
            {
                usingTtb     = true;
                expectedCode = MessageCode.TsTtbMsg;

                byte[]            buffer;
                string            tableName = CommandOptions.Table;
                ICollection <Row> rows      = CommandOptions.Rows;

                using (var os = new OtpOutputStream())
                {
                    os.WriteByte(OtpExternal.VersionTag);

                    // {tsputreq, tableName, emptyList, rows}
                    os.WriteTupleHead(4);
                    os.WriteAtom(TsPutReqAtom);
                    os.WriteStringAsBinary(tableName);
                    os.WriteNil();

                    if (rows.Count > 0)
                    {
                        os.WriteListHead(rows.Count);

                        foreach (Row r in CommandOptions.Rows)
                        {
                            os.WriteTupleHead(r.Cells.Count);
                            foreach (Cell c in r.Cells)
                            {
                                c.ToTtbCell(os);
                            }
                        }

                        os.WriteNil();
                    }
                    else
                    {
                        os.WriteNil();
                    }

                    buffer = os.ToArray();
                }

                rv = new TsTtbMsg(buffer);
            }
            else
            {
                var req = new TsPutReq();

                req.table = CommandOptions.Table;

                if (EnumerableUtil.NotNullOrEmpty(CommandOptions.Columns))
                {
                    req.columns.AddRange(CommandOptions.Columns.Select(c => c.ToTsColumn()));
                }

                req.rows.AddRange(CommandOptions.Rows.Select(r => r.ToTsRow()));

                rv = req;
            }

            return(rv);
        }