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 os 30from suite_subprocess import suite_subprocess 31import wiredtiger, wttest 32 33# test_util14.py 34# Utilities: wt truncate 35class test_util14(wttest.WiredTigerTestCase, suite_subprocess): 36 tablename = 'test_util14.a' 37 nentries = 1000 38 39 def test_truncate_process(self): 40 """ 41 Test truncate in a 'wt' process 42 """ 43 params = 'key_format=S,value_format=S' 44 self.session.create('table:' + self.tablename, params) 45 self.assertTrue(os.path.exists(self.tablename + ".wt")) 46 cursor = self.session.open_cursor('table:' + self.tablename, None, None) 47 for i in range(0, self.nentries): 48 cursor[str(i)] = str(i) 49 cursor.close() 50 51 self.runWt(["truncate", "table:" + self.tablename]) 52 53 """ 54 Test to confirm table exists and is empty 55 """ 56 outfile="outfile.txt" 57 errfile="errfile.txt" 58 self.assertTrue(os.path.exists(self.tablename + ".wt")) 59 self.runWt(["read", 'table:' + self.tablename, 'NoMatch'], 60 outfilename=outfile, errfilename=errfile, failure=True) 61 self.check_empty_file(outfile) 62 self.check_file_contains(errfile, 'NoMatch: not found\n') 63 64 """ 65 Tests for error cases 66 1. Missing URI 67 2. Invalid URI 68 3. Valid but incorrect URI 69 4. Double URI 70 """ 71 self.runWt(["truncate"], 72 outfilename=outfile, errfilename=errfile, failure=True) 73 self.check_empty_file(outfile) 74 self.check_file_contains(errfile, 'usage:') 75 76 self.runWt(["truncate", "foobar"], 77 outfilename=outfile, errfilename=errfile, failure=True) 78 self.check_empty_file(outfile) 79 self.check_file_contains(errfile, 'No such file or directory') 80 81 self.runWt(["truncate", 'table:xx' + self.tablename], 82 outfilename=outfile, errfilename=errfile, failure=True) 83 self.check_empty_file(outfile) 84 self.check_file_contains(errfile, 'No such file or directory') 85 86 self.runWt(["truncate", 'table:' + self.tablename, 'table:' + self.tablename], 87 outfilename=outfile, errfilename=errfile, failure=True) 88 self.check_empty_file(outfile) 89 self.check_file_contains(errfile, 'usage:') 90 91if __name__ == '__main__': 92 wttest.run() 93