• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang framework.NewClient函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: TestStreamError

func TestStreamError(t *testing.T) {
	_, err := framework.NewClient().StreamExecute("select count(abcd) from vitess_big", nil)
	want := "error: Unknown column"
	if err == nil || !strings.HasPrefix(err.Error(), want) {
		t.Errorf("Error: %v, must start with %s", err, want)
	}
}
开发者ID:hadmagic,项目名称:vitess,代码行数:7,代码来源:stream_test.go


示例17: TestForUpdate

func TestForUpdate(t *testing.T) {
	for _, mode := range []string{"for update", "lock in share mode"} {
		client := framework.NewClient()
		query := fmt.Sprintf("select * from vitess_test where intval=2 %s", mode)
		_, err := client.Execute(query, nil)
		want := "error: Disallowed"
		if err == nil || !strings.HasPrefix(err.Error(), want) {
			t.Errorf("Error: %v, must have prefix %s", err, want)
		}

		// We should not get errors here
		err = client.Begin()
		if err != nil {
			t.Error(err)
			return
		}
		_, err = client.Execute(query, nil)
		if err != nil {
			t.Error(err)
			return
		}
		err = client.Commit()
		if err != nil {
			t.Error(err)
			return
		}
	}
}
开发者ID:dumbunny,项目名称:vitess,代码行数:28,代码来源:transaction_test.go


示例18: TestUncache

func TestUncache(t *testing.T) {
	// Verify rowcache is working vitess_cached2
	err := verifyvitessCached2(t, "vitess_cached2")
	if err != nil {
		t.Error(err)
		return
	}

	// Disable rowcache for vitess_cached2
	client := framework.NewClient()
	_, err = client.Execute("alter table vitess_cached2 comment 'vitess_nocache'", nil)
	if err != nil {
		t.Error(err)
		return
	}
	_, err = client.Execute("select * from vitess_cached2 where eid = 2 and bid = 'foo'", nil)
	if err != nil {
		t.Error(err)
	}
	if tstat, ok := framework.TableStats()["vitess_cached2"]; ok {
		t.Errorf("table stats was found: %v, want not found", tstat)
	}

	// Re-enable rowcache and verify it's working
	_, err = client.Execute("alter table vitess_cached2 comment ''", nil)
	if err != nil {
		t.Error(err)
		return
	}
	err = verifyvitessCached2(t, "vitess_cached2")
	if err != nil {
		t.Error(err)
		return
	}
}
开发者ID:aaijazi,项目名称:vitess,代码行数:35,代码来源:cache_test.go


示例19: TestBatchRead

func TestBatchRead(t *testing.T) {
	client := framework.NewClient()
	queries := []querytypes.BoundQuery{{
		Sql:           "select * from vitess_a where id = :a",
		BindVariables: map[string]interface{}{"a": 2},
	}, {
		Sql:           "select * from vitess_b where id = :b",
		BindVariables: map[string]interface{}{"b": 2},
	}}
	qr1 := sqltypes.Result{
		Fields: []*querypb.Field{{
			Name: "eid",
			Type: sqltypes.Int64,
		}, {
			Name: "id",
			Type: sqltypes.Int32,
		}, {
			Name: "name",
			Type: sqltypes.VarChar,
		}, {
			Name: "foo",
			Type: sqltypes.VarBinary,
		}},
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeTrusted(sqltypes.Int64, []byte("1")),
				sqltypes.MakeTrusted(sqltypes.Int32, []byte("2")),
				sqltypes.MakeTrusted(sqltypes.VarChar, []byte("bcde")),
				sqltypes.MakeTrusted(sqltypes.VarBinary, []byte("fghi")),
			},
		},
	}
	qr2 := sqltypes.Result{
		Fields: []*querypb.Field{{
			Name: "eid",
			Type: sqltypes.Int64,
		}, {
			Name: "id",
			Type: sqltypes.Int32,
		}},
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeTrusted(sqltypes.Int64, []byte("1")),
				sqltypes.MakeTrusted(sqltypes.Int32, []byte("2")),
			},
		},
	}
	want := []sqltypes.Result{qr1, qr2}

	qrl, err := client.ExecuteBatch(queries, false)
	if err != nil {
		t.Error(err)
		return
	}
	if !reflect.DeepEqual(qrl, want) {
		t.Errorf("ExecueBatch: \n%#v, want \n%#v", qrl, want)
	}
}
开发者ID:CowLeo,项目名称:vitess,代码行数:60,代码来源:batch_test.go


示例20: TestNocacheListArgs

func TestNocacheListArgs(t *testing.T) {
	client := framework.NewClient()
	query := "select * from vitess_test where intval in ::list"

	qr, err := client.Execute(
		query,
		map[string]interface{}{
			"list": []interface{}{2, 3, 4},
		},
	)
	if err != nil {
		t.Error(err)
		return
	}
	if qr.RowsAffected != 2 {
		t.Errorf("rows affected: %d, want 2", qr.RowsAffected)
	}

	qr, err = client.Execute(
		query,
		map[string]interface{}{
			"list": []interface{}{3, 4},
		},
	)
	if err != nil {
		t.Error(err)
		return
	}
	if qr.RowsAffected != 1 {
		t.Errorf("rows affected: %d, want 1", qr.RowsAffected)
	}

	qr, err = client.Execute(
		query,
		map[string]interface{}{
			"list": []interface{}{3},
		},
	)
	if err != nil {
		t.Error(err)
		return
	}
	if qr.RowsAffected != 1 {
		t.Errorf("rows affected: %d, want 1", qr.RowsAffected)
	}

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang framework.NewDefaultClient函数代码示例发布时间:2022-05-28
下一篇:
Golang framework.DebugVars函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap