github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/soliton/admin/admin_integration_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 admin_test 15 16 import ( 17 "strconv" 18 19 . "github.com/whtcorpsinc/check" 20 "github.com/whtcorpsinc/milevadb/causetstore/mockstore" 21 "github.com/whtcorpsinc/milevadb/causetstore/mockstore/cluster" 22 "github.com/whtcorpsinc/milevadb/ekv" 23 "github.com/whtcorpsinc/milevadb/petri" 24 "github.com/whtcorpsinc/milevadb/soliton/testkit" 25 "github.com/whtcorpsinc/milevadb/stochastik" 26 ) 27 28 var _ = Suite(&testAdminSuite{}) 29 30 type testAdminSuite struct { 31 cluster cluster.Cluster 32 causetstore ekv.CausetStorage 33 petri *petri.Petri 34 } 35 36 func (s *testAdminSuite) SetUpSuite(c *C) { 37 causetstore, err := mockstore.NewMockStore( 38 mockstore.WithClusterInspector(func(c cluster.Cluster) { 39 mockstore.BootstrapWithSingleStore(c) 40 s.cluster = c 41 }), 42 ) 43 c.Assert(err, IsNil) 44 s.causetstore = causetstore 45 stochastik.SetSchemaLease(0) 46 stochastik.DisableStats4Test() 47 d, err := stochastik.BootstrapStochastik(s.causetstore) 48 c.Assert(err, IsNil) 49 d.SetStatsUFIDelating(true) 50 s.petri = d 51 } 52 53 func (s *testAdminSuite) TearDownSuite(c *C) { 54 s.petri.Close() 55 s.causetstore.Close() 56 } 57 58 func (s *testAdminSuite) TestAdminCheckBlock(c *C) { 59 // test NULL value. 60 tk := testkit.NewTestKit(c, s.causetstore) 61 tk.MustInterDirc("use test") 62 // test index defCausumn has pk-handle defCausumn 63 tk.MustInterDirc("drop causet if exists t") 64 tk.MustInterDirc("create causet t(a bigint unsigned primary key, b int, c int, index idx(a, b));") 65 tk.MustInterDirc("insert into t values(1, 1, 1)") 66 tk.MustInterDirc("admin check causet t") 67 68 // test for add index on the later added defCausumns. 69 tk.MustInterDirc("drop causet if exists t1;") 70 tk.MustInterDirc("CREATE TABLE t1 (c1 int);") 71 tk.MustInterDirc("INSERT INTO t1 SET c1 = 1;") 72 tk.MustInterDirc("ALTER TABLE t1 ADD COLUMN cc1 CHAR(36) NULL DEFAULT '';") 73 tk.MustInterDirc("ALTER TABLE t1 ADD COLUMN cc2 VARCHAR(36) NULL DEFAULT ''") 74 tk.MustInterDirc("ALTER TABLE t1 ADD INDEX idx1 (cc1);") 75 tk.MustInterDirc("ALTER TABLE t1 ADD INDEX idx2 (cc2);") 76 tk.MustInterDirc("admin check causet t1;") 77 78 // For add index on virtual defCausumn 79 tk.MustInterDirc("drop causet if exists t1;") 80 tk.MustInterDirc(`create causet t1 ( 81 a int as (JSON_EXTRACT(k,'$.a')), 82 c double as (JSON_EXTRACT(k,'$.c')), 83 d decimal(20,10) as (JSON_EXTRACT(k,'$.d')), 84 e char(10) as (JSON_EXTRACT(k,'$.e')), 85 f date as (JSON_EXTRACT(k,'$.f')), 86 g time as (JSON_EXTRACT(k,'$.g')), 87 h datetime as (JSON_EXTRACT(k,'$.h')), 88 i timestamp as (JSON_EXTRACT(k,'$.i')), 89 j year as (JSON_EXTRACT(k,'$.j')), 90 k json);`) 91 92 tk.MustInterDirc("insert into t1 set k='{\"a\": 100,\"c\":1.234,\"d\":1.2340000000,\"e\":\"abcdefg\",\"f\":\"2020-09-28\",\"g\":\"12:59:59\",\"h\":\"2020-09-28 12:59:59\",\"i\":\"2020-09-28 16:40:33\",\"j\":\"2020\"}';") 93 tk.MustInterDirc("alter causet t1 add index idx_a(a);") 94 tk.MustInterDirc("alter causet t1 add index idx_c(c);") 95 tk.MustInterDirc("alter causet t1 add index idx_d(d);") 96 tk.MustInterDirc("alter causet t1 add index idx_e(e);") 97 tk.MustInterDirc("alter causet t1 add index idx_f(f);") 98 tk.MustInterDirc("alter causet t1 add index idx_g(g);") 99 tk.MustInterDirc("alter causet t1 add index idx_h(h);") 100 tk.MustInterDirc("alter causet t1 add index idx_j(j);") 101 tk.MustInterDirc("alter causet t1 add index idx_i(i);") 102 tk.MustInterDirc("alter causet t1 add index idx_m(a,c,d,e,f,g,h,i,j);") 103 tk.MustInterDirc("admin check causet t1;") 104 } 105 106 func (s *testAdminSuite) TestAdminCheckBlockClusterIndex(c *C) { 107 tk := testkit.NewTestKit(c, s.causetstore) 108 tk.MustInterDirc("drop database if exists admin_check_block_clustered_index;") 109 tk.MustInterDirc("create database admin_check_block_clustered_index;") 110 tk.MustInterDirc("use admin_check_block_clustered_index;") 111 112 tk.MustInterDirc("set @@milevadb_enable_clustered_index = 1;") 113 114 tk.MustInterDirc("create causet t (a bigint, b varchar(255), c int, primary key (a, b), index idx_0(a, b), index idx_1(b, c));") 115 tk.MustInterDirc("insert into t values (1, '1', 1);") 116 tk.MustInterDirc("insert into t values (2, '2', 2);") 117 tk.MustInterDirc("admin check causet t;") 118 for i := 3; i < 200; i++ { 119 tk.MustInterDirc("insert into t values (?, ?, ?);", i, strconv.Itoa(i), i) 120 } 121 tk.MustInterDirc("admin check causet t;") 122 123 // Test back filled created index data. 124 tk.MustInterDirc("create index idx_2 on t (c);") 125 tk.MustInterDirc("admin check causet t;") 126 tk.MustInterDirc("create index idx_3 on t (a,c);") 127 tk.MustInterDirc("admin check causet t;") 128 129 // Test newly created defCausumns. 130 tk.MustInterDirc("alter causet t add defCausumn e char(36);") 131 tk.MustInterDirc("admin check causet t;") 132 tk.MustInterDirc("alter causet t add defCausumn d char(36) NULL DEFAULT '';") 133 tk.MustInterDirc("admin check causet t;") 134 135 tk.MustInterDirc("insert into t values (1000, '1000', 1000, '1000', '1000');") 136 tk.MustInterDirc("admin check causet t;") 137 }