public void Should_Construct_CounterResponse_From_DtUpdateResp()
        {
            var key     = new RiakString("riak_generated_key");
            var context = new RiakString("1234");

            var updateResp = new DtUpdateResp();

            updateResp.key           = key;
            updateResp.context       = context;
            updateResp.counter_value = DefaultIncrement;

            var update = new UpdateCounter.Builder(DefaultIncrement)
                         .WithBucketType(BucketType)
                         .WithBucket(Bucket)
                         .Build();

            update.OnSuccess(updateResp);

            CounterResponse response = update.Response;

            Assert.NotNull(response);
            Assert.AreEqual(key, response.Key);
            Assert.AreEqual(RiakString.ToBytes(context), response.Context);
            Assert.AreEqual(DefaultIncrement, response.Value);
        }
Exemple #2
0
        public void Should_Construct_PreflistResponse_From_Resp()
        {
            string node_name   = "node-foo";
            long   partitionId = long.MaxValue;

            var preflistItem = new RpbBucketKeyPreflistItem();

            preflistItem.node      = RiakString.ToBytes(node_name);
            preflistItem.partition = partitionId;
            preflistItem.primary   = true;

            var fetchResp = new RpbGetBucketKeyPreflistResp();

            fetchResp.preflist.Add(preflistItem);

            var fetch = new FetchPreflist.Builder()
                        .WithBucketType(BucketType)
                        .WithBucket(Bucket)
                        .WithKey(Key)
                        .Build();

            fetch.OnSuccess(fetchResp);

            Assert.AreEqual(1, fetch.Response.Value.Count());
        }
        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);
        }
 internal TsColumnDescription ToTsColumn()
 {
     return(new TsColumnDescription
     {
         name = RiakString.ToBytes(name),
         type = (TsColumnType)type
     });
 }
Exemple #5
0
        public Cell(object value, ColumnType valueType)
        {
            if (value == null)
            {
                isNull         = true;
                this.valueType = ColumnType.Null;
            }
            else
            {
                this.valueType = valueType;
                switch (valueType)
                {
                case ColumnType.Boolean:
                    booleanValue = Convert.ToBoolean(value);
                    break;

                case ColumnType.Double:
                    doubleValue = Convert.ToDouble(value);
                    break;

                case ColumnType.SInt64:
                    sint64Value = Convert.ToInt64(value);
                    break;

                case ColumnType.Timestamp:
                    if (value is DateTime)
                    {
                        timestampValue = DateTimeUtil.ToUnixTimeMillis((DateTime)value);
                    }
                    else
                    {
                        timestampValue = Convert.ToInt64(value);
                    }

                    break;

                case ColumnType.Varchar:
                case ColumnType.Blob:
                    var bytes = value as byte[];
                    if (bytes != null)
                    {
                        varcharValue = bytes;
                    }
                    else
                    {
                        var s = Convert.ToString(value);
                        varcharValue = RiakString.ToBytes(s);
                    }

                    break;

                default:
                    string msg = string.Format("Unknown value type: {0}", valueType);
                    throw new ArgumentException(msg);
                }
            }
        }
Exemple #6
0
        public Cell(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value", "Value must not be null.");
            }

            varcharValue = RiakString.ToBytes(value);
            valueType    = ColumnType.Varchar;
        }
        public void Are_Equatable()
        {
            TsCell c0 = new TsCell {
                boolean_value = Boolean0
            };
            TsCell c1 = new TsCell {
                boolean_value = Boolean0
            };

            Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1));

            c0 = new TsCell {
                double_value = Double0
            };
            c1 = new TsCell {
                double_value = Double0
            };
            Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1));

            c0 = new TsCell {
                sint64_value = Long0
            };
            c1 = new TsCell {
                sint64_value = Long0
            };
            Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1));

            var ut = DateTimeUtil.ToUnixTimeMillis(Timestamp0);

            c0 = new TsCell {
                timestamp_value = ut
            };
            c1 = new TsCell {
                timestamp_value = ut
            };
            Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1));

            c0 = new TsCell {
                varchar_value = RiakString.ToBytes(Varchar0)
            };
            c1 = new TsCell {
                varchar_value = RiakString.ToBytes(Varchar0)
            };
            Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1));

            c0 = new TsCell {
                varchar_value = Blob0
            };
            c1 = new TsCell {
                varchar_value = Blob0
            };
            Assert.AreEqual(c0, c1, string.Format("c0 {0} c1 {1}", c0, c1));
        }
