当前位置: 首页>>代码示例>>Golang>>正文


Golang framework.NewClient函数代码示例

本文整理汇总了Golang中github.com/youtube/vitess/go/vt/tabletserver/endtoend/framework.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestPoolSize

func TestPoolSize(t *testing.T) {
	vstart := framework.DebugVars()
	defer framework.Server.SetPoolSize(framework.Server.PoolSize())
	framework.Server.SetPoolSize(1)

	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		framework.NewClient().Execute("select sleep(0.5) from dual", nil)
		wg.Done()
	}()
	// The queries have to be different so consolidator doesn't kick in.
	go func() {
		framework.NewClient().Execute("select sleep(0.49) from dual", nil)
		wg.Done()
	}()
	wg.Wait()

	vend := framework.DebugVars()
	if err := verifyIntValue(vend, "ConnPoolCapacity", 1); err != nil {
		t.Error(err)
	}
	if err := compareIntDiff(vend, "ConnPoolWaitCount", vstart, 1); err != nil {
		t.Error(err)
	}
}
开发者ID:CowLeo,项目名称:vitess,代码行数:26,代码来源:config_test.go

示例2: TestConsolidation

func TestConsolidation(t *testing.T) {
	vstart := framework.DebugVars()
	defer framework.Server.SetPoolSize(framework.Server.PoolSize())
	framework.Server.SetPoolSize(1)

	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		framework.NewClient().Execute("select sleep(0.25) from dual", nil)
		wg.Done()
	}()
	go func() {
		framework.NewClient().Execute("select sleep(0.25) from dual", nil)
		wg.Done()
	}()
	wg.Wait()

	vend := framework.DebugVars()
	if err := compareIntDiff(vend, "Waits/TotalCount", vstart, 1); err != nil {
		t.Error(err)
	}
	if err := compareIntDiff(vend, "Waits/Histograms/Consolidations/Count", vstart, 1); err != nil {
		t.Error(err)
	}
}
开发者ID:BobbWu,项目名称:vitess,代码行数:25,代码来源:nocache_test.go

示例3: TestStrictMode

func TestStrictMode(t *testing.T) {
	queries := []string{
		"insert into vitess_a(eid, id, name, foo) values (7, 1+1, '', '')",
		"insert into vitess_d(eid, id) values (1, 1)",
		"update vitess_a set eid = 1+1 where eid = 1 and id = 1",
		"insert into vitess_d(eid, id) values (1, 1)",
		"insert into upsert_test(id1, id2) values " +
			"(1, 1), (2, 2) on duplicate key update id1 = 1",
		"insert into upsert_test(id1, id2) select eid, id " +
			"from vitess_a limit 1 on duplicate key update id2 = id1",
		"insert into upsert_test(id1, id2) values " +
			"(1, 1) on duplicate key update id1 = 2+1",
	}

	// Strict mode on.
	func() {
		client := framework.NewClient()
		err := client.Begin()
		if err != nil {
			t.Error(err)
			return
		}
		defer client.Rollback()

		want := "error: DML too complex"
		for _, query := range queries {
			_, err = client.Execute(query, nil)
			if err == nil || err.Error() != want {
				t.Errorf("Execute(%s): %v, want %s", query, err, want)
			}
		}
	}()

	// Strict mode off.
	func() {
		framework.Server.SetStrictMode(false)
		defer framework.Server.SetStrictMode(true)

		for _, query := range queries {
			client := framework.NewClient()
			err := client.Begin()
			if err != nil {
				t.Error(err)
				return
			}
			_, err = client.Execute(query, nil)
			if err != nil {
				t.Error(err)
			}
			client.Rollback()
		}
	}()
}
开发者ID:CowLeo,项目名称:vitess,代码行数:53,代码来源:config_test.go

示例4: TestNull

func TestNull(t *testing.T) {
	client := framework.NewClient()
	qr, err := client.Execute("select null from dual", nil)
	if err != nil {
		t.Error(err)
		return
	}
	want := mproto.QueryResult{
		Fields: []mproto.Field{
			{
				Name:  "NULL",
				Type:  mysql.TypeNull,
				Flags: mysql.FlagBinary,
			},
		},
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			[]sqltypes.Value{
				sqltypes.Value{},
			},
		},
	}
	if !reflect.DeepEqual(*qr, want) {
		t.Errorf("Execute: \n%#v, want \n%#v", *qr, want)
	}
}
开发者ID:hadoop835,项目名称:vitess,代码行数:26,代码来源:compatibility_test.go

