github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/stochastikctx/variable/sysvar_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 variable 15 16 import ( 17 "testing" 18 19 "github.com/whtcorpsinc/BerolinaSQL/allegrosql" 20 "github.com/whtcorpsinc/BerolinaSQL/terror" 21 . "github.com/whtcorpsinc/check" 22 ) 23 24 func TestT(t *testing.T) { 25 CustomVerboseFlag = true 26 TestingT(t) 27 } 28 29 var _ = Suite(&testSysVarSuite{}) 30 31 type testSysVarSuite struct { 32 } 33 34 func (*testSysVarSuite) TestSysVar(c *C) { 35 f := GetSysVar("autocommit") 36 c.Assert(f, NotNil) 37 38 f = GetSysVar("wrong-var-name") 39 c.Assert(f, IsNil) 40 41 f = GetSysVar("explicit_defaults_for_timestamp") 42 c.Assert(f, NotNil) 43 c.Assert(f.Value, Equals, "1") 44 45 f = GetSysVar("port") 46 c.Assert(f, NotNil) 47 c.Assert(f.Value, Equals, "4000") 48 49 f = GetSysVar("milevadb_low_resolution_tso") 50 c.Assert(f.Value, Equals, "0") 51 52 f = GetSysVar("milevadb_replica_read") 53 c.Assert(f.Value, Equals, "leader") 54 55 f = GetSysVar("milevadb_enable_block_partition") 56 c.Assert(f.Value, Equals, "on") 57 } 58 59 func (*testSysVarSuite) TestTxnMode(c *C) { 60 seVar := NewStochastikVars() 61 c.Assert(seVar, NotNil) 62 c.Assert(seVar.TxnMode, Equals, "") 63 err := seVar.setTxnMode("pessimistic") 64 c.Assert(err, IsNil) 65 err = seVar.setTxnMode("optimistic") 66 c.Assert(err, IsNil) 67 err = seVar.setTxnMode("") 68 c.Assert(err, IsNil) 69 err = seVar.setTxnMode("something else") 70 c.Assert(err, NotNil) 71 } 72 73 func (*testSysVarSuite) TestBoolToInt32(c *C) { 74 c.Assert(BoolToInt32(true), Equals, int32(1)) 75 c.Assert(BoolToInt32(false), Equals, int32(0)) 76 } 77 78 func (*testSysVarSuite) TestError(c *C) { 79 ekvErrs := []*terror.Error{ 80 ErrUnsupportedValueForVar, 81 ErrUnknownSystemVar, 82 ErrIncorrectScope, 83 ErrUnknownTimeZone, 84 ErrReadOnly, 85 ErrWrongValueForVar, 86 ErrWrongTypeForVar, 87 ErrTruncatedWrongValue, 88 ErrMaxPreparedStmtCountReached, 89 ErrUnsupportedIsolationLevel, 90 } 91 for _, err := range ekvErrs { 92 c.Assert(terror.ToALLEGROSQLError(err).Code != allegrosql.ErrUnknown, IsTrue) 93 } 94 }