Exemplo n.º 1
0
        public CreateQueueResponse CreateQueue(CreateQueueRequest request)
        {
            if (request.QueueName.Length > 80 ||
                request.QueueName.Any(c => !char.IsLetterOrDigit(c) && !SqsQueueDefinition.ValidNonAlphaNumericChars.Contains(c)))
            {
                throw new AmazonSQSException("Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length");
            }

            var qUrl = Guid.NewGuid().ToString("N");

            var qd = request.Attributes.ToQueueDefinition(SqsQueueNames.GetSqsQueueName(request.QueueName), qUrl, disableBuffering: true);

            var existingQueue = queues.SingleOrDefault(kvp => kvp.Value.QueueDefinition.QueueName.Equals(qd.QueueName, StringComparison.OrdinalIgnoreCase)).Value;

            if (existingQueue != null)
            {   // If an existing q with same name, attributes must match, which we only check 2 of currently in Fake
                if (existingQueue.QueueDefinition.VisibilityTimeout == qd.VisibilityTimeout &&
                    existingQueue.QueueDefinition.ReceiveWaitTime == qd.ReceiveWaitTime)
                {   // Same, so return the existing q
                    return(new CreateQueueResponse
                    {
                        QueueUrl = existingQueue.QueueDefinition.QueueUrl
                    });
                }

                throw new QueueNameExistsException($"Queue with name [{qd.QueueName}] already exists");
            }

            qd.QueueArn = Guid.NewGuid().ToString("N");

            var q = new FakeSqsQueue
            {
                QueueDefinition = qd
            };

            if (!queues.TryAdd(qUrl, q))
            {
                throw new Exception("This should not happen, somehow the QueueUrl already exists");
            }

            return(new CreateQueueResponse
            {
                QueueUrl = q.QueueDefinition.QueueUrl
            });
        }
Exemplo n.º 2
0
        public CreateQueueResponse CreateQueue(CreateQueueRequest request)
        {
            if (request.QueueName.Length > 80 ||
                request.QueueName.Any(c => !char.IsLetterOrDigit(c) && !SqsQueueDefinition.ValidNonAlphaNumericChars.Contains(c)))
            {
                throw new AmazonSQSException("Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length");
            }

            var qUrl = Guid.NewGuid().ToString("N");

            var qd = request.Attributes.ToQueueDefinition(SqsQueueNames.GetSqsQueueName(request.QueueName), qUrl, disableBuffering: true);

            var existingQueue = queues.SingleOrDefault(kvp => kvp.Value.QueueDefinition.QueueName.Equals(qd.QueueName, StringComparison.InvariantCultureIgnoreCase)).Value;

            if (existingQueue != null)
            {   // If an existing q with same name, attributes must match, which we only check 2 of currently in Fake
                if (existingQueue.QueueDefinition.VisibilityTimeout == qd.VisibilityTimeout &&
                    existingQueue.QueueDefinition.ReceiveWaitTime == qd.ReceiveWaitTime)
                {   // Same, so return the existing q
                    return new CreateQueueResponse
                    {
                        QueueUrl = existingQueue.QueueDefinition.QueueUrl
                    };
                }

                throw new QueueNameExistsException("Queue with name [{0}] already exists".Fmt(qd.QueueName));
            }

            qd.QueueArn = Guid.NewGuid().ToString("N");

            var q = new FakeSqsQueue
            {
                QueueDefinition = qd
            };

            if (!queues.TryAdd(qUrl, q))
            {
                throw new Exception("This should not happen, somehow the QueueUrl already exists");
            }

            return new CreateQueueResponse
            {
                QueueUrl = q.QueueDefinition.QueueUrl
            };
        }