예제 #1
0
        public void OperateMapInfinity()
        {
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey17");

            client.Delete(null, key);

            Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get(0)] = Value.Get(17);
            inputMap[Value.Get(4)] = Value.Get(2);
            inputMap[Value.Get(5)] = Value.Get(15);
            inputMap[Value.Get(9)] = Value.Get(10);

            // Write values to empty map.
            Record record = client.Operate(null, key,
                                           MapOperation.PutItems(MapPolicy.Default, binName, inputMap)
                                           );

            AssertRecordFound(key, record);

            record = client.Operate(null, key,
                                    MapOperation.GetByKeyRange(binName, Value.Get(5), Value.INFINITY, MapReturnType.KEY)
                                    );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            long v = (long)results[i++];

            Assert.AreEqual(5L, v);

            v = (long)results[i++];
            Assert.AreEqual(9L, v);
        }
        public void OperateMapPutItems()
        {
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey2");

            client.Delete(null, key);

            Dictionary <Value, Value> addMap = new Dictionary <Value, Value>();

            addMap[Value.Get(12)]    = Value.Get("myval");
            addMap[Value.Get(-8734)] = Value.Get("str2");
            addMap[Value.Get(1)]     = Value.Get("my default");

            Dictionary <Value, Value> putMap = new Dictionary <Value, Value>();

            putMap[Value.Get(12)] = Value.Get("myval12222");
            putMap[Value.Get(13)] = Value.Get("str13");

            Dictionary <Value, Value> updateMap = new Dictionary <Value, Value>();

            updateMap[Value.Get(13)] = Value.Get("myval2");

            Dictionary <Value, Value> replaceMap = new Dictionary <Value, Value>();

            replaceMap[Value.Get(12)]    = Value.Get(23);
            replaceMap[Value.Get(-8734)] = Value.Get("changed");

            MapPolicy putMode    = MapPolicy.Default;
            MapPolicy addMode    = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.CREATE_ONLY);
            MapPolicy updateMode = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.UPDATE_ONLY);

            Record record = client.Operate(null, key,
                                           MapOperation.PutItems(addMode, binName, addMap),
                                           MapOperation.PutItems(putMode, binName, putMap),
                                           MapOperation.PutItems(updateMode, binName, updateMap),
                                           MapOperation.PutItems(updateMode, binName, replaceMap),
                                           MapOperation.GetByKey(binName, Value.Get(1), MapReturnType.VALUE),
                                           MapOperation.GetByKey(binName, Value.Get(-8734), MapReturnType.VALUE),
                                           MapOperation.GetByKeyRange(binName, Value.Get(12), Value.Get(15), MapReturnType.KEY_VALUE)
                                           );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            long size = (long)results[i++];

            Assert.AreEqual(3, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            string str = (string)results[i++];

            Assert.AreEqual("my default", str);

            str = (string)results[i++];
            Assert.AreEqual("changed", str);

            IList list = (IList)results[i++];

            Assert.AreEqual(2, list.Count);
        }
        public void OperateMapSwitch()
        {
            // Switch from unordered map to a key ordered map.
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey4");

            client.Delete(null, key);

            Record record = client.Operate(null, key,
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get(4), Value.Get(4)),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get(3), Value.Get(3)),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get(2), Value.Get(2)),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get(1), Value.Get(1)),
                                           MapOperation.GetByIndex(binName, 2, MapReturnType.KEY_VALUE),
                                           MapOperation.GetByIndexRange(binName, 0, 10, MapReturnType.KEY_VALUE)
                                           );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 3;

            long size = (long)results[i++];

            Assert.AreEqual(4, size);

            IList list = (IList)results[i++];

            Assert.AreEqual(1, list.Count);

            list = (IList)results[i++];
            Assert.AreEqual(4, list.Count);

            record = client.Operate(null, key,
                                    MapOperation.SetMapPolicy(new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.UPDATE), binName),
                                    MapOperation.GetByKeyRange(binName, Value.Get(3), Value.Get(5), MapReturnType.COUNT),
                                    MapOperation.GetByKeyRange(binName, Value.Get(-5), Value.Get(2), MapReturnType.KEY_VALUE),
                                    MapOperation.GetByIndexRange(binName, 0, 10, MapReturnType.KEY_VALUE));

            AssertRecordFound(key, record);

            results = record.GetList(binName);
            i       = 0;

            object obj = results[i++];

            Assert.IsNull(obj);

            long val = (long)results[i++];

            Assert.AreEqual(2, val);

            list = (IList)results[i++];
            Assert.AreEqual(1, list.Count);
            KeyValuePair <object, object> entry = (KeyValuePair <object, object>)list[0];

            Assert.AreEqual(1L, entry.Value);

            list  = (IList)results[i++];
            entry = (KeyValuePair <object, object>)list[3];
            Assert.AreEqual(4L, entry.Key);
        }