def test_signed_int_64(self): self.assertRaises(InvalidArgumentException, SignedInt64, -0x7FFFFFFFFFFFFFFF - 2) self.assertRaises(InvalidArgumentException, SignedInt64, 0x7FFFFFFFFFFFFFFF + 1) x = SignedInt64(0x7FFFFFFFFFFFFFFF) self.assertEqual(0x7FFFFFFFFFFFFFFF, x.value) x = SignedInt64(-0x7FFFFFFFFFFFFFFF-1) self.assertEqual(-0x7FFFFFFFFFFFFFFF-1, x.value)
def test_incr_multi(self): keys = self.gen_key_list(amount=5, prefix="incr_multi") def _multi_lim_assert(expected): for k, v in self.cb.get_multi(keys).items(): self.assertTrue(k in keys) self.assertEqual(v.content, expected) self.cb.remove_multi(keys, quiet=True) self.bin_coll.increment_multi(keys, initial=SignedInt64(5)) _multi_lim_assert(5) self.bin_coll.increment_multi(keys) _multi_lim_assert(6) self.bin_coll.decrement_multi(keys, delta=DeltaValue(1)) _multi_lim_assert(5) self.bin_coll.increment_multi(keys, delta=DeltaValue(10)) _multi_lim_assert(15) self.bin_coll.decrement_multi(keys, delta=DeltaValue(6)) _multi_lim_assert(9) self.cb.remove(keys[0]) self.assertRaises(DocumentNotFoundException, self.bin_coll.increment_multi, keys)
def test_incr_extended(self): key = self.gen_key("incr_extended") self.cb.remove(key, quiet=True) rv = self.bin_coll.increment(key, initial=SignedInt64(10)) #self.assertEqual(rv.content, 10) srv = self.cb.upsert(key, "42", cas=rv.cas) self.assertTrue(srv.success) # test with multiple values? klist = self.gen_key_list(amount=5, prefix="incr_extended_list") try: self.bin_coll.increment_multi(klist) except DocumentNotFoundException: pass rvs = self.bin_coll.increment_multi(klist, initial=SignedInt64(40)) # no content in MutationResults - perhaps this would be a good reason for it to have one? #[self.assertEqual(x.content, 40) for x in rvs.values()] self.assertEqual(sorted(list(rvs.keys())), sorted(klist))
def test_trivial_incrdecr(self): key = self.gen_key("trivial_incrdecr") self.cb.remove(key, quiet=True) rv_arith = self.bin_coll.increment(key, initial=SignedInt64(1), delta=DeltaValue(1)) rv_get = self.cb.get(key) # self.assertEqual(rv_arith.content, 1) SDK3 MutationResult has no content self.assertEqual(int(rv_get.content), 1) rv = self.bin_coll.increment(key) # self.assertEqual(rv.content, 2) rv = self.bin_coll.decrement(key, delta=DeltaValue(1)) # self.assertEqual(rv.content, 1) self.assertEqual(int(self.cb.get(key).content), 1) rv = self.bin_coll.decrement(key, delta=DeltaValue(1)) # self.assertEqual(rv.content, 0) self.assertEqual(int(self.cb.get(key).content), 0)
# tag::get_and_touch[] result = collection.get_and_touch("document-key", timedelta(seconds=10)) # end::get_and_touch[] # tag::increment[] # Increment binary value by 1 collection.binary().increment("counter-key", IncrementOptions(delta=DeltaValue(1))) # end::increment[] # tag::increment_w_seed[] # Increment binary value by 5, if key doesn't exist, seed it at 1000 collection.binary().increment( "counter-key", IncrementOptions(delta=DeltaValue(5), initial=SignedInt64(1000))) # end::increment_w_seed[] # tag::decrement[] # Decrement binary value by 1 collection.binary().decrement("counter-key", DecrementOptions(delta=DeltaValue(1))) # end::decrement[] # tag::decrement_w_seed[] # Decrement binary value by 2, if key doesn't exist, seed it at 1000 collection.binary().decrement( "counter-key", DecrementOptions(delta=DeltaValue(2), initial=SignedInt64(1000))) # end::decrement_w_seed[]
def test_counter_increment_default_no_key(self): result = self.coll.binary().increment(self.COUNTER_KEY, IncrementOptions(initial=SignedInt64(100))) self.assertTrue(result.success) self.assertEqual(100, self.coll.get(self.COUNTER_KEY).content_as[int])
result = collection.touch("document-key", timedelta(seconds=10)) #end::touch[] """ ---- == Atomic document modifications The value of a document can be increased or decreased atomically using `.increment()` and `.decrement()`. .Increment [source,csharp] ---- // increment binary value by 1, if document doesn’t exist, seed it at 1000 """ #tag::increment[] collection.increment("document-key", DeltaValue(1), initial=SignedInt64(1000)) #end::increment[] """ --- [source,csharp] ---- .Increment (with options) // increment binary value by 1, if document doesn’t exist, seed it at 1000 // optional arguments: // - Expiration (TimeSpan) """ #tag::increment_w_expiration[] collection.increment("document-key", DeltaValue(1), initial=SignedInt64(1000),