Beispiel #1
0
    def drop(self, populate, with_cursor, reopen, drop_index):
        uri = self.uri + self.name
        populate(self, uri, 'key_format=S' + self.extra_config, 10)

        # Open cursors should cause failure.
        if with_cursor:
            cursor = self.session.open_cursor(uri, None, None)
            self.assertRaises(wiredtiger.WiredTigerError,
                lambda: self.session.drop(uri, None))
            cursor.close()

        if reopen:
            self.reopen_conn()

        if drop_index:
            drop_uri = complex_populate_index_name(self, uri, 0)
        else:
            drop_uri = uri
        self.session.drop(drop_uri, None)
        confirm_does_not_exist(self, drop_uri)
Beispiel #2
0
    def drop(self, populate, with_cursor, reopen, drop_index):
        uri = self.uri + self.name
        populate(self, uri, 'key_format=S' + self.extra_config, 10)

        # Open cursors should cause failure.
        if with_cursor:
            cursor = self.session.open_cursor(uri, None, None)
            self.assertRaises(wiredtiger.WiredTigerError,
                              lambda: self.session.drop(uri, None))
            cursor.close()

        if reopen:
            self.reopen_conn()

        if drop_index:
            drop_uri = complex_populate_index_name(self, uri, 0)
        else:
            drop_uri = uri
        self.session.drop(drop_uri, None)
        confirm_does_not_exist(self, drop_uri)
Beispiel #3
0
    def test_stat_cursor_reset(self):
        # The number of btree_entries reported is influenced by the
        # number of column groups and indices.  Each insert will have
        # a multiplied effect.
        if self.pop == simple_populate:
            multiplier = 1   # no declared colgroup is like one big colgroup
        else:
            multiplier = complex_populate_colgroup_count() + \
                         complex_populate_index_count()
        n = 100
        self.pop(self, self.uri, 'key_format=S', n)
        statc = self.stat_cursor(self.uri)
        self.assertEqual(statc[stat.dsrc.btree_entries][2], n * multiplier)

        c = self.session.open_cursor(self.uri)
        c.set_key(key_populate(c, 200))
        if self.pop == simple_populate:
            c.set_value(value_populate(c, 200))
        else:
            v = complex_value_populate(c, 200)
            c.set_value(v[0], v[1], v[2], v[3])
        c.insert()

        # Test that cursor reset re-loads the values.
        self.assertEqual(statc[stat.dsrc.btree_entries][2], n * multiplier)
        statc.reset()
        n += 1
        self.assertEqual(statc[stat.dsrc.btree_entries][2], n * multiplier)

        # For applications with indices and/or column groups, verify
        # that there is a way to count the base number of entries.
        if self.pop != simple_populate:
            statc.close()
            statc = self.stat_cursor(
                complex_populate_index_name(self, self.uri))
            self.assertEqual(statc[stat.dsrc.btree_entries][2], n)
            statc.close()
            statc = self.stat_cursor(
                complex_populate_colgroup_name(self, self.uri))
            self.assertEqual(statc[stat.dsrc.btree_entries][2], n)
        statc.close()
