コード例 #1
0
// runTestFlow runs a flow with the given processors and returns the results.
// Any errors stop the current test.
func runTestFlow(
	t *testing.T, srv serverutils.TestServerInterface, procs ...distsqlrun.ProcessorSpec,
) sqlbase.EncDatumRows {
	kvDB := srv.KVClient().(*client.DB)
	distSQLSrv := srv.DistSQLServer().(*distsqlrun.ServerImpl)

	req := distsqlrun.SetupFlowRequest{
		Txn: client.NewTxn(context.TODO(), *kvDB).Proto,
		Flow: distsqlrun.FlowSpec{
			FlowID:     distsqlrun.FlowID{UUID: uuid.MakeV4()},
			Processors: procs,
		},
	}

	var rowBuf distsqlrun.RowBuffer

	flow, err := distSQLSrv.SetupSyncFlow(context.TODO(), &req, &rowBuf)
	if err != nil {
		t.Fatal(err)
	}
	flow.Start(func() {})
	flow.Wait()
	flow.Cleanup()

	if rowBuf.Err != nil {
		t.Fatal(rowBuf.Err)
	}
	if !rowBuf.Closed {
		t.Errorf("output not closed")
	}
	return rowBuf.Rows
}