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 glob
30import os.path
31import time
32import helper, wiredtiger, wttest
33from wiredtiger import stat
34
35# test_stat_log01.py
36#    Statistics log
37class test_stat_log01(wttest.WiredTigerTestCase):
38    """
39    Test statistics log
40    """
41
42    # Tests need to setup the connection in their own way.
43    def setUpConnectionOpen(self, dir):
44        return None
45
46    def setUpSessionOpen(self, conn):
47        return None
48
49    def test_stats_log_default(self):
50        self.conn = self.wiredtiger_open(
51            None, "create,statistics=(fast),statistics_log=(wait=1)")
52        # Wait for the default interval, to ensure stats have been written.
53        time.sleep(2)
54        self.check_stats_file(".")
55
56    def test_stats_log_name(self):
57        os.mkdir("foo")
58        self.conn = self.wiredtiger_open(
59            None, "create,statistics=(fast),statistics_log=(wait=1,path=foo)")
60        # Wait for the default interval, to ensure stats have been written.
61        time.sleep(2)
62        self.check_stats_file("foo")
63
64    def test_stats_log_on_close_and_log(self):
65        self.conn = self.wiredtiger_open(None,
66            "create,statistics=(fast),statistics_log=(on_close=true,wait=1)")
67        # Wait for the default interval, to ensure stats have been written.
68        time.sleep(2)
69        self.close_conn()
70        self.check_stats_file(".")
71
72    def test_stats_log_on_close(self):
73        self.conn = self.wiredtiger_open(None,
74            "create,statistics=(fast),statistics_log=(on_close=true)")
75        # Close the connection to ensure the statistics get generated.
76        self.close_conn()
77        self.check_stats_file(".")
78
79    def check_stats_file(self, dir):
80        files = glob.glob(dir + '/' + 'WiredTigerStat.[0-9]*')
81        self.assertTrue(files)
82
83if __name__ == '__main__':
84    wttest.run()
85