Example #1
0
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)
	}
}
Example #2
0
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)
	}
}
Example #3
0
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()
		}
	}()
}
Example #4
0
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")
}
Example #5
0
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
	}
}
Example #6
0
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)
	}
}
Example #7
0
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)
	}
}
Example #8
0
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)
	}
}
Example #9
0
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)
	}
}
Example #10
0
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)
		}
	}
}
Example #11
0
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)
	}
}
Example #12
0
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
		}
	}
}
Example #13
0
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)
		}
	}
}
Example #14
0
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
	}
}
Example #15
0
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
	}
}
Example #16
0
func TestBinary(t *testing.T) {
	client := framework.NewDefaultClient()
	defer client.Execute("delete from vtocc_test where intval in (4,5)", nil)

	binaryData := "\x00'\"\b\n\r\t\x1a\\\x00\x0f\xf0\xff"
	// Test without bindvars.
	_, err := client.Execute(
		"insert into vtocc_test values "+
			"(4, null, null, '\\0\\'\\\"\\b\\n\\r\\t\\Z\\\\\x00\x0f\xf0\xff')",
		nil,
	)
	if err != nil {
		t.Error(err)
		return
	}
	qr, err := client.Execute("select binval from vtocc_test where intval=4", nil)
	if err != nil {
		t.Error(err)
		return
	}
	want := mproto.QueryResult{
		Fields: []mproto.Field{
			{
				Name:  "binval",
				Type:  mysql.TypeVarString,
				Flags: mysql.FlagBinary,
			},
		},
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			[]sqltypes.Value{
				sqltypes.Value{Inner: sqltypes.String(binaryData)},
			},
		},
	}
	if !reflect.DeepEqual(*qr, want) {
		t.Errorf("Execute: \n%#v, want \n%#v", *qr, want)
	}

	// Test with bindvars.
	_, err = client.Execute(
		"insert into vtocc_test values(5, null, null, :bindata)",
		map[string]interface{}{"bindata": binaryData},
	)
	if err != nil {
		t.Error(err)
		return
	}
	qr, err = client.Execute("select binval from vtocc_test where intval=5", nil)
	if err != nil {
		t.Error(err)
		return
	}
	if !reflect.DeepEqual(*qr, want) {
		t.Errorf("Execute: \n%#v, want \n%#v", *qr, want)
	}
}
Example #17
0
func TestNoData(t *testing.T) {
	qr, err := framework.NewDefaultClient().Execute("select * from vtocc_cached2 where eid = 6 and name = 'bar'", nil)
	if err != nil {
		t.Error(err)
		return
	}
	if qr.RowsAffected != 0 {
		t.Errorf("RowsAffected: %d, want 0", qr.RowsAffected)
	}
}
Example #18
0
func TestAutoCommitOff(t *testing.T) {
	framework.DefaultServer.SetAutoCommit(false)
	defer framework.DefaultServer.SetAutoCommit(true)

	_, err := framework.NewDefaultClient().Execute("insert into vtocc_test values(4, null, null, null)", nil)
	want := "error: unsupported query"
	if err == nil || !strings.HasPrefix(err.Error(), want) {
		t.Errorf("Error: %v, must start with %s", err, want)
	}
}
Example #19
0
func TestIntegrityError(t *testing.T) {
	vstart := framework.DebugVars()
	client := framework.NewDefaultClient()
	_, err := client.Execute("insert into vtocc_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)
	}
}
Example #20
0
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)
	}
}
Example #21
0
func TestQueryStats(t *testing.T) {
	client := framework.NewDefaultClient()
	vstart := framework.DebugVars()

	start := time.Now()
	query := "select /* query_stats */ eid from vtocc_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)
	}
	stat.Time = 0
	want := framework.QueryStat{
		Query:      query,
		Table:      "vtocc_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 vtocc_a where dontexist(eid) = :eid"
	_, _ = client.Execute(query, bv)
	stat = framework.QueryStats()[query]
	stat.Time = 0
	want = framework.QueryStat{
		Query:      query,
		Table:      "vtocc_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/vtocc_a.PASS_SELECT", vstart, 2); err != nil {
		t.Error(err)
	}
	if err := compareIntDiff(vend, "QueryRowCounts/vtocc_a.PASS_SELECT", vstart, 2); err != nil {
		t.Error(err)
	}
	if err := compareIntDiff(vend, "QueryErrorCounts/vtocc_a.PASS_SELECT", vstart, 1); err != nil {
		t.Error(err)
	}
}
Example #22
0
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()
	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)
	}
}
Example #23
0
func TestSpotCheck(t *testing.T) {
	vstart := framework.DebugVars()
	client := framework.NewDefaultClient()
	_, err := client.Execute("select * from vtocc_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.DefaultServer.SetSpotCheckRatio(framework.DefaultServer.SpotCheckRatio())
	framework.DefaultServer.SetSpotCheckRatio(1)
	if err := verifyIntValue(framework.DebugVars(), "RowcacheSpotCheckRatio", 1); err != nil {
		t.Error(err)
	}

	vstart = framework.DebugVars()
	_, err = client.Execute("select * from vtocc_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 vtocc_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 vtocc_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)
	}
}
Example #24
0
func verifyVtoccCached2(t *testing.T, table string) error {
	client := framework.NewDefaultClient()
	query := fmt.Sprintf("select * from %s where eid = 2 and bid = 'foo'", table)
	_, err := client.Execute(query, nil)
	if err != nil {
		return err
	}
	tstart := framework.TableStats()[table]
	_, err = client.Execute(query, nil)
	if err != nil {
		return err
	}
	tend := framework.TableStats()[table]
	if tend.Hits != tstart.Hits+1 {
		return fmt.Errorf("Hits: %d, want %d", tend.Hits, tstart.Hits+1)
	}
	return nil
}
Example #25
0
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)
	}
}
Example #26
0
func TestQueryRules(t *testing.T) {
	rules := tabletserver.NewQueryRules()
	err := rules.UnmarshalJSON(rulesJSON)
	if err != nil {
		t.Error(err)
		return
	}
	err = framework.DefaultServer.SetQueryRules("endtoend", rules)
	want := "Rule source identifier endtoend is not valid"
	if err == nil || err.Error() != want {
		t.Errorf("Error: %v, want %s", err, want)
	}

	framework.DefaultServer.RegisterQueryRuleSource("endtoend")
	defer framework.DefaultServer.UnRegisterQueryRuleSource("endtoend")
	err = framework.DefaultServer.SetQueryRules("endtoend", rules)
	if err != nil {
		t.Error(err)
		return
	}

	client := framework.NewDefaultClient()
	query := "select * from vtocc_test where intval=:asdfg"
	bv := map[string]interface{}{"asdfg": 1}
	_, err = client.Execute(query, bv)
	want = "error: Query disallowed due to rule: disallow bindvar 'asdfg'"
	if err == nil || err.Error() != want {
		t.Errorf("Error: %v, want %s", err, want)
	}

	err = framework.DefaultServer.SetQueryRules("endtoend", nil)
	if err != nil {
		t.Error(err)
		return
	}
	_, err = client.Execute(query, bv)
	if err != nil {
		t.Error(err)
		return
	}
}
Example #27
0
func TestCharaterSet(t *testing.T) {
	qr, err := framework.NewDefaultClient().Execute("select * from vtocc_test where intval=1", nil)
	if err != nil {
		t.Error(err)
		return
	}
	want := mproto.QueryResult{
		Fields: []mproto.Field{
			{
				Name:  "intval",
				Type:  3,
				Flags: 0,
			}, {
				Name:  "floatval",
				Type:  4,
				Flags: 0,
			}, {
				Name:  "charval",
				Type:  253,
				Flags: 0,
			}, {
				Name:  "binval",
				Type:  253,
				Flags: mysql.FlagBinary,
			},
		},
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			[]sqltypes.Value{
				sqltypes.Value{Inner: sqltypes.Numeric("1")},
				sqltypes.Value{Inner: sqltypes.Fractional("1.12345")},
				sqltypes.Value{Inner: sqltypes.String("\xc2\xa2")},
				sqltypes.Value{Inner: sqltypes.String("\x00\xff")},
			},
		},
	}
	if !reflect.DeepEqual(*qr, want) {
		t.Errorf("Execute: \n%#v, want \n%#v", *qr, want)
	}
}
Example #28
0
func TestCacheDisallows(t *testing.T) {
	client := framework.NewDefaultClient()
	testCases := []struct {
		query string
		bv    map[string]interface{}
		err   string
	}{{
		query: "select bid, eid from vtocc_cached2 where eid = 1 and bid = 1",
		err:   "error: type mismatch",
	}, {
		query: "select * from vtocc_cached2 where eid = 2 and bid = 'foo' limit :a",
		bv:    map[string]interface{}{"a": -1},
		err:   "error: negative limit",
	}}
	for _, tcase := range testCases {
		_, err := client.Execute(tcase.query, tcase.bv)
		if err == nil || !strings.HasPrefix(err.Error(), tcase.err) {
			t.Errorf("Error: %v, want %s", err, tcase.err)
			return
		}
	}
}
Example #29
0
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
	}
}
Example #30
0
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)
	}
}