Skip to content

Commit

Permalink
cr 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ken90242 committed Sep 7, 2023
1 parent 289cf77 commit b00196d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 61 deletions.
98 changes: 49 additions & 49 deletions curvefs/test/mds/fs_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,23 @@ class FSManagerTest : public ::testing::Test {
FsDetail detail2;
detail2.set_allocated_s3info(new S3Info(s3Info));

s3_req.set_fsname(kFsName2);
s3_req.set_allocated_fsdetail(new FsDetail(detail2));
s3_req.set_fstype(FSType::TYPE_S3);
s3_req.set_blocksize(kBlockSize);
s3_req.set_enablesumindir(enableSumInDir);
s3_req.set_owner("test");
s3_req.set_capacity((uint64_t)100*1024*1024*1024);

s3_mountPoint.set_hostname("host");
s3_mountPoint.set_port(90000);
s3_mountPoint.set_path("/a/b/c");
s3_mountPoint.set_cto(false);

vol_mountPoint.set_hostname("host");
vol_mountPoint.set_port(90000);
vol_mountPoint.set_path("/a/b/c");
vol_mountPoint.set_cto(false);
s3Req.set_fsname(kFsName2);
s3Req.set_allocated_fsdetail(new FsDetail(detail2));
s3Req.set_fstype(FSType::TYPE_S3);
s3Req.set_blocksize(kBlockSize);
s3Req.set_enablesumindir(enableSumInDir);
s3Req.set_owner("test");
s3Req.set_capacity((uint64_t)100*1024*1024*1024);

s3MountPoint.set_hostname("host");
s3MountPoint.set_port(90000);
s3MountPoint.set_path("/a/b/c");
s3MountPoint.set_cto(false);

volMountPoint.set_hostname("host");
volMountPoint.set_port(90000);
volMountPoint.set_path("/a/b/c");
volMountPoint.set_cto(false);
}

void TearDown() override {
Expand Down Expand Up @@ -264,7 +264,7 @@ class FSManagerTest : public ::testing::Test {
Invoke(RpcService<false>{})));
EXPECT_CALL(*s3Adapter_, BucketExist()).WillOnce(Return(true));

return fsManager_->CreateFs(&s3_req, &s3FsInfo);
return fsManager_->CreateFs(&s3Req, &s3FsInfo);
}

