Skip to content

Commit

Permalink
add read only test with code style
Browse files Browse the repository at this point in the history
  • Loading branch information
hououou committed Sep 29, 2023
1 parent aed7067 commit 376f252
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
7 changes: 3 additions & 4 deletions test/main/test_locking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ TEST_F(EmptyDBTest, testReadLock) {
uint64_t* count = (uint64_t*)mmap(
NULL, sizeof(uint64_t), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0);
*count = 0;
//create db
// create db
EXPECT_NO_THROW(createDBAndConn());
ASSERT_TRUE(
conn->query("CREATE NODE TABLE Person(name STRING, age INT64, PRIMARY KEY(name));")
->isSuccess());
ASSERT_TRUE(conn->query("CREATE NODE TABLE Person(name STRING, age INT64, PRIMARY KEY(name));")
->isSuccess());
ASSERT_TRUE(conn->query("CREATE (:Person {name: 'Alice', age: 25});")->isSuccess());
database.reset();
// test read write db
Expand Down
13 changes: 5 additions & 8 deletions test/main/test_read_only.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ namespace testing {

TEST_F(EmptyDBTest, testReadWrite) {
systemConfig->accessMode = AccessMode::READ_WRITE;
auto db=std::make_unique<main::Database>(databasePath, *systemConfig);
auto db = std::make_unique<main::Database>(databasePath, *systemConfig);
auto con = std::make_unique<main::Connection>(db.get());
// try create a node table, create nodes, success
ASSERT_TRUE(
con->query("CREATE NODE TABLE Person(name STRING, age INT64, PRIMARY KEY(name))")
->isSuccess());
ASSERT_TRUE(con->query("CREATE NODE TABLE Person(name STRING, age INT64, PRIMARY KEY(name))")
->isSuccess());
ASSERT_TRUE(con->query("CREATE (:Person {name: 'Alice', age: 25})")->isSuccess());
// try read from node table, success
ASSERT_TRUE(con->query("MATCH (:Person) RETURN COUNT(*)")->isSuccess());
Expand All @@ -25,14 +24,12 @@ TEST_F(EmptyDBTest, testReadWrite) {
systemConfig->accessMode = AccessMode::READ_ONLY;
std::unique_ptr<main::Database> db2;
std::unique_ptr<main::Connection> con2;
EXPECT_NO_THROW(db2=std::make_unique<main::Database>(databasePath, *systemConfig));
EXPECT_NO_THROW(db2 = std::make_unique<main::Database>(databasePath, *systemConfig));
EXPECT_NO_THROW(con2 = std::make_unique<main::Connection>(db2.get()));
// try write, fail
EXPECT_ANY_THROW(
con2->query("DROP TABLE Person"));
EXPECT_ANY_THROW(con2->query("DROP TABLE Person"));
// try read from node table, success
EXPECT_NO_THROW(con2->query("MATCH (:Person) RETURN COUNT(*)"));

}

} // namespace testing
Expand Down

0 comments on commit 376f252

Please sign in to comment.