Best Python code snippet using tempest_python
test_alter01.py
Source:test_alter01.py
...58 ('reopen', dict(reopen=True)),59 ]60 cache_alter=('', 'false', 'true')61 scenarios = make_scenarios(types, hints, resid, reopen)62 def verify_metadata(self, metastr):63 if metastr == '':64 return65 cursor = self.session.open_cursor('metadata:', None, None)66 #67 # Walk through all the metadata looking for the entries that are68 # the file URIs for components of the table.69 #70 found = False71 while True:72 ret = cursor.next()73 if ret != 0:74 break75 key = cursor.get_key()76 check_meta = ((key.find("lsm:") != -1 or key.find("file:") != -1) \77 and key.find(self.name) != -1)78 if check_meta:79 value = cursor[key]80 found = True81 self.assertTrue(value.find(metastr) != -1)82 cursor.close()83 self.assertTrue(found == True)84 # Alter: Change the access pattern hint after creation85 def test_alter01_access(self):86 uri = self.uri + self.name87 create_params = 'key_format=i,value_format=i,'88 complex_params = ''89 #90 # If we're not explicitly setting the parameter, then don't91 # modify create_params to test using the default.92 #93 if self.acreate != '':94 access_param = 'access_pattern_hint=%s' % self.acreate95 create_params += '%s,' % access_param96 complex_params += '%s,' % access_param97 else:98 # NOTE: This is hard-coding the default value. If the default99 # changes then this will fail and need to be fixed.100 access_param = 'access_pattern_hint=none'101 if self.ccreate != '':102 cache_param = 'cache_resident=%s' % self.ccreate103 create_params += '%s,' % cache_param104 complex_params += '%s,' % cache_param105 else:106 # NOTE: This is hard-coding the default value. If the default107 # changes then this will fail and need to be fixed.108 cache_param = 'cache_resident=false'109 cgparam = ''110 if self.use_cg or self.use_index:111 cgparam = 'columns=(k,v),'112 if self.use_cg:113 cgparam += 'colgroups=(g0),'114 self.session.create(uri, create_params + cgparam)115 # Add in column group or index settings.116 if self.use_cg:117 cgparam = 'columns=(v),'118 suburi = 'colgroup:' + self.name + ':g0'119 self.session.create(suburi, complex_params + cgparam)120 if self.use_index:121 suburi = 'index:' + self.name + ':i0'122 self.session.create(suburi, complex_params + cgparam)123 # Put some data in table.124 c = self.session.open_cursor(uri, None)125 for k in range(self.entries):126 c[k+1] = 1127 c.close()128 # Verify the string in the metadata129 self.verify_metadata(access_param)130 self.verify_metadata(cache_param)131 # Run through all combinations of the alter commands132 # for all allowed settings. This tests having only one or133 # the other set as well as having both set. It will also134 # cover trying to change the setting to its current value.135 for a in self.access_alter:136 alter_param = ''137 access_str = ''138 if a != '':139 access_str = 'access_pattern_hint=%s' % a140 for c in self.cache_alter:141 alter_param = '%s' % access_str142 cache_str = ''143 if c != '':144 cache_str = 'cache_resident=%s' % c145 alter_param += ',%s' % cache_str146 if alter_param != '':147 self.session.alter(uri, alter_param)148 if self.reopen:149 self.reopen_conn()150 special = self.use_cg or self.use_index151 if not special:152 self.verify_metadata(access_str)153 self.verify_metadata(cache_str)154 else:155 self.session.alter(suburi, alter_param)156 self.verify_metadata(access_str)157 self.verify_metadata(cache_str)158if __name__ == '__main__':...
test_alter03.py
Source:test_alter03.py
...30# test_alter03.py31# Check if app_metadata can be altered.32class test_alter03(wttest.WiredTigerTestCase):33 name = "alter03"34 def verify_metadata(self, table_metastr, file_metastr):35 if table_metastr == '' and file_metastr == '':36 return37 c = self.session.open_cursor('metadata:', None, None)38 if table_metastr != '':39 # We must find a table type entry for this object and it's value40 # should contain the provided table meta string.41 c.set_key('table:' + self.name)42 self.assertNotEqual(c.search(), wiredtiger.WT_NOTFOUND)43 value = c.get_value()44 self.assertTrue(value.find(table_metastr) != -1)45 if file_metastr != '':46 # We must find a file type entry for the object and it's value47 # should contain the provided file meta string.48 c.set_key('file:' + self.name + '.wt')49 self.assertNotEqual(c.search(), wiredtiger.WT_NOTFOUND)50 value = c.get_value()51 self.assertTrue(value.find(file_metastr) != -1)52 c.close()53 # Alter Table: Change the app_metadata and verify54 def test_alter03_table_app_metadata(self):55 uri = "table:" + self.name56 entries = 10057 create_params = 'key_format=i,value_format=i,'58 app_meta_orig = 'app_metadata="meta_data_1",'59 self.session.create(uri, create_params + app_meta_orig)60 # Put some data in table.61 c = self.session.open_cursor(uri, None)62 for k in range(entries):63 c[k+1] = 164 c.close()65 # Verify the string in the metadata66 self.verify_metadata(app_meta_orig, app_meta_orig)67 # Alter app metadata and verify68 self.session.alter(uri, 'app_metadata="meta_data_2",')69 self.verify_metadata('app_metadata="meta_data_2",', 'app_metadata="meta_data_2",')70 # Alter app metadata, explicitly asking for exclusive access and verify71 self.session.alter(uri, 'app_metadata="meta_data_3",exclusive_refreshed=true,')72 self.verify_metadata('app_metadata="meta_data_3",', 'app_metadata="meta_data_3",')73 # Alter app metadata without taking exclusive lock and verify that only74 # table object gets modified75 self.session.alter(uri, 'app_metadata="meta_data_4",exclusive_refreshed=false,')76 self.verify_metadata('app_metadata="meta_data_4",', 'app_metadata="meta_data_3",')77 # Open a cursor, insert some data and try to alter with session open.78 # We should fail unless we ask not to take an exclusive lock79 c2 = self.session.open_cursor(uri, None)80 for k in range(entries):81 c2[k+1] = 282 self.assertRaisesException(wiredtiger.WiredTigerError,83 lambda: self.session.alter(uri, 'app_metadata="meta_data_5",'))84 self.verify_metadata('app_metadata="meta_data_4",', 'app_metadata="meta_data_3",')85 self.assertRaisesException(wiredtiger.WiredTigerError,86 lambda: self.session.alter(uri,87 'exclusive_refreshed=true,app_metadata="meta_data_5",'))88 self.verify_metadata('app_metadata="meta_data_4",', 'app_metadata="meta_data_3",')89 self.session.alter(uri, 'app_metadata="meta_data_5",exclusive_refreshed=false,')90 self.verify_metadata('app_metadata="meta_data_5",', 'app_metadata="meta_data_3",')91 c2.close()92 # Close and reopen the connection.93 # Confirm we retain the app_metadata as expected after reopen94 self.reopen_conn()95 self.verify_metadata('app_metadata="meta_data_5",', 'app_metadata="meta_data_3",')96 # Alter LSM: A non exclusive alter should not be allowed97 def test_alter03_lsm_app_metadata(self):98 uri = "lsm:" + self.name99 create_params = 'key_format=i,value_format=i,'100 app_meta_orig = 'app_metadata="meta_data_1",'101 self.session.create(uri, create_params + app_meta_orig)102 self.assertRaisesWithMessage(wiredtiger.WiredTigerError,103 lambda: self.session.alter(uri,104 'exclusive_refreshed=false,app_metadata="meta_data_2",'),105 '/is applicable only on simple tables/')106 self.session.alter(uri, 'exclusive_refreshed=true,app_metadata="meta_data_2",')107if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!