public void OperateMapScore() { // Test score. Key key = new Key(args.ns, args.set, "opmkey10"); client.Delete(null, key); MapPolicy mapPolicy = new MapPolicy(MapOrder.KEY_VALUE_ORDERED, MapWriteMode.UPDATE); Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>(); inputMap[Value.Get("weiling")] = Value.Get(0); inputMap[Value.Get("briann")] = Value.Get(0); inputMap[Value.Get("brianb")] = Value.Get(0); inputMap[Value.Get("meher")] = Value.Get(0); // Create map. Record record = client.Operate(null, key, MapOperation.PutItems(mapPolicy, binName, inputMap)); AssertRecordFound(key, record); // Change scores record = client.Operate(null, key, MapOperation.Increment(mapPolicy, binName, Value.Get("weiling"), Value.Get(10)), MapOperation.Increment(mapPolicy, binName, Value.Get("briann"), Value.Get(20)), MapOperation.Increment(mapPolicy, binName, Value.Get("brianb"), Value.Get(1)), MapOperation.Increment(mapPolicy, binName, Value.Get("meher"), Value.Get(20)) ); AssertRecordFound(key, record); // Query top 3 scores record = client.Operate(null, key, MapOperation.GetByRankRange(binName, -3, 3, MapReturnType.KEY)); AssertRecordFound(key, record); // Remove people with score 10 and display top 3 again record = client.Operate(null, key, MapOperation.RemoveByValue(binName, Value.Get(10), MapReturnType.KEY), MapOperation.GetByRankRange(binName, -3, 3, MapReturnType.KEY) ); AssertRecordFound(key, record); IList results = record.GetList(binName); int i = 0; IList list = (IList)results[i++]; string s = (string)list[0]; Assert.AreEqual("weiling", s); list = (IList)results[i++]; s = (string)list[0]; Assert.AreEqual("brianb", s); s = (string)list[1]; Assert.AreEqual("briann", s); s = (string)list[2]; Assert.AreEqual("meher", s); }
public void OperateMapRemove() { // Test remove. Key key = new Key(args.ns, args.set, "opmkey7"); 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); inputMap[Value.Get("Sally")] = Value.Get(79); inputMap[Value.Get("Lenny")] = Value.Get(84); inputMap[Value.Get("Abe")] = Value.Get(88); List <Value> removeItems = new List <Value>(); removeItems.Add(Value.Get("Sally")); removeItems.Add(Value.Get("UNKNOWN")); removeItems.Add(Value.Get("Lenny")); Record record = client.Operate(null, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap), MapOperation.RemoveByKey(binName, Value.Get("NOTFOUND"), MapReturnType.VALUE), MapOperation.RemoveByKey(binName, Value.Get("Jim"), MapReturnType.VALUE), MapOperation.RemoveByKeyList(binName, removeItems, MapReturnType.COUNT), MapOperation.RemoveByValue(binName, Value.Get(55), MapReturnType.KEY), MapOperation.Size(binName)); AssertRecordFound(key, record); IList results = record.GetList(binName); int i = 0; long val = (long)results[i++]; Assert.AreEqual(7, val); object obj = results[i++]; Assert.IsNull(obj); val = (long)results[i++]; Assert.AreEqual(98, val); val = (long)results[i++]; Assert.AreEqual(2, val); IList list = (IList)results[i++]; Assert.AreEqual(1, list.Count); Assert.AreEqual("Charlie", (string)list[0]); val = (long)results[i++]; Assert.AreEqual(3, val); }