Exemple #8
0
        public void Fetching_A_Map_Produces_Expected_Values()
        {
            string key = Guid.NewGuid().ToString();

            SaveMap(key);

            var fetch = new FetchMap.Builder()
                        .WithBucketType(BucketType)
                        .WithBucket(Bucket)
                        .WithKey(key)
                        .Build();

            RiakResult rslt = client.Execute(fetch);

            Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage);

            MapResponse response = fetch.Response;

            Assert.IsNotNull(response);

            Assert.IsNotEmpty(response.Context);
            Assert.IsNotNull(response.Value);
            Assert.AreEqual(1, response.Value.Counters["counter_1"]);
            Assert.AreEqual((RiakString)"value_1", (RiakString)response.Value.Sets["set_1"][0]);
            Assert.AreEqual((RiakString)"register_value_1", (RiakString)response.Value.Registers["register_1"]);
            Assert.AreEqual(true, response.Value.Flags["flag_1"]);

            Map map2 = response.Value.Maps["map_2"];

            Assert.AreEqual(2, map2.Counters["counter_1"]);
            Assert.AreEqual(RiakString.ToBytes("value_1"), map2.Sets["set_1"][0]);
            Assert.AreEqual(RiakString.ToBytes("register_value_1"), map2.Registers["register_1"]);
            Assert.AreEqual(true, map2.Flags["flag_1"]);

            Map map3 = map2.Maps["map_3"];

            Assert.AreEqual(3, map3.Counters["counter_1"]);
        }
        public void Should_Construct_MapResponse_From_DtFetchResp()
        {
            var key     = new RiakString("riak_generated_key");
            var context = new RiakString("1234");

            var fetchResp = new DtFetchResp();

            fetchResp.type    = DtFetchResp.DataType.MAP;
            fetchResp.value   = new DtValue();
            fetchResp.context = context;

            Func <IEnumerable <MapEntry> > createMapEntries = () =>
            {
                var mapEntries = new List <MapEntry>();

                var mapField = new MapField();
                mapField.type = MapField.MapFieldType.COUNTER;
                mapField.name = new RiakString("counter_1");
                var mapEntry = new MapEntry();
                mapEntry.field         = mapField;
                mapEntry.counter_value = 50;
                mapEntries.Add(mapEntry);

                mapField       = new MapField();
                mapField.type  = MapField.MapFieldType.SET;
                mapField.name  = new RiakString("set_1");
                mapEntry       = new MapEntry();
                mapEntry.field = mapField;
                mapEntry.set_value.Add(RiakString.ToBytes("value_1"));
                mapEntry.set_value.Add(RiakString.ToBytes("value_2"));
                mapEntries.Add(mapEntry);

                mapField                = new MapField();
                mapField.type           = MapField.MapFieldType.REGISTER;
                mapField.name           = new RiakString("register_1");
                mapEntry                = new MapEntry();
                mapEntry.field          = mapField;
                mapEntry.register_value = RiakString.ToBytes("1234");
                mapEntries.Add(mapEntry);

                mapField            = new MapField();
                mapField.type       = MapField.MapFieldType.FLAG;
                mapField.name       = new RiakString("flag_1");
                mapEntry            = new MapEntry();
                mapEntry.field      = mapField;
                mapEntry.flag_value = true;
                mapEntries.Add(mapEntry);

                return(mapEntries);
            };

            fetchResp.value.map_value.AddRange(createMapEntries());

            var map_1_field = new MapField();

            map_1_field.type = MapField.MapFieldType.MAP;
            map_1_field.name = new RiakString("map_1");
            var map_1_entry = new MapEntry();

            map_1_entry.field = map_1_field;
            map_1_entry.map_value.AddRange(createMapEntries());

            fetchResp.value.map_value.Add(map_1_entry);

            Action <Map> verifyMap = (map) =>
            {
                Assert.AreEqual(50, map.Counters["counter_1"]);
                Assert.AreEqual(RiakString.ToBytes("value_1"), map.Sets["set_1"][0]);
                Assert.AreEqual(RiakString.ToBytes("value_2"), map.Sets["set_1"][1]);
                Assert.AreEqual(RiakString.ToBytes("1234"), map.Registers["register_1"]);
                Assert.IsTrue(map.Flags["flag_1"]);
            };

            var fetch = new FetchMap.Builder()
                        .WithBucketType(BucketType)
                        .WithBucket(Bucket)
                        .WithKey(key)
                        .Build();

            fetch.OnSuccess(fetchResp);

            MapResponse response = fetch.Response;

            Assert.NotNull(response);
            Assert.AreEqual(key, response.Key);
            Assert.AreEqual(RiakString.ToBytes(context), response.Context);

            verifyMap(response.Value);
            verifyMap(response.Value.Maps["map_1"]);
        }
