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


Golang framework.NewDefaultClient函数代码示例

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


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

示例1: TestConsolidation

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

	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		framework.NewDefaultClient().Execute("select sleep(0.25) from dual", nil)
		wg.Done()
	}()
	go func() {
		framework.NewDefaultClient().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:zhaoyta,项目名称:vitess,代码行数:25,代码来源:nocache_test.go

示例2: TestPoolSize

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

	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		framework.NewDefaultClient().Execute("select sleep(0.25) from dual", nil)
		wg.Done()
	}()
	// The queries have to be different so consolidator doesn't kick in.
	go func() {
		framework.NewDefaultClient().Execute("select sleep(0.24) 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:zhaoyta,项目名称:vitess,代码行数:26,代码来源:config_test.go

示例3: TestStrictMode

func TestStrictMode(t *testing.T) {
	queries := []string{
		"insert into vtocc_a(eid, id, name, foo) values (7, 1+1, '', '')",
		"insert into vtocc_d(eid, id) values (1, 1)",
		"update vtocc_a set eid = 1+1 where eid = 1 and id = 1",
		"insert into vtocc_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 vtocc_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.NewDefaultClient()
		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.DefaultServer.SetStrictMode(false)
		defer framework.DefaultServer.SetStrictMode(true)

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

示例4: TestSchemaReload

func TestSchemaReload(t *testing.T) {
	conn, err := mysql.Connect(connParams)
	if err != nil {
		t.Error(err)
		return
	}
	_, err = conn.ExecuteFetch("create table vtocc_temp(intval int)", 10, false)
	if err != nil {
		t.Error(err)
		return
	}
	defer func() {
		_, _ = conn.ExecuteFetch("drop table vtocc_temp", 10, false)
		conn.Close()
	}()
	framework.DefaultServer.ReloadSchema()
	client := framework.NewDefaultClient()
	waitTime := 50 * time.Millisecond
	for i := 0; i < 10; i++ {
		time.Sleep(waitTime)
		waitTime += 50 * time.Millisecond
		_, err = client.Execute("select * from vtocc_temp", nil)
		if err == nil {
			return
		}
		want := "error: table vtocc_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:zhaoyta,项目名称:vitess,代码行数:33,代码来源:nocache_test.go

示例5: TestCacheListArgs

func TestCacheListArgs(t *testing.T) {
	client := framework.NewDefaultClient()
	query := "select * from vtocc_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:zhaoyta,项目名称:vitess,代码行数:34,代码来源:cache_test.go

示例6: TestNull

func TestNull(t *testing.T) {
	client := framework.NewDefaultClient()
	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:e4x,项目名称:vitess,代码行数:26,代码来源:compatibility_test.go

示例7: TestQueryTimeout

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

	client := framework.NewDefaultClient()
	err := client.Begin()
	if err != nil {
		t.Error(err)
		return
	}
	_, err = client.Execute("select sleep(0.5) from vtocc_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(10*time.Millisecond)); err != nil {
		t.Error(err)
	}
	if err := compareIntDiff(vend, "Kills/Queries", vstart, 1); err != nil {
		t.Error(err)
	}
}
开发者ID:zhaoyta,项目名称:vitess,代码行数:29,代码来源:config_test.go

示例8: TestDBAStatements

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

	qr, err := client.Execute("show variables like 'version'", nil)
	if err != nil {
		t.Error(err)
		return
	}
	wantCol := sqltypes.Value{Inner: sqltypes.String("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 vtocc_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 vtocc_a", nil)
	if err != nil {
		t.Error(err)
		return
	}
	if qr.RowsAffected != 4 {
		t.Errorf("RowsAffected: %d, want 4", qr.RowsAffected)
	}
}
开发者ID:zhaoyta,项目名称:vitess,代码行数:31,代码来源:nocache_test.go

示例9: TestCacheStats

func TestCacheStats(t *testing.T) {
	client := framework.NewDefaultClient()
	query := "select * from vtocc_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/vtocc_cached2.Hits", vstart, 1); err != nil {
		t.Error(err)
	}

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

示例10: TestCacheTypes

func TestCacheTypes(t *testing.T) {
	client := framework.NewDefaultClient()
	badRequests := []struct {
		query string
		bv    map[string]interface{}
	}{{
		query: "select * from vtocc_cached2 where eid = 'str' and bid = 'str'",
	}, {
		query: "select * from vtocc_cached2 where eid = :str and bid = :str",
		bv:    map[string]interface{}{"str": "str"},
	}, {
		query: "select * from vtocc_cached2 where eid = 1 and bid = 1",
	}, {
		query: "select * from vtocc_cached2 where eid = :id and bid = :id",
		bv:    map[string]interface{}{"id": 1},
	}, {
		query: "select * from vtocc_cached2 where eid = 1.2 and bid = 1.2",
	}, {
		query: "select * from vtocc_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:zhaoyta,项目名称:vitess,代码行数:29,代码来源:cache_test.go

示例11: TestTxTimeout

func TestTxTimeout(t *testing.T) {
	vstart := framework.DebugVars()

	defer framework.DefaultServer.SetTxTimeout(framework.DefaultServer.TxTimeout())
	framework.DefaultServer.SetTxTimeout(1 * time.Millisecond)
	if err := verifyIntValue(framework.DebugVars(), "TransactionPoolTimeout", int(1*time.Millisecond)); err != nil {
		t.Error(err)
	}

	catcher := framework.NewTxCatcher()
	defer catcher.Close()
	client := framework.NewDefaultClient()
	err := client.Begin()
	if err != nil {
		t.Error(err)
		return
	}
	time.Sleep(5 * time.Millisecond)
	err = client.Commit()
	want := "not_in_tx: Transaction"
	if err == nil || !strings.HasPrefix(err.Error(), want) {
		t.Errorf("Error: %v, must contain %s", err, want)
	}
	tx, err := catcher.Next()
	if err != nil {
		t.Error(err)
		return
	}
	if tx.Conclusion != "kill" {
		t.Errorf("Conclusion: %s, want kill", tx.Conclusion)
	}
	if err := compareIntDiff(framework.DebugVars(), "Kills/Transactions", vstart, 1); err != nil {
		t.Error(err)
	}
}
开发者ID:zhaoyta,项目名称:vitess,代码行数:35,代码来源:transaction_test.go

示例12: TestForUpdate

func TestForUpdate(t *testing.T) {
	for _, mode := range []string{"for update", "lock in share mode"} {
		client := framework.NewDefaultClient()
		query := fmt.Sprintf("select * from vtocc_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:zhaoyta,项目名称:vitess,代码行数:28,代码来源:transaction_test.go

示例13: TestUncacheableTables

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

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

示例14: TestUncache

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

	// Disable rowcache for vtocc_cached2
	client := framework.NewDefaultClient()
	_, err = client.Execute("alter table vtocc_cached2 comment 'vtocc_nocache'", nil)
	if err != nil {
		t.Error(err)
		return
	}
	_, err = client.Execute("select * from vtocc_cached2 where eid = 2 and bid = 'foo'", nil)
	if err != nil {
		t.Error(err)
	}
	if tstat, ok := framework.TableStats()["vtocc_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 vtocc_cached2 comment ''", nil)
	if err != nil {
		t.Error(err)
		return
	}
	err = verifyVtoccCached2(t, "vtocc_cached2")
	if err != nil {
		t.Error(err)
		return
	}
}
开发者ID:zhaoyta,项目名称:vitess,代码行数:35,代码来源:cache_test.go

示例15: TestNocacheListArgs

func TestNocacheListArgs(t *testing.T) {
	client := framework.NewDefaultClient()
	query := "select * from vtocc_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:zhaoyta,项目名称:vitess,代码行数:59,代码来源:nocache_test.go


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