示例5: TestQueryTimeout

func TestQueryTimeout(t *testing.T) {
	vstart := framework.DebugVars()
	defer framework.Server.QueryTimeout.Set(framework.Server.QueryTimeout.Get())
	framework.Server.QueryTimeout.Set(100 * time.Millisecond)

	client := framework.NewClient()
	err := client.Begin()
	if err != nil {
		t.Error(err)
		return
	}
	_, err = client.Execute("select sleep(1) from vitess_test", nil)
	want := "error: the query was killed"
	if err == nil || !strings.HasPrefix(err.Error(), want) {
		t.Errorf("Error: %v, must start with %s", err, want)
	}
	_, err = client.Execute("select 1 from dual", nil)
	want = "not_in_tx: Transaction"
	if err == nil || !strings.HasPrefix(err.Error(), want) {
		t.Errorf("Error: %v, must start with %s", err, want)
	}
	vend := framework.DebugVars()
	if err := verifyIntValue(vend, "QueryTimeout", int(100*time.Millisecond)); err != nil {
		t.Error(err)
	}
	if err := compareIntDiff(vend, "Kills/Queries", vstart, 1); err != nil {
		t.Error(err)
	}
}
开发者ID:CowLeo,项目名称:vitess,代码行数:29,代码来源:config_test.go

示例6: TestNull

func TestNull(t *testing.T) {
	client := framework.NewClient()
	qr, err := client.Execute("select null from dual", nil)
	if err != nil {
		t.Error(err)
		return
	}
	want := mproto.QueryResult{
		Fields: []mproto.Field{
			{
				Name:  "NULL",
				Type:  mysql.TypeNull,
				Flags: mysql.FlagBinary,
			},
		},
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			[]sqltypes.Value{
				sqltypes.Value{},
			},
		},
	}
	if !reflect.DeepEqual(*qr, want) {
		t.Errorf("Execute: \n%#v, want \n%#v", *qr, want)
	}
	wantTypes := []query.Type{
		sqltypes.Null,
	}
	for i, field := range qr.Fields {
		got := sqltypes.MySQLToType(field.Type, field.Flags)
		if got != wantTypes[i] {
			t.Errorf("Unexpected type: col: %d, %d, want %d", i, got, wantTypes[i])
		}
	}
}
开发者ID:hadmagic,项目名称:vitess,代码行数:35,代码来源:compatibility_test.go

示例7: TestUncacheableTables

func TestUncacheableTables(t *testing.T) {
	client := framework.NewClient()

	nocacheTables := []struct {
		name   string
		create string
		drop   string
	}{{
		create: "create table vitess_nocache(eid int, primary key (eid)) comment 'vitess_nocache'",
		drop:   "drop table vitess_nocache",
	}, {
		create: "create table vitess_nocache(somecol int)",
		drop:   "drop table vitess_nocache",
	}, {
		create: "create table vitess_nocache(charcol varchar(10), primary key(charcol))",
		drop:   "drop table vitess_nocache",
	}}
	for _, tcase := range nocacheTables {
		_, err := client.Execute(tcase.create, nil)
		if err != nil {
			t.Error(err)
			return
		}
		table, ok := framework.DebugSchema()["vitess_nocache"]
		client.Execute(tcase.drop, nil)
		if !ok {
			t.Errorf("%s: table vitess_nocache not found in schema", tcase.create)
			continue
		}
		if table.Type != schema.CacheNone {
			t.Errorf("Type: %d, want %d", table.Type, schema.CacheNone)
		}
	}
}
开发者ID:aaijazi,项目名称:vitess,代码行数:34,代码来源:cache_test.go

示例8: TestCacheTypes

func TestCacheTypes(t *testing.T) {
	client := framework.NewClient()
	badRequests := []struct {
		query string
		bv    map[string]interface{}
	}{{
		query: "select * from vitess_cached2 where eid = 'str' and bid = 'str'",
	}, {
		query: "select * from vitess_cached2 where eid = :str and bid = :str",
		bv:    map[string]interface{}{"str": "str"},
	}, {
		query: "select * from vitess_cached2 where eid = 1 and bid = 1",
	}, {
		query: "select * from vitess_cached2 where eid = :id and bid = :id",
		bv:    map[string]interface{}{"id": 1},
	}, {
		query: "select * from vitess_cached2 where eid = 1.2 and bid = 1.2",
	}, {
		query: "select * from vitess_cached2 where eid = :fl and bid = :fl",
		bv:    map[string]interface{}{"fl": 1.2},
	}}
	want := "error: type mismatch"
	for _, request := range badRequests {
		_, err := client.Execute(request.query, request.bv)
		if err == nil || !strings.HasPrefix(err.Error(), want) {
			t.Errorf("Error: %v, want %s", err, want)
		}
	}
}
开发者ID:littleyang,项目名称:vitess,代码行数:29,代码来源:cache_test.go

