Exemplo n.º 1
0
 public void LoadOpenSearchResultCollection(Terradue.OpenSearch.Result.IOpenSearchResultCollection osr)
 {
     this.osr = osr;
 }
Exemplo n.º 2
0
 public void ApplyResultFilters(Terradue.OpenSearch.Request.OpenSearchRequest request, ref Terradue.OpenSearch.Result.IOpenSearchResultCollection osr, string finalContentType)
 {
 }
Exemplo n.º 3
0
        internal TestUnitResult MakeQuery(IOpenSearchable entity, FiltersDefinition fd)
        {
            List <IMetric> metrics = new List <IMetric>();

            log.DebugFormat("[{1}] > Query {0} {2}...", fd.Name, Task.CurrentId, fd.Label);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            DateTimeOffset timeStart = DateTimeOffset.UtcNow;

            var parameters = fd.GetNameValueCollection();

            return(catalogue_task_factory.StartNew(() =>
            {
                return ose.Query(entity, parameters);
            }).ContinueWith <TestUnitResult>(task =>
            {
                var respTime = sw.ElapsedMilliseconds;
                Terradue.OpenSearch.Result.IOpenSearchResultCollection results = null;
                try
                {
                    results = task.Result;
                }
                catch (AggregateException e)
                {
                    log.DebugFormat("[{0}] < No results for {2}. Exception: {1}", Task.CurrentId, e.InnerException.Message, fd.Label);
                    log.Debug(e.InnerException.StackTrace);
                    metrics.Add(new ExceptionMetric(e.InnerException));
                    metrics.Add(new LongMetric(MetricName.maxTotalResults, -1, "#"));
                    metrics.Add(new LongMetric(MetricName.totalReadResults, -1, "#"));
                }
                finally
                {
                    sw.Stop();
                }
                DateTimeOffset timeStop = DateTimeOffset.UtcNow;
                metrics.Add(new DateTimeMetric(MetricName.startTime, timeStart, "dateTime"));
                metrics.Add(new DateTimeMetric(MetricName.endTime, timeStop, "dateTime"));
                metrics.Add(new StringMetric(MetricName.dataCollectionDivision, fd.Label, "string"));
                if (results != null)
                {
                    foundItems.AddRange(results.Items);

                    long serializedSize = 0;
                    try
                    {
                        serializedSize = Encoding.Default.GetBytes(results.SerializeToString()).Length;
                    }
                    catch
                    {
                    }
                    var metricsArray = results.ElementExtensions.ReadElementExtensions <Terradue.OpenSearch.Benchmarking.Metrics>("Metrics", "http://www.terradue.com/metrics", Terradue.OpenSearch.Benchmarking.MetricFactory.Serializer);
                    if (metricsArray == null || metricsArray.Count() == 0)
                    {
                        log.Warn("No query metrics found! Response Time and error rate may be biased!");
                        metrics.Add(new LongMetric(MetricName.responseTime, respTime, "ms"));
                        metrics.Add(new LongMetric(MetricName.size, serializedSize, "bytes"));
                        metrics.Add(new LongMetric(MetricName.beginGetResponseTime, timeStart.Ticks, "ticks"));
                        metrics.Add(new LongMetric(MetricName.endGetResponseTime, timeStop.Ticks, "ticks"));
                    }
                    else
                    {
                        Terradue.OpenSearch.Benchmarking.Metrics osMetrics = metricsArray.First();
                        Terradue.OpenSearch.Benchmarking.Metric _sizeMetric = osMetrics.Metric.FirstOrDefault(m => m.Identifier == "size");
                        Terradue.OpenSearch.Benchmarking.Metric _responseTimeMetric = osMetrics.Metric.FirstOrDefault(m => m.Identifier == "responseTime");
                        Terradue.OpenSearch.Benchmarking.Metric _retryNumberMetric = osMetrics.Metric.FirstOrDefault(m => m.Identifier == "retryNumber");
                        Terradue.OpenSearch.Benchmarking.Metric _beginGetResponseTime = osMetrics.Metric.FirstOrDefault(m => m.Identifier == "beginGetResponseTime");
                        Terradue.OpenSearch.Benchmarking.Metric _endGetResponseTime = osMetrics.Metric.FirstOrDefault(m => m.Identifier == "endGetResponseTime");

                        log.DebugFormat("[{4}] < {0}/{1} entries for {6} {5}. {2}bytes in {3}ms", results.Count, results.TotalResults, _sizeMetric.Value, _responseTimeMetric.Value, Task.CurrentId, fd.Label, fd.Name);
                        if (_responseTimeMetric != null)
                        {
                            metrics.Add(new LongMetric(MetricName.responseTime, Convert.ToInt64(_responseTimeMetric.Value), "ms"));
                        }
                        else
                        {
                            metrics.Add(new LongMetric(MetricName.responseTime, respTime, "ms"));
                        }

                        if (_sizeMetric != null)
                        {
                            metrics.Add(new LongMetric(MetricName.size, Convert.ToInt64(_sizeMetric.Value), "bytes"));
                        }
                        else
                        {
                            metrics.Add(new LongMetric(MetricName.size, serializedSize, "bytes"));
                        }

                        if (_retryNumberMetric != null)
                        {
                            metrics.Add(new LongMetric(MetricName.retryNumber, Convert.ToInt64(_retryNumberMetric.Value), "#"));
                        }
                        else
                        {
                            metrics.Add(new LongMetric(MetricName.retryNumber, 1, "#"));
                        }

                        if (_beginGetResponseTime != null && _endGetResponseTime != null)
                        {
                            metrics.Add(new LongMetric(MetricName.beginGetResponseTime, Convert.ToInt64(_beginGetResponseTime.Value), "ticks"));
                            metrics.Add(new LongMetric(MetricName.endGetResponseTime, Convert.ToInt64(_endGetResponseTime.Value), "ticks"));
                        }
                        else
                        {
                            metrics.Add(new LongMetric(MetricName.beginGetResponseTime, timeStart.Ticks, "ticks"));
                            metrics.Add(new LongMetric(MetricName.endGetResponseTime, timeStop.Ticks, "ticks"));
                        }
                    }
                    metrics.Add(new LongMetric(MetricName.maxTotalResults, results.TotalResults, "#"));
                    metrics.Add(new LongMetric(MetricName.totalReadResults, results.Count, "#"));

                    if (results.Count == 0)
                    {
                        if (results.TotalResults > 0 && !ignoreEmptyResult)
                        {
                            log.WarnFormat("[{1}] no entries for {2} whilst {0} totalResult. This seems to be an error.", results.TotalResults, Task.CurrentId, fd.Label);
                            metrics.Add(new ExceptionMetric(new InvalidOperationException("No entries found")));
                        }
                    }
                    else
                    {
                        try
                        {
                            Stopwatch sw3 = new Stopwatch();
                            sw3.Start();
                            metrics.AddRange(AnalyzeResults(results, fd));
                            sw3.Stop();
                            metrics.Add(new LongMetric(MetricName.analysisTime, sw3.ElapsedMilliseconds, "msec"));
                        }
                        catch (Exception e)
                        {
                            metrics.Add(new ExceptionMetric(e));
                            log.ErrorFormat("[{0}] < Analysis failed for results {2} : {1}", Task.CurrentId, e.Message, fd.Label);
                            log.Debug(e.StackTrace);
                        }
                    }
                }

                return new TestUnitResult(metrics, fd);
            }).Result);
        }