diff --git a/go/test/endtoend/vreplication/lookupindex_helper_test.go b/go/test/endtoend/vreplication/lookup_vindex_helper_test.go similarity index 59% rename from go/test/endtoend/vreplication/lookupindex_helper_test.go rename to go/test/endtoend/vreplication/lookup_vindex_helper_test.go index 864a5e0f7fc..1c74dadc642 100644 --- a/go/test/endtoend/vreplication/lookupindex_helper_test.go +++ b/go/test/endtoend/vreplication/lookup_vindex_helper_test.go @@ -29,7 +29,7 @@ import ( binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" ) -type lookupIndex struct { +type lookupVindex struct { typ string name string tableKeyspace string @@ -42,64 +42,64 @@ type lookupIndex struct { t *testing.T } -func (li *lookupIndex) String() string { - return li.typ + " " + li.name + " on " + li.tableKeyspace + "." + li.table + " (" + li.columns[0] + ")" +func (lv *lookupVindex) String() string { + return lv.typ + " " + lv.name + " on " + lv.tableKeyspace + "." + lv.table + " (" + lv.columns[0] + ")" } -func (li *lookupIndex) create() { - cols := strings.Join(li.columns, ",") +func (lv *lookupVindex) create() { + cols := strings.Join(lv.columns, ",") args := []string{ "LookupVindex", - "--name", li.name, - "--table-keyspace=" + li.ownerTableKeyspace, + "--name", lv.name, + "--table-keyspace=" + lv.ownerTableKeyspace, "create", - "--keyspace=" + li.tableKeyspace, - "--type=" + li.typ, - "--table-owner=" + li.ownerTable, + "--keyspace=" + lv.tableKeyspace, + "--type=" + lv.typ, + "--table-owner=" + lv.ownerTable, "--table-owner-columns=" + cols, "--tablet-types=PRIMARY", } - if li.ignoreNulls { + if lv.ignoreNulls { args = append(args, "--ignore-nulls") } err := vc.VtctldClient.ExecuteCommand(args...) - require.NoError(li.t, err, "error executing LookupVindex create: %v", err) - waitForWorkflowState(li.t, vc, fmt.Sprintf("%s.%s", li.ownerTableKeyspace, li.name), binlogdatapb.VReplicationWorkflowState_Running.String()) - li.expectWriteOnly(true) + require.NoError(lv.t, err, "error executing LookupVindex create: %v", err) + waitForWorkflowState(lv.t, vc, fmt.Sprintf("%s.%s", lv.ownerTableKeyspace, lv.name), binlogdatapb.VReplicationWorkflowState_Running.String()) + lv.expectWriteOnly(true) } -func (li *lookupIndex) cancel() { +func (lv *lookupVindex) cancel() { panic("not implemented") } -func (li *lookupIndex) externalize() { +func (lv *lookupVindex) externalize() { args := []string{ "LookupVindex", - "--name", li.name, - "--table-keyspace=" + li.ownerTableKeyspace, + "--name", lv.name, + "--table-keyspace=" + lv.ownerTableKeyspace, "externalize", - "--keyspace=" + li.tableKeyspace, + "--keyspace=" + lv.tableKeyspace, } err := vc.VtctldClient.ExecuteCommand(args...) - require.NoError(li.t, err, "error executing LookupVindex externalize: %v", err) - li.expectWriteOnly(false) + require.NoError(lv.t, err, "error executing LookupVindex externalize: %v", err) + lv.expectWriteOnly(false) } -func (li *lookupIndex) show() error { +func (lv *lookupVindex) show() error { return nil } -func (li *lookupIndex) expectWriteOnly(expected bool) { - vschema, err := vc.VtctldClient.ExecuteCommandWithOutput("GetVSchema", li.ownerTableKeyspace) - require.NoError(li.t, err, "error executing GetVSchema: %v", err) - vdx := gjson.Get(vschema, fmt.Sprintf("vindexes.%s", li.name)) - require.NotNil(li.t, vdx, "lookup vindex %s not found", li.name) +func (lv *lookupVindex) expectWriteOnly(expected bool) { + vschema, err := vc.VtctldClient.ExecuteCommandWithOutput("GetVSchema", lv.ownerTableKeyspace) + require.NoError(lv.t, err, "error executing GetVSchema: %v", err) + vdx := gjson.Get(vschema, fmt.Sprintf("vindexes.%s", lv.name)) + require.NotNil(lv.t, vdx, "lookup vindex %s not found", lv.name) want := "" if expected { want = "true" } - require.Equal(li.t, want, vdx.Get("params.write_only").String(), "expected write_only parameter to be %s", want) + require.Equal(lv.t, want, vdx.Get("params.write_only").String(), "expected write_only parameter to be %s", want) } func getNumRowsInQuery(t *testing.T, query string) int { diff --git a/go/test/endtoend/vreplication/lookupindex_test.go b/go/test/endtoend/vreplication/lookup_vindex_test.go similarity index 90% rename from go/test/endtoend/vreplication/lookupindex_test.go rename to go/test/endtoend/vreplication/lookup_vindex_test.go index 348a0ee5906..c0864b26cca 100644 --- a/go/test/endtoend/vreplication/lookupindex_test.go +++ b/go/test/endtoend/vreplication/lookup_vindex_test.go @@ -63,7 +63,7 @@ create table t1( `, } -func setupLookupIndexKeyspace(t *testing.T) map[string]*cluster.VttabletProcess { +func setupLookupVindexKeyspace(t *testing.T) map[string]*cluster.VttabletProcess { tablets := make(map[string]*cluster.VttabletProcess) if _, err := vc.AddKeyspace(t, []*Cell{vc.Cells["zone1"]}, lookupClusterSpec.keyspaceName, "-80,80-", lookupClusterSpec.vschema, lookupClusterSpec.schema, defaultReplicas, defaultRdonly, 200, nil); err != nil { @@ -80,14 +80,14 @@ func setupLookupIndexKeyspace(t *testing.T) map[string]*cluster.VttabletProcess type lookupTestCase struct { name string - li *lookupIndex + lv *lookupVindex initQuery string runningQuery string postExternalizeQuery string cleanupQuery string } -func TestLookupIndex(t *testing.T) { +func TestLookupVindex(t *testing.T) { setSidecarDBName("_vt") origDefaultReplicas := defaultReplicas origDefaultRdonly := defaultRdonly @@ -101,7 +101,7 @@ func TestLookupIndex(t *testing.T) { defer vc.TearDown() vttablet.InitVReplicationConfigDefaults() - _ = setupLookupIndexKeyspace(t) + _ = setupLookupVindexKeyspace(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')" @@ -111,7 +111,7 @@ func TestLookupIndex(t *testing.T) { testCases := []lookupTestCase{ { name: "non-unique lookup index, one column", - li: &lookupIndex{ + lv: &lookupVindex{ typ: "consistent_lookup", name: "t1_c2_lookup", tableKeyspace: lookupClusterSpec.keyspaceName, @@ -125,7 +125,7 @@ func TestLookupIndex(t *testing.T) { }, { name: "lookup index, two columns", - li: &lookupIndex{ + lv: &lookupVindex{ typ: "lookup", name: "t1_c2_val_lookup", tableKeyspace: lookupClusterSpec.keyspaceName, @@ -139,7 +139,7 @@ func TestLookupIndex(t *testing.T) { }, { name: "unique lookup index, one column", - li: &lookupIndex{ + lv: &lookupVindex{ typ: "lookup_unique", name: "t1_c2_unique_lookup", tableKeyspace: lookupClusterSpec.keyspaceName, @@ -168,7 +168,7 @@ func testLookupVindex(t *testing.T, tc *lookupTestCase) { vtgateConn, cancel := getVTGateConn() defer cancel() var totalRows int - li := tc.li + lv := tc.lv t.Run("init data", func(t *testing.T) { totalRows += getNumRowsInQuery(t, tc.initQuery) @@ -177,28 +177,28 @@ func testLookupVindex(t *testing.T, tc *lookupTestCase) { }) t.Run("create", func(t *testing.T) { - tc.li.create() + tc.lv.create() - lks := li.tableKeyspace - vindexName := li.name + lks := lv.tableKeyspace + vindexName := lv.name waitForRowCount(t, vtgateConn, lks, vindexName, totalRows) totalRows += getNumRowsInQuery(t, tc.runningQuery) _, err := vtgateConn.ExecuteFetch(tc.runningQuery, 1000, false) require.NoError(t, err) - waitForRowCount(t, vtgateConn, tc.li.ownerTableKeyspace, li.name, totalRows) + waitForRowCount(t, vtgateConn, tc.lv.ownerTableKeyspace, lv.name, totalRows) }) t.Run("externalize", func(t *testing.T) { - tc.li.externalize() + tc.lv.externalize() totalRows += getNumRowsInQuery(t, tc.postExternalizeQuery) _, err := vtgateConn.ExecuteFetch(tc.postExternalizeQuery, 1000, false) require.NoError(t, err) - waitForRowCount(t, vtgateConn, tc.li.ownerTableKeyspace, li.name, totalRows) + waitForRowCount(t, vtgateConn, tc.lv.ownerTableKeyspace, lv.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) + waitForRowCount(t, vtgateConn, tc.lv.ownerTableKeyspace, lv.name, 0) }) }