Ejemplo n.º 1
0
    def test_invalid_item(self):
        itcoll = ItemOptionDict()
        itcoll.add(None)
        self.assertRaises(ArgumentError, self.cb.upsert_multi, itcoll)

        self.assertRaises(ArgumentError, self.cb.upsert_multi,
                          ItemSequence([None]))
Ejemplo n.º 2
0
 def test_item_format(self):
     # Tests whether things like 'CAS' and 'format' are honored
     k = self.gen_key("itm_format_options")
     it = Item(k, {})
     itcoll = ItemOptionDict()
     itcoll.dict[it] = {"format": FMT_BYTES}
     self.assertRaises(ValueFormatError, self.cb.upsert_multi, itcoll)
 def test_item_format(self):
     # Tests whether things like 'CAS' and 'format' are honored
     k = self.gen_key("itm_format_options")
     it = Item(k, {})
     itcoll = ItemOptionDict()
     itcoll.dict[it] = { "format" : FMT_BYTES }
     self.assertRaises(ValueFormatError, self.cb.set_multi, itcoll)
Ejemplo n.º 4
0
    def test_items_append(self):
        k = self.gen_key("itm_append")
        it = Item(k, "MIDDLE")
        itcoll = ItemOptionDict()
        itcoll.add(it)

        self.cb.set_multi(itcoll, format=FMT_UTF8)

        itcoll.add(it, fragment="_END")
        self.cb.append_items(itcoll, format=FMT_UTF8)
        self.assertEqual(it.value, "MIDDLE_END")

        itcoll.add(it, fragment="BEGIN_")
        self.cb.prepend_items(itcoll, format=FMT_UTF8)
        self.assertEqual(it.value, "BEGIN_MIDDLE_END")

        rv = self.cb.get(it.key)
        self.assertEqual(rv.value, "BEGIN_MIDDLE_END")

        # Try without a 'fragment' specifier
        self.assertRaises(ArgumentError,
                          self.cb.append_items, ItemSequence([it]))
        itcoll.add(it)
        self.assertRaises(ArgumentError,
                          self.cb.append_items, itcoll)
Ejemplo n.º 5
0
    def test_create_and_add(self):
        itcoll = ItemOptionDict()
        itcoll.create_and_add('foo', value='fooValue', cas=123, persist_to=-1)
        itcoll.create_and_add('bar', value='barValue', cas=321, replicate_to=-1)

        dd = itcoll.dict
        self.assertEqual(2, len(dd))

        def _find_item(key):
            for k, v in dd.items():
                if k.key == key:
                    return k, v

        foo_item, foo_options = _find_item('foo')
        self.assertIsInstance(foo_item, Item)
        self.assertEqual('foo', foo_item.key)
        self.assertEqual('fooValue', foo_item.value)
        self.assertEqual(123, foo_item.cas)
        self.assertEqual(1, len(foo_options))
        self.assertEqual(-1, foo_options['persist_to'])

        bar_item, bar_options = _find_item('bar')
        self.assertIsInstance(bar_item, Item)
        self.assertEqual('bar', bar_item.key)
        self.assertEqual('barValue', bar_item.value)
        self.assertEqual(321, bar_item.cas)
        self.assertEqual(1, len(bar_options))
        self.assertEqual(-1, bar_options['replicate_to'])
Ejemplo n.º 6
0
    def test_invalid_item(self):
        itcoll = ItemOptionDict()
        itcoll.add(None)
        self.assertRaises(ArgumentError, self.cb.upsert_multi, itcoll)

        self.assertRaises(ArgumentError,
                          self.cb.upsert_multi, ItemSequence([None]))
    def test_items_append(self):
        k = self.gen_key("itm_append")
        it = Item(k, "MIDDLE")
        itcoll = ItemOptionDict()
        itcoll.add(it)

        self.cb.set_multi(itcoll, format=FMT_UTF8)

        itcoll.add(it, fragment="_END")
        self.cb.append_items(itcoll, format=FMT_UTF8)
        self.assertEqual(it.value, "MIDDLE_END")

        itcoll.add(it, fragment="BEGIN_")
        self.cb.prepend_items(itcoll, format=FMT_UTF8)
        self.assertEqual(it.value, "BEGIN_MIDDLE_END")

        rv = self.cb.get(it.key)
        self.assertEqual(rv.value, "BEGIN_MIDDLE_END")

        # Try without a 'fragment' specifier
        self.assertRaises(ArgumentError,
                          self.cb.append_items, ItemSequence([it]))
        itcoll.add(it)
        self.assertRaises(ArgumentError,
                          self.cb.append_items, itcoll)
