vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletserver/vstreamer/snapshot_conn_test.go (about)

     1  /*
     2  Copyright 2020 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package vstreamer
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  	"github.com/stretchr/testify/require"
    25  
    26  	"vitess.io/vitess/go/sqltypes"
    27  )
    28  
    29  func TestStartSnapshot(t *testing.T) {
    30  	if testing.Short() {
    31  		t.Skip()
    32  	}
    33  
    34  	execStatements(t, []string{
    35  		"create table t1(id int, val varbinary(128), primary key(id))",
    36  		"insert into t1 values (1, 'aaa')",
    37  	})
    38  	defer execStatements(t, []string{
    39  		"drop table t1",
    40  	})
    41  
    42  	ctx := context.Background()
    43  	conn, err := snapshotConnect(ctx, env.TabletEnv.Config().DB.AppWithDB())
    44  	require.NoError(t, err)
    45  	defer conn.Close()
    46  
    47  	conn.startSnapshot(ctx, "t1")
    48  
    49  	// This second row should not be in the result.
    50  	execStatement(t, "insert into t1 values(2, 'bbb')")
    51  
    52  	wantqr := &sqltypes.Result{
    53  		Rows: [][]sqltypes.Value{
    54  			{sqltypes.NewInt32(1), sqltypes.NewVarBinary("aaa")},
    55  		},
    56  		StatusFlags: sqltypes.ServerStatusNoIndexUsed | sqltypes.ServerStatusAutocommit | sqltypes.ServerStatusInTrans,
    57  	}
    58  	qr, err := conn.ExecuteFetch("select * from t1", 10, false)
    59  	require.NoError(t, err)
    60  	assert.Equal(t, wantqr, qr)
    61  }