Exemplo n.º 1
0
        public void RenewBlobLease()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);
            string             leaseId       = string.Empty;

            try
            {
                CloudBlob blob = blobUtil.CreateRandomBlob(container, blobName);

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        leaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.RenewLease(containerName, blobName, leaseId), Utility.GenComparisonData("Renew Lease", true));
                        Test.Assert(CommandAgent.SnapshotAzureStorageBlob(containerName, blobName, leaseId), Utility.GenComparisonData("Snapshot blob", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 2
0
        public void ChangeContainerLease()
        {
            string             containerName = Utility.GenNameString("container");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);
            string             leaseId       = string.Empty;
            string             porposedId    = Guid.NewGuid().ToString();

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, string.Empty), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        leaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.ChangeLease(containerName, string.Empty, leaseId, porposedId), Utility.GenComparisonData("Change Container Lease", true));

                        Test.Assert(!CommandAgent.RemoveAzureStorageContainer(containerName, leaseId), Utility.GenComparisonData("Remove container", false));
                        Test.Assert(CommandAgent.RemoveAzureStorageContainer(containerName, porposedId), Utility.GenComparisonData("Remove container", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, porposedId);
            }
        }
Exemplo n.º 3
0
        public void LeaseOnLeasedContainer()
        {
            string             containerName = Utility.GenNameString("container");
            string             leaseId       = string.Empty;
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null), Utility.GenComparisonData("Acquire Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        leaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }

                    Test.Assert(!CommandAgent.AcquireLease(containerName, null), Utility.GenComparisonData("Acquire Lease", false));
                    CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, leaseId);
            }
        }
Exemplo n.º 4
0
        public void BreakContainerLease()
        {
            string             containerName = Utility.GenNameString("container");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);
            string             lease         = string.Empty;

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, string.Empty), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        lease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert((CommandAgent as NodeJSAgent).ShowAzureStorageContainer(containerName), Utility.GenComparisonData("Show container without lease ID", true));

                        Test.Assert(CommandAgent.BreakLease(containerName, string.Empty), Utility.GenComparisonData("Break Container Lease", true));
                        Test.Assert(!(CommandAgent as NodeJSAgent).ShowAzureStorageContainer(containerName, lease), Utility.GenComparisonData("Show container with lease ID", false));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 5
0
        public void BreakContainerLeaseWithInvalidDuration()
        {
            string             containerName  = Utility.GenNameString("container");
            string             containerLease = string.Empty;
            int                leaseDuration  = 15;
            int                breakDuration  = 61;
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: leaseDuration), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(!CommandAgent.BreakLease(containerName, null, breakDuration), Utility.GenComparisonData("Break Container Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLease);
            }
        }
Exemplo n.º 6
0
        public void LeaseOnNonExistingContainer()
        {
            string containerName = Utility.GenNameString("container");

            Test.Assert(!CommandAgent.AcquireLease(containerName, null), Utility.GenComparisonData("Acquire Container Lease", false));
            CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
        }
