public void DeleteQueue()
 {
     try {
         _client.DeleteQueueAsync(_queueUrl).Wait();
     } catch (Exception ex) {
         // This may get deleted by a tear down
     }
 }
Esempio n. 2
0
 public static async Task DeleteQueueByQueueUrl(string queueUrl)
 {
     using (var client = new AmazonSQSClient(ConfigManager.ConfigSettings.AccessKey, ConfigManager.ConfigSettings.Secret, Amazon.RegionEndpoint.USWest2))
     {
         await client.DeleteQueueAsync(queueUrl);
     }
 }
Esempio n. 3
0
        public void UnmonitorEmail(string emailaddr)
        {
            if (monitors.ContainsKey(emailaddr))
            {
                var monitor = monitors[emailaddr];
                try
                {
                    var unsubresponse = snsclient.UnsubscribeAsync(new UnsubscribeRequest
                    {
                        SubscriptionArn = monitor.subscription_arn
                    });
                    var unsubresult = unsubresponse.Result;
                }
                catch (AmazonSimpleNotificationServiceException e)
                {
                    Console.WriteLine("Unable to unsubscripe topic for {0}: {1}", emailaddr, e.Message);
                }
                try
                {
                    var sqsresponse = sqsclient.DeleteQueueAsync(new DeleteQueueRequest
                    {
                        QueueUrl = monitor.sqsqueue_url
                    });

                    DeleteQueueResponse sqsresult = sqsresponse.Result;
                }
                catch (AmazonSQSException e)
                {
                    Console.WriteLine("Unable to delete queue for {0}: {1}", emailaddr, e.Message);
                }
            }
        }
Esempio n. 4
0
        protected override void Dispose(bool disposing)
        {
            foreach (string arn in _topicArns)
            {
                try
                {
                    Client.DeleteTopicAsync(new DeleteTopicRequest
                    {
                        TopicArn = arn
                    }).Wait();
                }
                catch { };
            }

            foreach (string url in _queueUrl)
            {
                try
                {
                    sqsClient.DeleteQueueAsync(new DeleteQueueRequest
                    {
                        QueueUrl = url
                    }).Wait();
                }
                catch { };
            }

            if (sqsClient != null)
            {
                sqsClient.Dispose();
                sqsClient = null;
            }
            base.Dispose(disposing);
        }
Esempio n. 5
0
        public void DeleteQueue()
        {
            if (_subscription == null)
            {
                return;
            }

            using (var sqsClient = new AmazonSQSClient(_awsConnection.Credentials, _awsConnection.Region))
            {
                //Does the queue exist - this is an HTTP call, we should cache the results for a period of time
                (bool exists, string name)queueExists = QueueExists(sqsClient, _subscription.ChannelName.ToValidSQSQueueName());

                if (queueExists.exists)
                {
                    try
                    {
                        sqsClient.DeleteQueueAsync(queueExists.name).Wait();
                    }
                    catch (Exception)
                    {
                        //don't break on an exception here, if we can't delete, just exit
                        s_logger.LogError("Could not delete queue {ChannelName}", queueExists.name);
                    }
                }
            }
        }
Esempio n. 6
0
        private static async Task DeleteTopicAsync(Topic topic)
        {
            var settings  = GetSettingsAsync().Result;
            var snsClient = new AmazonSimpleNotificationServiceClient(
                settings.AWSAccessKeyID,
                settings.AWSSecretAccessKey,
                RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName));

            var sqsClient = new AmazonSQSClient(
                settings.AWSAccessKeyID,
                settings.AWSSecretAccessKey,
                RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName));

            // Cleanup topic & queue & local file
            try { await snsClient.DeleteTopicAsync(new DeleteTopicRequest()
                {
                    TopicArn = topic.TopicARN
                }); } catch (Exception ex) { Debug.WriteLine(ex.Message); }
            try { await sqsClient.DeleteQueueAsync(new DeleteQueueRequest()
                {
                    QueueUrl = topic.QueueUrl
                }); } catch (Exception ex) { Debug.WriteLine(ex.Message); }

            // TODO Delete the errored/complete files on startup?
            File.Delete(Path.Combine(GetTempDirectory(), topic.TopicFileName));
            Debug.WriteLine($"Deleted topic {topic.TopicARN}");
            Debug.WriteLine($"Deleted topic file {topic.TopicFileName}");
        }
 /// <summary>
 /// Deletes the transport's input queue
 /// </summary>
 public void DeleteQueue()
 {
     using (var client = new AmazonSQSClient(_credentials, _amazonSqsConfig))
     {
         AsyncHelpers.RunSync(() => client.DeleteQueueAsync(_queueUrl));
     }
 }
