Skip to content

Commit f100223

Browse files
committed
add back func
1 parent d5d4cd6 commit f100223

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

go/test/endtoend/vreplication/resharding_workflows_v2_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,3 +947,34 @@ func tstApplySchemaOnlineDDL(t *testing.T, sql string, keyspace string) {
947947
"--sql", sql, keyspace)
948948
require.NoError(t, err, fmt.Sprintf("ApplySchema Error: %s", err))
949949
}
950+
951+
func validateTableRoutingRule(t *testing.T, table, tabletType, fromKeyspace, toKeyspace string) {
952+
tabletType = strings.ToLower(strings.TrimSpace(tabletType))
953+
rr := getRoutingRules(t)
954+
// We set matched = true by default because it is possible, if --no-routing-rules is set while creating
955+
// a workflow, that the routing rules are empty when the workflow starts.
956+
// We set it to false below when the rule is found, but before matching the routed keyspace.
957+
matched := true
958+
for _, r := range rr.GetRules() {
959+
fromRule := fmt.Sprintf("%s.%s", fromKeyspace, table)
960+
if tabletType != "" && tabletType != "primary" {
961+
fromRule = fmt.Sprintf("%s@%s", fromRule, tabletType)
962+
}
963+
if r.FromTable == fromRule {
964+
// We found the rule, so we can set matched to false here and check for the routed keyspace below.
965+
matched = false
966+
require.NotEmpty(t, r.ToTables)
967+
toTable := r.ToTables[0]
968+
// The ToTables value is of the form "routedKeyspace.table".
969+
routedKeyspace, routedTable, ok := strings.Cut(toTable, ".")
970+
require.True(t, ok)
971+
require.Equal(t, table, routedTable)
972+
if routedKeyspace == toKeyspace {
973+
// We found the rule, the table and keyspace matches, so our search is done.
974+
matched = true
975+
break
976+
}
977+
}
978+
}
979+
require.Truef(t, matched, "routing rule for %s.%s from %s to %s not found", fromKeyspace, table, tabletType, toKeyspace)
980+
}

0 commit comments

Comments
 (0)