Ejemplo n.º 8
0
    def batch_iter(self, startval, nitems, use_values=False, view_load=False):
        itmcoll = ItemOptionDict()
        for x in xrange(startval, startval + nitems):
            key = self.gen_str(self.kseed, self.ksize, x)
            itm = DatatypeItem(key=self.gen_str(self.kseed, self.ksize, x),
                               ix=x,
                               use_datatypes=self.use_datatypes)
            options = {}
            if use_values and not(view_load):
                itm.set_value(self.gen_str(self.vseed, self.vsize, x))
                options['format'] = itm.expected_datatype

            elif use_values and view_load:
                itm.set_value(self.gen_json(key, x))

            itmcoll.add(itm, **options)

        return itmcoll
    def test_items_ignorecas(self):
        k = self.gen_key("itm_ignorecas")
        it = Item(k, "a value")
        itcoll = ItemOptionDict()
        itcoll.add(it)
        self.cb.set_multi(itcoll)
        self.assertTrue(it.cas)

        # Set it again
        rv = self.cb.set(it.key, it.value)
        self.assertTrue(rv.cas)
        self.assertFalse(rv.cas == it.cas)

        # Should raise an error without ignore_cas
        self.assertRaises(KeyExistsError, self.cb.set_multi, itcoll)
        self.assertTrue(it.cas)

        itcoll.add(it, ignore_cas=True)
        self.cb.set_multi(itcoll)
        rv = self.cb.get(it.key)
        self.assertEqual(rv.cas, it.cas)
Ejemplo n.º 10
0
    def test_create_and_add(self):
        itcoll = ItemOptionDict()
        itcoll.create_and_add('foo', value='fooValue', cas=123, persist_to=-1)
        itcoll.create_and_add('bar',
                              value='barValue',
                              cas=321,
                              replicate_to=-1)

        dd = itcoll.dict
        self.assertEqual(2, len(dd))

        def _find_item(key):
            for k, v in dd.items():
                if k.key == key:
                    return k, v

        foo_item, foo_options = _find_item('foo')
        self.assertIsInstance(foo_item, Item)
        self.assertEqual('foo', foo_item.key)
        self.assertEqual('fooValue', foo_item.value)
        self.assertEqual(123, foo_item.cas)
        self.assertEqual(1, len(foo_options))
        self.assertEqual(-1, foo_options['persist_to'])

        bar_item, bar_options = _find_item('bar')
        self.assertIsInstance(bar_item, Item)
        self.assertEqual('bar', bar_item.key)
        self.assertEqual('barValue', bar_item.value)
        self.assertEqual(321, bar_item.cas)
        self.assertEqual(1, len(bar_options))
        self.assertEqual(-1, bar_options['replicate_to'])
Ejemplo n.º 11
0
    def test_items_ignorecas(self):
        k = self.gen_key("itm_ignorecas")
        it = Item(k, "a value")
        itcoll = ItemOptionDict()
        itcoll.add(it)
        self.cb.upsert_multi(itcoll)
        self.assertTrue(it.cas)

        # Set it again
        rv = self.cb.upsert(it.key, it.value)
        self.assertTrue(rv.cas)
        self.assertFalse(rv.cas == it.cas)

        # Should raise an error without ignore_cas
        self.assertRaises(KeyExistsError, self.cb.upsert_multi, itcoll)
        self.assertTrue(it.cas)

        itcoll.add(it, ignore_cas=True)
        self.cb.upsert_multi(itcoll)
        rv = self.cb.get(it.key)
        self.assertEqual(rv.cas, it.cas)
Ejemplo n.º 12
0
 def test_pycbc366(self):
     itcoll = ItemOptionDict()
     itcoll.create_and_add('foo', replica=True)
     self.assertRaises(ArgumentError, self.cb.get_multi, itcoll)
Ejemplo n.º 13
0
 def test_pycbc366(self):
     itcoll = ItemOptionDict()
     itcoll.create_and_add('foo', replica=True)
     self.assertRaises(ArgumentError, self.cb.get_multi, itcoll)