public void OperateMapMixed() { // Test normal operations with map operations. if (!args.ValidateMap()) { return; } Key key = new Key(args.ns, args.set, "opmkey2"); client.Delete(null, key); Dictionary <Value, Value> itemMap = new Dictionary <Value, Value>(); itemMap[Value.Get(12)] = Value.Get("myval"); itemMap[Value.Get(-8734)] = Value.Get("str2"); itemMap[Value.Get(1)] = Value.Get("my default"); itemMap[Value.Get(7)] = Value.Get(1); Record record = client.Operate(null, key, MapOperation.PutItems(new MapPolicy(MapOrder.KEY_VALUE_ORDERED, MapWriteMode.UPDATE), binName, itemMap), Operation.Put(new Bin("otherbin", "hello")) ); AssertRecordFound(key, record); long size = record.GetLong(binName); Assert.AreEqual(4, size); record = client.Operate(null, key, MapOperation.GetByKey(binName, Value.Get(12), MapReturnType.INDEX), Operation.Append(new Bin("otherbin", Value.Get("goodbye"))), Operation.Get("otherbin") ); AssertRecordFound(key, record); long index = record.GetLong(binName); Assert.AreEqual(3, index); IList results = record.GetList("otherbin"); string val = (string)results[1]; Assert.AreEqual("hellogoodbye", val); }
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 OperateMapRank() { // Test rank. if (!args.ValidateMap()) { return; } Key key = new Key(args.ns, args.set, "opmkey6"); client.Delete(null, key); Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>(); inputMap[Value.Get("Charlie")] = Value.Get(55); inputMap[Value.Get("Jim")] = Value.Get(98); inputMap[Value.Get("John")] = Value.Get(76); inputMap[Value.Get("Harry")] = Value.Get(82); // Write values to empty map. Record record = client.Operate(null, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap)); AssertRecordFound(key, record); // Increment some user scores. record = client.Operate(null, key, MapOperation.Increment(MapPolicy.Default, binName, Value.Get("John"), Value.Get(5)), MapOperation.Decrement(MapPolicy.Default, binName, Value.Get("Jim"), Value.Get(4)) ); AssertRecordFound(key, record); // Get scores. record = client.Operate(null, key, MapOperation.GetByRankRange(binName, -2, 2, MapReturnType.KEY), MapOperation.GetByRankRange(binName, 0, 2, MapReturnType.KEY_VALUE), MapOperation.GetByRank(binName, 0, MapReturnType.VALUE), MapOperation.GetByRank(binName, 2, MapReturnType.KEY), MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.RANK), MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.COUNT), MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.KEY_VALUE), MapOperation.GetByValueRange(binName, Value.Get(81), Value.Get(82), MapReturnType.KEY), MapOperation.GetByValue(binName, Value.Get(77), MapReturnType.KEY), MapOperation.GetByValue(binName, Value.Get(81), MapReturnType.RANK), MapOperation.GetByKey(binName, Value.Get("Charlie"), MapReturnType.RANK), MapOperation.GetByKey(binName, Value.Get("Charlie"), MapReturnType.REVERSE_RANK) ); AssertRecordFound(key, record); IList results = record.GetList(binName); int i = 0; IList list = (IList)results[i++]; string str; long val; str = (string)list[0]; Assert.AreEqual("Harry", str); str = (string)list[1]; Assert.AreEqual("Jim", str); list = (IList)results[i++]; KeyValuePair <object, object> entry = (KeyValuePair <object, object>)list[0]; Assert.AreEqual("Charlie", entry.Key); Assert.AreEqual(55L, entry.Value); entry = (KeyValuePair <object, object>)list[1]; Assert.AreEqual("John", entry.Key); Assert.AreEqual(81L, entry.Value); val = (long)results[i++]; Assert.AreEqual(55, val); str = (string)results[i++]; Assert.AreEqual("Harry", str); list = (IList)results[i++]; val = (long)list[0]; Assert.AreEqual(3, val); val = (long)results[i++]; Assert.AreEqual(1, val); list = (IList)results[i++]; entry = (KeyValuePair <object, object>)list[0]; Assert.AreEqual("Jim", entry.Key); Assert.AreEqual(94L, entry.Value); list = (IList)results[i++]; str = (string)list[0]; Assert.AreEqual("John", str); list = (IList)results[i++]; Assert.AreEqual(0, list.Count); list = (IList)results[i++]; val = (long)list[0]; Assert.AreEqual(1, val); val = (long)results[i++]; Assert.AreEqual(0, val); val = (long)results[i++]; Assert.AreEqual(3, val); }