Exemplo n.º 7
0
        public void BreakBlobLease()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                string    proposedId = Guid.NewGuid().ToString();
                CloudBlob blob       = blobUtil.CreateRandomBlob(container, blobName);
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, proposedId), Utility.GenComparisonData("Acquire Blob Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        string lease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.BreakLease(containerName, blobName), Utility.GenComparisonData("Break Blob Lease", true));

                        Test.Assert((CommandAgent as NodeJSAgent).ShowAzureStorageBlob(blobName, containerName), Utility.GenComparisonData("Show blob without lease ID", true));
                        Test.Assert(!(CommandAgent as NodeJSAgent).ShowAzureStorageBlob(blobName, containerName, lease), Utility.GenComparisonData("Show blob with lease ID", false));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 8
0
        public void BreakContainerLeaseWithDurationShorterThanRemainingTime()
        {
            string             containerName = Utility.GenNameString("container");
            int                leaseDuration = 30;
            int                breakDuration = 5;
            int                remainingTime = breakDuration;
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: leaseDuration), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        Test.Assert(CommandAgent.BreakLease(containerName, null, breakDuration), Utility.GenComparisonData("Break Container Lease", true));

                        remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime <= breakDuration, Utility.GenComparisonData("Validate remaining time", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Thread.Sleep((remainingTime + 1) * 1000);
                container.Delete();
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 9
0
        public void BreakInfiniteLease()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                string    proposedId = Guid.NewGuid().ToString();
                CloudBlob blob       = blobUtil.CreateRandomBlob(container, blobName);
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, proposedId), Utility.GenComparisonData("Acquire Blob Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        string lease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.BreakLease(containerName, blobName), Utility.GenComparisonData("Break Blob Lease", true));

                        int remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime == 0, Utility.GenComparisonData("Validate remaining time", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 10
0
        public void ReleaseExpiredLease()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = string.Empty;

            Random random   = new Random();
            int    duration = random.Next(15, 60);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                string    blobLease = string.Empty;
                CloudBlob blob      = blobUtil.CreateRandomBlob(container, blobName);
                blob.Metadata["test1"] = "m1";
                blob.Metadata["test2"] = "m2";

                // Acquire with account SAS
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                // Wait for the lease expired
                Thread.Sleep(duration * 1000);

                Test.Assert(CommandAgent.ReleaseLease(containerName, null, containerLease), Utility.GenComparisonData("Release Container Lease", true));
                Test.Assert(CommandAgent.ReleaseLease(containerName, blobName, blobLease), Utility.GenComparisonData("Release Blob Lease", true));
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 11
0
        public void ChangeWithUnmatchLeaseID()
        {
            string             containerName         = Utility.GenNameString("container");
            string             blobName              = Utility.GenNameString("blob");
            string             containerLeaseId      = string.Empty;
            string             blobLeaseId           = string.Empty;
            string             proposedId            = Guid.NewGuid().ToString();
            string             wrongContainerLeaseId = Guid.NewGuid().ToString();
            string             wrongBlobLeaseId      = Guid.NewGuid().ToString();
            CloudBlobContainer container             = blobUtil.CreateContainer(containerName);
            CloudBlob          blob = blobUtil.CreateRandomBlob(container, blobName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: 30), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLeaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: 30), Utility.GenComparisonData("Acquire Container Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLeaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(!CommandAgent.ChangeLease(containerName, null, wrongContainerLeaseId, proposedId), Utility.GenComparisonData("Change Container Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

                Test.Assert(!CommandAgent.ChangeLease(containerName, blobName, wrongBlobLeaseId, proposedId), Utility.GenComparisonData("Change Blob Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLeaseId);
            }
        }
Exemplo n.º 12
0
        public void LeaseWithoutEnoughPermission()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                CloudBlob blob = blobUtil.CreateRandomBlob(container, blobName);
                string    containerSasToken = string.Empty;

                // Create a container SAS
                Test.Assert(CommandAgent.NewAzureStorageContainerSAS(containerName, string.Empty, "rl", DateTime.UtcNow, DateTime.UtcNow + TimeSpan.FromMinutes(5)),
                            Utility.GenComparisonData("container sas create", true));
                if (lang == Language.NodeJS)
                {
                    containerSasToken = (CommandAgent as NodeJSAgent).Output[0]["sas"] as string;
                }

                // Create an account SAS
                SharedAccessAccountPolicy policy = new SharedAccessAccountPolicy()
                {
                    Permissions            = SharedAccessAccountPermissions.Read,
                    ResourceTypes          = SharedAccessAccountResourceTypes.Container,
                    Services               = SharedAccessAccountServices.Blob,
                    SharedAccessStartTime  = DateTimeOffset.UtcNow,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow + TimeSpan.FromMinutes(5)
                };

                string accountSasToken = Utility.GenerateAccountSAS(policy);

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, accountSasToken);

                Test.Assert(!CommandAgent.AcquireLease(containerName, null), Utility.GenComparisonData("Acquire Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
                Test.Assert(!CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, containerSasToken);

                Test.Assert(!CommandAgent.AcquireLease(containerName, null), Utility.GenComparisonData("Acquire Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
                Test.Assert(!CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 13
0
        public void ChangeWithInvalidProposedLeaseID()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            string             containerLease = string.Empty;
            string             blobLease      = string.Empty;
            string             invalidLeaseId = "1234567890poiuyytrewq";
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            CloudBlob          blob           = blobUtil.CreateRandomBlob(container, blobName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, string.Empty), Utility.GenComparisonData("Acquire container Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
                Test.Assert(!CommandAgent.ChangeLease(containerName, null, containerLease, invalidLeaseId), Utility.GenComparisonData("Change Container Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, invalidLeaseId);

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire blob Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(!CommandAgent.ChangeLease(containerName, blobName, blobLease, invalidLeaseId), Utility.GenComparisonData("Change Blob Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, invalidLeaseId);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLease);
            }
        }
Exemplo n.º 14
0
        public void LeaseOnNonExistingBlob()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                Test.Assert(!CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire Blob Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 15
0
        public void LeaseContainerWithInvalidID()
        {
            string             containerName  = Utility.GenNameString("container");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             invalidLeaseID = "abcefggdfdsfsdsddsdds";

            try
            {
                Test.Assert(!CommandAgent.AcquireLease(containerName, null, proposedLeaseId: invalidLeaseID), Utility.GenComparisonData("Acquire Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, invalidLeaseID);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 16
0
        public void BreakBlobLeaseAndAcquireAgain()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            string             blobLease     = string.Empty;
            int                leaseDuration = 15;
            int                breakDuration = 30;
            int                remainingTime = breakDuration;
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                CloudBlob blob = blobUtil.CreateRandomBlob(container, blobName);
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: leaseDuration), Utility.GenComparisonData("Acquire Blob Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        Test.Assert(CommandAgent.BreakLease(containerName, blobName, breakDuration), Utility.GenComparisonData("Break Blob Lease", true));

                        remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime <= leaseDuration, Utility.GenComparisonData("Validate remaining time", true));

                        Test.Assert(!CommandAgent.AcquireLease(containerName, blobName, duration: leaseDuration), Utility.GenComparisonData("Acquire Blob Lease", false));
                        CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

                        Thread.Sleep((remainingTime + 1) * 1000);
                        Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: leaseDuration), Utility.GenComparisonData("Acquire Blob Lease", true));
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                        Test.Assert(CommandAgent.RemoveAzureStorageBlob(blobName, containerName, leaseId: blobLease), Utility.GenComparisonData("Delete Blob With Lease", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 17
0
        public void LeaseBlobWithInvalidID()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            string             invalidLeaseID = "1223545698787879789456465";
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);

            try
            {
                CloudBlob blob = blobUtil.CreateRandomBlob(container, blobName);

                Test.Assert(!CommandAgent.AcquireLease(containerName, blobName, proposedLeaseId: invalidLeaseID), Utility.GenComparisonData("Acquire Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, invalidLeaseID);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 18
0
        public void BreakBlobLeaseWithDuration()
        {
            string containerName = Utility.GenNameString("container");
            string blobName      = Utility.GenNameString("blob");

            int[]  durations = { 0, 0, 60 };
            Random random    = new Random();

            durations[1] = random.Next(0, 60);
            CloudBlobContainer container = blobUtil.CreateContainer(containerName);

            try
            {
                CloudBlob blob = blobUtil.CreateRandomBlob(container, blobName);

                foreach (int duration in durations)
                {
                    Test.Assert(CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire Blob Lease", true));

                    if (lang == Language.NodeJS)
                    {
                        try
                        {
                            Test.Assert(CommandAgent.BreakLease(containerName, blobName, duration), Utility.GenComparisonData("Break Blob Lease", true));

                            int remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                            Test.Assert(remainingTime <= duration, Utility.GenComparisonData("Validate remaining time", true));
                            Thread.Sleep((remainingTime + 1) * 1000);
                        }
                        catch (Exception e)
                        {
                            Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                        }
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 19
0
        public void BreakBlobLeaseWithInvalidDuration()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            int                leaseDuration = 15;
            int                breakDuration = 61;
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);
            CloudBlob          blob          = blobUtil.CreateRandomBlob(container, blobName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: leaseDuration), Utility.GenComparisonData("Acquire Blob Lease", true));

                Test.Assert(!CommandAgent.BreakLease(containerName, blobName, breakDuration), Utility.GenComparisonData("Break Blob Lease With Invalid Duration", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 20
0
        public void LeaseContainerWithInvalidDuration()
        {
            string             containerName = Utility.GenNameString("container");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                Test.Assert(!CommandAgent.AcquireLease(containerName, null, duration: 0), Utility.GenComparisonData("Acquire Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

                Test.Assert(!CommandAgent.AcquireLease(containerName, null, duration: 10), Utility.GenComparisonData("Acquire Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

                Test.Assert(!CommandAgent.AcquireLease(containerName, null, duration: 100), Utility.GenComparisonData("Acquire Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 21
0
        public void ChangeLeaseBySAS()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = string.Empty;
            string             porposedId     = Guid.NewGuid().ToString();

            Random random   = new Random();
            int    duration = random.Next(15, 60);

            try
            {
                string containerSasToken = string.Empty;
                string accountSasToken   = string.Empty;

                // Create a container SAS
                Test.Assert(CommandAgent.NewAzureStorageContainerSAS(containerName, string.Empty, "w", DateTime.UtcNow, DateTime.UtcNow + TimeSpan.FromMinutes(5)),
                            Utility.GenComparisonData("container sas create", true));
                if (lang == Language.NodeJS)
                {
                    containerSasToken = (CommandAgent as NodeJSAgent).Output[0]["sas"] as string;
                }

                // Use an account SAS
                SharedAccessAccountPolicy policy = new SharedAccessAccountPolicy()
                {
                    Permissions            = SharedAccessAccountPermissions.Write,
                    ResourceTypes          = SharedAccessAccountResourceTypes.Container | SharedAccessAccountResourceTypes.Object,
                    Services               = SharedAccessAccountServices.Blob,
                    SharedAccessStartTime  = DateTimeOffset.UtcNow,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow + TimeSpan.FromMinutes(5)
                };

                accountSasToken = Utility.GenerateAccountSAS(policy);

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, accountSasToken);

                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.ChangeLease(containerName, null, containerLease, porposedId), Utility.GenComparisonData("Change Lease", true));

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = porposedId
                        };
                        container.SetMetadata(condition);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                string    blobLease = string.Empty;
                CloudBlob blob      = blobUtil.CreateRandomBlob(container, blobName);
                blob.Metadata["test1"] = "m1";
                blob.Metadata["test2"] = "m2";

                // Acquire with account SAS
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        // Change with container SAS
                        CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, containerSasToken);

                        Test.Assert(CommandAgent.ChangeLease(containerName, blobName, blobLease, porposedId), Utility.GenComparisonData("Change Lease", true));

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = porposedId
                        };
                        blob.SetMetadata(condition);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, porposedId);
            }
        }
Exemplo n.º 22
0
        public void LeaseWithInfiniteDurationBySAS()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = string.Empty;

            try
            {
                string accountSasToken   = string.Empty;
                string containerSasToken = string.Empty;

                // Create a container SAS
                Test.Assert(CommandAgent.NewAzureStorageContainerSAS(containerName, string.Empty, "w", DateTime.UtcNow, DateTime.UtcNow + TimeSpan.FromMinutes(5)),
                            Utility.GenComparisonData("container sas create", true));
                if (lang == Language.NodeJS)
                {
                    containerSasToken = (CommandAgent as NodeJSAgent).Output[0]["sas"] as string;
                }

                // Use an account SAS
                SharedAccessAccountPolicy policy = new SharedAccessAccountPolicy()
                {
                    Permissions            = SharedAccessAccountPermissions.Write,
                    ResourceTypes          = SharedAccessAccountResourceTypes.Container,
                    Services               = SharedAccessAccountServices.Blob,
                    SharedAccessStartTime  = DateTimeOffset.UtcNow,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow + TimeSpan.FromMinutes(5)
                };

                accountSasToken = Utility.GenerateAccountSAS(policy);

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, accountSasToken);

                bool throwException = false;
                Test.Assert(CommandAgent.AcquireLease(containerName, null), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        try
                        {
                            container.Delete();
                        }
                        catch (StorageException se)
                        {
                            throwException = true;
                            Test.Info(string.Format("Expected: {0} error: {1}", MethodBase.GetCurrentMethod().Name, se.Message));
                        }

                        Test.Assert(throwException, "Should ever throw exception");
                        throwException = false;

                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = containerLease
                        };
                        container.SetMetadata(condition);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                throwException = false;
                string    blobLease = string.Empty;
                CloudBlob blob      = blobUtil.CreateRandomBlob(container, blobName);
                blob.Metadata["test1"] = "m1";
                blob.Metadata["test2"] = "m2";

                // Use a container SAS
                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, containerSasToken);

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        try
                        {
                            blob.SetMetadata();
                        }
                        catch (StorageException se)
                        {
                            throwException = true;
                            Test.Info(string.Format("Expected: {0} error: {1}", MethodBase.GetCurrentMethod().Name, se.Message));
                        }

                        Test.Assert(throwException, "Should ever throw exception");
                        throwException = false;

                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = blobLease
                        };
                        blob.SetMetadata(condition);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLease);
            }
        }
Exemplo n.º 23
0
        public void BreakLeaseBySAS()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = string.Empty;

            Random random        = new Random();
            int    duration      = random.Next(15, 60);
            int    remainingTime = duration;

            try
            {
                string containerSasToken = string.Empty;
                string accountSasToken   = string.Empty;

                // Create a container SAS
                Test.Assert(CommandAgent.NewAzureStorageContainerSAS(containerName, string.Empty, "w", DateTime.UtcNow, DateTime.UtcNow + TimeSpan.FromMinutes(5)),
                            Utility.GenComparisonData("container sas create", true));
                if (lang == Language.NodeJS)
                {
                    containerSasToken = (CommandAgent as NodeJSAgent).Output[0]["sas"] as string;
                }

                // Use an account SAS
                SharedAccessAccountPolicy policy = new SharedAccessAccountPolicy()
                {
                    Permissions            = SharedAccessAccountPermissions.Write,
                    ResourceTypes          = SharedAccessAccountResourceTypes.Container | SharedAccessAccountResourceTypes.Object,
                    Services               = SharedAccessAccountServices.Blob,
                    SharedAccessStartTime  = DateTimeOffset.UtcNow,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow + TimeSpan.FromMinutes(5)
                };

                accountSasToken = Utility.GenerateAccountSAS(policy);

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, accountSasToken);

                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: duration), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.BreakLease(containerName, null), Utility.GenComparisonData("Break Container Lease", true));
                        remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime <= duration, Utility.GenComparisonData("Validate remaining time", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                string    blobLease = string.Empty;
                CloudBlob blob      = blobUtil.CreateRandomBlob(container, blobName);

                // Acquire with account SAS
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: duration), Utility.GenComparisonData("Acquire Blob Lease With Account SAS", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        // Break with container SAS
                        CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, containerSasToken);

                        Test.Assert(CommandAgent.BreakLease(containerName, blobName), Utility.GenComparisonData("Break Blob Lease With Container SAS", true));
                        remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime <= duration, Utility.GenComparisonData("Validate remaining time", true));
                        Thread.Sleep((remainingTime + 1) * 1000);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemplo n.º 24
0
        public void LeaseWithProposedId()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = Guid.NewGuid().ToString();

            try
            {
                bool throwException = false;
                Test.Assert(CommandAgent.AcquireLease(containerName, null, containerLease), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        try
                        {
                            container.Delete();
                        }
                        catch (StorageException se)
                        {
                            throwException = true;
                            Test.Info(string.Format("Expected: {0} error: {1}", MethodBase.GetCurrentMethod().Name, se.Message));
                        }

                        Test.Assert(throwException, "Should ever throw exception");
                        throwException = false;

                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = containerLease
                        };
                        container.SetMetadata(condition);

                        Test.Assert((CommandAgent as NodeJSAgent).SetAzureStorageContainerACL(containerName, BlobContainerPublicAccessType.Off, containerLease),
                                    Utility.GenComparisonData("Set container ACL with lease ID", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                throwException = false;
                string    blobLease = Guid.NewGuid().ToString();
                CloudBlob blob      = blobUtil.CreateRandomBlob(container, blobName);
                blob.Metadata["test1"] = "m1";
                blob.Metadata["test2"] = "m2";

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, blobLease), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        try
                        {
                            blob.SetMetadata();
                        }
                        catch (StorageException se)
                        {
                            throwException = true;
                            Test.Info(string.Format("Expected: {0} error: {1}", MethodBase.GetCurrentMethod().Name, se.Message));
                        }

                        Test.Assert(throwException, "Should ever throw exception");
                        throwException = false;

                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = blobLease
                        };
                        blob.SetMetadata(condition);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLease);
            }
        }
Exemplo n.º 25
0
        public void RenewExpiredLease()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = string.Empty;

            Random random   = new Random();
            int    duration = random.Next(15, 60);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                string    blobLease = string.Empty;
                CloudBlob blob      = blobUtil.CreateRandomBlob(container, blobName);
                blob.Metadata["test1"] = "m1";
                blob.Metadata["test2"] = "m2";

                // Acquire with account SAS
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                // Wait for the lease expired
                Thread.Sleep(duration * 1000);

                Test.Assert(CommandAgent.RenewLease(containerName, null, containerLease), Utility.GenComparisonData("Renew Container Lease", true));
                Test.Assert(CommandAgent.RenewLease(containerName, blobName, blobLease), Utility.GenComparisonData("Renew Blob Lease", true));

                bool throwException = false;
                try
                {
                    container.Delete();
                }
                catch (StorageException se)
                {
                    throwException = true;
                    Test.Info(string.Format("Expected: {0} error: {1}", MethodBase.GetCurrentMethod().Name, se.Message));
                }

                Test.Assert(throwException, "Should ever throw exception");
                throwException = false;

                try
                {
                    blob.SetMetadata();
                }
                catch (StorageException se)
                {
                    throwException = true;
                    Test.Info(string.Format("Expected: {0} error: {1}", MethodBase.GetCurrentMethod().Name, se.Message));
                }

                Test.Assert(throwException, "Should ever throw exception");
                throwException = false;

                try
                {
                    AccessCondition condition = new AccessCondition()
                    {
                        LeaseId = blobLease
                    };

                    blob.SetMetadata(condition);
                }
                catch (StorageException se)
                {
                    Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, se.Message));
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLease);
            }
        }
Exemplo n.º 26
0
        public void RenewLeaseWithDurationInSeconds()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = string.Empty;

            Random random   = new Random();
            int    duration = random.Next(15, 60);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.RenewLease(containerName, null, containerLease), Utility.GenComparisonData("Renew Lease", true));

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = containerLease
                        };
                        container.SetMetadata(condition);

                        Test.Assert((CommandAgent as NodeJSAgent).SetAzureStorageContainerACL(containerName, BlobContainerPublicAccessType.Off, containerLease),
                                    Utility.GenComparisonData("Set container ACL with lease ID", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                string    blobLease = string.Empty;
                CloudBlob blob      = blobUtil.CreateRandomBlob(container, blobName);
                blob.Metadata["test1"] = "m1";
                blob.Metadata["test2"] = "m2";

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.RenewLease(containerName, blobName, blobLease), Utility.GenComparisonData("Renew Lease", true));

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = blobLease
                        };
                        blob.SetMetadata(condition);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLease);
            }
        }
Exemplo n.º 27
0
        public void LeaseAfterReleaseLease()
        {
            string containerName = Utility.GenNameString("container");
            string blobName      = Utility.GenNameString("blob");

            string destContainerName = Utility.GenNameString("container");
            string destBlobName      = Utility.GenNameString("blob");

            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            CloudBlobContainer destContainer  = blobUtil.CreateContainer(destContainerName);
            string             containerLease = string.Empty;

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.ReleaseLease(containerName, null, containerLease), Utility.GenComparisonData("Release Lease", true));

                        Test.Assert(!(CommandAgent as NodeJSAgent).SetAzureStorageContainerACL(containerName, BlobContainerPublicAccessType.Off, containerLease),
                                    Utility.GenComparisonData("Set container ACL with lease ID", false));
                        CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }

                    Test.Assert(CommandAgent.AcquireLease(containerName, null), Utility.GenComparisonData("Acquire Container Lease", true));
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                string    blobLease     = string.Empty;
                string    destBlobLease = string.Empty;
                CloudBlob blob          = blobUtil.CreateRandomBlob(container, blobName, StorageBlobType.BlockBlob);
                CloudBlob destBlob      = blobUtil.CreateRandomBlob(destContainer, destBlobName, StorageBlobType.BlockBlob);
                blob.Metadata["test1"] = "m1";
                blob.Metadata["test2"] = "m2";

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire Source Blob Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(CommandAgent.AcquireLease(destContainerName, destBlobName), Utility.GenComparisonData("Acquire Dest Blob Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        destBlobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(CommandAgent.StartAzureStorageBlobCopy(containerName, blobName, destContainerName, destBlobName, blobLease, destBlobLease),
                            Utility.GenComparisonData("Start copy blob", true));

                Test.Assert(CommandAgent.ReleaseLease(containerName, blobName, blobLease), Utility.GenComparisonData("Release Source Blob Lease", true));
                Test.Assert(CommandAgent.ReleaseLease(destContainerName, destBlobName, destBlobLease), Utility.GenComparisonData("Release Dest Blob Lease", true));

                Test.Assert(CommandAgent.StartAzureStorageBlobCopy(containerName, blobName, destContainerName, destBlobName),
                            Utility.GenComparisonData("Start copy blob", true));
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLease);
            }
        }
