github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/soliton/stmtsummary/variables_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package stmtsummary 15 16 import ( 17 . "github.com/whtcorpsinc/check" 18 "github.com/whtcorpsinc/milevadb/config" 19 ) 20 21 var _ = Suite(&testVariablesSuite{}) 22 23 type testVariablesSuite struct { 24 } 25 26 func (s *testVariablesSuite) TestSetInVariable(c *C) { 27 sv := newSysVars() 28 st := sv.getVariable(typeMaxStmtCount) 29 c.Assert(st, Equals, int64(config.GetGlobalConfig().StmtSummary.MaxStmtCount)) 30 31 sv.setVariable(typeMaxStmtCount, "10", false) 32 st = sv.getVariable(typeMaxStmtCount) 33 c.Assert(st, Equals, int64(10)) 34 sv.setVariable(typeMaxStmtCount, "100", false) 35 st = sv.getVariable(typeMaxStmtCount) 36 c.Assert(st, Equals, int64(100)) 37 sv.setVariable(typeMaxStmtCount, "10", true) 38 st = sv.getVariable(typeMaxStmtCount) 39 c.Assert(st, Equals, int64(10)) 40 sv.setVariable(typeMaxStmtCount, "100", true) 41 st = sv.getVariable(typeMaxStmtCount) 42 c.Assert(st, Equals, int64(100)) 43 sv.setVariable(typeMaxStmtCount, "10", false) 44 st = sv.getVariable(typeMaxStmtCount) 45 c.Assert(st, Equals, int64(100)) 46 sv.setVariable(typeMaxStmtCount, "", true) 47 st = sv.getVariable(typeMaxStmtCount) 48 c.Assert(st, Equals, int64(10)) 49 sv.setVariable(typeMaxStmtCount, "", false) 50 st = sv.getVariable(typeMaxStmtCount) 51 c.Assert(st, Equals, int64(config.GetGlobalConfig().StmtSummary.MaxStmtCount)) 52 } 53 54 func (s *testVariablesSuite) TestSetBoolVariable(c *C) { 55 sv := newSysVars() 56 en := sv.getVariable(typeEnable) 57 c.Assert(en > 0, Equals, config.GetGlobalConfig().StmtSummary.Enable) 58 59 sv.setVariable(typeEnable, "OFF", false) 60 en = sv.getVariable(typeEnable) 61 c.Assert(en > 0, Equals, false) 62 sv.setVariable(typeEnable, "ON", false) 63 en = sv.getVariable(typeEnable) 64 c.Assert(en > 0, Equals, true) 65 sv.setVariable(typeEnable, "OFF", true) 66 en = sv.getVariable(typeEnable) 67 c.Assert(en > 0, Equals, false) 68 sv.setVariable(typeEnable, "ON", true) 69 en = sv.getVariable(typeEnable) 70 c.Assert(en > 0, Equals, true) 71 sv.setVariable(typeEnable, "OFF", false) 72 en = sv.getVariable(typeEnable) 73 c.Assert(en > 0, Equals, true) 74 sv.setVariable(typeEnable, "", true) 75 en = sv.getVariable(typeEnable) 76 c.Assert(en > 0, Equals, false) 77 sv.setVariable(typeEnable, "ON", false) 78 en = sv.getVariable(typeEnable) 79 c.Assert(en > 0, Equals, true) 80 sv.setVariable(typeEnable, "", false) 81 en = sv.getVariable(typeEnable) 82 c.Assert(en > 0, Equals, config.GetGlobalConfig().StmtSummary.Enable) 83 } 84 85 func (s *testVariablesSuite) TestMinValue(c *C) { 86 sv := newSysVars() 87 sv.setVariable(typeMaxStmtCount, "0", false) 88 v := sv.getVariable(typeMaxStmtCount) 89 c.Assert(v, Greater, int64(0)) 90 91 sv.setVariable(typeMaxALLEGROSQLLength, "0", false) 92 v = sv.getVariable(typeMaxALLEGROSQLLength) 93 c.Assert(v, Equals, int64(0)) 94 95 sv.setVariable(typeHistorySize, "0", false) 96 v = sv.getVariable(typeHistorySize) 97 c.Assert(v, Equals, int64(0)) 98 99 sv.setVariable(typeRefreshInterval, "0", false) 100 v = sv.getVariable(typeRefreshInterval) 101 c.Assert(v, Greater, int64(0)) 102 }