예제 #1
0
 public void test_NumberAvg()
 {
     FillMap <float>();
     FillMap <double>();
     Assert.AreEqual(4.5d, map.Aggregate(Aggregators.NumberAvg()));
     Assert.AreEqual(4.5d, map.Aggregate(Aggregators.NumberAvg("this")));
 }
예제 #2
0
        public void test_LongSum_withPredicate_field()
        {
            FillMap <Header>();
            var predicate = Predicates.IsGreaterThan("id", 5);

            Assert.AreEqual(30, map.Aggregate(Aggregators.LongSum("id"), predicate));
        }
예제 #3
0
 public void test_FixedPointSum()
 {
     FillMap <float>();
     FillMap <double>();
     Assert.AreEqual(90, map.Aggregate(Aggregators.FixedPointSum()));
     Assert.AreEqual(90, map.Aggregate(Aggregators.FixedPointSum("this")));
 }
예제 #4
0
 public void testAggregate_NullPredicate()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         map.Aggregate(Aggregators.LongSum("id"), null);
     });
 }
예제 #5
0
 public StatsRouter CreateStatsRouter(
     Serializers serializers,
     BufferBuilder bufferBuilder,
     Aggregators optionalAggregators)
 {
     return(new StatsRouter(serializers, bufferBuilder, optionalAggregators));
 }
예제 #6
0
        public void test_Count_with_Predicate()
        {
            FillMap <int>();
            var predicate = Predicates.IsGreaterThan("this", 5);

            Assert.AreEqual(4, map.Aggregate(Aggregators.Count(), predicate));
            Assert.AreEqual(4, map.Aggregate(Aggregators.Count("this"), predicate));
        }
        public async Task Test_LongSum_field()
        {
            var dictionary = await Client.GetMapAsync <string, Header>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => new Header(i, new Handle(false)));

            Assert.AreEqual(45, await dictionary.AggregateAsync(Aggregators.LongSum("id")));
        }
        public async Task Test_AggregateAny()
        {
            var dictionary = await Client.GetMapAsync <string, Item>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => new Item(new Header(i, new Handle(false)), new int[1], new int[1]));

            Assert.AreEqual(10, await dictionary.AggregateAsync(Aggregators.Count("enabled[any]")));
        }
        public override object VisitAggregator(CryslGrammarParser.AggregatorContext context)
        {
            Aggregator         aggregator      = new Aggregator();
            List <Aggregators> aggregatorsList = new List <Aggregators>();

            foreach (var varName in context.VARNAME())
            {
                Aggregators aggregators = new Aggregators();
                //check for aggregators name
                if (varName.Symbol.TokenIndex < context.COLON().Symbol.TokenIndex&& varName.Symbol.TokenIndex < context.EQUALS().Symbol.TokenIndex)
                {
                    aggregator.Aggregator_Name = varName.GetText();
                }

                //check for aggregators varname and regex between aggregators
                if (varName.Symbol.TokenIndex > context.COLON().Symbol.TokenIndex&& varName.Symbol.TokenIndex > context.EQUALS().Symbol.TokenIndex)
                {
                    //aggregatorsDict.Add("aggregator_event_varname", varName.GetText());
                    aggregators.Aggregator_Event_Varname = varName.GetText();

                    //Check for OR symbol
                    foreach (var aggOrSymbol in context.OR())
                    {
                        if (!String.IsNullOrEmpty(aggOrSymbol.GetText()))
                        {
                            int tokenDifference = aggOrSymbol.Symbol.TokenIndex - varName.Symbol.TokenIndex;
                            if (tokenDifference == 1)
                            {
                                aggregators.Aggregator_Regex = aggOrSymbol.GetText();
                            }
                        }
                    }

                    //check for AND symbol
                    foreach (var aggAndSymbol in context.AND())
                    {
                        if (!String.IsNullOrEmpty(aggAndSymbol.GetText()))
                        {
                            int tokenDifference = aggAndSymbol.Symbol.TokenIndex - varName.Symbol.TokenIndex;
                            if (tokenDifference == 1)
                            {
                                //aggregatorsDict.Add("aggregator_regex", aggAndSymbol.GetText());
                                aggregators.Aggregator_Regex = aggAndSymbol.GetText();
                            }
                        }
                    }
                }
                if (!String.IsNullOrEmpty(aggregators.Aggregator_Event_Varname))
                {
                    aggregatorsList.Add(aggregators);
                }
            }
            aggregator.Aggregators = aggregatorsList;
            return(aggregator);
        }
        public async Task Test_BigIntegerSum()
        {
            var dictionary = await Client.GetMapAsync <string, BigInteger>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => new BigInteger(i));

            Assert.AreEqual(new BigInteger(45), await dictionary.AggregateAsync(Aggregators.BigIntegerSum()));
            Assert.AreEqual(new BigInteger(45), await dictionary.AggregateAsync(Aggregators.BigIntegerSum("this")));
        }
        public async Task TestAggregate_NullPredicate()
        {
            var dictionary = await Client.GetMapAsync <string, int>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await AssertEx.ThrowsAsync <ArgumentException>(async() =>
            {
                await dictionary.AggregateAsync(Aggregators.LongSum("id"), null);
            });
        }
