github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/domain/domain_test.go (about)

     1  // Copyright 2015 PingCAP, 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 domain
    15  
    16  import (
    17  	"sync/atomic"
    18  	"testing"
    19  	"time"
    20  
    21  	. "github.com/insionng/yougam/libraries/pingcap/check"
    22  	"github.com/insionng/yougam/libraries/pingcap/tidb/ast"
    23  	"github.com/insionng/yougam/libraries/pingcap/tidb/model"
    24  	"github.com/insionng/yougam/libraries/pingcap/tidb/sessionctx/variable"
    25  	"github.com/insionng/yougam/libraries/pingcap/tidb/store/localstore"
    26  	"github.com/insionng/yougam/libraries/pingcap/tidb/store/localstore/goleveldb"
    27  	"github.com/insionng/yougam/libraries/pingcap/tidb/util/mock"
    28  )
    29  
    30  func TestT(t *testing.T) {
    31  	TestingT(t)
    32  }
    33  
    34  var _ = Suite(&testSuite{})
    35  
    36  type testSuite struct {
    37  }
    38  
    39  func (*testSuite) TestT(c *C) {
    40  	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
    41  	store, err := driver.Open("memory")
    42  	c.Assert(err, IsNil)
    43  	defer store.Close()
    44  
    45  	ctx := mock.NewContext()
    46  
    47  	dom, err := NewDomain(store, 0)
    48  	c.Assert(err, IsNil)
    49  	store = dom.Store()
    50  	dd := dom.DDL()
    51  	c.Assert(dd, NotNil)
    52  	cs := &ast.CharsetOpt{
    53  		Chs: "utf8",
    54  		Col: "utf8_bin",
    55  	}
    56  	err = dd.CreateSchema(ctx, model.NewCIStr("aaa"), cs)
    57  	c.Assert(err, IsNil)
    58  	is := dom.InfoSchema()
    59  	c.Assert(is, NotNil)
    60  	dom, err = NewDomain(store, 0)
    61  	c.Assert(err, IsNil)
    62  
    63  	dom.SetLease(10 * time.Second)
    64  
    65  	m, err := dom.Stats()
    66  	c.Assert(err, IsNil)
    67  	c.Assert(m[ddlLastReloadSchemaTS], GreaterEqual, int64(0))
    68  
    69  	c.Assert(dom.GetScope("dummy_status"), Equals, variable.DefaultScopeFlag)
    70  
    71  	dom.SetLease(10 * time.Millisecond)
    72  	time.Sleep(20 * time.Millisecond)
    73  	atomic.StoreInt64(&dom.lastLeaseTS, 0)
    74  	dom.tryReload()
    75  
    76  	store.Close()
    77  	time.Sleep(1 * time.Second)
    78  }