Ejemplo n.º 1
0
        public void CreateQueue_byCustomDefinitionFail()
        {
            if (!TestConfig.Run_MiscTests) { Assert.Inconclusive(); }

            AuthToken at = new AuthToken(Properties.Settings.Default.ManageKey, Properties.Settings.Default.ServiceNamespace);
            Queues q = new Queues(at);
            QueueDefinition qd = new QueueDefinition("qFromCustomDef");
            //qd.MaxDeliveryCount = 10; // This should FAIL!
            qd.LockDuration = new TimeSpan(0, 0, 5);
            qd.MaxSizeInMegabytes = 5120;
            qd.DeadLetteringOnMessageExpiration = false;
            qd.DefaultMessageTimeToLive = new TimeSpan(0, 0, 30);
            qd.DuplicateDetectionHistoryTimeWindow = new TimeSpan(0, 0, 15);
            try
            {
                q.Create("qFromCustomDefFail", qd);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.ToString());
                if (!ex.Message.Contains("You must set a MaxDeliveryCount.") &&
                    !ex.Message.Contains("MaxDeliveryCount cannot be null."))
                {
                    Assert.Fail("Expected Exception Message Unexpected.");
                }
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public void Queues_Update()
        {
            if (!TestConfig.Run_Management_Queue_UpdateDeleteTests) { Assert.Inconclusive(); }

            base.RunningTest = base.TestList["Update"];
            q.Create(base.SingleTestName);
            base.QueuesCreated.Add(base.SingleTestName);

            QueueDefinition qdf1 = q.GetDefinition(base.SingleTestName);
            QueueDefinition qdf2 = new QueueDefinition(qdf1.QueueName, qdf1);
            qdf2.MaxSizeInMegabytes = 5120;

            q.Update(qdf1.QueueName, qdf2);

            Thread.Sleep(500);

            QueueDefinition qdf3 = q.GetDefinition(qdf2.QueueName);

            Assert.AreNotEqual<QueueDefinition>(qdf1, qdf3);
            Assert.AreEqual<QueueDefinition>(qdf2, qdf3);

            QueueDefinition qdf4 = new QueueDefinition(qdf3.QueueName, qdf3);

            // Micro$suck says this is immutable after creation, but, whatever.
            // Change from TimeSpan.MaxValue (default) to 30 minutes.
            qdf4.DefaultMessageTimeToLive = new TimeSpan(0, 30, 0);

            q.Update(qdf4.QueueName, qdf4);

            Thread.Sleep(500);

            QueueDefinition qdf5 = q.GetDefinition(qdf4.QueueName);

            Assert.AreNotEqual<QueueDefinition>(qdf3, qdf5);

            try
            {
                QueueDefinition qdf6 = new QueueDefinition(qdf5.QueueName, qdf5);
                qdf6.RequiresDuplicateDetection = (qdf6.RequiresDuplicateDetection) ? false : true;
                q.Update(qdf6.QueueName, qdf6);
                //The update should fail, and we should go no further. This can only be set at queue creation time.
                Assert.Fail("RequiresDuplicateDetection can only be set at queue creation time. If the Update operation succeeded, then this test should fail.");
            }
            catch //(Exception ex)
            {
                Console.WriteLine("Expected exception received attempting to update RequiresDuplicateDetection.");
                // Do nothing, pass.
            }
        }
Ejemplo n.º 3
0
 public QueueDefinition(string queueName, QueueDefinition queueDefinition)
 {
     QueueName = queueName;
     LockDuration = queueDefinition.LockDuration;
     MaxSizeInMegabytes = queueDefinition.MaxSizeInMegabytes;
     RequiresDuplicateDetection = queueDefinition.RequiresDuplicateDetection;
     DefaultMessageTimeToLive = queueDefinition.DefaultMessageTimeToLive;
     DeadLetteringOnMessageExpiration = queueDefinition.DeadLetteringOnMessageExpiration;
     DuplicateDetectionHistoryTimeWindow = queueDefinition.DuplicateDetectionHistoryTimeWindow;
     MaxDeliveryCount =
         (queueDefinition.MaxDeliveryCount < 0 || queueDefinition.MaxDeliveryCount > UInt16.MaxValue) ?
         UInt16.MaxValue :
         Convert.ToUInt16(queueDefinition.MaxDeliveryCount);
     EnableBatchedOperations = queueDefinition.EnableBatchedOperations;
 }
Ejemplo n.º 4
0
        public void CreateQueue_byCustomDefinition()
        {
            if (!TestConfig.Run_MiscTests) { Assert.Inconclusive(); }

            AuthToken at = new AuthToken(Properties.Settings.Default.ManageKey, Properties.Settings.Default.ServiceNamespace);
            Queues q = new Queues(at);
            QueueDefinition qd = new QueueDefinition("qFromCustomDef");
            qd.MaxDeliveryCount = 10;
            qd.LockDuration = new TimeSpan(0, 0, 5);
            qd.MaxSizeInMegabytes = 5120;
            qd.DeadLetteringOnMessageExpiration = false;
            qd.DefaultMessageTimeToLive = new TimeSpan(0, 0, 30);
            qd.DuplicateDetectionHistoryTimeWindow = new TimeSpan(0, 0, 15);
            q.Create("qFromCustomDef", qd);
            q.Delete("qFromCustomDef");
        }
Ejemplo n.º 5
0
 //[Obsolete("Suggest using create by typeof(QueueDefinition).")]
 //public static bool Create(AuthToken authToken, string queueName, string queueDefinition)
 //{
 //    try
 //    {
 //        if (!Exists(authToken, queueName))
 //        {
 //            Management.Queues q = new Management.Queues(authToken);
 //            q.Create(queueName, queueDefinition);
 //        }
 //        return true;
 //    }
 //    catch (Exception ex)
 //    {
 //        throw ex;
 //    }
 //}
 public static bool Create(AuthToken authToken, string queueName, QueueDefinition queueDefinition)
 {
     try
     {
         if (!Exists(authToken, queueName))
         {
             Management.Queues q = new Management.Queues(authToken);
             q.Create(queueName, queueDefinition);
         }
         return true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 6
0
        public void Queues_Create_byName_withQueueDefinition()
        {
            if (!TestConfig.Run_Management_Queue_CreateTests) { Assert.Inconclusive(); }

            base.RunningTest = base.TestList["Queues_Create_byName_withQueueDefinition"];
            string testName = base.SingleTestName;
            QueueDefinition qd = new QueueDefinition(testName);
            qd.DeadLetteringOnMessageExpiration = false;
            qd.DefaultMessageTimeToLive = new TimeSpan(0, 1, 0);
            qd.DuplicateDetectionHistoryTimeWindow = new TimeSpan(0, 0, 15);
            qd.EnableBatchedOperations = false;
            qd.LockDuration = new TimeSpan(0, 0, 5);
            qd.MaxDeliveryCount = 10;
            qd.MaxSizeInMegabytes = 1024;
            Assert.AreEqual<string>(testName, qd.QueueName);
            qd.RequiresDuplicateDetection = true;
            q.Create(testName, qd);
            base.QueuesCreated.Add(testName);
        }
        public void CreateQueue_FromDefinition()
        {
            if (!TestConfig.Run_CreateQueueFromDefinition)
            {
                Assert.Inconclusive("Test skipped.");
                return;
            }

            AuthToken at = new AuthToken(Properties.Settings.Default.ManageKey, Properties.Settings.Default.ServiceNamespace);
            Queues q = new Queues(at);
            #region "Pre-test clean-up"
            try
            {
                q.Delete("qWithDefaults");
                q.Delete("qWithDefaults2");
            }
            catch
            {
                // Do nothing.
            }
            #endregion

            q.Create("qWithDefaults");

            QueueDescription qd = null;
            int tries = 0;

            #region "Wait up to 10 seconds for the queue to publish."
            while (qd == null && tries < 10)
            {
                Thread.Sleep(1000);
                try
                {
                    var tmp = q.AtomPubList().Entries.Where(x => x.Title == "qwithdefaults");
                    if (tmp != null)
                    {
                        if (tmp.Count() == 1)
                        {
                            AtomPubFeedEntry ape = tmp.First();
                            if (ape.Content != null)
                            {
                                if (ape.Content.Value != null)
                                {
                                    qd = QueueDescription.DeserializeFrom(ape.Content.Value);
                                }
                            }
                        }
                    }
                }
                catch
                {
                    // Do nothing.
                }
                finally
                {
                    tries += 1;
                }
            }
            #endregion
            #region "Tried 10 x fail"
            if (tries == 10 && qd == null)
            {
                try
                {
                    q.Delete("qWithDefaults");
                }
                catch
                {
                    Console.WriteLine("Failure to create and/or delete could constitute a problem with Azure and/or Service Bus and/or Internet connection.");
                    Console.WriteLine("Could not clean-up: 'qWithDefaults' -- Suggest using Service Bus Explorer to remove this queue if it exists.");
                    // Do nothing.
                }
                finally
                {
                    Assert.Fail("Failed to retreive and/or delete newly created queue: 'qWithDefaults'");
                }
            }
            #endregion

            q.Create("qWithDefaults2", new QueueDefinition("qWithDefaults2", qd));

            QueueDescription qd2 = null;
            tries = 0;
            #region "Wait up to 10 seconds for the queue to publish."
            while (qd2 == null && tries < 10)
            {
                Thread.Sleep(1000);
                try
                {
                    var tmp = q.AtomPubList().Entries.Where(x => x.Title == "qwithdefaults2");
                    if (tmp != null)
                    {
                        if (tmp.Count() == 1)
                        {
                            AtomPubFeedEntry ape = tmp.First();
                            if (ape.Content != null)
                            {
                                if (ape.Content.Value != null)
                                {
                                    qd2 = QueueDescription.DeserializeFrom(ape.Content.Value);
                                }
                            }
                        }
                    }
                }
                catch // (Exception ex)
                {
                    // Do nothing.
                }
                finally
                {
                    tries += 1;
                }
            }
            #endregion
            #region "Tried 10 x fail"
            if (tries == 10 && qd2 == null)
            {
                try
                {
                    q.Delete("qWithDefaults");
                    q.Delete("qWithDefaults2");
                }
                catch
                {
                    Console.WriteLine("Failure to create and/or delete could constitute a problem with Azure and/or Service Bus and/or Internet connection.");
                    Console.WriteLine("Could not clean-up: 'qWithDefaults' and/or 'qWithDefaults2' -- Suggest using Service Bus Explorer to remove this queue if it exists.");
                    // Do nothing.
                }
                finally
                {
                    Assert.Fail("Failed to retreive and/or delete newly created queues: 'qWithDefaults', 'qWithDefaults2'");
                }
            }
            #endregion

            try
            {
                QueueDefinition qdc1 = new QueueDefinition("qWithDefaults", qd);
                QueueDefinition qdc2 = new QueueDefinition("qWithDefaults2", qd2);
                Assert.AreEqual<QueueDefinition>(qdc1, qdc2);
            }
            finally
            {
                #region "Cleanup"
                q.Delete("qWithDefaults");
                q.Delete("qWithDefaults2");
                #endregion
            }
        }
Ejemplo n.º 8
0
 //[Obsolete("Suggest using update by typeof(QueueDefinition).")]
 //public static bool Update(AuthToken authToken, string queueName, string queueDefinition)
 //{
 //    try
 //    {
 //        if (Exists(authToken, queueName))
 //        {
 //            Management.Queues q = new Management.Queues(authToken);
 //            q.Update(queueName, queueDefinition);
 //            return true;
 //        }
 //        else
 //        {
 //            throw new Exception(String.Format("Queue '{0}' does not exist to update.", queueName));
 //            //return false;
 //        }
 //    }
 //    catch (Exception ex)
 //    {
 //        throw ex;
 //    }
 //}
 public static bool Update(AuthToken authToken, string queueName, QueueDefinition queueDefinition)
 {
     try
     {
         if (Exists(authToken, queueName))
         {
             Management.Queues q = new Management.Queues(authToken);
             q.Update(queueName, queueDefinition);
             return true;
         }
         else
         {
             throw new Exception(String.Format("Queue '{0}' does not exist to update.", queueName));
             //return false;
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a new queue, using the retreived Description of an existing queue.
 /// </summary>
 /// <param name="queueName">The name of the (new) queue to create.</param>
 /// <param name="queueDescription">The description of an existing queue.</param>
 /// <returns>true | false</returns>
 public bool Create(string queueName, QueueDescription queueDescription)
 {
     QueueDefinition qDef = new QueueDefinition(queueName, queueDescription);
     return Create(queueName, qDef);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates a new queue using an existing or modified QueueDefinition.
 /// </summary>
 /// <param name="queueName">The name of the queue to create.</param>
 /// <param name="queueDefinition">An instance of QueueDefinition (such as might be taken from an existing QueueDescription).</param>
 /// <returns>true | false</returns>
 public bool Create(string queueName, QueueDefinition queueDefinition)
 {
     return Create(queueName, queueDefinition.ToString());
 }