/src/third_party/wiredtiger/test/suite/test_reconfig02.py

https://github.com/paralect/mongo · Python · 119 lines · 59 code · 12 blank · 48 comment · 6 complexity · 96a8717487ee57d2ce49f60801b7c10a MD5 · raw file

  1. #!/usr/bin/env python
  2. #
  3. # Public Domain 2014-2020 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. import fnmatch, os, time
  29. import wiredtiger, wttest
  30. # test_reconfig02.py
  31. # Smoke-test the connection reconfiguration operations.
  32. class test_reconfig02(wttest.WiredTigerTestCase):
  33. init_config = 'log=(archive=false,enabled,file_max=100K,prealloc=false,zero_fill=false)'
  34. uri = "table:reconfig02"
  35. entries = 1000
  36. def setUpConnectionOpen(self, dir):
  37. self.conn_config = self.init_config
  38. return wttest.WiredTigerTestCase.setUpConnectionOpen(self, dir)
  39. # Logging: reconfigure the things we can reconfigure.
  40. def test_reconfig02_simple(self):
  41. self.conn.reconfigure("log=(archive=false)")
  42. self.conn.reconfigure("log=(prealloc=false)")
  43. self.conn.reconfigure("log=(zero_fill=false)")
  44. self.conn.reconfigure("log=(archive=true)")
  45. self.conn.reconfigure("log=(prealloc=true)")
  46. self.conn.reconfigure("log=(zero_fill=true)")
  47. # Logging: reconfigure the things we can't reconfigure.
  48. def test_reconfig02_disable(self):
  49. msg = '/unknown configuration key/'
  50. self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
  51. lambda: self.conn.reconfigure("log=(enabled=true)"), msg)
  52. self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
  53. lambda: self.conn.reconfigure("log=(compressor=foo)"), msg)
  54. self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
  55. lambda: self.conn.reconfigure("log=(file_max=1MB)"), msg)
  56. self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
  57. lambda: self.conn.reconfigure("log=(path=foo)"), msg)
  58. self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
  59. lambda: self.conn.reconfigure("log=(recover=true)"), msg)
  60. # Logging starts on, but prealloc is off. Verify it is off.
  61. # Reconfigure it on and run again, making sure that log files
  62. # get pre-allocated.
  63. def test_reconfig02_prealloc(self):
  64. # Create a table just to write something into the log. Sleep
  65. # to give the worker thread a chance to run.
  66. self.session.create(self.uri, 'key_format=i,value_format=i')
  67. time.sleep(2)
  68. prep_logs = fnmatch.filter(os.listdir('.'), "*Prep*")
  69. # Make sure no pre-allocated log files exist.
  70. self.assertEqual(0, len(prep_logs))
  71. # Now turn on pre-allocation. Sleep to give the worker thread
  72. # a chance to run and verify pre-allocated log files exist.
  73. #
  74. # Potentially loop a few times in case it is a very slow system.
  75. self.conn.reconfigure("log=(prealloc=true)")
  76. for x in range(0, 100):
  77. time.sleep(1)
  78. prep_logs = fnmatch.filter(os.listdir('.'), "*Prep*")
  79. if len(prep_logs) != 0:
  80. break
  81. self.assertNotEqual(0, len(prep_logs))
  82. # Logging starts on, but archive is off. Verify it is off.
  83. # Reconfigure it on and run again, making sure that log files
  84. # get archived.
  85. def test_reconfig02_archive(self):
  86. self.session.create(self.uri, 'key_format=i,value_format=i')
  87. c = self.session.open_cursor(self.uri, None, None)
  88. for i in range(self.entries):
  89. c[i] = i + 1
  90. c.close()
  91. # Close and reopen connection to write a checkpoint, move to the
  92. # next log file and verify that archive did not run.
  93. orig_logs = fnmatch.filter(os.listdir('.'), "*gerLog*")
  94. self.reopen_conn()
  95. cur_logs = fnmatch.filter(os.listdir('.'), "*gerLog*")
  96. for o in orig_logs:
  97. self.assertEqual(True, o in cur_logs)
  98. # Now turn on archive, sleep a bit to allow the archive thread
  99. # to run and then confirm that all original logs are gone.
  100. self.conn.reconfigure("log=(archive=true)")
  101. self.session.checkpoint("force")
  102. time.sleep(2)
  103. cur_logs = fnmatch.filter(os.listdir('.'), "*gerLog*")
  104. for o in orig_logs:
  105. self.assertEqual(False, o in cur_logs)
  106. if __name__ == '__main__':
  107. wttest.run()