Esempio n. 8
0
        public async Task ReadMessageAsync()
        {
            var queueName = "local-reader-read-message-test-" + DateTime.Now.Ticks;

            using (var client = new AmazonSQSClient(TestUtils.GetAWSCredentials(), TestUtils.TestRegion))
            {
                var createResponse = await client.CreateQueueAsync(new CreateQueueRequest { QueueName = queueName });

                await TestUtils.WaitTillQueueIsCreatedAsync(client, createResponse.QueueUrl);

                try
                {
                    var manager = new ExternalCommandManager();
                    var message = manager.ReadMessage(TestUtils.TestProfile, TestUtils.TestRegion.SystemName, createResponse.QueueUrl);

                    Assert.Null(message);

                    await client.SendMessageAsync(new SendMessageRequest
                    {
                        MessageBody = "data",
                        QueueUrl    = createResponse.QueueUrl
                    });

                    message = manager.ReadMessage(TestUtils.TestProfile, TestUtils.TestRegion.SystemName, createResponse.QueueUrl);
                    Assert.NotNull(message);

                    manager.DeleteMessage(TestUtils.TestProfile, TestUtils.TestRegion.SystemName, createResponse.QueueUrl, message.ReceiptHandle);
                }
                finally
                {
                    await client.DeleteQueueAsync(createResponse.QueueUrl);
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        ///
        /// <para>DeleteCustomTopicGlobally:</para>
        ///
        /// <para>Deletes all messages and the topic of given workspace</para>
        ///
        /// <para>Check <seealso cref="IBPubSubServiceInterface.DeleteCustomTopicGlobally"/> for detailed documentation</para>
        ///
        /// </summary>
        public void DeleteCustomTopicGlobally(string _CustomTopic, Action <string> _ErrorMessageAction = null)
        {
            if (BUtility.CalculateStringMD5(_CustomTopic, out string TopicMD5, _ErrorMessageAction) &&
                CheckQueueExists(TopicMD5, out string QueueUrl))
            {
                try
                {
                    lock (SubscriberThreadsDictionaryLock)
                    {
                        if (SubscriberThreadsDictionary.ContainsKey(_CustomTopic))
                        {
                            var SubscriberThread = SubscriberThreadsDictionary[_CustomTopic];
                            if (SubscriberThread != null)
                            {
                                SubscriberThread.Item2.Set(true);
                            }
                            SubscriberThreadsDictionary.Remove(_CustomTopic);
                        }
                    }

                    using (var DeleteQueueTask = SQSClient.DeleteQueueAsync(QueueUrl))
                    {
                        DeleteQueueTask.Wait();
                    }
                }
                catch (Exception e)
                {
                    _ErrorMessageAction?.Invoke("BPubSubServiceAWS->DeleteCustomTopicGlobally->Callback: " + e.Message + ", Trace: " + e.StackTrace);
                    if (e.InnerException != null && e.InnerException != e)
                    {
                        _ErrorMessageAction?.Invoke("BPubSubServiceAWS->DeleteCustomTopicGlobally->Inner: " + e.InnerException.Message + ", Trace: " + e.InnerException.StackTrace);
                    }
                }
            }
        }
Esempio n. 10
0
        public async Task ListQueuesAsync()
        {
            if (!TestUtils.ProfileTestsEnabled)
            {
                return;
            }

            var queueName = "local-reader-list-queue-test-" + DateTime.Now.Ticks;

            using (var client = new AmazonSQSClient(TestUtils.GetAWSCredentials(), TestUtils.TestRegion))
            {
                var createResponse = await client.CreateQueueAsync(new CreateQueueRequest { QueueName = queueName });

                await TestUtils.WaitTillQueueIsCreatedAsync(client, createResponse.QueueUrl);

                try
                {
                    var aws    = new AWSServiceImpl();
                    var queues = await aws.ListQueuesAsync(TestUtils.TestProfile, TestUtils.TestRegion.SystemName);

                    Assert.True(queues.Contains(createResponse.QueueUrl));
                }
                finally
                {
                    await client.DeleteQueueAsync(createResponse.QueueUrl);
                }
            }
        }
 /// <summary>
 ///     Deletes the transport's input queue
 /// </summary>
 public void DeleteQueue()
 {
     using (var client = new AmazonSQSClient(m_AmazonInternalSettings.AmazonCredentialsFactory.Create(), m_AmazonInternalSettings.AmazonSqsConfig))
     {
         var queueUri = m_amazonSQSQueueContext.GetInputQueueUrl(Address);
         AsyncHelpers.RunSync(() => client.DeleteQueueAsync(queueUri));
     }
 }
Esempio n. 12
0
        public async ValueTask DisposeAsync()
        {
            await _snsClient.DeleteTopicAsync(TopicArn);

            await _sqsClient.DeleteQueueAsync(QueueUrl);

            _snsClient.Dispose();
            _sqsClient.Dispose();
        }
Esempio n. 13
0
        public void SQSCleanUp()
        {
            var sqsQueueList = sqsClient.ListQueuesAsync(prefix);

            foreach (string queue in sqsQueueList.Result.QueueUrls)
            {
                if (queue.Contains(prefix))
                {
                    try
                    {
                        sqsClient.DeleteQueueAsync(queue);
                    }
                    catch (Exception)
                    {
                        Console.Write("Failed to clean up queue {0}", queue);
                    }
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Deletes a queue with the specified name
        /// </summary>
        /// <param name="queueName">The name of the queue</param>
        /// <returns></returns>
        public async Task <bool> DeleteQueueAsync(string queueName)
        {
            var queueUrl = await GetQueueUrlAsync(queueName);

            var request  = new DeleteQueueRequest(queueUrl);
            var response = await _client.DeleteQueueAsync(request);

            var success = (int)response.HttpStatusCode >= 200 && (int)response.HttpStatusCode <= 299;

            return(success);
        }
Esempio n. 15
0
 public void DeleteQueue(Connection connection)
 {
     using (var sqsClient = new AmazonSQSClient(_awsConnection.Credentials, _awsConnection.Region))
     {
         //Does the queue exist - this is an HTTP call, we should cache the results for a period of time
         (bool exists, string name)queueExists = QueueExists(sqsClient, connection.ChannelName.ToValidSQSQueueName());
         if (!queueExists.exists)
         {
             sqsClient.DeleteQueueAsync(queueExists.name).Wait();
         }
     }
 }
Esempio n. 16
0
        public async Task DeleteChannelsAsync(IEnumerable <string> channelNames, CancellationToken cancellationToken = default)
        {
            if (channelNames is null)
            {
                throw new ArgumentNullException(nameof(channelNames));
            }

            foreach (string queueName in channelNames)
            {
                await _client.DeleteQueueAsync(GetQueueUri(queueName), cancellationToken).ConfigureAwait(false);
            }
        }
Esempio n. 17
0
        public async Task DeleteQueueExample()
        {
            // Create service client using the SDK's default logic for determining AWS credentials and region to use.
            // For information configuring service clients checkout the .NET developer guide: https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config.html
            AmazonSQSClient client = new AmazonSQSClient();

            var request = new DeleteQueueRequest
            {
                QueueUrl = "SQS_QUEUE_URL"
            };

            await client.DeleteQueueAsync(request);
        }
Esempio n. 18
0
        private static async Task Cleanup(AmazonSQSClient sqsClient, AmazonSimpleNotificationServiceClient snsClient, List <Task <string> > subscribeTask, string topic1Arn, string topic2Arn, string queueUrl)
        {
            foreach (var task in subscribeTask)
            {
                await snsClient.UnsubscribeAsync(task.Result);
            }

            await snsClient.DeleteTopicAsync(topic1Arn);

            await snsClient.DeleteTopicAsync(topic2Arn);

            await sqsClient.DeleteQueueAsync(queueUrl);
        }
Esempio n. 19
0
        public static async Task DeleteAllQueues()
        {
            using (var client = new AmazonSQSClient(ConfigManager.ConfigSettings.AccessKey, ConfigManager.ConfigSettings.Secret, Amazon.RegionEndpoint.USWest2))
            {
                var response = await client.ListQueuesAsync(new ListQueuesRequest());

                foreach (var queueUrl in response.QueueUrls)
                {
                    await PurgeQueueByQueueUrl(queueUrl);

                    await client.DeleteQueueAsync(queueUrl);
                }
            }
        }
Esempio n. 20
0
 /// <summary>
 /// Delete the queue
 /// </summary>
 /// <returns></returns>
 public async Task DeleteQueue()
 {
     try
     {
         if (string.IsNullOrWhiteSpace(queueUrl))
         {
             throw new InvalidOperationException("Queue not initialized");
         }
         await sqsClient.DeleteQueueAsync(queueUrl);
     }
     catch (Exception exc)
     {
         ReportErrorAndRethrow(exc, "DeleteQueue", ErrorCode.StreamProviderManagerBase);
     }
 }
        /// <summary>
        /// Initializes the Amazon SQS client object and then calls the
        /// DeleteQueueAsync method to delete the queue.
        /// </summary>
        public static async Task Main()
        {
            // If the Amazon SQS message queue is not in the same AWS Region as your
            // default user, you need to provide the AWS Region as a parameter to the
            // client constructor.
            var client = new AmazonSQSClient();

            string queueUrl = "https://sqs.us-east-2.amazonaws.com/0123456789ab/New-Example-Queue";

            var response = await client.DeleteQueueAsync(queueUrl);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("Successfully deleted the queue.");
            }
            else
            {
                Console.WriteLine("Could not delete the crew.");
            }
        }
Esempio n. 22
0
        public async Task ListQueuesAsync()
        {
            var queueName = "local-reader-list-queue-test-" + DateTime.Now.Ticks;

            using (var client = new AmazonSQSClient(TestUtils.GetAWSCredentials(), TestUtils.TestRegion))
            {
                var createResponse = await client.CreateQueueAsync(new CreateQueueRequest { QueueName = queueName });

                await TestUtils.WaitTillQueueIsCreatedAsync(client, createResponse.QueueUrl);

                try
                {
                    var manager = new ExternalCommandManager();
                    var queues  = manager.ListQueues(TestUtils.TestProfile, TestUtils.TestRegion.SystemName);

                    Assert.True(queues.Contains(createResponse.QueueUrl));
                }
                finally
                {
                    await client.DeleteQueueAsync(createResponse.QueueUrl);
                }
            }
        }
        public void DeleteAllTopics()
        {
            AmazonSimpleNotificationServiceClient clientSNS = AwsFactory.CreateClient <AmazonSimpleNotificationServiceClient>();
            AmazonSQSClient    clientSQS    = AwsFactory.CreateClient <AmazonSQSClient>();
            AmazonLambdaClient lambdaClient = AwsFactory.CreateClient <AmazonLambdaClient>();


            var topics = clientSNS.ListTopicsAsync();
            // var subs = clientSNS.ListSubscriptionsAsync(new ListSubscriptionsRequest());
            var filas = clientSQS.ListQueuesAsync("subs");

            filas.Result.QueueUrls.ForEach(i =>
            {
                var deleted = clientSQS.DeleteQueueAsync(i);
                if (deleted.Result.HttpStatusCode != HttpStatusCode.OK)
                {
                    int x = 0;
                }
            });

            string nextToken = "";

            do
            {
                var subs = clientSNS.ListSubscriptionsAsync(new ListSubscriptionsRequest(nextToken));

                subs.Result.Subscriptions.ForEach(i =>
                {
                    var deleted = clientSNS.UnsubscribeAsync(i.SubscriptionArn);
                });

                nextToken = subs.Result.NextToken;
            } while (!String.IsNullOrEmpty(nextToken));



            var mapper = lambdaClient.ListEventSourceMappingsAsync(new Amazon.Lambda.Model.ListEventSourceMappingsRequest
            {
                FunctionName = "WebhookDispatcher"
            });

            mapper.Result.EventSourceMappings.ToList().ForEach(i =>
            {
                var result = lambdaClient.DeleteEventSourceMappingAsync(new Amazon.Lambda.Model.DeleteEventSourceMappingRequest()
                {
                    UUID = i.UUID
                });
                if (result.Result.HttpStatusCode != HttpStatusCode.OK)
                {
                    int x = 0;
                }
            });


            topics.Result.Topics.ForEach(i =>
            {
                var deleted = clientSNS.DeleteTopicAsync(new DeleteTopicRequest()
                {
                    TopicArn = i.TopicArn
                });
            });
        }
Esempio n. 24
0
 private async Task DeleteQueue()
 {
     await sqsClient.DeleteQueueAsync(queueUrl);
 }
Esempio n. 25
0
        public async Task SetQueueConfigurationTests()
        {
            var filterRule = new FilterRule("Prefix", "test/");

            using (var sqsClient = new AmazonSQSClient())
            {
                string topicName      = UtilityMethods.GenerateName("events-test");
                var    createResponse = await sqsClient.CreateQueueAsync(topicName);

                var bucketName = await UtilityMethods.CreateBucketAsync(Client, "SetQueueConfigurationTests");

                try
                {
                    var queueArn = await sqsClient.AuthorizeS3ToSendMessageAsync(createResponse.QueueUrl, bucketName);

                    PutBucketNotificationRequest putRequest = new PutBucketNotificationRequest
                    {
                        BucketName          = bucketName,
                        QueueConfigurations = new List <QueueConfiguration>
                        {
                            new QueueConfiguration
                            {
                                Id     = "the-queue-test",
                                Queue  = queueArn,
                                Events = { EventType.ObjectCreatedPut },
                                Filter = new Filter
                                {
                                    S3KeyFilter = new S3KeyFilter
                                    {
                                        FilterRules = new List <FilterRule>
                                        {
                                            filterRule
                                        }
                                    }
                                }
                            }
                        }
                    };

                    await Client.PutBucketNotificationAsync(putRequest);

                    var getResponse = await Client.GetBucketNotificationAsync(bucketName);

                    Assert.Equal(1, getResponse.QueueConfigurations.Count);
                    Assert.Equal(1, getResponse.QueueConfigurations[0].Events.Count);
                    Assert.Equal(EventType.ObjectCreatedPut, getResponse.QueueConfigurations[0].Events[0]);

                    Assert.NotNull(getResponse.QueueConfigurations[0].Filter);
                    Assert.NotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter);
                    Assert.NotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules);
                    Assert.Equal(1, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules.Count);
                    Assert.Equal(filterRule.Name, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Name);
                    Assert.Equal(filterRule.Value, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Value);

                    Assert.Equal("the-queue-test", getResponse.QueueConfigurations[0].Id);
                    Assert.Equal(queueArn, getResponse.QueueConfigurations[0].Queue);

                    // Purge queue to remove test message sent configuration was setup.
                    await sqsClient.PurgeQueueAsync(createResponse.QueueUrl);

                    Thread.Sleep(TimeSpan.FromSeconds(1));

                    var putObjectRequest = new PutObjectRequest
                    {
                        BucketName  = bucketName,
                        Key         = "test/data.txt",
                        ContentBody = "Important Data"
                    };

                    await Client.PutObjectAsync(putObjectRequest);

                    string messageBody = null;
                    for (int i = 0; i < 5 && messageBody == null; i++)
                    {
                        var receiveResponse = await sqsClient.ReceiveMessageAsync(new ReceiveMessageRequest { QueueUrl = createResponse.QueueUrl, WaitTimeSeconds = 20 });

                        if (receiveResponse.Messages.Count != 0)
                        {
                            messageBody = receiveResponse.Messages[0].Body;
                        }
                    }


                    var evnt = S3EventNotification.ParseJson(messageBody);

                    Assert.Equal(1, evnt.Records.Count);
                    Assert.Equal(putObjectRequest.BucketName, evnt.Records[0].S3.Bucket.Name);
                    Assert.Equal(putObjectRequest.Key, evnt.Records[0].S3.Object.Key);
                    Assert.Equal(putObjectRequest.ContentBody.Length, evnt.Records[0].S3.Object.Size);
                }
                finally
                {
                    await sqsClient.DeleteQueueAsync(createResponse.QueueUrl);

                    await UtilityMethods.DeleteBucketWithObjectsAsync(Client, bucketName);
                }
            }
        }
Esempio n. 26
0
        public static async Task DeleteQueue(string queueUrl)
        {
            using var sqs = new AmazonSQSClient(Credentials);

            await sqs.DeleteQueueAsync(queueUrl);
        }
        public async Task FixIssueOfDLQBeingCleared()
        {
            var sqsClient = new AmazonSQSClient(RegionEndpoint.USEast2);

            var queueUrl = (await sqsClient.CreateQueueAsync("lambda-test-" + DateTime.Now.Ticks)).QueueUrl;
            var queueArn = (await sqsClient.GetQueueAttributesAsync(queueUrl, new List <string> {
                "QueueArn"
            })).QueueARN;

            try
            {
                var assembly = this.GetType().GetTypeInfo().Assembly;

                var fullPath             = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/TestFunction");
                var initialDeployCommand = new DeployFunctionCommand(new TestToolLogger(_testOutputHelper), fullPath, new string[0]);
                initialDeployCommand.FunctionName        = "test-function-" + DateTime.Now.Ticks;
                initialDeployCommand.Handler             = "TestFunction::TestFunction.Function::ToUpper";
                initialDeployCommand.Timeout             = 10;
                initialDeployCommand.MemorySize          = 512;
                initialDeployCommand.Role                = TestHelper.GetTestRoleArn();
                initialDeployCommand.Configuration       = "Release";
                initialDeployCommand.TargetFramework     = "netcoreapp1.0";
                initialDeployCommand.Runtime             = "dotnetcore1.0";
                initialDeployCommand.DeadLetterTargetArn = queueArn;
                initialDeployCommand.DisableInteractive  = true;


                var created = await initialDeployCommand.ExecuteAsync();

                try
                {
                    Assert.True(created);

                    var funcConfig = await initialDeployCommand.LambdaClient.GetFunctionConfigurationAsync(initialDeployCommand.FunctionName);

                    Assert.Equal(queueArn, funcConfig.DeadLetterConfig?.TargetArn);

                    var redeployCommand = new DeployFunctionCommand(new TestToolLogger(_testOutputHelper), fullPath, new string[0]);
                    redeployCommand.FunctionName       = initialDeployCommand.FunctionName;
                    redeployCommand.Configuration      = "Release";
                    redeployCommand.TargetFramework    = "netcoreapp1.0";
                    redeployCommand.Runtime            = "dotnetcore1.0";
                    redeployCommand.DisableInteractive = true;

                    var redeployed = await redeployCommand.ExecuteAsync();

                    Assert.True(redeployed);

                    funcConfig = await initialDeployCommand.LambdaClient.GetFunctionConfigurationAsync(initialDeployCommand.FunctionName);

                    Assert.Equal(queueArn, funcConfig.DeadLetterConfig?.TargetArn);

                    redeployCommand = new DeployFunctionCommand(new TestToolLogger(_testOutputHelper), fullPath, new string[0]);
                    redeployCommand.FunctionName        = initialDeployCommand.FunctionName;
                    redeployCommand.Configuration       = "Release";
                    redeployCommand.TargetFramework     = "netcoreapp1.0";
                    redeployCommand.Runtime             = "dotnetcore1.0";
                    redeployCommand.DeadLetterTargetArn = "";
                    redeployCommand.DisableInteractive  = true;

                    redeployed = await redeployCommand.ExecuteAsync();

                    Assert.True(redeployed);

                    funcConfig = await initialDeployCommand.LambdaClient.GetFunctionConfigurationAsync(initialDeployCommand.FunctionName);

                    Assert.Null(funcConfig.DeadLetterConfig?.TargetArn);
                }
                finally
                {
                    if (created)
                    {
                        await initialDeployCommand.LambdaClient.DeleteFunctionAsync(initialDeployCommand.FunctionName);
                    }
                }
            }
            finally
            {
                await sqsClient.DeleteQueueAsync(queueUrl);
            }
        }
        public async Task DlqIntegTest()
        {
            const int WAIT_TIME = 5000;
            var       queueName = "local-dlq-list-queue-test-" + DateTime.Now.Ticks;

            using (var client = new AmazonSQSClient(TestUtils.GetAWSCredentials(), TestUtils.TestRegion))
            {
                var createResponse = await client.CreateQueueAsync(new CreateQueueRequest { QueueName = queueName });

                await TestUtils.WaitTillQueueIsCreatedAsync(client, createResponse.QueueUrl);

                try
                {
                    var configFile = Path.GetFullPath(@"../../../../LambdaFunctions/ToUpperFunc/aws-lambda-tools-defaults.json");
                    var buildPath  = Path.GetFullPath(@"../../../../LambdaFunctions/ToUpperFunc/bin/debug/netcoreapp2.1");
                    var configInfo = LambdaDefaultsConfigFileParser.LoadFromFile(configFile);
                    var runtime    = LocalLambdaRuntime.Initialize(buildPath);
                    var function   = runtime.LoadLambdaFunctions(configInfo.FunctionInfos)[0];

                    var monitor = new DlqMonitor(runtime, function, TestUtils.TestProfile, TestUtils.TestRegion.SystemName, createResponse.QueueUrl);

                    monitor.Start();
                    await client.SendMessageAsync(new SendMessageRequest
                    {
                        QueueUrl    = createResponse.QueueUrl,
                        MessageBody = "\"testing dlq\""
                    });

                    Thread.Sleep(WAIT_TIME);
                    var logs = monitor.FetchNewLogs();
                    Assert.Single(logs);

                    Assert.Contains("testing dlq", logs[0].Logs);
                    Assert.NotNull(logs[0].ReceiptHandle);
                    Assert.NotEqual(DateTime.MinValue, logs[0].ProcessTime);

                    logs = monitor.FetchNewLogs();
                    Assert.Equal(0, logs.Count);

                    await client.SendMessageAsync(new SendMessageRequest
                    {
                        QueueUrl    = createResponse.QueueUrl,
                        MessageBody = "\"testing dlq1\""
                    });

                    await client.SendMessageAsync(new SendMessageRequest
                    {
                        QueueUrl    = createResponse.QueueUrl,
                        MessageBody = "\"testing dlq2\""
                    });

                    Thread.Sleep(WAIT_TIME);

                    logs = monitor.FetchNewLogs();
                    Assert.Equal(2, logs.Count);

                    monitor.Stop();
                    Thread.Sleep(WAIT_TIME);
                    await client.SendMessageAsync(new SendMessageRequest
                    {
                        QueueUrl    = createResponse.QueueUrl,
                        MessageBody = "\"testing dlq3\""
                    });

                    Thread.Sleep(WAIT_TIME);

                    logs = monitor.FetchNewLogs();
                    Assert.Equal(0, logs.Count);
                }
                finally
                {
                    await client.DeleteQueueAsync(createResponse.QueueUrl);
                }
            }
        }
 public async Task Teardown()
 {
     await _sqsClient.DeleteQueueAsync(_testQueueUrl);
 }
Esempio n. 30
0
 public void Dispose()
 {
     amazonSqsClient.DeleteQueueAsync(new DeleteQueueRequest(queueUrl)).Wait();
 }