Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
empiredan committed Jan 23, 2025
1 parent cdb7f79 commit 5e7105a
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/server/pegasus_server_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class pegasus_server_write : public dsn::replication::replica_base

friend class pegasus_server_write_test;
friend class pegasus_write_service_test;
friend class pegasus_write_service_impl_test;
friend class PegasusWriteServiceImplTest;
friend class rocksdb_wrapper_test;

std::unique_ptr<pegasus_write_service> _write_svc;
Expand Down
2 changes: 1 addition & 1 deletion src/server/pegasus_write_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class pegasus_write_service : dsn::replication::replica_base

private:
friend class pegasus_write_service_test;
friend class pegasus_write_service_impl_test;
friend class PegasusWriteServiceImplTest;
friend class pegasus_server_write_test;
friend class rocksdb_wrapper_test;

Expand Down
10 changes: 7 additions & 3 deletions src/server/pegasus_write_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,21 +661,27 @@ class pegasus_write_service::impl : public dsn::replication::replica_base
return raw_key;
}

// Calculate expire timestamp in seconds according to `req`, for the keys not present
// in the storage.
template <typename TRequest>
static inline int32_t calc_expire_on_non_existent(const TRequest &req)
{
return req.expire_ts_seconds > 0 ? req.expire_ts_seconds : 0;
}

// Calculate expire timestamp in seconds according to `req` and the old value in `get_ctx`,
// for the keys existing in the storage.
template <typename TRequest>
static inline int32_t calc_expire_on_existing(const TRequest &req,
const db_get_context &get_ctx)
{
if (req.expire_ts_seconds == 0) {
// Use the old value for the existing key in `get_ctx` as the expire timestamp.
return static_cast<int32_t>(get_ctx.expire_ts);
}

if (req.expire_ts_seconds < 0) {
// Reset expire timestamp to 0.
return 0;
}

Expand Down Expand Up @@ -844,10 +850,8 @@ class pegasus_write_service::impl : public dsn::replication::replica_base
private:
friend class pegasus_write_service_test;
friend class pegasus_server_write_test;
friend class pegasus_write_service_impl_test;
friend class PegasusWriteServiceImplTest;
friend class rocksdb_wrapper_test;
FRIEND_TEST(pegasus_write_service_impl_test, put_verify_timetag);
FRIEND_TEST(pegasus_write_service_impl_test, verify_timetag_compatible_with_version_0);

const std::string _primary_host_port;
const uint32_t _pegasus_data_version;
Expand Down
Loading

0 comments on commit 5e7105a

Please sign in to comment.