1#!/usr/bin/env python
2#
3# Public Domain 2014-2018 MongoDB, Inc.
4# Public Domain 2008-2014 WiredTiger, Inc.
5#
6# This is free and unencumbered software released into the public domain.
7#
8# Anyone is free to copy, modify, publish, use, compile, sell, or
9# distribute this software, either in source code form or as a compiled
10# binary, for any purpose, commercial or non-commercial, and by any
11# means.
12#
13# In jurisdictions that recognize copyright laws, the author or authors
14# of this software dedicate any and all copyright interest in the
15# software to the public domain. We make this dedication for the benefit
16# of the public at large and to the detriment of our heirs and
17# successors. We intend this dedication to be an overt act of
18# relinquishment in perpetuity of all present and future rights to this
19# software under copyright law.
20#
21# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27# OTHER DEALINGS IN THE SOFTWARE.
28
29import wiredtiger, wttest
30
31# test_drop_create.py
32#    Test dropping and creating
33class test_drop_create(wttest.WiredTigerTestCase):
34    def test_drop_create(self):
35        s, self.session = self.session, None
36        self.assertEqual(s.close(), 0)
37
38        for config in [None, 'key_format=S,value_format=S', None]:
39            s = self.conn.open_session()
40            self.assertEqual(s.drop("table:test", "force"), 0)
41            self.assertEqual(s.create("table:test", config), 0)
42            self.assertEqual(s.drop("table:test"), 0)
43            self.assertEqual(s.close(), 0)
44            s = self.conn.open_session()
45            self.assertNotEqual(s, None)
46            self.assertEqual(s.create("table:test", config), 0)
47            self.assertEqual(s.close(), 0)
48
49    def test_drop_create2(self):
50        s, self.session = self.session, None
51        self.assertEqual(s.close(), 0)
52
53        # Test creating the same table with multiple sessions, to ensure
54        # that session table cache is working as expected.
55        s = self.conn.open_session()
56        s2 = self.conn.open_session()
57        self.assertEqual(s.drop("table:test", "force"), 0)
58        self.assertEqual(s.create("table:test", 'key_format=S,value_format=S,columns=(k,v)'), 0)
59        # Ensure the table cache for the second session knows about this table
60        c2 = s2.open_cursor("table:test", None, None)
61        c2.close()
62        self.assertEqual(s.drop("table:test"), 0)
63        # Create a table with the same name, but a different schema
64        self.assertEqual(s.create("table:test", 'key_format=S,value_format=l,columns=(k,v)'), 0)
65        c2 = s2.open_cursor("table:test", None, None)
66        c2["Hi"] = 1
67        self.assertEqual(s.close(), 0)
68        self.assertEqual(s2.close(), 0)
69
70if __name__ == '__main__':
71    wttest.run()
72