예제 #12
0
        internal void Process(IOlapDataVector dataVector, IEnumerable <IGroup> groupList)
        {
            Aggregators.ForEach(a => a.Aggregate(dataVector));
            var group = groupList.FirstOrDefault();

            if (group == null)
            {
                return;
            }
            GetOrCreateGroup(group).Process(dataVector, groupList.Skip(1));
        }
        public async Task Test_LongAvg()
        {
            var dictionary = await Client.GetMapAsync <string, int>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => i);

            Assert.AreEqual(4.5d, await dictionary.AggregateAsync(Aggregators.LongAvg()));
            Assert.AreEqual(4.5d, await dictionary.AggregateAsync(Aggregators.LongAvg("this")));
        }
        public async Task Test_FixedPointSum_MixedObject()
        {
            var name = CreateUniqueName();

            await using var dictionary = await Client.GetMapAsync <string, object>(name);

            await Fill(dictionary, i => (int)i);
            await Fill(dictionary, i => (long)i);

            Assert.AreEqual(90, await dictionary.AggregateAsync(Aggregators.FixedPointSum()));
            Assert.AreEqual(90, await dictionary.AggregateAsync(Aggregators.FixedPointSum("this")));
        }
        public async Task Test_FloatingPointSum_MixedObject()
        {
            var dictionary = await Client.GetMapAsync <string, object>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => (float)i);
            await Fill(dictionary, i => (double)i);

            Assert.AreEqual(90d, await dictionary.AggregateAsync(Aggregators.FloatingPointSum()));
            Assert.AreEqual(90d, await dictionary.AggregateAsync(Aggregators.FloatingPointSum("this")));
        }
        public async Task Test_Count_with_Predicate()
        {
            var dictionary = await Client.GetMapAsync <string, int>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => i);

            var predicate = Predicates.GreaterThan("this", 5);

            Assert.AreEqual(4, await dictionary.AggregateAsync(Aggregators.Count(), predicate));
            Assert.AreEqual(4, await dictionary.AggregateAsync(Aggregators.Count("this"), predicate));
        }
