本文整理汇总了Golang中github.com/pingcap/tidb/util/mock.NewContext函数的典型用法代码示例。如果您正苦于以下问题:Golang NewContext函数的具体用法?Golang NewContext怎么用?Golang NewContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewContext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestStat
func (s *testStatSuite) TestStat(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_stat")
defer store.Close()
lease := 50 * time.Millisecond
d := newDDL(store, nil, nil, lease)
defer d.close()
time.Sleep(lease)
dbInfo := testSchemaInfo(c, d, "test")
testCreateSchema(c, mock.NewContext(), d, dbInfo)
m, err := d.Stats()
c.Assert(err, IsNil)
c.Assert(m[ddlOwnerID], Equals, d.uuid)
job := &model.Job{
SchemaID: dbInfo.ID,
Type: model.ActionDropSchema,
Args: []interface{}{dbInfo.Name},
}
ctx := mock.NewContext()
done := make(chan error, 1)
go func() {
done <- d.doDDLJob(ctx, job)
}()
ticker := time.NewTicker(d.lease * 1)
defer ticker.Stop()
ver := s.getDDLSchemaVer(c, d)
LOOP:
for {
select {
case <-ticker.C:
d.close()
c.Assert(s.getDDLSchemaVer(c, d), GreaterEqual, ver)
d.start()
case err := <-done:
c.Assert(err, IsNil)
m, err := d.Stats()
c.Assert(err, IsNil)
c.Assert(m[bgOwnerID], Equals, d.uuid)
break LOOP
}
}
}
开发者ID:anywhy,项目名称:tidb,代码行数:51,代码来源:stat_test.go
示例2: TestVersion
func (s *testEvaluatorSuite) TestVersion(c *C) {
defer testleak.AfterTest(c)()
ctx := mock.NewContext()
v, err := builtinVersion(nil, ctx)
c.Assert(err, IsNil)
c.Assert(v.GetString(), Equals, mysql.ServerVersion)
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:7,代码来源:builtin_info_test.go
示例3: TestT
func (*testSuite) TestT(c *C) {
driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
store, err := driver.Open("memory")
c.Assert(err, IsNil)
defer store.Close()
ctx := mock.NewContext()
dom, err := NewDomain(store, 0)
c.Assert(err, IsNil)
store = dom.Store()
dd := dom.DDL()
c.Assert(dd, NotNil)
err = dd.CreateSchema(ctx, model.NewCIStr("aaa"))
c.Assert(err, IsNil)
is := dom.InfoSchema()
c.Assert(is, NotNil)
dom, err = NewDomain(store, 0)
c.Assert(err, IsNil)
dom.SetLease(10 * time.Second)
m, err := dom.Stats()
c.Assert(err, IsNil)
c.Assert(m[ddlLastReloadSchemaTS], GreaterEqual, int64(0))
dom.SetLease(50 * time.Millisecond)
store.Close()
time.Sleep(1 * time.Second)
}
开发者ID:yzl11,项目名称:vessel,代码行数:30,代码来源:domain_test.go
示例4: TestSleep
func (s *testEvaluatorSuite) TestSleep(c *C) {
defer testleak.AfterTest(c)()
ctx := mock.NewContext()
sessVars := ctx.GetSessionVars()
// non-strict model
sessVars.StrictSQLMode = false
d := make([]types.Datum, 1)
ret, err := builtinSleep(d, ctx)
c.Assert(err, IsNil)
c.Assert(ret, DeepEquals, types.NewIntDatum(0))
d[0].SetInt64(-1)
ret, err = builtinSleep(d, ctx)
c.Assert(err, IsNil)
c.Assert(ret, DeepEquals, types.NewIntDatum(0))
// for error case under the strict model
sessVars.StrictSQLMode = true
d[0].SetNull()
_, err = builtinSleep(d, ctx)
c.Assert(err, NotNil)
d[0].SetFloat64(-2.5)
_, err = builtinSleep(d, ctx)
c.Assert(err, NotNil)
// strict model
d[0].SetFloat64(0.5)
start := time.Now()
ret, err = builtinSleep(d, ctx)
c.Assert(err, IsNil)
c.Assert(ret, DeepEquals, types.NewIntDatum(0))
sub := time.Since(start)
c.Assert(sub.Nanoseconds(), GreaterEqual, int64(0.5*1e9))
}
开发者ID:pingcap,项目名称:tidb,代码行数:34,代码来源:evaluator_test.go
示例5: TestDistinct
func (t *testDistinctSuit) TestDistinct(c *C) {
tblPlan := &testTablePlan{distinctTestData, []string{"id", "name"}, 0}
p := plans.DistinctDefaultPlan{
SelectList: &plans.SelectList{
HiddenFieldOffset: len(tblPlan.GetFields()),
},
Src: tblPlan,
}
rset := rsets.Recordset{
Plan: &p,
Ctx: mock.NewContext(),
}
r := map[int][]interface{}{}
err := rset.Do(func(data []interface{}) (bool, error) {
r[data[0].(int)] = data
return true, nil
})
c.Assert(err, IsNil)
expected := map[int][]interface{}{
10: {10, "hello"},
40: {40, "hello"},
60: {60, "hello"},
}
c.Assert(reflect.DeepEqual(r, expected), Equals, true)
}
开发者ID:lovedboy,项目名称:tidb,代码行数:28,代码来源:distinct_test.go
示例6: TestCount
func (s *testAggFuncSuite) TestCount(c *C) {
// Compose aggregate exec for "select c1, count(c2) from t";
// c1 c2
// 1 1
// 2 1
// 3 nil
c1 := ast.NewValueExpr(0)
rf1 := &ast.ResultField{Expr: c1}
col1 := &ast.ColumnNameExpr{Refer: rf1}
fc1 := &ast.AggregateFuncExpr{
F: ast.AggFuncFirstRow,
Args: []ast.ExprNode{col1},
}
c2 := ast.NewValueExpr(0)
rf2 := &ast.ResultField{Expr: c2}
col2 := &ast.ColumnNameExpr{Refer: rf2}
fc2 := &ast.AggregateFuncExpr{
F: ast.AggFuncCount,
Args: []ast.ExprNode{col2},
}
row1 := []interface{}{1, 1}
row2 := []interface{}{2, 1}
row3 := []interface{}{3, nil}
data := []([]interface{}){row1, row2, row3}
rows := make([]*Row, 0, 3)
for _, d := range data {
rows = append(rows, &Row{Data: d})
}
src := &mockExec{
rows: rows,
fields: []*ast.ResultField{rf1, rf2},
}
agg := &AggregateExec{
AggFuncs: []*ast.AggregateFuncExpr{fc1, fc2},
Src: src,
}
var (
row *Row
cnt int
)
for {
r, err := agg.Next()
c.Assert(err, IsNil)
if r == nil {
break
}
row = r
cnt++
}
c.Assert(cnt, Equals, 1)
c.Assert(row, NotNil)
ctx := mock.NewContext()
val, err := evaluator.Eval(ctx, fc1)
c.Assert(err, IsNil)
c.Assert(val, Equals, 1)
val, err = evaluator.Eval(ctx, fc2)
c.Assert(err, IsNil)
c.Assert(val, Equals, int64(2))
}
开发者ID:AkihiroSuda,项目名称:tidb,代码行数:60,代码来源:aggregate_test.go
示例7: TestRegexp
func (s *testEvaluatorSuite) TestRegexp(c *C) {
tbl := []struct {
pattern string
input string
match int64
}{
{"^$", "a", 0},
{"a", "a", 1},
{"a", "b", 0},
{"aA", "aA", 1},
{".", "a", 1},
{"^.$", "ab", 0},
{"..", "b", 0},
{".ab", "aab", 1},
{".*", "abcd", 1},
}
ctx := mock.NewContext()
for _, v := range tbl {
pattern := &ast.PatternRegexpExpr{
Pattern: ast.NewValueExpr(v.pattern),
Expr: ast.NewValueExpr(v.input),
}
match, err := Eval(ctx, pattern)
c.Assert(err, IsNil)
c.Assert(match, Equals, v.match, Commentf("%v", v))
}
}
开发者ID:mumubusu,项目名称:tidb,代码行数:27,代码来源:evaluator_test.go
示例8: TestSchema
func (s *testSchemaSuite) TestSchema(c *C) {
store := testCreateStore(c, "test_schema")
defer store.Close()
lease := 100 * time.Millisecond
d1 := newDDL(store, nil, nil, lease)
defer d1.close()
ctx := mock.NewContext()
dbInfo := testSchemaInfo(c, d1, "test")
job := testCreateSchema(c, ctx, d1, dbInfo)
testCheckSchemaState(c, d1, dbInfo, model.StatePublic)
testCheckJobDone(c, d1, job, true)
job = testDropSchema(c, ctx, d1, dbInfo)
testCheckSchemaState(c, d1, dbInfo, model.StateNone)
testCheckJobDone(c, d1, job, false)
job = &model.Job{
SchemaID: dbInfo.ID,
Type: model.ActionDropSchema,
}
err := d1.startDDLJob(ctx, job)
c.Assert(terror.ErrorEqual(err, infoschema.DatabaseNotExists), IsTrue)
}
开发者ID:youprofit,项目名称:tidb,代码行数:29,代码来源:schema_test.go
示例9: SetUpSuite
func (p *testShowSuit) SetUpSuite(c *C) {
nc := mock.NewContext()
p.ctx = nc
variable.BindSessionVars(p.ctx)
variable.BindGlobalVarAccessor(p.ctx, nc)
variable.RegisterStatistics(p.ms)
p.dbName = "testshowplan"
p.store = newStore(c, p.dbName)
p.txn, _ = p.store.Begin()
se := newSession(c, p.store, p.dbName)
p.createDBSQL = fmt.Sprintf("create database if not exists %s;", p.dbName)
p.dropDBSQL = fmt.Sprintf("drop database if exists %s;", p.dbName)
p.useDBSQL = fmt.Sprintf("use %s;", p.dbName)
p.createTableSQL = `CREATE TABLE test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));`
mustExecSQL(c, se, p.createDBSQL)
mustExecSQL(c, se, p.useDBSQL)
mustExecSQL(c, se, p.createTableSQL)
p.createSystemDBSQL = fmt.Sprintf("create database if not exists %s;", mysql.SystemDB)
p.createUserTableSQL = tidb.CreateUserTable
p.createDBPrivTableSQL = tidb.CreateDBPrivTable
p.createTablePrivTableSQL = tidb.CreateTablePrivTable
p.createColumnPrivTableSQL = tidb.CreateColumnPrivTable
mustExecSQL(c, se, p.createSystemDBSQL)
mustExecSQL(c, se, p.createUserTableSQL)
mustExecSQL(c, se, p.createDBPrivTableSQL)
mustExecSQL(c, se, p.createTablePrivTableSQL)
mustExecSQL(c, se, p.createColumnPrivTableSQL)
}
开发者ID:kellerli,项目名称:tidb,代码行数:33,代码来源:show_test.go
示例10: TestTableScanWithOrder
func (s *testPlanSuite) TestTableScanWithOrder(c *C) {
defer testleak.AfterTest(c)()
// Sort result by scanning PKHandle column.
sql := "select * from t order by a limit 1;"
stmt, err := s.ParseOneStmt(sql, "", "")
c.Assert(err, IsNil)
ast.SetFlag(stmt)
err = newMockResolve(stmt)
c.Assert(err, IsNil)
builder := &planBuilder{
allocator: new(idAllocator),
ctx: mock.NewContext(),
colMapper: make(map[*ast.ColumnNameExpr]int),
}
p := builder.build(stmt)
c.Assert(builder.err, IsNil)
logic, ok := p.(LogicalPlan)
c.Assert(ok, IsTrue)
// Get physical plan.
_, pp, _, err := logic.convert2PhysicalPlan(nil)
c.Assert(err, IsNil)
// Limit->Projection->PhysicalTableScan
// Get PhysicalTableScan plan.
cpp, ok := pp.p.GetChildByIndex(0).GetChildByIndex(0).(*PhysicalTableScan)
c.Assert(cpp, NotNil)
c.Assert(ok, IsTrue)
// Make sure KeepOrder is true.
c.Assert(cpp.KeepOrder, IsTrue)
}
开发者ID:c4pt0r,项目名称:tidb,代码行数:31,代码来源:plan_test.go
示例11: TestWhere
func (t *testWhereSuit) TestWhere(c *C) {
tblPlan := &testTablePlan{t.data, []string{"id", "name"}, 0}
pln := &plans.FilterDefaultPlan{
Plan: tblPlan,
Expr: &expression.BinaryOperation{
Op: opcode.GE,
L: &expression.Ident{
CIStr: model.NewCIStr("id"),
ReferScope: expression.IdentReferFromTable,
ReferIndex: 0,
},
R: expression.Value{
Val: 30,
},
},
}
cnt := 0
rset := rsets.Recordset{Plan: pln,
Ctx: mock.NewContext()}
rset.Do(func(data []interface{}) (bool, error) {
cnt++
return true, nil
})
c.Assert(cnt, Equals, 2)
}
开发者ID:lovedboy,项目名称:tidb,代码行数:26,代码来源:where_test.go
示例12: TestOrderBy
func (t *testOrderBySuit) TestOrderBy(c *C) {
tblPlan := &testTablePlan{t.data, []string{"id", "name"}, 0}
pln := &plans.OrderByDefaultPlan{
SelectList: &plans.SelectList{
HiddenFieldOffset: len(tblPlan.GetFields()),
ResultFields: tblPlan.GetFields(),
},
Src: tblPlan,
By: []expression.Expression{
&expression.Ident{
CIStr: model.NewCIStr("id"),
},
},
Ascs: []bool{false},
}
prev := 10000
rset := rsets.Recordset{
Plan: pln,
Ctx: mock.NewContext(),
}
err := rset.Do(func(data []interface{}) (bool, error) {
// DESC
if data[0].(int) > prev {
c.Error("should no be here", data[0], prev)
}
prev = data[0].(int)
return true, nil
})
if err != nil {
log.Error(err)
}
}
开发者ID:nengwang,项目名称:tidb,代码行数:34,代码来源:orderby_test.go
示例13: SetUpTest
func (s *testStmtSuite) SetUpTest(c *C) {
log.SetLevelByString("error")
s.dbName = "teststmts"
var err error
s.testDB, err = sql.Open(tidb.DriverName, tidb.EngineGoLevelDBMemory+"/"+s.dbName+"/"+s.dbName)
c.Assert(err, IsNil)
// create db
s.createDBSql = fmt.Sprintf("create database if not exists %s;", s.dbName)
s.dropDBSql = fmt.Sprintf("drop database if exists %s;", s.dbName)
s.useDBSql = fmt.Sprintf("use %s;", s.dbName)
s.createTableSql = `
CREATE TABLE test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));
CREATE TABLE test1(id INT NOT NULL DEFAULT 2, name varchar(255), PRIMARY KEY(id), INDEX name(name));
CREATE TABLE test2(id INT NOT NULL DEFAULT 3, name varchar(255), PRIMARY KEY(id));`
s.selectSql = `SELECT * from test limit 2;`
mustExec(c, s.testDB, s.createDBSql)
mustExec(c, s.testDB, s.useDBSql)
s.createSystemDBSQL = fmt.Sprintf("create database if not exists %s;", mysql.SystemDB)
s.createUserTableSQL = tidb.CreateUserTable
s.createDBPrivTableSQL = tidb.CreateDBPrivTable
s.createTablePrivTableSQL = tidb.CreateTablePrivTable
s.createColumnPrivTableSQL = tidb.CreateColumnPrivTable
mustExec(c, s.testDB, s.createSystemDBSQL)
mustExec(c, s.testDB, s.createUserTableSQL)
mustExec(c, s.testDB, s.createDBPrivTableSQL)
mustExec(c, s.testDB, s.createTablePrivTableSQL)
mustExec(c, s.testDB, s.createColumnPrivTableSQL)
s.ctx = mock.NewContext()
variable.BindSessionVars(s.ctx)
}
开发者ID:lovedboy,项目名称:tidb,代码行数:34,代码来源:create_test.go
示例14: TestSetCharsetStmt
func (s *testStmtSuite) TestSetCharsetStmt(c *C) {
testSQL := `SET NAMES utf8;`
stmtList, err := tidb.Compile(testSQL)
c.Assert(err, IsNil)
c.Assert(stmtList, HasLen, 1)
testStmt, ok := stmtList[0].(*stmts.SetCharsetStmt)
c.Assert(ok, IsTrue)
c.Assert(testStmt.IsDDL(), IsFalse)
c.Assert(len(testStmt.OriginText()), Greater, 0)
ctx := mock.NewContext()
variable.BindSessionVars(ctx)
sessionVars := variable.GetSessionVars(ctx)
for _, v := range variable.SetNamesVariables {
c.Assert(sessionVars.Systems[v] != "utf8", IsTrue)
}
_, err = testStmt.Exec(ctx)
c.Assert(err, IsNil)
for _, v := range variable.SetNamesVariables {
c.Assert(sessionVars.Systems[v], Equals, "utf8")
}
c.Assert(sessionVars.Systems[variable.CollationConnection], Equals, "utf8_general_ci")
mf := newMockFormatter()
testStmt.Explain(nil, mf)
c.Assert(mf.Len(), Greater, 0)
}
开发者ID:js-for-kids,项目名称:tidb,代码行数:30,代码来源:set_test.go
示例15: TestCast
func (s *testEvaluatorSuite) TestCast(c *C) {
f := types.NewFieldType(mysql.TypeLonglong)
expr := &ast.FuncCastExpr{
Expr: ast.NewValueExpr(1),
Tp: f,
}
ctx := mock.NewContext()
v, err := Eval(ctx, expr)
c.Assert(err, IsNil)
c.Assert(v, Equals, int64(1))
f.Flag |= mysql.UnsignedFlag
v, err = Eval(ctx, expr)
c.Assert(err, IsNil)
c.Assert(v, Equals, uint64(1))
f.Tp = mysql.TypeString
f.Charset = charset.CharsetBin
v, err = Eval(ctx, expr)
c.Assert(err, IsNil)
c.Assert(v, DeepEquals, []byte("1"))
f.Tp = mysql.TypeString
f.Charset = "utf8"
v, err = Eval(ctx, expr)
c.Assert(err, IsNil)
c.Assert(v, DeepEquals, "1")
expr.Expr = ast.NewValueExpr(nil)
v, err = Eval(ctx, expr)
c.Assert(err, IsNil)
c.Assert(v, IsNil)
}
开发者ID:mumubusu,项目名称:tidb,代码行数:34,代码来源:evaluator_test.go
示例16: TearDownSuite
func (s *testColumnSuite) TearDownSuite(c *C) {
testDropSchema(c, mock.NewContext(), s.d, s.dbInfo)
s.d.close()
err := s.store.Close()
c.Assert(err, IsNil)
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:7,代码来源:column_test.go
示例17: TestHaving
func (t *testHavingPlan) TestHaving(c *C) {
tblPlan := &testTablePlan{groupByTestData, []string{"id", "name"}, 0}
havingPlan := &plans.HavingPlan{
Src: tblPlan,
Expr: &expression.BinaryOperation{
Op: opcode.GE,
L: &expression.Ident{
CIStr: model.NewCIStr("id"),
},
R: &expression.Value{
Val: 20,
},
},
}
// having's behavior just like where
cnt := 0
rset := rsets.Recordset{
Plan: havingPlan,
Ctx: mock.NewContext(),
}
rset.Do(func(data []interface{}) (bool, error) {
cnt++
return true, nil
})
c.Assert(cnt, Equals, 2)
}
开发者ID:nengwang,项目名称:tidb,代码行数:27,代码来源:having_test.go
示例18: SetUpSuite
func (s *testColumnSuite) SetUpSuite(c *C) {
s.store = testCreateStore(c, "test_column")
s.d = newDDL(s.store, nil, nil, testLease)
s.dbInfo = testSchemaInfo(c, s.d, "test_column")
testCreateSchema(c, mock.NewContext(), s.d, s.dbInfo)
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:7,代码来源:column_test.go
示例19: mockContext
func mockContext() context.Context {
ctx := mock.NewContext()
ctx.Store = &mockStore{
client: &mockClient{},
}
return ctx
}
开发者ID:pingcap,项目名称:tidb,代码行数:7,代码来源:logical_plan_test.go
示例20: TestTrim
func (s *testEvaluatorSuite) TestTrim(c *C) {
tbl := []struct {
str interface{}
remstr interface{}
dir ast.TrimDirectionType
result interface{}
}{
{" bar ", nil, ast.TrimBothDefault, "bar"},
{"xxxbarxxx", "x", ast.TrimLeading, "barxxx"},
{"xxxbarxxx", "x", ast.TrimBoth, "bar"},
{"barxxyz", "xyz", ast.TrimTrailing, "barx"},
{nil, "xyz", ast.TrimBoth, nil},
{1, 2, ast.TrimBoth, "1"},
{" \t\rbar\n ", nil, ast.TrimBothDefault, "bar"},
}
ctx := mock.NewContext()
for _, v := range tbl {
f := &ast.FuncTrimExpr{
Str: ast.NewValueExpr(v.str),
Direction: v.dir,
}
if v.remstr != nil {
f.RemStr = ast.NewValueExpr(v.remstr)
}
r, err := Eval(ctx, f)
c.Assert(err, IsNil)
c.Assert(r, Equals, v.result)
}
}
开发者ID:mumubusu,项目名称:tidb,代码行数:30,代码来源:evaluator_test.go
注:本文中的github.com/pingcap/tidb/util/mock.NewContext函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论