コード例 #1
0
        //[TestMethod]
        public void TestSetBucketFileAccessMode()
        {
            var setBucketRequest = new SetBucketFileAccessModeRequest()
            {
                BucketName = this.bucketName,
                AccessMode = FileAccessMode.ReadOnly,
                Duration   = (long)TimeSpan.FromSeconds(300).TotalSeconds,
                HostList   = new[] { "10.6.143.99", "10.6.143.100" }, // client IPs
                Uid        = "501"
            };

            using (var setBucketResponse = client.SetBucketFileAccessMode(setBucketRequest))
            {
                Assert.IsTrue(
                    setBucketRequest.AccessMode == setBucketResponse.AccessMode ||
                    GetBucketFileAccessModeRequest.TransitionsToState((FileAccessMode)setBucketRequest.AccessMode, setBucketResponse.AccessMode),
                    "wrong access mode");

                Assert.IsTrue(setBucketRequest.Duration - setBucketResponse.Duration <= TimeSpan.FromSeconds(60).TotalSeconds, "wrong duration");
                Assert.IsTrue(setBucketRequest.HostList.SequenceEqual(setBucketResponse.HostList), "wrong host list");
                Assert.AreEqual(setBucketRequest.Uid, setBucketResponse.Uid, "wrong Uid");
            }

            if (!WaitForTransition(FileAccessMode.ReadOnly, TimeSpan.FromMinutes(5)))
            {
                Assert.Inconclusive("file access transition timed out");
            }

            var getAccessRequest = new GetFileAccessRequest()
            {
                BucketName = this.bucketName
            };

            using (var getAccessResponse = client.GetFileAccess(getAccessRequest))
            {
                Assert.IsTrue(getAccessResponse.MountPoints != null && getAccessResponse.MountPoints.Count >= 1, "missing mount points");
                Assert.IsTrue(getAccessResponse.Objects != null && getAccessResponse.Objects.Count == 1, "missing objects");
            }

            var setAccessMode2Request = new SetBucketFileAccessModeRequest()
            {
                BucketName = this.bucketName,
                AccessMode = FileAccessMode.Disabled
            };

            using (var getAccessMode2Response = client.SetBucketFileAccessMode(setAccessMode2Request))
            {
            }

            if (!WaitForTransition(FileAccessMode.Disabled, TimeSpan.FromMinutes(5)))
            {
                Assert.Inconclusive("file access transition timed out");
            }
        }