示例9: TestCacheListArgs

func TestCacheListArgs(t *testing.T) {
	client := framework.NewClient()
	query := "select * from vitess_cached1 where eid in ::list"
	successCases := []struct {
		bv       map[string]interface{}
		rowcount uint64
	}{{
		bv:       map[string]interface{}{"list": []interface{}{3, 4, 32768}},
		rowcount: 2,
	}, {
		bv:       map[string]interface{}{"list": []interface{}{3, 4}},
		rowcount: 2,
	}, {
		bv:       map[string]interface{}{"list": []interface{}{3}},
		rowcount: 1,
	}}
	for _, success := range successCases {
		qr, err := client.Execute(query, success.bv)
		if err != nil {
			t.Error(err)
			continue
		}
		if qr.RowsAffected != success.rowcount {
			t.Errorf("RowsAffected: %d, want %d", qr.RowsAffected, success.rowcount)
		}
	}

	_, err := client.Execute(query, map[string]interface{}{"list": []interface{}{}})
	want := "error: empty list supplied"
	if err == nil || !strings.HasPrefix(err.Error(), want) {
		t.Errorf("Error: %v, want %s", err, want)
		return
	}
}
开发者ID:aaijazi,项目名称:vitess,代码行数:34,代码来源:cache_test.go

示例10: TestCacheStats

func TestCacheStats(t *testing.T) {
	client := framework.NewClient()
	query := "select * from vitess_cached2 where eid = 2 and bid = 'foo'"
	_, err := client.Execute(query, nil)
	if err != nil {
		t.Error(err)
		return
	}
	vstart := framework.DebugVars()
	_, err = client.Execute(query, nil)
	if err != nil {
		t.Error(err)
		return
	}
	if err := compareIntDiff(framework.DebugVars(), "RowcacheStats/vitess_cached2.Hits", vstart, 1); err != nil {
		t.Error(err)
	}

	vstart = framework.DebugVars()
	_, err = client.Execute("update vitess_part2 set data2 = 2 where key3 = 1", nil)
	if err != nil {
		t.Error(err)
		return
	}
	_, err = client.Execute("select * from vitess_view where key2 = 1", nil)
	if err != nil {
		t.Error(err)
		return
	}
	if err := compareIntDiff(framework.DebugVars(), "RowcacheStats/vitess_view.Misses", vstart, 1); err != nil {
		t.Error(err)
	}
}
开发者ID:aaijazi,项目名称:vitess,代码行数:33,代码来源:cache_test.go

示例11: TestCacheTypes

func TestCacheTypes(t *testing.T) {
	client := framework.NewClient()
	badRequests := []struct {
		query string
		bv    map[string]interface{}
		out   string
	}{{
		query: "select * from vitess_cached2 where eid = 'str' and bid = 'str'",
		out:   "error: strconv.ParseInt",
	}, {
		query: "select * from vitess_cached2 where eid = :str and bid = :str",
		bv:    map[string]interface{}{"str": "str"},
		out:   "error: strconv.ParseInt",
	}, {
		query: "select * from vitess_cached2 where eid = 1 and bid = 1",
		out:   "error: type mismatch",
	}, {
		query: "select * from vitess_cached2 where eid = :id and bid = :id",
		bv:    map[string]interface{}{"id": 1},
		out:   "error: type mismatch",
	}, {
		query: "select * from vitess_cached2 where eid = 1.2 and bid = 1.2",
		out:   "error: type mismatch",
	}, {
		query: "select * from vitess_cached2 where eid = :fl and bid = :fl",
		bv:    map[string]interface{}{"fl": 1.2},
		out:   "error: type mismatch",
	}}
	for _, tcase := range badRequests {
		_, err := client.Execute(tcase.query, tcase.bv)
		if err == nil || !strings.HasPrefix(err.Error(), tcase.out) {
			t.Errorf("%s: %v, want %s", tcase.query, err, tcase.out)
		}
	}
}
开发者ID:aaijazi,项目名称:vitess,代码行数:35,代码来源:cache_test.go