예제 #17
0
        private void AssertAggregator <TResult>(AggregatorBase <TResult> aggregator, int classId)
        {
            var aggregatorType = aggregator.GetType();

            Assert.That(aggregator.FactoryId, Is.EqualTo(FactoryIds.AggregatorDsFactoryId));
            Assert.That(aggregator.ClassId, Is.EqualTo(classId));

            Assert.Throws <ArgumentException>(() => _ = Aggregators.Count(""));
            Assert.Throws <ArgumentException>(() => _ = Aggregators.Count(null));

            Assert.Throws <ArgumentNullException>(() => aggregator.WriteData(null));
            Assert.Throws <ArgumentNullException>(() => aggregator.ReadData(null));

            using var output = new ObjectDataOutput(1024, _serializationService, Endianness.BigEndian);
            aggregator.WriteData(output);

            using var input = new ObjectDataInput(output.Buffer, _serializationService, Endianness.BigEndian);
            var a = (AggregatorBase <TResult>)Activator.CreateInstance(aggregatorType);

            a.ReadData(input);

            Assert.That(a.AttributePath, Is.EqualTo(aggregator.AttributePath));

            var data = _serializationService.ToData(aggregator);

            if (aggregatorType.IsGenericType)
            {
                // doh - cannot deserialize generic types?
                IAggregator <object> x = null;

                if (aggregatorType.GetGenericTypeDefinition() == typeof(MaxAggregator <>))
                {
                    x = _serializationService.ToObject <MaxAggregator <object> >(data);
                }
                else if (aggregatorType.GetGenericTypeDefinition() == typeof(MinAggregator <>))
                {
                    x = _serializationService.ToObject <MinAggregator <object> >(data);
                }
                else
                {
                    Assert.Fail("Unsupported generic aggregator type.");
                }

                Assert.That(x.AttributePath, Is.EqualTo(aggregator.AttributePath));
            }
            else
            {
                var x = _serializationService.ToObject <IAggregator <TResult> >(data);
                Assert.That(x.AttributePath, Is.EqualTo(aggregator.AttributePath));
            }
        }
예제 #18
0
 public StatsRouter(
     Serializers serializers,
     BufferBuilder bufferBuilder,
     Aggregators optionalAggregators)
 {
     _serializers   = serializers;
     _bufferBuilder = bufferBuilder;
     if (optionalAggregators != null)
     {
         _optionalCountAggregator = optionalAggregators.OptionalCount;
         _optionalGaugeAggregator = optionalAggregators.OptionalGauge;
         _optionalSetAggregator   = optionalAggregators.OptionalSet;
     }
 }
예제 #19
0
        /// <summary>
        /// Duplicates configuration builder having own configuration lists. But registered configuration instances will still be the same.
        /// </summary>
        /// <returns>New instance of IStrategyBuilder</returns>
        IStrategyBuilder IStrategyBuilder.ShallowCopy()
        {
            return(new ReplayStrategyBuilder <TData>
            {
                ThreadCount = ThreadCount,
                DataReader = DataReader,
                SpeedMultiplier = SpeedMultiplier,
                Aggregators = Aggregators.ToArray(),

                ScenarioFactory = ScenarioFactory,

                FinishTimeout = FinishTimeout,
                InitialUserData = InitialUserData,
            });
        }
예제 #20
0
        public void Init()
        {
            _aggregator = new Aggregators
            {
                AggregationParams = new[] {
                    new AggregationInfo
                    {
                        MessageAggregateColumnNames = new[] { "Message", "MessageType", "Exception" }
                    }
                }
            };

            _message = new FieldsContainer();
            _message.Add("Message", "Exception");
        }
        public async Task Test_NumberAvg()
        {
            // .NET does not have a 'number' type, so we have to use 'object'

            var dictionary = await Client.GetMapAsync <string, object>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => (float)i);
            await Fill(dictionary, i => (double)i);
            await Fill(dictionary, i => (int)i);
            await Fill(dictionary, i => (long)i);

            Assert.AreEqual(4.5d, await dictionary.AggregateAsync(Aggregators.NumberAvg()));
            Assert.AreEqual(4.5d, await dictionary.AggregateAsync(Aggregators.NumberAvg("this")));
        }
        public async Task Test_FixedPointSum_MixedGeneric()
        {
            var name = CreateUniqueName();

            await using (var dictionary = await Client.GetMapAsync <string, int>(name))
            {
                await Fill(dictionary, i => i);
            }

            await using (var dictionary = await Client.GetMapAsync <string, long>(name))
            {
                await Fill(dictionary, i => i);
            }

            await using var d = await Client.GetMapAsync <string, int>(name);

            Assert.AreEqual(90, await d.AggregateAsync(Aggregators.FixedPointSum()));
            Assert.AreEqual(90, await d.AggregateAsync(Aggregators.FixedPointSum("this")));
        }