Beispiel #4
0
    def test_cursor_comparison(self):
        uri = self.type + "compare"
        uriX = self.type + "compareX"

        # Build the object.
        if self.type == "file:":
            simple_populate(self, uri, "key_format=" + self.keyfmt + self.config, 100)
            simple_populate(self, uriX, "key_format=" + self.keyfmt + self.config, 100)
            ix0_0 = None
            ix0_1 = None
            ix1_0 = None
            ixX_0 = None
        else:
            complex_populate(self, uri, "key_format=" + self.keyfmt + self.config, 100)
            complex_populate(self, uriX, "key_format=" + self.keyfmt + self.config, 100)
            ix0_0 = self.session.open_cursor(complex_populate_index_name(self, uri, 0), None)
            ix0_1 = self.session.open_cursor(complex_populate_index_name(self, uri, 0), None)
            ix1_0 = self.session.open_cursor(complex_populate_index_name(self, uri, 1), None)
            ixX_0 = self.session.open_cursor(complex_populate_index_name(self, uriX, 0), None)
            ix0_0.next()
            ix0_1.next()
            ix1_0.next()
            ixX_0.next()

        c1 = self.session.open_cursor(uri, None)
        c2 = self.session.open_cursor(uri, None)

        # Confirm failure unless the keys are set.
        msg = "/requires key be set/"
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError, lambda: c1.compare(c2), msg)
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError, lambda: c2.compare(c1), msg)

        # Test cursors before they're positioned.
        c1.set_key(key_populate(c1, 10))
        c2.set_key(key_populate(c2, 20))
        self.assertGreater(c2.compare(c1), 0)
        self.assertLess(c1.compare(c2), 0)
        c2.set_key(key_populate(c2, 10))
        self.assertEqual(c1.compare(c2), 0)
        self.assertEqual(c2.compare(c1), 0)

        # Confirm failure for different objects.
        cX = self.session.open_cursor(uriX, None)
        cX.set_key(key_populate(cX, 10))
        msg = "/must reference the same object/"
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError, lambda: cX.compare(c1), msg)
        msg = "/wt_cursor.* is None/"
        self.assertRaisesHavingMessage(exceptions.RuntimeError, lambda: cX.compare(None), msg)
        if ix0_0 != None:
            self.assertEqual(ix0_0.compare(ix0_1), 0)
            ix0_1.reset()
            ix0_1.prev()
            self.assertLess(ix0_0.compare(ix0_1), 0)
            self.assertGreater(ix0_1.compare(ix0_0), 0)
            # Main table vs. index not allowed
            msg = "/must reference the same object/"
            self.assertRaisesWithMessage(wiredtiger.WiredTigerError, lambda: c1.compare(ix0_0), msg)
            # Two unrelated indices not allowed
            self.assertRaisesWithMessage(wiredtiger.WiredTigerError, lambda: ixX_0.compare(ix0_0), msg)
            # Two different indices from same table not allowed
            self.assertRaisesWithMessage(wiredtiger.WiredTigerError, lambda: ix0_0.compare(ix1_0), msg)

        # Test cursors after they're positioned (shouldn't matter for compare).
        c1.set_key(key_populate(c1, 10))
        self.assertEqual(c1.search(), 0)
        c2.set_key(key_populate(c2, 20))
        self.assertEqual(c2.search(), 0)
        self.assertGreater(c2.compare(c1), 0)
        self.assertLess(c1.compare(c2), 0)
        c2.set_key(key_populate(c2, 10))
        self.assertEqual(c2.search(), 0)
        self.assertEqual(c1.compare(c2), 0)
        self.assertEqual(c2.compare(c1), 0)

        # Confirm failure for different objects.
        cX = self.session.open_cursor(uriX, None)
        cX.set_key(key_populate(cX, 10))
        self.assertEqual(cX.search(), 0)
        msg = "/must reference the same object/"
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError, lambda: cX.compare(c1), msg)
Beispiel #5
0
    def test_cursor_equality(self):
        uri = self.type + 'equality'
        uriX = self.type + 'compareX'

        # Build the object.
        if self.type == 'file:':
            simple_populate(
                self, uri, 'key_format=' + self.keyfmt + self.config, 100)
            simple_populate(
                self, uriX, 'key_format=' + self.keyfmt + self.config, 100)
            ix0_0 = None
            ix0_1 = None
            ix1_0 = None
            ixX_0 = None
        else:
            complex_populate(
                self, uri, 'key_format=' + self.keyfmt + self.config, 100)
            complex_populate(
                self, uriX, 'key_format=' + self.keyfmt + self.config, 100)
            ix0_0 = self.session.open_cursor(
                complex_populate_index_name(self, uri, 0), None)
            ix0_1 = self.session.open_cursor(
                complex_populate_index_name(self, uri, 0), None)
            ix1_0 = self.session.open_cursor(
                complex_populate_index_name(self, uri, 1), None)
            ixX_0 = self.session.open_cursor(
                complex_populate_index_name(self, uriX, 0), None)
            ix0_0.next()
            ix0_1.next()
            ix1_0.next()
            ixX_0.next()

        c1 = self.session.open_cursor(uri, None)
        c2 = self.session.open_cursor(uri, None)

        # Confirm failure unless the keys are set.
        msg = '/requires key be set/'
        self.assertRaisesWithMessage(
            wiredtiger.WiredTigerError, lambda: c1.equals(c2), msg)
        self.assertRaisesWithMessage(
            wiredtiger.WiredTigerError, lambda: c2.equals(c1), msg)

        # Test cursors before they're positioned.
        c1.set_key(key_populate(c1, 10))
        c2.set_key(key_populate(c2, 20))
        self.assertFalse(c1.equals(c2))
        self.assertFalse(c2.equals(c1))
        c2.set_key(key_populate(c2, 10))
        self.assertTrue(c1.equals(c2))
        self.assertTrue(c2.equals(c1))

        # Confirm failure for different objects.
        cX = self.session.open_cursor(uriX, None)
        cX.set_key(key_populate(cX, 10))
        msg = '/must reference the same object/'
        self.assertRaisesWithMessage(
            wiredtiger.WiredTigerError, lambda: cX.equals(c1), msg)
        msg = '/wt_cursor.* is None/'
        self.assertRaisesHavingMessage(
            exceptions.RuntimeError,  lambda: cX.equals(None), msg)
        if ix0_0 != None:
            self.assertTrue(ix0_0.equals(ix0_1))
            ix0_1.reset()
            ix0_1.prev()
            self.assertFalse(ix0_0.equals(ix0_1))
            # Main table vs. index not allowed
            msg = '/must reference the same object/'
            self.assertRaisesWithMessage(
                wiredtiger.WiredTigerError, lambda: c1.equals(ix0_0), msg)
            # Two unrelated indices not allowed
            self.assertRaisesWithMessage(
                wiredtiger.WiredTigerError, lambda: ixX_0.equals(ix0_0), msg)
            # Two different indices from same table not allowed
            self.assertRaisesWithMessage(
                wiredtiger.WiredTigerError, lambda: ix0_0.equals(ix1_0), msg)

        # Test cursors after they're positioned (internally, it's a different
        # search path if keys are positioned in the tree).
        c1.set_key(key_populate(c1, 10))
        self.assertEqual(c1.search(), 0)
        c2.set_key(key_populate(c2, 20))
        self.assertEqual(c2.search(), 0)
        self.assertFalse(c1.equals(c2))
        self.assertFalse(c2.equals(c1))
        c2.set_key(key_populate(c2, 10))
        self.assertEqual(c2.search(), 0)
        self.assertTrue(c1.equals(c2))
        self.assertTrue(c2.equals(c1))

        # Confirm failure for different objects.
        cX = self.session.open_cursor(uriX, None)
        cX.set_key(key_populate(cX, 10))
        self.assertEqual(cX.search(), 0)
        msg = '/must reference the same object/'
        self.assertRaisesWithMessage(
            wiredtiger.WiredTigerError, lambda: cX.equals(c1), msg)
    def test_cursor_comparison(self):
        uri = self.type + 'compare'
        uriX = self.type + 'compareX'

        # Build the object.
        if self.type == 'file:':
            simple_populate(
                self, uri, 'key_format=' + self.keyfmt + self.config, 100)
            simple_populate(
                self, uriX, 'key_format=' + self.keyfmt + self.config, 100)
            ix0_0 = None
            ix0_1 = None
            ix1_0 = None
            ixX_0 = None
        else:
            complex_populate(
                self, uri, 'key_format=' + self.keyfmt + self.config, 100)
            complex_populate(
                self, uriX, 'key_format=' + self.keyfmt + self.config, 100)
            ix0_0 = self.session.open_cursor(
                complex_populate_index_name(self, uri, 0), None)
            ix0_1 = self.session.open_cursor(
                complex_populate_index_name(self, uri, 0), None)
            ix1_0 = self.session.open_cursor(
                complex_populate_index_name(self, uri, 1), None)
            ixX_0 = self.session.open_cursor(
                complex_populate_index_name(self, uriX, 0), None)
            ix0_0.next()
            ix0_1.next()
            ix1_0.next()
            ixX_0.next()

        c1 = self.session.open_cursor(uri, None)
        c2 = self.session.open_cursor(uri, None)

        # Confirm failure unless the keys are set.
        msg = '/requires key be set/'
        self.assertRaisesWithMessage(
            wiredtiger.WiredTigerError, lambda: c1.compare(c2), msg)
        self.assertRaisesWithMessage(
            wiredtiger.WiredTigerError, lambda: c2.compare(c1), msg)

        # Test cursors before they're positioned.
        c1.set_key(key_populate(c1, 10))
        c2.set_key(key_populate(c2, 20))
        self.assertGreater(c2.compare(c1), 0)
        self.assertLess(c1.compare(c2), 0)
        c2.set_key(key_populate(c2, 10))
        self.assertEqual(c1.compare(c2), 0)
        self.assertEqual(c2.compare(c1), 0)

        # Confirm failure for different objects.
        cX = self.session.open_cursor(uriX, None)
        cX.set_key(key_populate(cX, 10))
        msg = '/must reference the same object/'
        self.assertRaisesWithMessage(
            wiredtiger.WiredTigerError, lambda: cX.compare(c1), msg)
        msg = '/wt_cursor.* is None/'
        self.assertRaisesHavingMessage(
            exceptions.RuntimeError,  lambda: cX.compare(None), msg)
        if ix0_0 != None:
            self.assertEqual(ix0_0.compare(ix0_1), 0)
            ix0_1.reset()
            ix0_1.prev()
            self.assertLess(ix0_0.compare(ix0_1), 0)
            self.assertGreater(ix0_1.compare(ix0_0), 0)
            # Main table vs. index not allowed
            msg = '/must reference the same object/'
            self.assertRaisesWithMessage(
                wiredtiger.WiredTigerError, lambda: c1.compare(ix0_0), msg)
            # Two unrelated indices not allowed
            self.assertRaisesWithMessage(
                wiredtiger.WiredTigerError, lambda: ixX_0.compare(ix0_0), msg)
            # Two different indices from same table not allowed
            self.assertRaisesWithMessage(
                wiredtiger.WiredTigerError, lambda: ix0_0.compare(ix1_0), msg)

        # Test cursors after they're positioned (shouldn't matter for compare).
        c1.set_key(key_populate(c1, 10))
        self.assertEqual(c1.search(), 0)
        c2.set_key(key_populate(c2, 20))
        self.assertEqual(c2.search(), 0)
        self.assertGreater(c2.compare(c1), 0)
        self.assertLess(c1.compare(c2), 0)
        c2.set_key(key_populate(c2, 10))
        self.assertEqual(c2.search(), 0)
        self.assertEqual(c1.compare(c2), 0)
        self.assertEqual(c2.compare(c1), 0)

        # Confirm failure for different objects.
        cX = self.session.open_cursor(uriX, None)
        cX.set_key(key_populate(cX, 10))
        self.assertEqual(cX.search(), 0)
        msg = '/must reference the same object/'
        self.assertRaisesWithMessage(
            wiredtiger.WiredTigerError, lambda: cX.compare(c1), msg)