mirror of
https://github.com/deepseek-ai/3FS
synced 2025-06-26 18:16:45 +00:00
Initial commit
This commit is contained in:
1
src/stubs/MetaService/CMakeLists.txt
Normal file
1
src/stubs/MetaService/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
target_add_lib(meta-stub stubs-common meta-fbs)
|
||||
48
src/stubs/MetaService/IMetaServiceStub.h
Normal file
48
src/stubs/MetaService/IMetaServiceStub.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/serde/ClientContext.h"
|
||||
#include "common/serde/MessagePacket.h"
|
||||
#include "common/utils/Coroutine.h"
|
||||
#include "fbs/meta/Common.h"
|
||||
#include "fbs/meta/Service.h"
|
||||
|
||||
namespace hf3fs::meta {
|
||||
|
||||
class IMetaServiceStub {
|
||||
public:
|
||||
using InterfaceType = IMetaServiceStub;
|
||||
|
||||
virtual ~IMetaServiceStub() = default;
|
||||
|
||||
#define IMETA_STUB_METHOD(NAME, REQ, RESP) \
|
||||
virtual CoTryTask<RESP> NAME(const REQ &req, \
|
||||
const net::UserRequestOptions &options, \
|
||||
serde::Timestamp *timestamp = nullptr) = 0
|
||||
|
||||
IMETA_STUB_METHOD(statFs, StatFsReq, StatFsRsp);
|
||||
IMETA_STUB_METHOD(stat, StatReq, StatRsp);
|
||||
IMETA_STUB_METHOD(create, CreateReq, CreateRsp);
|
||||
IMETA_STUB_METHOD(mkdirs, MkdirsReq, MkdirsRsp);
|
||||
IMETA_STUB_METHOD(symlink, SymlinkReq, SymlinkRsp);
|
||||
IMETA_STUB_METHOD(hardLink, HardLinkReq, HardLinkRsp);
|
||||
IMETA_STUB_METHOD(remove, RemoveReq, RemoveRsp);
|
||||
IMETA_STUB_METHOD(open, OpenReq, OpenRsp);
|
||||
IMETA_STUB_METHOD(sync, SyncReq, SyncRsp);
|
||||
IMETA_STUB_METHOD(close, CloseReq, CloseRsp);
|
||||
IMETA_STUB_METHOD(rename, RenameReq, RenameRsp);
|
||||
IMETA_STUB_METHOD(list, ListReq, ListRsp);
|
||||
IMETA_STUB_METHOD(truncate, TruncateReq, TruncateRsp);
|
||||
IMETA_STUB_METHOD(getRealPath, GetRealPathReq, GetRealPathRsp);
|
||||
IMETA_STUB_METHOD(setAttr, SetAttrReq, SetAttrRsp);
|
||||
IMETA_STUB_METHOD(pruneSession, PruneSessionReq, PruneSessionRsp);
|
||||
IMETA_STUB_METHOD(dropUserCache, DropUserCacheReq, DropUserCacheRsp);
|
||||
IMETA_STUB_METHOD(authenticate, AuthReq, AuthRsp);
|
||||
IMETA_STUB_METHOD(lockDirectory, LockDirectoryReq, LockDirectoryRsp);
|
||||
IMETA_STUB_METHOD(testRpc, TestRpcReq, TestRpcRsp);
|
||||
IMETA_STUB_METHOD(batchStat, BatchStatReq, BatchStatRsp);
|
||||
IMETA_STUB_METHOD(batchStatByPath, BatchStatByPathReq, BatchStatByPathRsp);
|
||||
|
||||
#undef IMETA_STUB_METHOD
|
||||
};
|
||||
|
||||
} // namespace hf3fs::meta
|
||||
44
src/stubs/MetaService/MetaServiceStub.cc
Normal file
44
src/stubs/MetaService/MetaServiceStub.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "MetaServiceStub.h"
|
||||
|
||||
#include "common/serde/ClientContext.h"
|
||||
#include "common/serde/ClientMockContext.h"
|
||||
#include "common/utils/Coroutine.h"
|
||||
#include "common/utils/UtcTimeSerde.h"
|
||||
#include "fbs/meta/Service.h"
|
||||
|
||||
#define IMPL_META_STUB_METHOD(NAME, REQ, RESP) \
|
||||
template <typename Context> \
|
||||
CoTryTask<RESP> MetaServiceStub<Context>::NAME(const REQ &req, \
|
||||
const net::UserRequestOptions &options, \
|
||||
hf3fs::serde::Timestamp *timestamp) { \
|
||||
co_return co_await MetaSerde<>::NAME<Context>(context_, req, &options, timestamp); \
|
||||
}
|
||||
|
||||
namespace hf3fs::meta {
|
||||
|
||||
IMPL_META_STUB_METHOD(statFs, StatFsReq, StatFsRsp);
|
||||
IMPL_META_STUB_METHOD(stat, StatReq, StatRsp);
|
||||
IMPL_META_STUB_METHOD(create, CreateReq, CreateRsp);
|
||||
IMPL_META_STUB_METHOD(mkdirs, MkdirsReq, MkdirsRsp);
|
||||
IMPL_META_STUB_METHOD(symlink, SymlinkReq, SymlinkRsp);
|
||||
IMPL_META_STUB_METHOD(hardLink, HardLinkReq, HardLinkRsp);
|
||||
IMPL_META_STUB_METHOD(remove, RemoveReq, RemoveRsp);
|
||||
IMPL_META_STUB_METHOD(open, OpenReq, OpenRsp);
|
||||
IMPL_META_STUB_METHOD(sync, SyncReq, SyncRsp);
|
||||
IMPL_META_STUB_METHOD(close, CloseReq, CloseRsp);
|
||||
IMPL_META_STUB_METHOD(rename, RenameReq, RenameRsp);
|
||||
IMPL_META_STUB_METHOD(list, ListReq, ListRsp);
|
||||
IMPL_META_STUB_METHOD(truncate, TruncateReq, TruncateRsp);
|
||||
IMPL_META_STUB_METHOD(getRealPath, GetRealPathReq, GetRealPathRsp);
|
||||
IMPL_META_STUB_METHOD(setAttr, SetAttrReq, SetAttrRsp);
|
||||
IMPL_META_STUB_METHOD(pruneSession, PruneSessionReq, PruneSessionRsp);
|
||||
IMPL_META_STUB_METHOD(dropUserCache, DropUserCacheReq, DropUserCacheRsp);
|
||||
IMPL_META_STUB_METHOD(authenticate, AuthReq, AuthRsp);
|
||||
IMPL_META_STUB_METHOD(lockDirectory, LockDirectoryReq, LockDirectoryRsp);
|
||||
IMPL_META_STUB_METHOD(testRpc, TestRpcReq, TestRpcRsp);
|
||||
IMPL_META_STUB_METHOD(batchStat, BatchStatReq, BatchStatRsp);
|
||||
IMPL_META_STUB_METHOD(batchStatByPath, BatchStatByPathReq, BatchStatByPathRsp);
|
||||
|
||||
template class MetaServiceStub<serde::ClientContext>;
|
||||
template class MetaServiceStub<serde::ClientMockContext>;
|
||||
} // namespace hf3fs::meta
|
||||
48
src/stubs/MetaService/MetaServiceStub.h
Normal file
48
src/stubs/MetaService/MetaServiceStub.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/serde/ClientContext.h"
|
||||
#include "fbs/meta/Service.h"
|
||||
#include "stubs/MetaService/IMetaServiceStub.h"
|
||||
|
||||
namespace hf3fs::meta {
|
||||
|
||||
template <typename Ctx>
|
||||
class MetaServiceStub : public IMetaServiceStub {
|
||||
public:
|
||||
explicit MetaServiceStub(Ctx ctx)
|
||||
: context_(std::move(ctx)) {}
|
||||
|
||||
#define META_STUB_METHOD(NAME, REQ, RESP) \
|
||||
CoTryTask<RESP> NAME(const REQ &req, const net::UserRequestOptions &options, serde::Timestamp *timestamp = nullptr) \
|
||||
override
|
||||
|
||||
META_STUB_METHOD(statFs, StatFsReq, StatFsRsp);
|
||||
META_STUB_METHOD(stat, StatReq, StatRsp);
|
||||
META_STUB_METHOD(create, CreateReq, CreateRsp);
|
||||
META_STUB_METHOD(mkdirs, MkdirsReq, MkdirsRsp);
|
||||
META_STUB_METHOD(symlink, SymlinkReq, SymlinkRsp);
|
||||
META_STUB_METHOD(hardLink, HardLinkReq, HardLinkRsp);
|
||||
META_STUB_METHOD(remove, RemoveReq, RemoveRsp);
|
||||
META_STUB_METHOD(open, OpenReq, OpenRsp);
|
||||
META_STUB_METHOD(sync, SyncReq, SyncRsp);
|
||||
META_STUB_METHOD(close, CloseReq, CloseRsp);
|
||||
META_STUB_METHOD(rename, RenameReq, RenameRsp);
|
||||
META_STUB_METHOD(list, ListReq, ListRsp);
|
||||
META_STUB_METHOD(truncate, TruncateReq, TruncateRsp);
|
||||
META_STUB_METHOD(getRealPath, GetRealPathReq, GetRealPathRsp);
|
||||
META_STUB_METHOD(setAttr, SetAttrReq, SetAttrRsp);
|
||||
META_STUB_METHOD(pruneSession, PruneSessionReq, PruneSessionRsp);
|
||||
META_STUB_METHOD(dropUserCache, DropUserCacheReq, DropUserCacheRsp);
|
||||
META_STUB_METHOD(authenticate, AuthReq, AuthRsp);
|
||||
META_STUB_METHOD(lockDirectory, LockDirectoryReq, LockDirectoryRsp);
|
||||
META_STUB_METHOD(testRpc, TestRpcReq, TestRpcRsp);
|
||||
META_STUB_METHOD(batchStat, BatchStatReq, BatchStatRsp);
|
||||
META_STUB_METHOD(batchStatByPath, BatchStatByPathReq, BatchStatByPathRsp);
|
||||
|
||||
#undef META_STUB_METHOD
|
||||
|
||||
private:
|
||||
Ctx context_;
|
||||
};
|
||||
|
||||
} // namespace hf3fs::meta
|
||||
148
src/stubs/MetaService/MockMetaServiceStub.h
Normal file
148
src/stubs/MetaService/MockMetaServiceStub.h
Normal file
@@ -0,0 +1,148 @@
|
||||
#pragma once
|
||||
|
||||
#include <folly/concurrency/AtomicSharedPtr.h>
|
||||
#include <optional>
|
||||
|
||||
#include "common/serde/ClientContext.h"
|
||||
#include "common/serde/MessagePacket.h"
|
||||
#include "common/utils/Coroutine.h"
|
||||
#include "common/utils/Result.h"
|
||||
#include "fbs/meta/Service.h"
|
||||
#include "fbs/mgmtd/ChainRef.h"
|
||||
#include "stubs/MetaService/IMetaServiceStub.h"
|
||||
#include "stubs/MetaService/MetaServiceStub.h"
|
||||
#include "stubs/common/Stub.h"
|
||||
|
||||
namespace hf3fs::meta {
|
||||
|
||||
using flat::ChainTableId;
|
||||
using flat::Uid;
|
||||
using flat::UserInfo;
|
||||
|
||||
class DummyMetaServiceStub : public IMetaServiceStub {
|
||||
public:
|
||||
~DummyMetaServiceStub() override = default;
|
||||
|
||||
#define NOT_IMPLEMENTED_FUNC(NAME, REQ, RESP) \
|
||||
CoTryTask<RESP> NAME(const REQ &req, const net::UserRequestOptions &, serde::Timestamp *) override { \
|
||||
co_return co_await NAME(req); \
|
||||
} \
|
||||
virtual CoTryTask<RESP> NAME(const REQ &) { co_return makeError(StatusCode::kNotImplemented); }
|
||||
|
||||
NOT_IMPLEMENTED_FUNC(statFs, StatFsReq, StatFsRsp);
|
||||
NOT_IMPLEMENTED_FUNC(stat, StatReq, StatRsp);
|
||||
NOT_IMPLEMENTED_FUNC(create, CreateReq, CreateRsp);
|
||||
NOT_IMPLEMENTED_FUNC(mkdirs, MkdirsReq, MkdirsRsp);
|
||||
NOT_IMPLEMENTED_FUNC(symlink, SymlinkReq, SymlinkRsp);
|
||||
NOT_IMPLEMENTED_FUNC(hardLink, HardLinkReq, HardLinkRsp);
|
||||
NOT_IMPLEMENTED_FUNC(remove, RemoveReq, RemoveRsp);
|
||||
NOT_IMPLEMENTED_FUNC(open, OpenReq, OpenRsp);
|
||||
NOT_IMPLEMENTED_FUNC(sync, SyncReq, SyncRsp);
|
||||
NOT_IMPLEMENTED_FUNC(close, CloseReq, CloseRsp);
|
||||
NOT_IMPLEMENTED_FUNC(rename, RenameReq, RenameRsp);
|
||||
NOT_IMPLEMENTED_FUNC(list, ListReq, ListRsp);
|
||||
NOT_IMPLEMENTED_FUNC(truncate, TruncateReq, TruncateRsp);
|
||||
NOT_IMPLEMENTED_FUNC(getRealPath, GetRealPathReq, GetRealPathRsp);
|
||||
NOT_IMPLEMENTED_FUNC(setAttr, SetAttrReq, SetAttrRsp);
|
||||
NOT_IMPLEMENTED_FUNC(pruneSession, PruneSessionReq, PruneSessionRsp);
|
||||
NOT_IMPLEMENTED_FUNC(dropUserCache, DropUserCacheReq, DropUserCacheRsp);
|
||||
NOT_IMPLEMENTED_FUNC(lockDirectory, LockDirectoryReq, LockDirectoryRsp);
|
||||
NOT_IMPLEMENTED_FUNC(testRpc, TestRpcReq, TestRpcRsp);
|
||||
NOT_IMPLEMENTED_FUNC(batchStat, BatchStatReq, BatchStatRsp);
|
||||
NOT_IMPLEMENTED_FUNC(batchStatByPath, BatchStatByPathReq, BatchStatByPathRsp);
|
||||
|
||||
virtual CoTryTask<AuthRsp> authenticate(const AuthReq &req) { co_return AuthRsp{req.user}; }
|
||||
CoTryTask<AuthRsp> authenticate(const AuthReq &req, const net::UserRequestOptions &, serde::Timestamp *) override {
|
||||
co_return co_await authenticate(req);
|
||||
}
|
||||
|
||||
#undef NOT_IMPLEMENTED_FUNC
|
||||
};
|
||||
|
||||
struct MockMetaStubHolder {
|
||||
void setStub(std::unique_ptr<DummyMetaServiceStub> st) { stub = std::move(st); }
|
||||
|
||||
folly::atomic_shared_ptr<IMetaServiceStub> stub;
|
||||
};
|
||||
|
||||
class DummyMetaServiceStubWithInode : public DummyMetaServiceStub {
|
||||
public:
|
||||
DummyMetaServiceStubWithInode(std::variant<File, Directory, Symlink> data)
|
||||
: inode_({InodeId(0x10de1d), {data, Acl{Uid(0), Gid(0), Permission(0777)}}}) {}
|
||||
|
||||
CoTryTask<CreateRsp> create(const CreateReq &) override { co_return CreateRsp(inode_, false); }
|
||||
CoTryTask<OpenRsp> open(const OpenReq &) override { co_return OpenRsp(inode_, false); }
|
||||
CoTryTask<StatRsp> stat(const StatReq &) override { co_return StatRsp(inode_); }
|
||||
|
||||
protected:
|
||||
Inode inode_;
|
||||
};
|
||||
class DummyMetaServiceStubWithDir : public DummyMetaServiceStubWithInode {
|
||||
public:
|
||||
DummyMetaServiceStubWithDir()
|
||||
: DummyMetaServiceStubWithInode(Directory{InodeId(0x10de1dff), Layout::newEmpty(ChainTableId(1), 512 << 10, 8)}) {
|
||||
}
|
||||
};
|
||||
class DummyMetaServiceStubWithFile : public DummyMetaServiceStubWithInode {
|
||||
public:
|
||||
DummyMetaServiceStubWithFile()
|
||||
: DummyMetaServiceStubWithInode(File(Layout::newEmpty(ChainTableId(1), 512 << 10, 8))) {}
|
||||
};
|
||||
class DummyMetaServiceStubWithSymlink : public DummyMetaServiceStubWithInode {
|
||||
public:
|
||||
DummyMetaServiceStubWithSymlink()
|
||||
: DummyMetaServiceStubWithInode(Symlink{"/b"}) {}
|
||||
};
|
||||
} // namespace hf3fs::meta
|
||||
|
||||
template <>
|
||||
struct ::hf3fs::stubs::StubMockContext<hf3fs::meta::IMetaServiceStub> {
|
||||
std::shared_ptr<meta::MockMetaStubHolder> stub;
|
||||
};
|
||||
|
||||
namespace hf3fs::meta {
|
||||
|
||||
template <>
|
||||
class MetaServiceStub<hf3fs::stubs::StubMockContext<IMetaServiceStub>> : public IMetaServiceStub {
|
||||
public:
|
||||
using ContextType = hf3fs::stubs::StubMockContext<IMetaServiceStub>;
|
||||
|
||||
MetaServiceStub(ContextType ctx)
|
||||
: stub_(std::move(ctx.stub)) {}
|
||||
~MetaServiceStub() override = default;
|
||||
|
||||
#define FORWARD_RPC_FUNC(NAME, REQ, RESP) \
|
||||
CoTryTask<RESP> NAME(const REQ &req, const net::UserRequestOptions &opts, serde::Timestamp *timestamp) override { \
|
||||
co_return co_await stub_->stub.load()->NAME(req, opts, timestamp); \
|
||||
}
|
||||
|
||||
FORWARD_RPC_FUNC(statFs, StatFsReq, StatFsRsp);
|
||||
FORWARD_RPC_FUNC(stat, StatReq, StatRsp);
|
||||
FORWARD_RPC_FUNC(create, CreateReq, CreateRsp);
|
||||
FORWARD_RPC_FUNC(mkdirs, MkdirsReq, MkdirsRsp);
|
||||
FORWARD_RPC_FUNC(symlink, SymlinkReq, SymlinkRsp);
|
||||
FORWARD_RPC_FUNC(hardLink, HardLinkReq, HardLinkRsp);
|
||||
FORWARD_RPC_FUNC(remove, RemoveReq, RemoveRsp);
|
||||
FORWARD_RPC_FUNC(open, OpenReq, OpenRsp);
|
||||
FORWARD_RPC_FUNC(sync, SyncReq, SyncRsp);
|
||||
FORWARD_RPC_FUNC(close, CloseReq, CloseRsp);
|
||||
FORWARD_RPC_FUNC(rename, RenameReq, RenameRsp);
|
||||
FORWARD_RPC_FUNC(list, ListReq, ListRsp);
|
||||
FORWARD_RPC_FUNC(truncate, TruncateReq, TruncateRsp);
|
||||
FORWARD_RPC_FUNC(getRealPath, GetRealPathReq, GetRealPathRsp);
|
||||
FORWARD_RPC_FUNC(setAttr, SetAttrReq, SetAttrRsp);
|
||||
FORWARD_RPC_FUNC(pruneSession, PruneSessionReq, PruneSessionRsp);
|
||||
FORWARD_RPC_FUNC(dropUserCache, DropUserCacheReq, DropUserCacheRsp);
|
||||
FORWARD_RPC_FUNC(authenticate, AuthReq, AuthRsp);
|
||||
FORWARD_RPC_FUNC(lockDirectory, LockDirectoryReq, LockDirectoryRsp);
|
||||
FORWARD_RPC_FUNC(testRpc, TestRpcReq, TestRpcRsp);
|
||||
FORWARD_RPC_FUNC(batchStat, BatchStatReq, BatchStatRsp);
|
||||
FORWARD_RPC_FUNC(batchStatByPath, BatchStatByPathReq, BatchStatByPathRsp);
|
||||
|
||||
#undef FORWARD_RPC_FUNC
|
||||
|
||||
private:
|
||||
std::shared_ptr<MockMetaStubHolder> stub_;
|
||||
};
|
||||
|
||||
} // namespace hf3fs::meta
|
||||
Reference in New Issue
Block a user