예제 #23
0
        public void Aggregate_AggregationColumnNameListaggregationColumnNameListIsNull_ReturnFalse()
        {
            var notificationAggregatorsValidator = new NotificationAggregatorsValidator();
            var listMessages = new List <NotificationMessage> {
                new NotificationMessage()
            };
            var aggregator = new Aggregators
            {
                AggregationParams = new[] {
                    new AggregationInfo
                    {
                        MessageAggregateColumnNames = new[] { "ApplicationName", "MessageType", "Exception" }
                    }
                }
            };

            notificationAggregatorsValidator.SetAggregators(aggregator);

            notificationAggregatorsValidator.AggregateIfPossible(listMessages, _message).Should().BeFalse();
        }
예제 #24
0
        private StatsBufferize CreateStatsBufferize(
            Telemetry telemetry,
            ITransport transport,
            int bufferCapacity,
            AdvancedStatsConfig config,
            Serializers serializers,
            ClientSideAggregationConfig optionalClientSideAggregationConfig)
        {
            var bufferHandler = new BufferBuilderHandler(telemetry, transport);
            var bufferBuilder = new BufferBuilder(bufferHandler, bufferCapacity, "\n");

            Aggregators optionalAggregators = null;

            if (optionalClientSideAggregationConfig != null)
            {
                var parameters = new MetricAggregatorParameters(
                    serializers.MetricSerializer,
                    bufferBuilder,
                    optionalClientSideAggregationConfig.MaxUniqueStatsBeforeFlush,
                    optionalClientSideAggregationConfig.FlushInterval);

                optionalAggregators = new Aggregators
                {
                    OptionalCount = new CountAggregator(parameters),
                    OptionalGauge = new GaugeAggregator(parameters),
                    OptionalSet   = new SetAggregator(parameters, telemetry),
                };
            }

            var statsRouter = _factory.CreateStatsRouter(serializers, bufferBuilder, optionalAggregators);

            var statsBufferize = _factory.CreateStatsBufferize(
                statsRouter,
                config.MaxMetricsInAsyncQueue,
                config.MaxBlockDuration,
                config.DurationBeforeSendingNotFullBuffer);

            return(statsBufferize);
        }
