Skip to content

Commit

Permalink
Added & fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EinKrebs committed Mar 25, 2024
1 parent 07e5686 commit d9f88e6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 74 deletions.
4 changes: 2 additions & 2 deletions coordinator/provider/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ func (qc *qdbCoordinator) lockCoordinator(ctx context.Context, initialRouter boo
return registerRouter()
}

// TODO : unit tests
// RunCoordinator side effect: it runs an asynchronous goroutine
// that checks the availability of the SPQR router
// TODO : unit tests
func (qc *qdbCoordinator) RunCoordinator(ctx context.Context, initialRouter bool) {
if !qc.lockCoordinator(ctx, initialRouter) {
return
Expand All @@ -342,7 +342,7 @@ func (qc *qdbCoordinator) RunCoordinator(ctx context.Context, initialRouter bool
if err != nil {
spqrlog.Zero.Error().
Err(err).
Msg("faild to list key ranges")
Msg("failed to list key ranges")
}

for _, r := range ranges {
Expand Down
66 changes: 66 additions & 0 deletions test/feature/features/move.feature
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ Feature: Move test
"""
001
"""
When I run SQL on host "coordinator"
"""
SHOW key_ranges
"""
Then command return code should be "0"
And SQL result should match json_exactly
"""
[
{
"Key range ID":"krid1",
"Distribution ID":"ds1",
"Lower bound":"1",
"Shard ID":"sh2"
},
{
"Key range ID":"krid2",
"Distribution ID":"ds1",
"Lower bound":"11",
"Shard ID":"sh2"
}
]
"""

Scenario: MOVE KEY RANGE works with many rows
When I run SQL on host "shard1"
Expand Down Expand Up @@ -111,6 +133,28 @@ Feature: Move test
"""
.*001(.|\n)*002(.|\n)*003(.|\n)*004(.|\n)*005
"""
When I run SQL on host "coordinator"
"""
SHOW key_ranges
"""
Then command return code should be "0"
And SQL result should match json_exactly
"""
[
{
"Key range ID":"krid1",
"Distribution ID":"ds1",
"Lower bound":"1",
"Shard ID":"sh2"
},
{
"Key range ID":"krid2",
"Distribution ID":"ds1",
"Lower bound":"11",
"Shard ID":"sh2"
}
]
"""

Scenario: MOVE KEY RANGE works with many tables
When I run SQL on host "shard1"
Expand Down Expand Up @@ -168,6 +212,28 @@ Feature: Move test
"""
002
"""
When I run SQL on host "coordinator"
"""
SHOW key_ranges
"""
Then command return code should be "0"
And SQL result should match json_exactly
"""
[
{
"Key range ID":"krid1",
"Distribution ID":"ds1",
"Lower bound":"1",
"Shard ID":"sh2"
},
{
"Key range ID":"krid2",
"Distribution ID":"ds1",
"Lower bound":"11",
"Shard ID":"sh2"
}
]
"""

Scenario: Move to non-existent shard fails
When I run SQL on host "coordinator"
Expand Down
83 changes: 11 additions & 72 deletions test/feature/features/move_recover.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,28 @@ Feature: Move recover test
"""
Then command return code should be "0"

Scenario: Interrapted transaction continues
Scenario: Planned transaction continues
When I record in qdb data transfer transaction with name "krid2"
"""
{"to_shard": "sh1",
{
"to_shard": "sh1",
"from_shard": "sh2",
"from_transaction": "tx2",
"to_transaction": "tx1",
"from_tx_status": "process",
"to_tx_status": "commit"
"status": "planned"
}
"""
Then command return code should be "0"
When I run SQL on host "shard1"
"""
CREATE TABLE xMove(w_id INT, s TEXT);
insert into xMove(w_id, s) values(1, '001');
insert into xMove(w_id, s) values(11, '002');
"""
Then command return code should be "0"
When I run SQL on host "shard2"
"""
CREATE TABLE xMove(w_id INT, s TEXT);
insert into xMove(w_id, s) values(11, '002');
BEGIN;
DELETE FROM xMove WHERE w_id = 11;
PREPARE TRANSACTION 'tx2';
SELECT * FROM xMove
"""
Then command return code should be "0"
And SQL result should match regexp
"""
002
"""
Given host "coordinator" is stopped
When I execute SQL on host "coordinator2"
"""
Expand All @@ -71,46 +60,28 @@ Feature: Move recover test
002
"""

Scenario: Interrapted transaction rollbacks
Scenario: DataCopied transaction continues
When I record in qdb data transfer transaction with name "krid2"
"""
{"to_shard": "sh1",
{
"to_shard": "sh1",
"from_shard": "sh2",
"from_transaction": "tx2",
"to_transaction": "tx1",
"from_tx_status": "process",
"to_tx_status": "process"
"status": "data_copied"
}
"""
Then command return code should be "0"
When I run SQL on host "shard1"
"""
CREATE TABLE xMove(w_id INT, s TEXT);
insert into xMove(w_id, s) values(1, '001');
BEGIN;
insert into xMove(w_id, s) values(11, '002');
PREPARE TRANSACTION 'tx2';
SELECT * FROM xMove
insert into xMove(w_id, s) values (1, '001'), (11, '002');
"""
Then command return code should be "0"
And SQL result should not match regexp
"""
002
"""
When I run SQL on host "shard2"
"""
CREATE TABLE xMove(w_id INT, s TEXT);
insert into xMove(w_id, s) values(11, '002');
BEGIN;
DELETE FROM xMove WHERE w_id = 11;
PREPARE TRANSACTION 'tx2';
SELECT * FROM xMove
"""
Then command return code should be "0"
And SQL result should match regexp
"""
002
"""
Given host "coordinator" is stopped
When I execute SQL on host "coordinator2"
"""
Expand All @@ -124,46 +95,14 @@ Feature: Move recover test
Then command return code should be "0"
And SQL result should match regexp
"""
001
"""
And SQL result should not match regexp
"""
002
001(.|\n)*002
"""
When I run SQL on host "shard2"
"""
SELECT * FROM xMove
"""
Then command return code should be "0"
And SQL result should match regexp
And SQL result should not match regexp
"""
002
"""

Scenario: coordinator saves transaction to QDB and processes it on restart
When I run SQL on host "shard1"
"""
CREATE TABLE xMove(w_id INT, s TEXT);
insert into xMove(w_id, s) values(1, '001');
"""
Then command return code should be "0"
When I run SQL on host "shard2"
"""
CREATE TABLE xMove(w_id INT, s TEXT);
insert into xMove(w_id, s) values(11, '002');
"""
Then command return code should be "0"
When I execute SQL on host "coordinator"
"""
MOVE KEY RANGE krid1 to sh2
"""
Then command return code should be "0"
And qdb should contain transaction "krid1"
Given host "coordinator" is stopped
When I execute SQL on host "coordinator2"
"""
SHOW routers
"""
Then command return code should be "0"
And qdb should not contain transaction "krid1"

0 comments on commit d9f88e6

Please sign in to comment.