public async Task FilterLogEventsTest_TwoResponses()
        {
            var request       = new FilterLogEventsRequest();
            var firstResponse = new FilterLogEventsResponse()
            {
                NextToken = "foo"
            };
            var secondResponse = new FilterLogEventsResponse()
            {
                NextToken = null
            };
            var token = new CancellationToken();

            _mockClient.SetupSequence(x => x.FilterLogEventsAsync(It.IsAny <FilterLogEventsRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(firstResponse)
            .ReturnsAsync(secondResponse);

            var numResponses = 0;

            await foreach (var desination in _mockClient.Object.Paginators.FilterLogEvents(request).Responses.WithCancellation(token))
            {
                numResponses += 1;
            }
            Assert.Equal(2, numResponses);
        }
Пример #2
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            FilterLogEventsResponse response = new FilterLogEventsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("events", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <FilteredLogEvent, FilteredLogEventUnmarshaller>(FilteredLogEventUnmarshaller.Instance);
                    response.Events = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("nextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("searchedLogStreams", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <SearchedLogStream, SearchedLogStreamUnmarshaller>(SearchedLogStreamUnmarshaller.Instance);
                    response.SearchedLogStreams = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Пример #3
0
        private async Task ReadRecords()
        {
            var request = new FilterLogEventsRequest()
            {
                LogGroupName        = _context.LogGroupName,
                StartTime           = Progress.NextIterationStart.ToUnixTimeMilliseconds(),
                EndTime             = Progress.NextIterationEnd.ToUnixTimeMilliseconds(),
                NextToken           = Progress.NextToken,
                FilterPattern       = _context.EventFilterPattern,
                LogStreamNamePrefix = _context.LogStreamNamePrefix,
                LogStreamNames      = _context.LogStreamNames,
                Limit = _context.ReadMaxBatchSize
            };

            _context.Logger.Debug("Calling AWS API with input {@Request}", request);
            _readResponse = await ReadRecordsWithExponentialBackoff(request);

            _context.Logger.Debug("AWS API returned {HttpStatusCode} with {RecordCount} records, {ResponseSize} bytes",
                                  _readResponse.HttpStatusCode, _readResponse.Events.Count, _readResponse.ContentLength);

            if (_readResponse.HttpStatusCode != HttpStatusCode.OK)
            {
                throw new ApplicationException("AWS Service call did not return OK status code");
            }

            RecordCount = _readResponse.Events.Count;
            SizeBytes   = (int)_readResponse.ContentLength;
        }
Пример #4
0
        public void MultiThreadBufferFullTest()
        {
            global::NLog.Logger logger;
            try
            {
                LogManager.Configuration = new XmlLoggingConfiguration("Regular.config");
            }
            catch (FileNotFoundException)
            {
                LogManager.Configuration = new XmlLoggingConfiguration("./test/AWS.Logger.NLog.Tests/Regular.config");
            }
            logger = LogManager.GetLogger("loggerMultiThreadBufferFull");
            var tasks       = new List <Task>();
            var streamNames = new List <string>();
            var count       = 200;
            var totcount    = 0;

            for (int i = 0; i < 2; i++)
            {
                tasks.Add(Task.Factory.StartNew(() => NLogThread(count, logger)));
                totcount = totcount + count;
            }
            Task.WaitAll(tasks.ToArray());

            string region       = "us-west-2";
            string logGroupName = "AWSNLogGroupMultiThreadBufferFullTest";

            Thread.Sleep(10000);
            AmazonCloudWatchLogsClient client = new AmazonCloudWatchLogsClient(
                Amazon.RegionEndpoint.GetBySystemName(region));

            DescribeLogStreamsResponse describeLogstreamsResponse = client.DescribeLogStreamsAsync(new DescribeLogStreamsRequest
            {
                Descending   = true,
                LogGroupName = logGroupName,
                OrderBy      = "LastEventTime"
            }).Result;


            List <string> logStreamNames = new List <string>();

            logStreamNames.Add(describeLogstreamsResponse.LogStreams[0].LogStreamName);
            FilterLogEventsResponse filterLogEventsResponse = client.FilterLogEventsAsync(new FilterLogEventsRequest
            {
                FilterPattern  = "maximum",
                LogGroupName   = logGroupName,
                LogStreamNames = logStreamNames
            }).Result;

            Assert.NotEmpty(filterLogEventsResponse.Events);
        }
        public async Task FilterLogEventsTest__OnlyUsedOnce()
        {
            var request   = new FilterLogEventsRequest();
            var response  = new FilterLogEventsResponse();
            var token     = new CancellationToken();
            var paginator = _mockClient.Object.Paginators.FilterLogEvents(request);

            _mockClient.Setup(x => x.FilterLogEventsAsync(It.IsAny <FilterLogEventsRequest>(), It.IsAny <CancellationToken>())).ReturnsAsync(response);

            // Should work the first time
            await LoopOverFilterLogEvents(paginator, token);

            // Second time should throw an exception
            await Assert.ThrowsAsync <System.InvalidOperationException>(async() => await LoopOverFilterLogEvents(paginator, token));
        }
Пример #6
0
        public void MultiThreadBufferFullTest()
        {
            ILog logger;

            XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
            logger = LogManager.GetLogger("MultiThreadBufferFullTest");

            var tasks    = new List <Task>();
            var count    = 200;
            var totcount = 0;

            for (int i = 0; i < 2; i++)
            {
                tasks.Add(Task.Factory.StartNew(() => Log4NetThread(count, logger)));
                totcount = totcount + count;
            }
            Task.WaitAll(tasks.ToArray(), 10000);

            Thread.Sleep(10000);
            string region       = "us-west-2";
            string logGroupName = "AWSLog4NetGroupMultiThreadBufferFullTest";

            AmazonCloudWatchLogsClient client = new AmazonCloudWatchLogsClient(
                Amazon.RegionEndpoint.GetBySystemName(region));

            DescribeLogStreamsResponse describeLogstreamsResponse = client.DescribeLogStreamsAsync(new DescribeLogStreamsRequest
            {
                Descending   = true,
                LogGroupName = logGroupName,
                OrderBy      = "LastEventTime"
            }).Result;

            List <string> logStreamNames = new List <string>();

            logStreamNames.Add(describeLogstreamsResponse.LogStreams[0].LogStreamName);
            FilterLogEventsResponse filterLogEventsResponse = client.FilterLogEventsAsync(new FilterLogEventsRequest
            {
                FilterPattern  = "maximum",
                LogGroupName   = logGroupName,
                LogStreamNames = logStreamNames
            }).Result;

            Assert.NotEmpty(filterLogEventsResponse.Events);
        }
Пример #7
0
        public void MultiThreadBufferFullTest()
        {
            var tasks       = new List <Task>();
            var streamNames = new List <string>();

            ILoggerMultiThreadTestSetup("multiThreadBufferFullTest.json");
            logger = ILoggerTest.LoggerSetup();
            var count    = 200;
            var totcount = 0;

            for (int i = 0; i < 2; i++)
            {
                tasks.Add(Task.Factory.StartNew(() => ILoggerThread(count)));
                totcount = totcount + count;
            }
            Task.WaitAll(tasks.ToArray(), 10000);

            //Sleep is introduced to give suffiecient time for the logstream to get posted on CloudWatchLogs
            Thread.Sleep(5000);
            string region       = ILoggerTest._configSection.Config.Region;
            string logGroupName = ILoggerTest._configSection.Config.LogGroup;

            AmazonCloudWatchLogsClient client = new AmazonCloudWatchLogsClient(
                Amazon.RegionEndpoint.GetBySystemName(region));

            DescribeLogStreamsResponse describeLogstreamsResponse = client.DescribeLogStreamsAsync(new DescribeLogStreamsRequest
            {
                Descending   = true,
                LogGroupName = logGroupName,
                OrderBy      = "LastEventTime"
            }).Result;

            List <string> logStreamNames = new List <string>();

            logStreamNames.Add(describeLogstreamsResponse.LogStreams[0].LogStreamName);
            FilterLogEventsResponse filterLogEventsResponse = client.FilterLogEventsAsync(new FilterLogEventsRequest
            {
                FilterPattern  = "maximum",
                LogGroupName   = logGroupName,
                LogStreamNames = logStreamNames
            }).Result;

            Assert.NotEmpty(filterLogEventsResponse.Events);
        }
Пример #8
0
        public bool FilterPatternExists(string logGroupName, string filterPattern)
        {
            DescribeLogStreamsResponse describeLogstreamsResponse;

            try
            {
                describeLogstreamsResponse = Client.
                                             DescribeLogStreamsAsync(new DescribeLogStreamsRequest
                {
                    Descending   = true,
                    LogGroupName = logGroupName,
                    OrderBy      = "LastEventTime"
                }).Result;
            }
            catch (Exception) {
                return(false);
            }

            if (describeLogstreamsResponse.LogStreams.Count > 0)
            {
                List <string> logStreamNames = new List <string>();
                logStreamNames.Add(describeLogstreamsResponse.LogStreams[0].LogStreamName);
                FilterLogEventsResponse filterLogEventsResponse = Client.
                                                                  FilterLogEventsAsync(new FilterLogEventsRequest
                {
                    FilterPattern  = filterPattern,
                    LogGroupName   = logGroupName,
                    LogStreamNames = logStreamNames
                }).Result;

                return(filterLogEventsResponse.Events.Count > 0);
            }
            else
            {
                return(false);
            }
        }
        public async Task FilterLogEventsTest__CancellationToken()
        {
            var request       = new FilterLogEventsRequest();
            var firstResponse = new FilterLogEventsResponse()
            {
                NextToken = "foo"
            };
            var secondResponse = new FilterLogEventsResponse()
            {
                NextToken = null
            };
            var paginator = _mockClient.Object.Paginators.FilterLogEvents(request);

            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;

            tokenSource.Cancel();

            _mockClient.SetupSequence(x => x.FilterLogEventsAsync(It.IsAny <FilterLogEventsRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(firstResponse)
            .ReturnsAsync(secondResponse);

            await Assert.ThrowsAsync <OperationCanceledException>(async() => await LoopOverFilterLogEvents(paginator, token));
        }