static bool CompareVolume(const Volume& first, const Volume& second) {
Expand Down Expand Up @@ -316,11 +316,11 @@ class FSManagerTest : public ::testing::Test {
const std::string kFsName2 = "fs2";
uint64_t volumeSize;
CreateFsRequest req;
CreateFsRequest s3_req;
CreateFsRequest s3Req;
GetLeaderResponse2 getLeaderResponse;
FsInfo s3FsInfo;
Mountpoint s3_mountPoint;
Mountpoint vol_mountPoint;
Mountpoint s3MountPoint;
Mountpoint volMountPoint;
FsInfo volumeFsInfo1;
};

Expand Down Expand Up @@ -541,7 +541,7 @@ TEST_F(FSManagerTest, test_fail_create_s3_fs_on_failed_root_node_creation) {
EXPECT_CALL(*s3Adapter_, BucketExist()).WillOnce(Return(true));
EXPECT_CALL(*topoManager_, DeletePartition(_))
.WillOnce(Return(TopoStatusCode::TOPO_OK));
ret = fsManager_->CreateFs(&s3_req, &s3FsInfo);
ret = fsManager_->CreateFs(&s3Req, &s3FsInfo);
ASSERT_EQ(ret, FSStatusCode::INSERT_ROOT_INODE_ERROR);
ASSERT_EQ(fsStorage_->Get(kFsName2, &wrapper), FSStatusCode::NOT_FOUND);
}
Expand All @@ -554,8 +554,8 @@ TEST_F(FSManagerTest, test_fail_create_duplicate_s3_fs_with_different_fsname) {
std::string fsName3 = "fs3";
EXPECT_CALL(*s3Adapter_, BucketExist()).WillOnce(Return(false));

s3_req.set_fsname(fsName3);
ret = fsManager_->CreateFs(&s3_req, &s3FsInfo);
s3Req.set_fsname(fsName3);
ret = fsManager_->CreateFs(&s3Req, &s3FsInfo);
ASSERT_EQ(ret, FSStatusCode::S3_INFO_ERROR);
}

Expand Down Expand Up @@ -599,28 +599,28 @@ TEST_F(FSManagerTest, test_success_mount_s3_fs) {
CreateS3Fs();
FSStatusCode ret;
FsInfo fsInfo4;
ret = fsManager_->MountFs(kFsName2, s3_mountPoint, &fsInfo4);
ret = fsManager_->MountFs(kFsName2, s3MountPoint, &fsInfo4);
ASSERT_EQ(ret, FSStatusCode::OK);
ASSERT_TRUE(CompareS3Fs(s3FsInfo, fsInfo4));
ASSERT_EQ(MessageDifferencer::Equals(fsInfo4.mountpoints(0), s3_mountPoint),
ASSERT_EQ(MessageDifferencer::Equals(fsInfo4.mountpoints(0), s3MountPoint),
true);
}

TEST_F(FSManagerTest, test_fail_repeated_mount_s3_fs) {
CreateS3Fs();
FSStatusCode ret;
FsInfo fsInfo4;
ret = fsManager_->MountFs(kFsName2, s3_mountPoint, &fsInfo4);
ret = fsManager_->MountFs(kFsName2, s3MountPoint, &fsInfo4);
ASSERT_EQ(ret, FSStatusCode::OK);
ret = fsManager_->MountFs(kFsName2, s3_mountPoint, &fsInfo4);
ret = fsManager_->MountFs(kFsName2, s3MountPoint, &fsInfo4);
ASSERT_EQ(ret, FSStatusCode::MOUNT_POINT_CONFLICT);
}

TEST_F(FSManagerTest, test_fail_delete_s3_fs_with_existing_mount_path) {
CreateS3Fs();
FSStatusCode ret;
FsInfo fsInfo4;
ret = fsManager_->MountFs(kFsName2, s3_mountPoint, &fsInfo4);
ret = fsManager_->MountFs(kFsName2, s3MountPoint, &fsInfo4);
ASSERT_EQ(ret, FSStatusCode::OK);
ret = fsManager_->DeleteFs(kFsName2);
ASSERT_EQ(ret, FSStatusCode::FS_BUSY);
Expand All @@ -630,19 +630,19 @@ TEST_F(FSManagerTest, test_success_umount_s3_fs_with_mount_path) {
CreateS3Fs();
FSStatusCode ret;
FsInfo fsInfo4;
ret = fsManager_->MountFs(kFsName2, s3_mountPoint, &fsInfo4);
ret = fsManager_->MountFs(kFsName2, s3MountPoint, &fsInfo4);
ASSERT_EQ(ret, FSStatusCode::OK);
ret = fsManager_->UmountFs(kFsName2, s3_mountPoint);
ret = fsManager_->UmountFs(kFsName2, s3MountPoint);
ASSERT_EQ(ret, FSStatusCode::OK);
}

TEST_F(FSManagerTest, test_success_delete_s3_fs_without_mount_path) {
CreateS3Fs();
FSStatusCode ret;
FsInfo fsInfo4;
ret = fsManager_->MountFs(kFsName2, s3_mountPoint, &fsInfo4);
ret = fsManager_->MountFs(kFsName2, s3MountPoint, &fsInfo4);
ASSERT_EQ(ret, FSStatusCode::OK);
ret = fsManager_->UmountFs(kFsName2, s3_mountPoint);
ret = fsManager_->UmountFs(kFsName2, s3MountPoint);
ASSERT_EQ(ret, FSStatusCode::OK);
ret = fsManager_->DeleteFs(kFsName2);
ASSERT_EQ(ret, FSStatusCode::OK);
Expand Down Expand Up @@ -699,7 +699,7 @@ TEST_F(FSManagerTest, test_fail_mount_volume_fs_on_space_creation_error) {

EXPECT_CALL(*spaceManager_, AddVolume(_))
.WillOnce(Return(space::SpaceErrCreate));
ret = fsManager_->MountFs(kFsName1, vol_mountPoint, &fsInfo3);
ret = fsManager_->MountFs(kFsName1, volMountPoint, &fsInfo3);
ASSERT_EQ(ret, FSStatusCode::INIT_SPACE_ERROR);
}

Expand All @@ -710,11 +710,11 @@ TEST_F(FSManagerTest, test_success_mount_volume_fs) {

EXPECT_CALL(*spaceManager_, AddVolume(_))
.WillOnce(Return(space::SpaceOk));
ret = fsManager_->MountFs(kFsName1, vol_mountPoint, &fsInfo3);
ret = fsManager_->MountFs(kFsName1, volMountPoint, &fsInfo3);
ASSERT_EQ(ret, FSStatusCode::OK);
ASSERT_TRUE(CompareVolumeFs(volumeFsInfo1, fsInfo3));
ASSERT_EQ(MessageDifferencer::Equals(fsInfo3.mountpoints(0),
vol_mountPoint), true);
volMountPoint), true);
std::pair<std::string, uint64_t> tpair;
std::string mountpath = "host:90000:/a/b/c";
ASSERT_TRUE(fsManager_->GetClientAliveTime(mountpath, &tpair));
Expand All @@ -728,9 +728,9 @@ TEST_F(FSManagerTest, test_fail_repeated_mount_volume_fs) {

EXPECT_CALL(*spaceManager_, AddVolume(_))
.WillOnce(Return(space::SpaceOk));
ret = fsManager_->MountFs(kFsName1, vol_mountPoint, &fsInfo3);
ret = fsManager_->MountFs(kFsName1, volMountPoint, &fsInfo3);
// mount volumefs mountpoint exist
ret = fsManager_->MountFs(kFsName1, vol_mountPoint, &fsInfo3);
ret = fsManager_->MountFs(kFsName1, volMountPoint, &fsInfo3);
ASSERT_EQ(ret, FSStatusCode::MOUNT_POINT_CONFLICT);
}

Expand All @@ -741,9 +741,9 @@ TEST_F(FSManagerTest, test_fail_umount_volume_fs_on_failed_uninit_space) {

EXPECT_CALL(*spaceManager_, AddVolume(_))
.WillOnce(Return(space::SpaceOk));
ret = fsManager_->MountFs(kFsName1, vol_mountPoint, &fsInfo3);
ret = fsManager_->MountFs(kFsName1, volMountPoint, &fsInfo3);
EXPECT_CALL(*spaceManager_, GetVolumeSpace(_)).WillOnce(Return(nullptr));
ret = fsManager_->UmountFs(kFsName1, vol_mountPoint);
ret = fsManager_->UmountFs(kFsName1, volMountPoint);
ASSERT_EQ(ret, FSStatusCode::UNINIT_SPACE_ERROR);
}

Expand All @@ -762,8 +762,8 @@ TEST_F(FSManagerTest, test_success_umount_volume_fs_after_uninit) {
EXPECT_CALL(*volumeSpace,
ReleaseBlockGroups(Matcher<const std::string &>(_)))
.WillOnce(Return(space::SpaceOk));
ret = fsManager_->MountFs(kFsName1, vol_mountPoint, &fsInfo3);
ret = fsManager_->UmountFs(kFsName1, vol_mountPoint);
ret = fsManager_->MountFs(kFsName1, volMountPoint, &fsInfo3);
ret = fsManager_->UmountFs(kFsName1, volMountPoint);
ASSERT_EQ(ret, FSStatusCode::OK);
ASSERT_FALSE(fsManager_->GetClientAliveTime(mountpath, &tpair));
}
Expand All @@ -782,10 +782,10 @@ TEST_F(FSManagerTest, test_fail_umount_volume_fs_non_existent_mount_path) {
EXPECT_CALL(*volumeSpace,
ReleaseBlockGroups(Matcher<const std::string &>(_)))
.WillOnce(Return(space::SpaceOk));
ret = fsManager_->MountFs(kFsName1, vol_mountPoint, &fsInfo3);
ret = fsManager_->UmountFs(kFsName1, vol_mountPoint);
ret = fsManager_->MountFs(kFsName1, volMountPoint, &fsInfo3);
ret = fsManager_->UmountFs(kFsName1, volMountPoint);
// umount not exist mountpoint
ret = fsManager_->UmountFs(kFsName1, vol_mountPoint);
ret = fsManager_->UmountFs(kFsName1, volMountPoint);
ASSERT_EQ(ret, FSStatusCode::MOUNT_POINT_NOT_EXIST);
}

Expand All @@ -804,8 +804,8 @@ TEST_F(FSManagerTest,
EXPECT_CALL(*volumeSpace,
ReleaseBlockGroups(Matcher<const std::string &>(_)))
.WillOnce(Return(space::SpaceOk));
ret = fsManager_->MountFs(kFsName1, vol_mountPoint, &fsInfo3);
ret = fsManager_->UmountFs(kFsName1, vol_mountPoint);
ret = fsManager_->MountFs(kFsName1, volMountPoint, &fsInfo3);
ret = fsManager_->UmountFs(kFsName1, volMountPoint);
ret = fsManager_->DeleteFs(kFsName1);
ASSERT_EQ(ret, FSStatusCode::OK);
}
Expand Down Expand Up @@ -840,11 +840,11 @@ TEST_F(FSManagerTest, test_success_restore_session_after_client_timeout) {
RefreshSessionRequest request;
RefreshSessionResponse response;
request.set_fsname(kFsName1);
*request.mutable_mountpoint() = vol_mountPoint;
*request.mutable_mountpoint() = volMountPoint;
fsManager_->RefreshSession(&request, &response);
ASSERT_EQ(FSStatusCode::OK, fsManager_->GetFsInfo(kFsName1, &info));
ASSERT_EQ(1, info.mountpoints_size());
ASSERT_EQ(MessageDifferencer::Equals(info.mountpoints(0), vol_mountPoint),
ASSERT_EQ(MessageDifferencer::Equals(info.mountpoints(0), volMountPoint),
true);
fsManager_->Stop();
}
Expand Down
23 changes: 11 additions & 12 deletions curvefs/test/mds/mds_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <google/protobuf/util/message_differencer.h>
#include <gtest/gtest.h>
#include <functional>
#include <memory>
#include <string>

#include "curvefs/test/mds/fake_metaserver.h"
Expand Down Expand Up @@ -121,7 +122,6 @@ class MdsServiceTest : public ::testing::Test {
metaserverOptions.metaserverAddr = kMetaServerAddr;
metaserverOptions.rpcTimeoutMs = 5000;
fsStorage_ = std::make_shared<MemoryFsStorage>();
mockFsStorage_ = std::make_shared<MockMemoryFsStorage>();
metaserverClient_ =
std::make_shared<MetaserverClient>(metaserverOptions);
// init mock topology manager
Expand Down Expand Up @@ -168,7 +168,7 @@ class MdsServiceTest : public ::testing::Test {

// init client
ASSERT_EQ(channel.Init(server.listen_address(), nullptr), 0);
stub_ = new MdsService_Stub(&channel);
stub_ = std::unique_ptr<MdsService_Stub>(new MdsService_Stub(&channel));

volume.set_blocksize(4096);
volume.set_volumename("volume1");
Expand All @@ -179,9 +179,9 @@ class MdsServiceTest : public ::testing::Test {
volume.set_autoextend(false);
volume.add_cluster(kClusterAddr);

volumeSpace = new MockVolumeSpace();
volumeSpace = std::unique_ptr<MockVolumeSpace>(new MockVolumeSpace());
EXPECT_CALL(*spaceManager_, GetVolumeSpace(_))
.WillRepeatedly(Return(volumeSpace));
.WillRepeatedly(Return(volumeSpace.get()));
EXPECT_CALL(*volumeSpace,
ReleaseBlockGroups(Matcher<const std::string &>(_)))
.WillRepeatedly(Return(space::SpaceOk));
Expand Down Expand Up @@ -292,8 +292,6 @@ class MdsServiceTest : public ::testing::Test {
}

void TearDown() override {
delete volumeSpace;

server.Stop(10);
server.Join();
}
Expand All @@ -319,7 +317,6 @@ class MdsServiceTest : public ::testing::Test {
}

std::shared_ptr<FsManager> fsManager_;
std::shared_ptr<MockMemoryFsStorage> mockFsStorage_;
std::shared_ptr<FsStorage> fsStorage_;
std::shared_ptr<MockSpaceManager> spaceManager_;
std::shared_ptr<MetaserverClient> metaserverClient_;
Expand All @@ -328,8 +325,10 @@ class MdsServiceTest : public ::testing::Test {
std::shared_ptr<MockS3Adapter> s3Adapter_;
std::shared_ptr<MdsServiceImpl> mdsService_;

MdsService_Stub* stub_;
MockVolumeSpace* volumeSpace;
std::unique_ptr<MdsService_Stub> stub_;
std::unique_ptr<MockVolumeSpace> volumeSpace;

MockMemoryFsStorage mockFsStorage_;
FakeCurveFSService fakeCurveFSService;
FakeMetaserverImpl metaserverService;
MockCliService2 mockCliService2;
Expand Down Expand Up @@ -479,7 +478,7 @@ TEST_F(MdsServiceTest, test_fail_get_fsinfo_missing_fsid_and_fsname) {

TEST_F(MdsServiceTest, test_success_get_fsinfo_fsid_with_volume_fstype) {
FsInfoWrapper fsInfoWrapper(fsinfo1);
EXPECT_CALL(*mockFsStorage_, Get(_, _))
EXPECT_CALL(mockFsStorage_, Get(_, _))
.WillRepeatedly(DoAll(
SetArgPointee<1>(fsInfoWrapper),
Return(FSStatusCode::OK)));
Expand Down Expand Up @@ -519,7 +518,7 @@ TEST_F(MdsServiceTest, test_success_get_fsinfo_fsid_with_s3_fstype) {

TEST_F(MdsServiceTest, test_success_get_fsinfo_fsname_with_volume_fstype) {
FsInfoWrapper fsInfoWrapper(fsinfo1);
EXPECT_CALL(*mockFsStorage_, Get(_, _))
EXPECT_CALL(mockFsStorage_, Get(_, _))
.WillRepeatedly(DoAll(
SetArgPointee<1>(fsInfoWrapper),
Return(FSStatusCode::OK)));
Expand Down Expand Up @@ -692,7 +691,7 @@ TEST_F(MdsServiceTest, test_fail_delete_fs_mount_paths_still_exist) {
}

FsInfoWrapper fsInfoWrapper(fsinfo1);
EXPECT_CALL(*mockFsStorage_, Get(_, _))
EXPECT_CALL(mockFsStorage_, Get(_, _))
.WillRepeatedly(DoAll(
SetArgPointee<1>(fsInfoWrapper),
Return(FSStatusCode::OK)));
Expand Down

0 comments on commit b00196d

Please sign in to comment.