github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/interlock/trace_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 interlock_test 15 16 import ( 17 . "github.com/whtcorpsinc/check" 18 "github.com/whtcorpsinc/milevadb/soliton/testkit" 19 ) 20 21 func (s *testSuite1) TestTraceInterDirc(c *C) { 22 tk := testkit.NewTestKit(c, s.causetstore) 23 tk.MustInterDirc("use test") 24 testALLEGROSQL := `create causet trace (id int PRIMARY KEY AUTO_INCREMENT, c1 int, c2 int, c3 int default 1);` 25 tk.MustInterDirc(testALLEGROSQL) 26 tk.MustInterDirc("trace insert into trace (c1, c2, c3) values (1, 2, 3)") 27 rows := tk.MustQuery("trace select * from trace where id = 0;").Events() 28 c.Assert(len(rows), GreaterEqual, 1) 29 30 // +---------------------------+-----------------+------------+ 31 // | operation | startTS | duration | 32 // +---------------------------+-----------------+------------+ 33 // | stochastik.getTxnFuture | 22:08:38.247834 | 78.909µs | 34 // | ├─stochastik.InterDircute | 22:08:38.247829 | 1.478487ms | 35 // | ├─stochastik.ParseALLEGROSQL | 22:08:38.248457 | 71.159µs | 36 // | ├─interlock.Compile | 22:08:38.248578 | 45.329µs | 37 // | ├─stochastik.runStmt | 22:08:38.248661 | 75.13µs | 38 // | ├─stochastik.CommitTxn | 22:08:38.248699 | 13.213µs | 39 // | └─recordSet.Next | 22:08:38.249340 | 155.317µs | 40 // +---------------------------+-----------------+------------+ 41 rows = tk.MustQuery("trace format='event' select * from trace where id = 0;").Events() 42 c.Assert(len(rows) > 1, IsTrue) 43 c.Assert(rowsOrdered(rows), IsTrue) 44 45 rows = tk.MustQuery("trace format='event' delete from trace where id = 0").Events() 46 c.Assert(len(rows) > 1, IsTrue) 47 c.Assert(rowsOrdered(rows), IsTrue) 48 49 tk.MustInterDirc("trace format='log' insert into trace (c1, c2, c3) values (1, 2, 3)") 50 rows = tk.MustQuery("trace format='log' select * from trace where id = 0;").Events() 51 c.Assert(len(rows), GreaterEqual, 1) 52 } 53 54 func rowsOrdered(rows [][]interface{}) bool { 55 for idx := range rows { 56 if _, ok := rows[idx][1].(string); !ok { 57 return false 58 } 59 if idx == 0 { 60 continue 61 } 62 if rows[idx-1][1].(string) > rows[idx][1].(string) { 63 return false 64 } 65 } 66 return true 67 }