Ejemplo n.º 1
0
func testStreamExecuteError(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testStreamExecuteError")
	f.HasError = true
	testErrorHelper(t, f, "StreamExecute", func(ctx context.Context) error {
		f.ErrorWait = make(chan struct{})
		ctx = callerid.NewContext(ctx, TestCallerID, TestVTGateCallerID)
		stream, err := conn.StreamExecute(ctx, TestTarget, StreamExecuteQuery, StreamExecuteBindVars)
		if err != nil {
			t.Fatalf("StreamExecute failed: %v", err)
		}
		qr, err := stream.Recv()
		if err != nil {
			t.Fatalf("StreamExecute failed: cannot read result1: %v", err)
		}
		if len(qr.Rows) == 0 {
			qr.Rows = nil
		}
		if !reflect.DeepEqual(*qr, StreamExecuteQueryResult1) {
			t.Errorf("Unexpected result1 from StreamExecute: got %v wanted %v", qr, StreamExecuteQueryResult1)
		}
		// signal to the server that the first result has been received
		close(f.ErrorWait)
		// After 1 result, we expect to get an error (no more results).
		qr, err = stream.Recv()
		if err == nil {
			t.Fatalf("StreamExecute channel wasn't closed")
		}
		return err
	})
	f.HasError = false
}
Ejemplo n.º 2
0
func testSplitQueryPanics(t *testing.T, conn tabletconn.TabletConn) {
	t.Log("testSplitQueryPanics")
	ctx := context.Background()
	if _, err := conn.SplitQuery(ctx, splitQueryBoundQuery, splitQuerySplitColumn, splitQuerySplitCount); err == nil || !strings.Contains(err.Error(), "caught test panic") {
		t.Fatalf("unexpected panic error: %v", err)
	}
}
Ejemplo n.º 3
0
func testExecuteBatchPanics(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testExecuteBatchPanics")
	testPanicHelper(t, f, "ExecuteBatch", func(ctx context.Context) error {
		_, err := conn.ExecuteBatch(ctx, TestTarget, ExecuteBatchQueries, TestAsTransaction, ExecuteBatchTransactionID)
		return err
	})
}
Ejemplo n.º 4
0
func testStreamExecute2Error(t *testing.T, conn tabletconn.TabletConn) {
	t.Log("testStreamExecute2Error")
	ctx := context.Background()
	stream, errFunc, err := conn.StreamExecute2(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
	if err != nil {
		t.Fatalf("StreamExecute2 failed: %v", err)
	}
	qr, ok := <-stream
	if !ok {
		t.Fatalf("StreamExecute2 failed: cannot read result1")
	}
	if len(qr.Rows) == 0 {
		qr.Rows = nil
	}
	if !reflect.DeepEqual(*qr, streamExecuteQueryResult1) {
		t.Errorf("Unexpected result1 from StreamExecute2: got %v wanted %v", qr, streamExecuteQueryResult1)
	}
	// signal to the server that the first result has been received
	close(errorWait)
	// After 1 result, we expect to get an error (no more results).
	qr, ok = <-stream
	if ok {
		t.Fatalf("StreamExecute2 channel wasn't closed")
	}
	err = errFunc()
	if err == nil {
		t.Fatalf("StreamExecute2 was expecting an error, didn't get one")
	}
	if !strings.Contains(err.Error(), expectedErrMatch) {
		t.Errorf("Unexpected error from StreamExecute2: got %v, wanted err containing %v", err, expectedErrMatch)
	}
	// reset state for the test
	errorWait = make(chan struct{})
}
Ejemplo n.º 5
0
func testUpdateStreamError(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testUpdateStreamError")
	f.HasError = true
	testErrorHelper(t, f, "UpdateStream", func(ctx context.Context) error {
		f.ErrorWait = make(chan struct{})
		ctx = callerid.NewContext(ctx, TestCallerID, TestVTGateCallerID)
		stream, err := conn.UpdateStream(ctx, TestTarget, UpdateStreamPosition, UpdateStreamTimestamp)
		if err != nil {
			t.Fatalf("UpdateStream failed: %v", err)
		}
		qr, err := stream.Recv()
		if err != nil {
			t.Fatalf("UpdateStream failed: cannot read result1: %v", err)
		}
		if !reflect.DeepEqual(*qr, UpdateStreamStreamEvent1) {
			t.Errorf("Unexpected result1 from UpdateStream: got %v wanted %v", qr, UpdateStreamStreamEvent1)
		}
		// signal to the server that the first result has been received
		close(f.ErrorWait)
		// After 1 result, we expect to get an error (no more results).
		qr, err = stream.Recv()
		if err == nil {
			t.Fatalf("UpdateStream channel wasn't closed")
		}
		return err
	})
	f.HasError = false
}
Ejemplo n.º 6
0
func testUpdateStream(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testUpdateStream")
	ctx := context.Background()
	ctx = callerid.NewContext(ctx, TestCallerID, TestVTGateCallerID)
	stream, err := conn.UpdateStream(ctx, TestTarget, UpdateStreamPosition, UpdateStreamTimestamp)
	if err != nil {
		t.Fatalf("UpdateStream failed: %v", err)
	}
	qr, err := stream.Recv()
	if err != nil {
		t.Fatalf("UpdateStream failed: cannot read result1: %v", err)
	}
	if !reflect.DeepEqual(*qr, UpdateStreamStreamEvent1) {
		t.Errorf("Unexpected result1 from UpdateStream: got %v wanted %v", qr, UpdateStreamStreamEvent1)
	}
	qr, err = stream.Recv()
	if err != nil {
		t.Fatalf("UpdateStream failed: cannot read result2: %v", err)
	}
	if !reflect.DeepEqual(*qr, UpdateStreamStreamEvent2) {
		t.Errorf("Unexpected result2 from UpdateStream: got %v wanted %v", qr, UpdateStreamStreamEvent2)
	}
	qr, err = stream.Recv()
	if err != io.EOF {
		t.Fatalf("UpdateStream errFunc failed: %v", err)
	}
}
Ejemplo n.º 7
0
func testStreamExecute(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testStreamExecute")
	ctx := context.Background()
	ctx = callerid.NewContext(ctx, TestCallerID, TestVTGateCallerID)
	stream, err := conn.StreamExecute(ctx, TestTarget, StreamExecuteQuery, StreamExecuteBindVars)
	if err != nil {
		t.Fatalf("StreamExecute failed: %v", err)
	}
	qr, err := stream.Recv()
	if err != nil {
		t.Fatalf("StreamExecute failed: cannot read result1: %v", err)
	}
	if len(qr.Rows) == 0 {
		qr.Rows = nil
	}
	if !reflect.DeepEqual(*qr, StreamExecuteQueryResult1) {
		t.Errorf("Unexpected result1 from StreamExecute: got %v wanted %v", qr, StreamExecuteQueryResult1)
	}
	qr, err = stream.Recv()
	if err != nil {
		t.Fatalf("StreamExecute failed: cannot read result2: %v", err)
	}
	if len(qr.Fields) == 0 {
		qr.Fields = nil
	}
	if !reflect.DeepEqual(*qr, StreamExecuteQueryResult2) {
		t.Errorf("Unexpected result2 from StreamExecute: got %v wanted %v", qr, StreamExecuteQueryResult2)
	}
	qr, err = stream.Recv()
	if err != io.EOF {
		t.Fatalf("StreamExecute errFunc failed: %v", err)
	}
}
Ejemplo n.º 8
0
func testBegin2Panics(t *testing.T, conn tabletconn.TabletConn) {
	t.Log("testBegin2Panics")
	ctx := context.Background()
	if _, err := conn.Begin2(ctx); err == nil || !strings.Contains(err.Error(), "caught test panic") {
		t.Fatalf("unexpected panic error: %v", err)
	}
}
Ejemplo n.º 9
0
func testRollback(t *testing.T, conn tabletconn.TabletConn) {
	ctx := context.Background()
	err := conn.Rollback(ctx, rollbackTransactionID)
	if err != nil {
		t.Fatalf("Rollback failed: %v", err)
	}
}
Ejemplo n.º 10
0
func testSplitQueryPanics(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testSplitQueryPanics")
	testPanicHelper(t, f, "SplitQuery", func(ctx context.Context) error {
		_, err := conn.SplitQuery(ctx, TestTarget, SplitQueryBoundQuery, SplitQuerySplitColumn, SplitQuerySplitCount)
		return err
	})
}
Ejemplo n.º 11
0
func testCommit(t *testing.T, conn tabletconn.TabletConn) {
	ctx := context.Background()
	err := conn.Commit(ctx, commitTransactionID)
	if err != nil {
		t.Fatalf("Commit failed: %v", err)
	}
}
Ejemplo n.º 12
0
func testReadTransactionPanics(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testReadTransactionPanics")
	testPanicHelper(t, f, "ReadTransaction", func(ctx context.Context) error {
		_, err := conn.ReadTransaction(ctx, TestTarget, Dtid)
		return err
	})
}
Ejemplo n.º 13
0
func testStreamExecute(t *testing.T, conn tabletconn.TabletConn) {
	t.Log("testStreamExecute")
	ctx := context.Background()
	stream, errFunc, err := conn.StreamExecute(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
	if err != nil {
		t.Fatalf("StreamExecute failed: %v", err)
	}
	qr, ok := <-stream
	if !ok {
		t.Fatalf("StreamExecute failed: cannot read result1")
	}
	if len(qr.Rows) == 0 {
		qr.Rows = nil
	}
	if !reflect.DeepEqual(*qr, streamExecuteQueryResult1) {
		t.Errorf("Unexpected result1 from StreamExecute: got %v wanted %v", qr, streamExecuteQueryResult1)
	}
	qr, ok = <-stream
	if !ok {
		t.Fatalf("StreamExecute failed: cannot read result2")
	}
	if len(qr.Fields) == 0 {
		qr.Fields = nil
	}
	if !reflect.DeepEqual(*qr, streamExecuteQueryResult2) {
		t.Errorf("Unexpected result2 from StreamExecute: got %v wanted %v", qr, streamExecuteQueryResult2)
	}
	qr, ok = <-stream
	if ok {
		t.Fatalf("StreamExecute channel wasn't closed")
	}
	if err := errFunc(); err != nil {
		t.Fatalf("StreamExecute errFunc failed: %v", err)
	}
}
Ejemplo n.º 14
0
func testStreamExecuteError(t *testing.T, conn tabletconn.TabletConn, fake *FakeQueryService) {
	ctx := context.Background()
	ctx = callerid.NewContext(ctx, testCallerID, testVTGateCallerID)
	stream, err := conn.StreamExecute(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
	if err != nil {
		t.Fatalf("StreamExecute failed: %v", err)
	}
	qr, err := stream.Recv()
	if err != nil {
		t.Fatalf("StreamExecute failed: cannot read result1: %v", err)
	}
	if len(qr.Rows) == 0 {
		qr.Rows = nil
	}
	if !reflect.DeepEqual(*qr, streamExecuteQueryResult1) {
		t.Errorf("Unexpected result1 from StreamExecute: got %v wanted %v", qr, streamExecuteQueryResult1)
	}
	// signal to the server that the first result has been received
	close(fake.errorWait)
	// After 1 result, we expect to get an error (no more results).
	qr, err = stream.Recv()
	if err == nil {
		t.Fatalf("StreamExecute channel wasn't closed")
	}
	verifyError(t, err, "StreamExecute")
}
Ejemplo n.º 15
0
func testBeginPanics(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testBeginPanics")
	testPanicHelper(t, f, "Begin", func(ctx context.Context) error {
		_, err := conn.Begin(ctx, TestTarget)
		return err
	})
}
Ejemplo n.º 16
0
func testExecutePanics(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testExecutePanics")
	testPanicHelper(t, f, "Execute", func(ctx context.Context) error {
		_, err := conn.Execute(ctx, TestTarget, ExecuteQuery, ExecuteBindVars, ExecuteTransactionID)
		return err
	})
}
Ejemplo n.º 17
0
func testRollback2Panics(t *testing.T, conn tabletconn.TabletConn) {
	t.Log("testRollback2Panics")
	ctx := context.Background()
	if err := conn.Rollback2(ctx, rollbackTransactionID); err == nil || !strings.Contains(err.Error(), "caught test panic") {
		t.Fatalf("unexpected panic error: %v", err)
	}
}
Ejemplo n.º 18
0
func testStreamExecute2Error(t *testing.T, conn tabletconn.TabletConn, fake *FakeQueryService) {
	t.Log("testStreamExecute2Error")
	ctx := context.Background()
	stream, errFunc, err := conn.StreamExecute2(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
	if err != nil {
		t.Fatalf("StreamExecute2 failed: %v", err)
	}
	qr, ok := <-stream
	if !ok {
		t.Fatalf("StreamExecute2 failed: cannot read result1")
	}
	if len(qr.Rows) == 0 {
		qr.Rows = nil
	}
	if !reflect.DeepEqual(*qr, streamExecuteQueryResult1) {
		t.Errorf("Unexpected result1 from StreamExecute2: got %v wanted %v", qr, streamExecuteQueryResult1)
	}
	// signal to the server that the first result has been received
	close(fake.errorWait)
	// After 1 result, we expect to get an error (no more results).
	qr, ok = <-stream
	if ok {
		t.Fatalf("StreamExecute2 channel wasn't closed")
	}
	err = errFunc()
	verifyError(t, err, "StreamExecute2")
}
Ejemplo n.º 19
0
func testExecuteBatch2Panics(t *testing.T, conn tabletconn.TabletConn) {
	t.Log("testExecuteBatch2Panics")
	ctx := context.Background()
	if _, err := conn.ExecuteBatch2(ctx, executeBatchQueries, true, executeBatchTransactionID); err == nil || !strings.Contains(err.Error(), "caught test panic") {
		t.Fatalf("unexpected panic error: %v", err)
	}
}
Ejemplo n.º 20
0
func testStreamHealth(t *testing.T, conn tabletconn.TabletConn) {
	t.Log("testStreamHealth")
	streamHealthSynchronization = make(chan struct{})
	ctx := context.Background()

	c, errFunc, err := conn.StreamHealth(ctx)
	if err != nil {
		t.Fatalf("StreamHealth failed: %v", err)
	}
	// channel should have one response, then closed
	shr, ok := <-c
	if !ok {
		t.Fatalf("StreamHealth got no response")
	}

	if !reflect.DeepEqual(*shr, *testStreamHealthStreamHealthResponse) {
		t.Errorf("invalid StreamHealthResponse: got %v expected %v", *shr, *testStreamHealthStreamHealthResponse)
	}

	// close streamHealthSynchronization so server side knows we
	// got the response, and it can send the error
	close(streamHealthSynchronization)

	_, ok = <-c
	if ok {
		t.Fatalf("StreamHealth wasn't closed")
	}
	err = errFunc()
	if !strings.Contains(err.Error(), testStreamHealthError) {
		t.Fatalf("StreamHealth failed with the wrong error: %v", err)
	}
}
Ejemplo n.º 21
0
func testBeginExecuteBatchPanics(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testBeginExecuteBatchPanics")
	testPanicHelper(t, f, "BeginExecuteBatch", func(ctx context.Context) error {
		_, _, err := conn.BeginExecuteBatch(ctx, TestTarget, ExecuteBatchQueries, true)
		return err
	})
}
Ejemplo n.º 22
0
func testRollback2(t *testing.T, conn tabletconn.TabletConn) {
	ctx := context.Background()
	ctx = callerid.NewContext(ctx, testCallerID, testVTGateCallerID)
	err := conn.Rollback2(ctx, rollbackTransactionID)
	if err != nil {
		t.Fatalf("Rollback2 failed: %v", err)
	}
}
Ejemplo n.º 23
0
func testRollbackError(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testRollbackError")
	f.HasError = true
	testErrorHelper(t, f, "Rollback", func(ctx context.Context) error {
		return conn.Rollback(ctx, TestTarget, CommitTransactionID)
	})
	f.HasError = false
}
Ejemplo n.º 24
0
func testStartCommitError(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testStartCommitError")
	f.HasError = true
	testErrorHelper(t, f, "StartCommit", func(ctx context.Context) error {
		return conn.StartCommit(ctx, TestTarget, CommitTransactionID, Dtid)
	})
	f.HasError = false
}
Ejemplo n.º 25
0
func testCommit(t *testing.T, conn tabletconn.TabletConn) {
	ctx := context.Background()
	ctx = callerid.NewContext(ctx, testCallerID, testVTGateCallerID)
	err := conn.Commit(ctx, commitTransactionID)
	if err != nil {
		t.Fatalf("Commit failed: %v", err)
	}
}
Ejemplo n.º 26
0
func testCommitPreparedError(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testCommitPreparedError")
	f.HasError = true
	testErrorHelper(t, f, "CommitPrepared", func(ctx context.Context) error {
		return conn.CommitPrepared(ctx, TestTarget, Dtid)
	})
	f.HasError = false
}
Ejemplo n.º 27
0
func testResolveTransactionError(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testResolveTransactionError")
	f.HasError = true
	testErrorHelper(t, f, "ResolveTransaction", func(ctx context.Context) error {
		return conn.ResolveTransaction(ctx, TestTarget, Dtid)
	})
	f.HasError = false
}
Ejemplo n.º 28
0
func testExecuteError(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testExecuteError")
	f.HasError = true
	testErrorHelper(t, f, "Execute", func(ctx context.Context) error {
		_, err := conn.Execute(ctx, TestTarget, ExecuteQuery, ExecuteBindVars, ExecuteTransactionID)
		return err
	})
	f.HasError = false
}
Ejemplo n.º 29
0
func testRollback(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testRollback")
	ctx := context.Background()
	ctx = callerid.NewContext(ctx, TestCallerID, TestVTGateCallerID)
	err := conn.Rollback(ctx, TestTarget, RollbackTransactionID)
	if err != nil {
		t.Fatalf("Rollback failed: %v", err)
	}
}
Ejemplo n.º 30
0
func testSplitQueryError(t *testing.T, conn tabletconn.TabletConn, f *FakeQueryService) {
	t.Log("testSplitQueryError")
	f.HasError = true
	testErrorHelper(t, f, "SplitQuery", func(ctx context.Context) error {
		_, err := conn.SplitQuery(ctx, TestTarget, SplitQueryBoundQuery, SplitQuerySplitColumn, SplitQuerySplitCount)
		return err
	})
	f.HasError = false
}