public void GET_REQUEST_BODY_GETS_NULL_WHEN_PASS_NULL_START_DATE()
        {
            DateTime?startDate = null;
            string   result    = ElasticSearchRESTAdapter.GetRequestBody(start: startDate);

            Assert.IsNull(result);
        }
        public void GET_REQUEST_BODY_RETURNS_CORRECT_WHEN_PARAMETERS_CORRECT()
        {
            DateTime?startDate = DateTime.Now.AddDays(-1);
            DateTime?endDate   = DateTime.Now;

            string result = ElasticSearchRESTAdapter.GetRequestBody(start: startDate, end: endDate);

            Assert.IsNotNull(result);
        }
        public void GET_REQUEST_BODY_RETURNS_NULL_WHEN_START_DATE_GREATER_THAN_END_DATE()
        {
            DateTime?startDate = DateTime.Now;
            DateTime?endDate   = DateTime.Now.AddDays(-1);

            string result = ElasticSearchRESTAdapter.GetRequestBody(start: startDate, end: endDate);

            Assert.IsNull(result);
        }
        public void GET_REQUEST_BODY_GETS_NULL_WHEN_PASS_END_DATE_IS_CORRECT_BUT_START_DATE_IS_NULL()
        {
            DateTime?startDate = null;
            DateTime?endDate   = DateTime.Now;

            string result = ElasticSearchRESTAdapter.GetRequestBody(start: startDate, end: endDate);

            Assert.IsNull(result);
        }
        public void GET_REQUEST_BODY_GETS_NULL_WHEN_PASS_BOTH_PARAMETERS_NULL()
        {
            DateTime?startDate = null;
            DateTime?endDate   = null;

            string result = ElasticSearchRESTAdapter.GetRequestBody(start: startDate, end: endDate);

            Assert.IsNull(result);
        }
        public void GET_FULL_INDEX_NAME_RETURNS_NULL_WHEN_INDEXPATTERN_IS_NULL()
        {
            string   indexName         = "index-1";
            string   indexPattern      = null;
            DateTime?indexPatternValue = DateTime.Now;

            string result = ElasticSearchRESTAdapter.GetFullIndexName(index: indexName, indexPattern: indexPattern, indexPatternValue: indexPatternValue);

            Assert.IsNull(result);
        }
        public void GET_FULL_INDEX_NAME_RETURNS_VALUE_WHEN_INDEXPATTERN_IS_DATE_FORMAT()
        {
            string   indexName         = "index-1";
            string   indexPattern      = "yyyy.MM.dd";
            DateTime?indexPatternValue = DateTime.Now;

            string result = ElasticSearchRESTAdapter.GetFullIndexName(index: indexName, indexPattern: indexPattern, indexPatternValue: indexPatternValue);

            string expected = indexName + "-" + indexPatternValue.Value.ToString(indexPattern);

            Assert.AreEqual(expected, result);
        }
        public void GET_FULL_INDEX_NAME_RETURNS_VALUE_WHEN_INDEXPATTERN_IS_CORRECT()
        {
            string   indexName         = "index-1";
            string   indexPattern      = "*";
            DateTime?indexPatternValue = null;

            string result = ElasticSearchRESTAdapter.GetFullIndexName(index: indexName, indexPattern: indexPattern, indexPatternValue: indexPatternValue);

            string expected = indexName + "-" + indexPattern;

            Assert.AreEqual(expected, result);
        }
Esempio n. 9
0
        private async Task ProcessIndexAsync(SearchIndex searchIndex)
        {
            DateTime startDate     = this._kpiService.GetSearchRange(searchIndex.IndexId); // Get last log insertion date
            int      fragmentCount = CalculateLoopCount(startDate);                        // Calculate fragment count

            DateTime searchRange = startDate;

            for (int i = 0; i < fragmentCount; i++)
            {
                searchRange = searchRange.AddMinutes(CommonFunctions.UnifyingConstant); // add 15 min for each iteration.

                string requestBody   = ElasticSearchRESTAdapter.GetRequestBody(start: searchRange);
                string fullIndexName = ElasticSearchRESTAdapter.GetFullIndexName(index: searchIndex.IndexName, indexPattern: searchIndex.IndexPattern, indexPatternValue: searchRange);
                Root   responseRoot  = await ElasticSearchRESTAdapter.GetResponseFromElasticUrlAsync(urlAddress : searchIndex.UrlAddress, index : fullIndexName, requestBody : requestBody);

                if (responseRoot == null)
                {
                    // Root is null for current search range
                    // Check for next day of search range > today
                    // Example: searchRange: 05.01.2020 -> 06.01.2020 > 10.01.2020 ?
                    double checkForNextDay = (DateTime.Now - searchRange.AddDays(1)).TotalMilliseconds;
                    if (checkForNextDay < 0)
                    {
                        break; // it became greater than current date.
                    }

                    searchRange = searchRange.AddDays(1); // Increase search range by one day
                    // then increase the current loop iterator for increment above to prevent out of range exception.
                    // 24 Hour * 60 Min / fragmentation by minute) - 1 for current iteration
                    i += (24 * 60 / CommonFunctions.UnifyingConstant) - 1;

                    ConsoleLogging.LogLine($"{searchIndex.UrlAddress}-> {searchIndex.IndexName} is expired, skipped to [{i + 1}/{fragmentCount}].");
                    continue;
                }

                InsertDataToDatabase(aggregation: responseRoot.Aggregation, indexId: searchIndex.IndexId, logDate: searchRange);

                ConsoleLogging.LogLine($"{searchIndex.UrlAddress}-> {searchIndex.IndexName} [{i + 1}/{fragmentCount}] added.");
            }
        }