示例12: TestDBAStatements

func TestDBAStatements(t *testing.T) {
	client := framework.NewClient()

	qr, err := client.Execute("show variables like 'version'", nil)
	if err != nil {
		t.Error(err)
		return
	}
	wantCol := sqltypes.MakeTrusted(sqltypes.VarChar, []byte("version"))
	if !reflect.DeepEqual(qr.Rows[0][0], wantCol) {
		t.Errorf("Execute: \n%#v, want \n%#v", qr.Rows[0][0], wantCol)
	}

	qr, err = client.Execute("describe vitess_a", nil)
	if err != nil {
		t.Error(err)
		return
	}
	if qr.RowsAffected != 4 {
		t.Errorf("RowsAffected: %d, want 4", qr.RowsAffected)
	}

	qr, err = client.Execute("explain vitess_a", nil)
	if err != nil {
		t.Error(err)
		return
	}
	if qr.RowsAffected != 4 {
		t.Errorf("RowsAffected: %d, want 4", qr.RowsAffected)
	}
}
开发者ID:BobbWu,项目名称:vitess,代码行数:31,代码来源:nocache_test.go

示例13: TestSchemaReload

func TestSchemaReload(t *testing.T) {
	conn, err := mysql.Connect(connParams)
	if err != nil {
		t.Error(err)
		return
	}
	_, err = conn.ExecuteFetch("create table vitess_temp(intval int)", 10, false)
	if err != nil {
		t.Error(err)
		return
	}
	defer func() {
		_, _ = conn.ExecuteFetch("drop table vitess_temp", 10, false)
		conn.Close()
	}()
	framework.Server.ReloadSchema()
	client := framework.NewClient()
	waitTime := 50 * time.Millisecond
	for i := 0; i < 10; i++ {
		time.Sleep(waitTime)
		waitTime += 50 * time.Millisecond
		_, err = client.Execute("select * from vitess_temp", nil)
		if err == nil {
			return
		}
		want := "error: table vitess_temp not found in schema"
		if err.Error() != want {
			t.Errorf("Error: %v, want %s", err, want)
			return
		}
	}
	t.Error("schema did not reload")
}
开发者ID:BobbWu,项目名称:vitess,代码行数:33,代码来源:nocache_test.go

示例14: TestNull

func TestNull(t *testing.T) {
	client := framework.NewClient()
	qr, err := client.Execute("select null from dual", nil)
	if err != nil {
		t.Error(err)
		return
	}
	want := sqltypes.Result{
		Fields: []*querypb.Field{
			{
				Name: "NULL",
				Type: sqltypes.Null,
			},
		},
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			{
				{},
			},
		},
	}
	if !reflect.DeepEqual(*qr, want) {
		t.Errorf("Execute: \n%#v, want \n%#v", *qr, want)
	}
}
开发者ID:medvednikov,项目名称:vitess,代码行数:25,代码来源:compatibility_test.go

示例15: TestStreamTerminate

func TestStreamTerminate(t *testing.T) {
	client := framework.NewClient()
	err := populateBigData(client)
	if err != nil {
		t.Error(err)
		return
	}
	defer client.Execute("delete from vitess_big", nil)

	called := false
	err = client.Stream(
		"select * from vitess_big b1, vitess_big b2 order by b1.id, b2.id",
		nil,
		func(*mproto.QueryResult) error {
			if !called {
				queries := framework.StreamQueryz()
				if l := len(queries); l != 1 {
					t.Errorf("len(queries): %d, want 1", l)
					return errors.New("no queries from StreamQueryz")
				}
				err := framework.StreamTerminate(queries[0].ConnID)
				if err != nil {
					return err
				}
				called = true
			}
			time.Sleep(10 * time.Millisecond)
			return nil
		},
	)
	want := "error: the query was killed"
	if err == nil || !strings.HasPrefix(err.Error(), want) {
		t.Errorf("Error: %v, must start with %s", err, want)
	}
}
开发者ID:hadmagic,项目名称:vitess,代码行数:35,代码来源:stream_test.go


注:本文中的github.com/youtube/vitess/go/vt/tabletserver/endtoend/framework.NewClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。