This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial raft_recover implementation and test
- Loading branch information
1 parent
fa3a40d
commit 5b49e37
Showing
9 changed files
with
221 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "../lib/cluster.h" | ||
#include "../lib/runner.h" | ||
|
||
/****************************************************************************** | ||
* | ||
* Fixture holding a bootstrapd raft caluster. | ||
* | ||
*****************************************************************************/ | ||
|
||
struct cluster | ||
{ | ||
FIXTURE_CLUSTER; | ||
}; | ||
|
||
static void *setupCluster(const MunitParameter params[], | ||
MUNIT_UNUSED void *user_data) | ||
{ | ||
struct cluster *f = munit_malloc(sizeof *f); | ||
SETUP_CLUSTER(3); | ||
CLUSTER_BOOTSTRAP; | ||
return f; | ||
} | ||
|
||
static void tearDownCluster(void *data) | ||
{ | ||
struct cluster *f = data; | ||
TEAR_DOWN_CLUSTER; | ||
free(f); | ||
} | ||
|
||
/****************************************************************************** | ||
* | ||
* Recover tests. | ||
* | ||
*****************************************************************************/ | ||
|
||
SUITE(raft_recover) | ||
|
||
/* Attempting to recover a running instance results in RAFT_BUSY. */ | ||
TEST(raft_recover, busy, setupCluster, tearDownCluster, 0, NULL) | ||
{ | ||
struct cluster *f = data; | ||
struct raft *raft; | ||
struct raft_configuration configuration; | ||
int rv; | ||
|
||
/* Start all servers. */ | ||
CLUSTER_START; | ||
|
||
raft = CLUSTER_RAFT(0); | ||
CLUSTER_CONFIGURATION(&configuration); | ||
rv = raft_recover(raft, &configuration); | ||
munit_assert_int(rv, ==, RAFT_BUSY); | ||
raft_configuration_close(&configuration); | ||
|
||
return MUNIT_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "../lib/runner.h" | ||
#include "../lib/uv.h" | ||
|
||
/****************************************************************************** | ||
* | ||
* Fixture | ||
* | ||
*****************************************************************************/ | ||
|
||
struct fixture | ||
{ | ||
FIXTURE_UV; | ||
}; | ||
|
||
static void *setupIo(const MunitParameter params[], void *user_data) | ||
{ | ||
struct fixture *f = munit_malloc(sizeof *f); | ||
SETUP_UV; | ||
return f; | ||
} | ||
|
||
static void tearDownIo(void *data) | ||
{ | ||
struct fixture *f = data; | ||
TEAR_DOWN_UV; | ||
free(f); | ||
} | ||
|
||
/****************************************************************************** | ||
* | ||
* UvRecover | ||
* | ||
*****************************************************************************/ | ||
|
||
SUITE(UvRecover) | ||
|
||
/* Invoke UvRecover and assert that it fails with the given error. */ | ||
#define RECOVER_ERROR(RV, CONF) \ | ||
{ \ | ||
int rv_; \ | ||
rv_ = f->io.recover(&f->io, CONF); \ | ||
munit_assert_int(rv_, ==, RV); \ | ||
} | ||
|
||
/* Invoke UvRecover and assert that it succeeds */ | ||
#define RECOVER(CONF) RECOVER_ERROR(0, CONF) | ||
|
||
/* If the instance has been already initialized, an error is returned. */ | ||
/* A new configuration is saved as last entry on disk. */ | ||
TEST(UvRecover, newConfiguration, setupIo, tearDownIo, 0, NULL) | ||
{ | ||
struct fixture *f = data; | ||
struct raft_configuration configuration1; | ||
struct raft_configuration configuration2; | ||
int rv; | ||
|
||
/* Boostrap using an initial configuration */ | ||
raft_configuration_init(&configuration1); | ||
rv = raft_configuration_add(&configuration1, 1, "1", true); | ||
munit_assert_int(rv, ==, 0); | ||
rv = raft_configuration_add(&configuration1, 2, "2", true); | ||
munit_assert_int(rv, ==, 0); | ||
rv = f->io.bootstrap(&f->io, &configuration1); | ||
munit_assert_int(rv, ==, 0); | ||
|
||
/* Boostrap using a different configuration */ | ||
raft_configuration_init(&configuration2); | ||
rv = raft_configuration_add(&configuration2, 1, "1", true); | ||
munit_assert_int(rv, ==, 0); | ||
|
||
RECOVER(&configuration2); | ||
|
||
raft_configuration_close(&configuration1); | ||
raft_configuration_close(&configuration2); | ||
|
||
return 0; | ||
} |