Skip to content

Commit

Permalink
Add more tests. Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Nayak <[email protected]>
  • Loading branch information
rohit-nayak-ps committed Nov 29, 2024
1 parent 2a867f6 commit ce1da4c
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions go/test/endtoend/vreplication/lookupindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type lookupTestCase struct {
initQuery string
runningQuery string
postExternalizeQuery string
cleanupQuery string
}

func TestLookupIndex(t *testing.T) {
Expand All @@ -102,9 +103,14 @@ func TestLookupIndex(t *testing.T) {
tabs := setupLookupIndexKeyspace(t)
_ = tabs

initQuery := "insert into t1 (c1, c2, val) values (1, 1, 'val1'), (2, 2, 'val2'), (3, 3, 'val3')"
runningQuery := "insert into t1 (c1, c2, val) values (4, 4, 'val4'), (5, 5, 'val5'), (6, 6, 'val6')"
postExternalizeQuery := "insert into t1 (c1, c2, val) values (7, 7, 'val7'), (8, 8, 'val8'), (9, 9, 'val9')"
cleanupQuery := "delete from t1"

testCases := []lookupTestCase{
{
name: "lookup index",
name: "non-unique lookup index, one column",
li: &lookupIndex{
typ: "consistent_lookup",
name: "t1_c2_lookup",
Expand All @@ -116,25 +122,54 @@ func TestLookupIndex(t *testing.T) {
ignoreNulls: true,
t: t,
},
initQuery: "insert into t1 (c1, c2, val) values (1, 1, 'val1'), (2, 2, 'val2'), (3, 3, 'val3')",
runningQuery: "insert into t1 (c1, c2, val) values (4, 4, 'val4'), (5, 5, 'val5'), (6, 6, 'val6')",
postExternalizeQuery: "insert into t1 (c1, c2, val) values (7, 7, 'val7'), (8, 8, 'val8'), (9, 9, 'val9')",
},
{
name: "lookup index, two columns",
li: &lookupIndex{
typ: "lookup",
name: "t1_c2_val_lookup",
tableKeyspace: lookupClusterSpec.keyspaceName,
table: "t1",
columns: []string{"c2", "val"},
ownerTable: "t1",
ownerTableKeyspace: lookupClusterSpec.keyspaceName,
ignoreNulls: true,
t: t,
},
},
{
name: "unique lookup index, one column",
li: &lookupIndex{
typ: "lookup_unique",
name: "t1_c2_unique_lookup",
tableKeyspace: lookupClusterSpec.keyspaceName,
table: "t1",
columns: []string{"c2"},
ownerTable: "t1",
ownerTableKeyspace: lookupClusterSpec.keyspaceName,
ignoreNulls: true,
t: t,
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.initQuery = initQuery
tc.runningQuery = runningQuery
tc.postExternalizeQuery = postExternalizeQuery
tc.cleanupQuery = cleanupQuery
testLookupVindex(t, &tc)
})
}
}

func testLookupVindex(t *testing.T, tc *lookupTestCase) {

vtgateConn, cancel := getVTGateConn()
defer cancel()
var totalRows int
li := tc.li

t.Run("init data", func(t *testing.T) {
totalRows += getNumRowsInQuery(t, tc.initQuery)
_, err := vtgateConn.ExecuteFetch(tc.initQuery, 1000, false)
Expand All @@ -161,4 +196,9 @@ func testLookupVindex(t *testing.T, tc *lookupTestCase) {
waitForRowCount(t, vtgateConn, tc.li.ownerTableKeyspace, li.name, totalRows)
})

t.Run("cleanup", func(t *testing.T) {
_, err := vtgateConn.ExecuteFetch(tc.cleanupQuery, 1000, false)
require.NoError(t, err)
waitForRowCount(t, vtgateConn, tc.li.ownerTableKeyspace, li.name, 0)
})
}

0 comments on commit ce1da4c

Please sign in to comment.