Exemplo n.º 28
0
        public void LeaseWithDurationInSeconds()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = string.Empty;

            try
            {
                bool   throwException = false;
                Random random         = new Random();
                int    duration       = random.Next(15, 60);

                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        try
                        {
                            container.Delete();
                        }
                        catch (StorageException se)
                        {
                            throwException = true;
                            Test.Info(string.Format("Expected: {0} error: {1}", MethodBase.GetCurrentMethod().Name, se.Message));
                        }

                        Test.Assert(throwException, "Should ever throw exception");
                        throwException = false;

                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = containerLease
                        };
                        container.SetMetadata(condition);

                        Test.Assert((CommandAgent as NodeJSAgent).SetAzureStorageContainerACL(containerName, BlobContainerPublicAccessType.Container, containerLease),
                                    Utility.GenComparisonData("Set container ACL with lease ID", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                throwException = false;
                string    blobLease = string.Empty;
                CloudBlob blob      = blobUtil.CreateRandomBlob(container, blobName);
                blob.Metadata["test1"] = "m1";
                blob.Metadata["test2"] = "m2";

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        try
                        {
                            blob.SetMetadata();
                        }
                        catch (StorageException se)
                        {
                            throwException = true;
                            Test.Info(string.Format("Expected: {0} error: {1}", MethodBase.GetCurrentMethod().Name, se.Message));
                        }

                        Test.Assert(throwException, "Should ever throw exception");
                        throwException = false;

                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = blobLease
                        };
                        blob.SetMetadata(condition);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                // Wait for the lease expired
                Thread.Sleep(duration * 1000);

                // Should be successful without lease ID
                blob.Metadata["test3"] = "m3";
                blob.SetMetadata();
                Test.Assert(CommandAgent.RemoveAzureStorageContainer(containerName), Utility.GenComparisonData("Remove container", true));
            }
            finally
            {
                // Don't need a lease ID as it is supposed to expire when runs to here.
                blobUtil.RemoveContainer(containerName);
            }
        }