Ejemplo n.º 1
0
        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);
        }