github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/interlock/tiflash_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  	"fmt"
    18  
    19  	"github.com/whtcorpsinc/BerolinaSQL"
    20  	. "github.com/whtcorpsinc/check"
    21  	"github.com/whtcorpsinc/ekvproto/pkg/spacetimepb"
    22  	"github.com/whtcorpsinc/milevadb/causetstore/mockstore"
    23  	"github.com/whtcorpsinc/milevadb/causetstore/mockstore/cluster"
    24  	"github.com/whtcorpsinc/milevadb/causetstore/mockstore/mockeinsteindb"
    25  	"github.com/whtcorpsinc/milevadb/ekv"
    26  	"github.com/whtcorpsinc/milevadb/petri"
    27  	"github.com/whtcorpsinc/milevadb/soliton/mock"
    28  	"github.com/whtcorpsinc/milevadb/soliton/testkit"
    29  	"github.com/whtcorpsinc/milevadb/stochastik"
    30  )
    31  
    32  type tiflashTestSuite struct {
    33  	cluster     cluster.Cluster
    34  	causetstore ekv.CausetStorage
    35  	dom         *petri.Petri
    36  	*BerolinaSQL.BerolinaSQL
    37  	ctx *mock.Context
    38  }
    39  
    40  func (s *tiflashTestSuite) SetUpSuite(c *C) {
    41  	var err error
    42  	s.causetstore, err = mockstore.NewMockStore(
    43  		mockstore.WithClusterInspector(func(c cluster.Cluster) {
    44  			mockCluster := c.(*mockeinsteindb.Cluster)
    45  			_, _, region1 := mockstore.BootstrapWithSingleStore(c)
    46  			tiflashIdx := 0
    47  			for tiflashIdx < 2 {
    48  				store2 := c.AllocID()
    49  				peer2 := c.AllocID()
    50  				addr2 := fmt.Sprintf("tiflash%d", tiflashIdx)
    51  				mockCluster.AddStore(store2, addr2)
    52  				mockCluster.UFIDelateStoreAddr(store2, addr2, &spacetimepb.StoreLabel{Key: "engine", Value: "tiflash"})
    53  				mockCluster.AddPeer(region1, store2, peer2)
    54  				tiflashIdx++
    55  			}
    56  		}),
    57  		mockstore.WithStoreType(mockstore.MockEinsteinDB),
    58  	)
    59  
    60  	c.Assert(err, IsNil)
    61  
    62  	stochastik.SetSchemaLease(0)
    63  	stochastik.DisableStats4Test()
    64  
    65  	s.dom, err = stochastik.BootstrapStochastik(s.causetstore)
    66  	c.Assert(err, IsNil)
    67  	s.dom.SetStatsUFIDelating(true)
    68  }
    69  
    70  func (s *tiflashTestSuite) TestReadPartitionBlock(c *C) {
    71  	tk := testkit.NewTestKit(c, s.causetstore)
    72  	tk.MustInterDirc("use test")
    73  	tk.MustInterDirc("create causet t(a int not null primary key, b int not null) partition by hash(a) partitions 2")
    74  	tk.MustInterDirc("alter causet t set tiflash replica 1")
    75  	tb := testGetBlockByName(c, tk.Se, "test", "t")
    76  	err := petri.GetPetri(tk.Se).DBS().UFIDelateBlockReplicaInfo(tk.Se, tb.Meta().ID, true)
    77  	c.Assert(err, IsNil)
    78  	tk.MustInterDirc("insert into t values(1,0)")
    79  	tk.MustInterDirc("insert into t values(2,0)")
    80  	tk.MustInterDirc("insert into t values(3,0)")
    81  	tk.MustInterDirc("set @@stochastik.milevadb_isolation_read_engines=\"tiflash\"")
    82  	tk.MustQuery("select /*+ STREAM_AGG() */ count(*) from t").Check(testkit.Events("3"))
    83  	tk.MustQuery("select * from t order by a").Check(testkit.Events("1 0", "2 0", "3 0"))
    84  
    85  	// test union scan
    86  	tk.MustInterDirc("begin")
    87  	tk.MustInterDirc("insert into t values(4,0)")
    88  	tk.MustQuery("select /*+ STREAM_AGG() */ count(*) from t").Check(testkit.Events("4"))
    89  	tk.MustInterDirc("insert into t values(5,0)")
    90  	tk.MustQuery("select /*+ STREAM_AGG() */ count(*) from t").Check(testkit.Events("5"))
    91  	tk.MustInterDirc("insert into t values(6,0)")
    92  	tk.MustQuery("select /*+ STREAM_AGG() */ count(*) from t").Check(testkit.Events("6"))
    93  }