Skip to content

Commit

Permalink
Fixed unittests & Removed incorrect one
Browse files Browse the repository at this point in the history
  • Loading branch information
EinKrebs committed Feb 14, 2024
1 parent 90030f2 commit 33e0964
Showing 1 changed file with 8 additions and 120 deletions.
128 changes: 8 additions & 120 deletions router/qrouter/proxy_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,14 @@ func TestJoins(t *testing.T) {
Name: "sshjt1",
ColumnNames: []string{"i"},
},
"xjoin": {
Name: "xjoin",
ColumnNames: []string{"i"},
},
"yjoin": {
Name: "yjoin",
ColumnNames: []string{"i"},
},
},
})

Expand Down Expand Up @@ -932,126 +940,6 @@ func TestCopySingleShard(t *testing.T) {
}
}

func TestInsertMultiDistribution(t *testing.T) {
assert := assert.New(t)

type tcase struct {
query string
distribution string
exp routingstate.RoutingState
err error
}
db, _ := qdb.NewMemQDB(MemQDBPath)
distribution1 := "ds1"
distribution2 := "ds2"

assert.NoError(db.CreateDistribution(context.TODO(), qdb.NewDistribution(distribution1, nil)))
assert.NoError(db.CreateDistribution(context.TODO(), qdb.NewDistribution(distribution2, nil)))

assert.NoError(db.AddShardingRule(context.TODO(), &qdb.ShardingRule{
ID: "id1",
DistributionId: distribution1,
TableName: "",
Entries: []qdb.ShardingRuleEntry{
{
Column: "i",
},
},
}))

assert.NoError(db.AddShardingRule(context.TODO(), &qdb.ShardingRule{
ID: "id2",
DistributionId: distribution2,
TableName: "",
Entries: []qdb.ShardingRuleEntry{
{
Column: "i",
},
},
}))

assert.NoError(db.AddKeyRange(context.TODO(), &qdb.KeyRange{
ShardID: "sh1",
DistributionId: distribution1,
KeyRangeID: "id1",
LowerBound: []byte("1"),
}))

assert.NoError(db.AddKeyRange(context.TODO(), &qdb.KeyRange{
ShardID: "sh2",
DistributionId: distribution2,
KeyRangeID: "id2",
LowerBound: []byte("1"),
}))

lc := local.NewLocalCoordinator(db)

pr, err := qrouter.NewProxyRouter(map[string]*config.Shard{
"sh1": {
Hosts: nil,
},
"sh2": {
Hosts: nil,
},
}, lc, &config.QRouter{
DefaultRouteBehaviour: "BLOCK",
})

assert.NoError(err)

for _, tt := range []tcase{
{

query: "INSERT INTO xxxdst1(i) VALUES(5);",
distribution: distribution1,
exp: routingstate.ShardMatchState{
Route: &routingstate.DataShardRoute{
Shkey: kr.ShardKey{
Name: "sh1",
},
Matchedkr: &kr.KeyRange{
ShardID: "sh1",
ID: "id1",
Distribution: distribution1,
LowerBound: []byte("1"),
},
},
TargetSessionAttrs: "any",
},
err: nil,
},
{
query: "INSERT INTO xxxdst1(i) VALUES(5);",
distribution: distribution2,
exp: routingstate.ShardMatchState{
Route: &routingstate.DataShardRoute{
Shkey: kr.ShardKey{
Name: "sh2",
},
Matchedkr: &kr.KeyRange{
ShardID: "sh2",
ID: "id2",
Distribution: distribution2,
LowerBound: []byte("1"),
},
},
TargetSessionAttrs: "any",
},
err: nil,
},
} {
parserRes, err := lyx.Parse(tt.query)

assert.NoError(err, "query %s", tt.query)

tmp, err := pr.Route(context.TODO(), parserRes, session.NewDummyHandler(tt.distribution))

assert.NoError(err, "query %s", tt.query)

assert.Equal(tt.exp, tmp, tt.query)
}
}

func TestSetStmt(t *testing.T) {
assert := assert.New(t)

Expand Down

0 comments on commit 33e0964

Please sign in to comment.