Exemple #10
0
        internal override TsCell ToTsCell()
        {
            TsCell rv = null;

            if (ReferenceEquals(null, v))
            {
                throw new InvalidOperationException("typed Cells require a non-null value");
            }

            if (vtype == typeof(string))
            {
                rv = new TsCell
                {
                    varchar_value = RiakString.ToBytes((string)Convert.ChangeType(v, TypeCode.String))
                };
            }
            else if (vtype == typeof(byte[]))
            {
                var bytes = (byte[])AsObject;
                rv = new TsCell
                {
                    varchar_value = bytes
                };
            }
            else if (IsIntegerType(vtype))
            {
                rv = new TsCell
                {
                    sint64_value = (long)Convert.ChangeType(v, TypeCode.Int64)
                };
            }
            else if (vtype == typeof(DateTime))
            {
                var dt = (DateTime)Convert.ChangeType(v, TypeCode.DateTime);
                rv = new TsCell
                {
                    timestamp_value = DateTimeUtil.ToUnixTimeMillis(dt)
                };
            }
            else if (vtype == typeof(bool))
            {
                rv = new TsCell
                {
                    boolean_value = (bool)Convert.ChangeType(v, TypeCode.Boolean)
                };
            }
            else if (IsDoubleType(vtype))
            {
                rv = new TsCell
                {
                    double_value = (double)Convert.ChangeType(v, TypeCode.Double)
                };
            }
            else
            {
                string msg = string.Format("could not convert {0}, type: {1}", v.ToString(), v.GetType().Name);
                throw new InvalidOperationException(msg);
            }

            return(rv);
        }
        public void Should_Parse_Resp()
        {
            var rsp = new TsGetResp();

            rsp.columns.AddRange(TsCols);
            rsp.rows.AddRange(TsRows);

            Get cmd = BuildGetReqWithTimeout();

            cmd.OnSuccess(rsp);

            GetResponse response = cmd.Response;

            var rcols = response.Columns.ToArray();

            CollectionAssert.AreEqual(Columns, rcols);

            var rr = response.Value.ToArray();

            for (int i = 0; i < rr.Length; i++)
            {
                TsRow    tsr  = TsRows[i];
                TsCell[] tscs = tsr.cells.ToArray();

                Row    r   = rr[i];
                Cell[] rcs = r.Cells.ToArray();

                Assert.AreEqual(tsr.cells.Count, rcs.Length);

                for (int j = 0; j < tscs.Length; j++)
                {
                    TsCell tsc = tscs[j];
                    Cell   c   = rcs[j];

                    if (tsc.boolean_valueSpecified)
                    {
                        Assert.AreEqual(tsc.boolean_value, c.AsObject);
                    }
                    else if (tsc.double_valueSpecified)
                    {
                        Assert.AreEqual(tsc.double_value, c.AsObject);
                    }
                    else if (tsc.sint64_valueSpecified)
                    {
                        Assert.AreEqual(tsc.sint64_value, c.AsObject);
                    }
                    else if (tsc.timestamp_valueSpecified)
                    {
                        var dt = (Cell <DateTime>)c;
                        Assert.AreEqual(tsc.timestamp_value, DateTimeUtil.ToUnixTimeMillis(dt.Value));
                    }
                    else if (tsc.varchar_valueSpecified)
                    {
                        byte[] tsc_val = tsc.varchar_value;

                        var    cell_str = (Cell <string>)c;
                        byte[] cell_val = RiakString.ToBytes(cell_str.Value);

                        CollectionAssert.AreEqual(tsc_val, cell_val);
                    }
                    else
                    {
                        Assert.Fail();
                    }
                }
            }
        }