本文整理汇总了Golang中github.com/youtube/vitess/go/vt/tabletserver/endtoend/framework.DebugVars函数的典型用法代码示例。如果您正苦于以下问题:Golang DebugVars函数的具体用法?Golang DebugVars怎么用?Golang DebugVars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DebugVars函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
}
示例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)
}
}
示例3: 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)
}
}
示例4: 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)
}
}
示例5: 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)
}
}
示例6: TestQueryStats
func TestQueryStats(t *testing.T) {
client := framework.NewClient()
vstart := framework.DebugVars()
start := time.Now()
query := "select /* query_stats */ eid from vitess_a where eid = :eid"
bv := map[string]interface{}{"eid": 1}
_, _ = client.Execute(query, bv)
stat := framework.QueryStats()[query]
duration := int(time.Now().Sub(start))
if stat.Time <= 0 || stat.Time > duration {
t.Errorf("stat.Time: %d, must be between 0 and %d", stat.Time, duration)
}
if stat.MysqlTime <= 0 || stat.MysqlTime > duration {
t.Errorf("stat.MysqlTime: %d, must be between 0 and %d", stat.MysqlTime, duration)
}
stat.Time = 0
stat.MysqlTime = 0
want := framework.QueryStat{
Query: query,
Table: "vitess_a",
Plan: "PASS_SELECT",
QueryCount: 1,
RowCount: 2,
ErrorCount: 0,
}
if stat != want {
t.Errorf("stat: %+v, want %+v", stat, want)
}
query = "select /* query_stats */ eid from vitess_a where dontexist(eid) = :eid"
_, _ = client.Execute(query, bv)
stat = framework.QueryStats()[query]
stat.Time = 0
stat.MysqlTime = 0
want = framework.QueryStat{
Query: query,
Table: "vitess_a",
Plan: "PASS_SELECT",
QueryCount: 1,
RowCount: 0,
ErrorCount: 1,
}
if stat != want {
t.Errorf("stat: %+v, want %+v", stat, want)
}
vend := framework.DebugVars()
if err := compareIntDiff(vend, "QueryCounts/vitess_a.PASS_SELECT", vstart, 2); err != nil {
t.Error(err)
}
if err := compareIntDiff(vend, "QueryRowCounts/vitess_a.PASS_SELECT", vstart, 2); err != nil {
t.Error(err)
}
if err := compareIntDiff(vend, "QueryErrorCounts/vitess_a.PASS_SELECT", vstart, 1); err != nil {
t.Error(err)
}
}
示例7: TestIntegrityError
func TestIntegrityError(t *testing.T) {
vstart := framework.DebugVars()
client := framework.NewClient()
_, err := client.Execute("insert into vitess_test values(1, null, null, null)", nil)
want := "error: Duplicate entry '1'"
if err == nil || !strings.HasPrefix(err.Error(), want) {
t.Errorf("Error: %v, want prefix %s", err, want)
}
if err := compareIntDiff(framework.DebugVars(), "InfoErrors/DupKey", vstart, 1); err != nil {
t.Error(err)
}
}
示例8: TestSimpleRead
func TestSimpleRead(t *testing.T) {
vstart := framework.DebugVars()
_, err := framework.NewClient().Execute("select * from vitess_test where intval=1", nil)
if err != nil {
t.Error(err)
return
}
vend := framework.DebugVars()
if err := compareIntDiff(vend, "Queries/TotalCount", vstart, 1); err != nil {
t.Error(err)
}
if err := compareIntDiff(vend, "Queries/Histograms/PASS_SELECT/Count", vstart, 1); err != nil {
t.Error(err)
}
}
示例9: TestSimpleRead
func TestSimpleRead(t *testing.T) {
vstart := framework.DebugVars()
_, err := framework.NewDefaultClient().Execute("select * from vtocc_test where intval=1", nil)
if err != nil {
t.Error(err)
return
}
vend := framework.DebugVars()
v1 := framework.FetchInt(vstart, "Queries.TotalCount")
v2 := framework.FetchInt(vend, "Queries.TotalCount")
if v1+1 != v2 {
t.Errorf("Queries.TotalCount: %d, want %d", v1+1, v2)
}
v1 = framework.FetchInt(vstart, "Queries.Histograms.PASS_SELECT.Count")
v2 = framework.FetchInt(vend, "Queries.Histograms.PASS_SELECT.Count")
if v1+1 != v2 {
t.Errorf("Queries...Count: %d, want %d", v1+1, v2)
}
}
示例10: TestTxPoolSize
func TestTxPoolSize(t *testing.T) {
vstart := framework.DebugVars()
client1 := framework.NewDefaultClient()
err := client1.Begin()
if err != nil {
t.Error(err)
return
}
defer client1.Rollback()
if err := verifyIntValue(framework.DebugVars(), "TransactionPoolAvailable", framework.BaseConfig.TransactionCap-1); err != nil {
t.Error(err)
}
defer framework.DefaultServer.SetTxPoolSize(framework.DefaultServer.TxPoolSize())
framework.DefaultServer.SetTxPoolSize(1)
defer framework.DefaultServer.BeginTimeout.Set(framework.DefaultServer.BeginTimeout.Get())
timeout := 1 * time.Millisecond
framework.DefaultServer.BeginTimeout.Set(timeout)
vend := framework.DebugVars()
if err := verifyIntValue(vend, "TransactionPoolAvailable", 0); err != nil {
t.Error(err)
}
if err := verifyIntValue(vend, "TransactionPoolCapacity", 1); err != nil {
t.Error(err)
}
if err := verifyIntValue(vend, "BeginTimeout", int(timeout)); err != nil {
t.Error(err)
}
client2 := framework.NewDefaultClient()
err = client2.Begin()
want := "tx_pool_full"
if err == nil || !strings.Contains(err.Error(), want) {
t.Errorf("Error: %v, must contain %s", err, want)
}
if err := compareIntDiff(framework.DebugVars(), "Errors/TxPoolFull", vstart, 1); err != nil {
t.Error(err)
}
}
示例11: TestQueryCache
func TestQueryCache(t *testing.T) {
defer framework.DefaultServer.SetQueryCacheCap(framework.DefaultServer.QueryCacheCap())
framework.DefaultServer.SetQueryCacheCap(1)
bindVars := map[string]interface{}{"ival1": 1, "ival2": 1}
client := framework.NewDefaultClient()
_, _ = client.Execute("select * from vtocc_test where intval=:ival1", bindVars)
_, _ = client.Execute("select * from vtocc_test where intval=:ival2", bindVars)
vend := framework.DebugVars()
if err := verifyIntValue(vend, "QueryCacheLength", 1); err != nil {
t.Error(err)
}
if err := verifyIntValue(vend, "QueryCacheSize", 1); err != nil {
t.Error(err)
}
if err := verifyIntValue(vend, "QueryCacheCapacity", 1); err != nil {
t.Error(err)
}
framework.DefaultServer.SetQueryCacheCap(10)
_, _ = client.Execute("select * from vtocc_test where intval=:ival1", bindVars)
vend = framework.DebugVars()
if err := verifyIntValue(vend, "QueryCacheLength", 2); err != nil {
t.Error(err)
}
if err := verifyIntValue(vend, "QueryCacheSize", 2); err != nil {
t.Error(err)
}
_, _ = client.Execute("select * from vtocc_test where intval=1", bindVars)
vend = framework.DebugVars()
if err := verifyIntValue(vend, "QueryCacheLength", 3); err != nil {
t.Error(err)
}
if err := verifyIntValue(vend, "QueryCacheSize", 3); err != nil {
t.Error(err)
}
}
示例12: TestTrailingComment
func TestTrailingComment(t *testing.T) {
vstart := framework.DebugVars()
v1 := framework.FetchInt(vstart, "QueryCacheLength")
bindVars := map[string]interface{}{"ival": 1}
client := framework.NewClient()
for _, query := range []string{
"select * from vitess_test where intval=:ival",
"select * from vitess_test where intval=:ival /* comment */",
"select * from vitess_test where intval=:ival /* comment1 */ /* comment2 */",
} {
_, err := client.Execute(query, bindVars)
if err != nil {
t.Error(err)
return
}
v2 := framework.FetchInt(framework.DebugVars(), "QueryCacheLength")
if v2 != v1+1 {
t.Errorf("QueryCacheLength(%s): %d, want %d", query, v2, v1+1)
}
}
}
示例13: TestSpotCheck
func TestSpotCheck(t *testing.T) {
vstart := framework.DebugVars()
client := framework.NewClient()
_, err := client.Execute("select * from vitess_cached2 where eid = 2 and bid = 'foo'", nil)
if err != nil {
t.Error(err)
return
}
if err := compareIntDiff(framework.DebugVars(), "RowcacheSpotCheckCount", vstart, 0); err != nil {
t.Error(err)
}
defer framework.Server.SetSpotCheckRatio(framework.Server.SpotCheckRatio())
framework.Server.SetSpotCheckRatio(1)
if err := verifyIntValue(framework.DebugVars(), "RowcacheSpotCheckRatio", 1); err != nil {
t.Error(err)
}
vstart = framework.DebugVars()
_, err = client.Execute("select * from vitess_cached2 where eid = 2 and bid = 'foo'", nil)
if err != nil {
t.Error(err)
return
}
if err := compareIntDiff(framework.DebugVars(), "RowcacheSpotCheckCount", vstart, 1); err != nil {
t.Error(err)
}
vstart = framework.DebugVars()
_, err = client.Execute("select * from vitess_cached1 where eid in (9)", nil)
if err != nil {
t.Error(err)
return
}
if err := compareIntDiff(framework.DebugVars(), "RowcacheSpotCheckCount", vstart, 0); err != nil {
t.Error(err)
}
_, err = client.Execute("select * from vitess_cached1 where eid in (9)", nil)
if err != nil {
t.Error(err)
return
}
if err := compareIntDiff(framework.DebugVars(), "RowcacheSpotCheckCount", vstart, 1); err != nil {
t.Error(err)
}
}
示例14: TestMexResultSize
func TestMexResultSize(t *testing.T) {
defer framework.DefaultServer.SetMaxResultSize(framework.DefaultServer.MaxResultSize())
framework.DefaultServer.SetMaxResultSize(2)
client := framework.NewDefaultClient()
query := "select * from vtocc_test"
_, err := client.Execute(query, nil)
want := "error: Row count exceeded"
if err == nil || !strings.HasPrefix(err.Error(), want) {
t.Errorf("Error: %v, must start with %s", err, want)
}
if err := verifyIntValue(framework.DebugVars(), "MaxResultSize", 2); err != nil {
t.Error(err)
}
framework.DefaultServer.SetMaxResultSize(10)
_, err = client.Execute(query, nil)
if err != nil {
t.Error(err)
return
}
}
示例15: TestAutoCommit
func TestAutoCommit(t *testing.T) {
client := framework.NewDefaultClient()
defer client.Execute("delete from vtocc_test where intval=4", nil)
catcher := framework.NewTxCatcher()
defer catcher.Close()
vstart := framework.DebugVars()
query := "insert into vtocc_test (intval, floatval, charval, binval) " +
"values(4, null, null, null)"
_, err := client.Execute(query, nil)
if err != nil {
t.Error(err)
return
}
tx, err := catcher.Next()
if err != nil {
t.Error(err)
return
}
want := []string{query}
if !reflect.DeepEqual(tx.Queries, want) {
t.Errorf("queries: %v, want %v", tx.Queries, want)
}
if !reflect.DeepEqual(tx.Conclusion, "commit") {
t.Errorf("conclusion: %s, want commit", tx.Conclusion)
}
qr, err := client.Execute("select * from vtocc_test", nil)
if err != nil {
t.Error(err)
return
}
if qr.RowsAffected != 4 {
t.Errorf("rows affected: %d, want 4", qr.RowsAffected)
}
_, err = client.Execute("delete from vtocc_test where intval=4", nil)
if err != nil {
t.Error(err)
return
}
qr, err = client.Execute("select * from vtocc_test", nil)
if err != nil {
t.Error(err)
return
}
if qr.RowsAffected != 3 {
t.Errorf("rows affected: %d, want 4", qr.RowsAffected)
}
expectedDiffs := []struct {
tag string
diff int
}{{
tag: "Transactions/TotalCount",
diff: 2,
}, {
tag: "Transactions/Histograms/Completed/Count",
diff: 2,
}, {
tag: "Queries/TotalCount",
diff: 4,
}, {
tag: "Queries/Histograms/BEGIN/Count",
diff: 0,
}, {
tag: "Queries/Histograms/COMMIT/Count",
diff: 0,
}, {
tag: "Queries/Histograms/INSERT_PK/Count",
diff: 1,
}, {
tag: "Queries/Histograms/DML_PK/Count",
diff: 1,
}, {
tag: "Queries/Histograms/PASS_SELECT/Count",
diff: 2,
}}
vend := framework.DebugVars()
for _, expected := range expectedDiffs {
if err := compareIntDiff(vend, expected.tag, vstart, expected.diff); err != nil {
t.Error(err)
}
}
}