예제 #25
0
        public void Tests()
        {
            AssertAggregator((CountAggregator)Aggregators.Count("name"), AggregatorDataSerializerHook.Count);

            AssertAggregator((BigIntegerSumAggregator)Aggregators.BigIntegerSum("name"), AggregatorDataSerializerHook.BigIntSum);
            AssertAggregator((DoubleSumAggregator)Aggregators.DoubleSum("name"), AggregatorDataSerializerHook.DoubleSum);
            AssertAggregator((FixedSumAggregator)Aggregators.FixedPointSum("name"), AggregatorDataSerializerHook.FixedSum);
            AssertAggregator((LongSumAggregator)Aggregators.LongSum("name"), AggregatorDataSerializerHook.LongSum);
            AssertAggregator((FloatingPointSumAggregator)Aggregators.FloatingPointSum("name"), AggregatorDataSerializerHook.FloatingPointSum);
            AssertAggregator((IntegerSumAggregator)Aggregators.IntegerSum("name"), AggregatorDataSerializerHook.IntSum);

            AssertAggregator((NumberAverageAggregator)Aggregators.NumberAvg("name"), AggregatorDataSerializerHook.NumberAvg);
            AssertAggregator((DoubleAverageAggregator)Aggregators.DoubleAvg("name"), AggregatorDataSerializerHook.DoubleAvg);
            AssertAggregator((IntegerAverageAggregator)Aggregators.IntegerAvg("name"), AggregatorDataSerializerHook.IntAvg);
            AssertAggregator((LongAverageAggregator)Aggregators.LongAvg("name"), AggregatorDataSerializerHook.LongAvg);

            AssertAggregator((MaxAggregator <int>)Aggregators.Max <int>("name"), AggregatorDataSerializerHook.Max);
            AssertAggregator((MinAggregator <int>)Aggregators.Min <int>("name"), AggregatorDataSerializerHook.Min);

            AssertAggregator((CountAggregator)Aggregators.Count(), AggregatorDataSerializerHook.Count);

            AssertAggregator((BigIntegerSumAggregator)Aggregators.BigIntegerSum(), AggregatorDataSerializerHook.BigIntSum);
            AssertAggregator((DoubleSumAggregator)Aggregators.DoubleSum(), AggregatorDataSerializerHook.DoubleSum);
            AssertAggregator((FixedSumAggregator)Aggregators.FixedPointSum(), AggregatorDataSerializerHook.FixedSum);
            AssertAggregator((LongSumAggregator)Aggregators.LongSum(), AggregatorDataSerializerHook.LongSum);
            AssertAggregator((FloatingPointSumAggregator)Aggregators.FloatingPointSum(), AggregatorDataSerializerHook.FloatingPointSum);
            AssertAggregator((IntegerSumAggregator)Aggregators.IntegerSum(), AggregatorDataSerializerHook.IntSum);

            AssertAggregator((NumberAverageAggregator)Aggregators.NumberAvg(), AggregatorDataSerializerHook.NumberAvg);
            AssertAggregator((DoubleAverageAggregator)Aggregators.DoubleAvg(), AggregatorDataSerializerHook.DoubleAvg);
            AssertAggregator((IntegerAverageAggregator)Aggregators.IntegerAvg(), AggregatorDataSerializerHook.IntAvg);
            AssertAggregator((LongAverageAggregator)Aggregators.LongAvg(), AggregatorDataSerializerHook.LongAvg);

            AssertAggregator((MaxAggregator <int>)Aggregators.Max <int>(), AggregatorDataSerializerHook.Max);
            AssertAggregator((MinAggregator <int>)Aggregators.Min <int>(), AggregatorDataSerializerHook.Min);
        }
예제 #26
0
 public void test_Count()
 {
     FillMap <int>();
     Assert.AreEqual(10, map.Aggregate(Aggregators.Count()));
     Assert.AreEqual(10, map.Aggregate(Aggregators.Count("this")));
 }
예제 #27
0
파일: OlapCube.cs 프로젝트: lanicon/OLAP
 public OlapCube Min <T>(Func <IOlapDataVector, object> valueSelector, Func <IOlapDataVector, bool> aggregatePred = null, string title = "Min")
 {
     Aggregators.Add(AggregatorFactory.CreateMin <T>(valueSelector, aggregatePred));
     ValueTitles.Add(title);
     return(this);
 }
예제 #28
0
파일: OlapCube.cs 프로젝트: lanicon/OLAP
 public OlapCube Count <T>(Func <IOlapDataVector, bool> aggregatePred = null, string title = "Count")
 {
     Aggregators.Add(AggregatorFactory.CreateCount <T>(aggregatePred));
     ValueTitles.Add(title);
     return(this);
 }
예제 #29
0
파일: OlapCube.cs 프로젝트: lanicon/OLAP
 public OlapCube Aggregate(IAggregator aggregator, string title = "")
 {
     Aggregators.Add(aggregator);
     ValueTitles.Add(title);
     return(this);
 }
예제 #30
0
 public AAggregators GetAggregators(int readerId)
 {
     return(Aggregators.FirstOrDefault(x => Rules.Where(y => y.Value.Contains(readerId)).Any(z => z.Value.Contains(x.Id))));
 }