Esempio n. 1
0
        private void StartTotalUsageProjection()
        {
            var eventName = nameof(CalculatorActor.CalculationPerformed);

            StartProjection(eventName,
                            KnownProjectionsNames.TotalFunctionUsage,
                            nameof(FunctionsTotalUsageProjector),
                            FunctionTotalUsageFlow.Instance,
                            FunctionTotalUsageSink.Create(Context, eventName));
        }
Esempio n. 2
0
        public async Task Given_journal_When_starting_projection_stream_Then_projection_launched_producing_data()
        {
            var dep = await Init();

            _output.WriteLine(Sys.Settings.ToString());
            //generate some data
            var calculationActor = Sys.ActorOf(Props.Create <CalculatorActor>(), "CalculatorOne");

            calculationActor.Tell(new CalculatorActorProtocol.CalculateExpression("1+2-3"));
            calculationActor.Tell(new CalculatorActorProtocol.CalculateExpression("1-2*3"));
            calculationActor.Tell(new CalculatorActorProtocol.CalculateExpression("1/2+3"));

            var eventName = nameof(CalculatorActor.CalculationPerformed);

            var readJournal      = PersistenceQuery.Get(Sys).ReadJournalFor <SqlReadJournal>(SqlReadJournal.Identifier);
            var sharedKillSwitch = KillSwitches.Shared("test");
            var source           = readJournal.EventsByTag(eventName, Offset.NoOffset())
                                   .Via(sharedKillSwitch.Flow <EventEnvelope>());

            var flow = FunctionTotalUsageFlow.Instance;
            var sink = FunctionTotalUsageSink.Create(Sys, eventName);

            source.Via(flow).To(sink).Run(Sys.Materializer());

            await Task.Delay(5000);

            var projected = new FindProjectionQuery(dep.CreateFunctionUsageContext()).ExecuteForFunctionsTotalUsage();

            Assert.Equal(3, projected.Sequence);

            var usage = await new FunctionsTotalUsageQuery(dep.CreateFunctionUsageContext()).Execute();

            usage.Should().BeEquivalentTo(
                new FunctionTotalUsage {
                FunctionName = "AddChecked", InvocationsCount = 2
            },
                new FunctionTotalUsage {
                FunctionName = "SubtractChecked", InvocationsCount = 2
            },
                new FunctionTotalUsage {
                FunctionName = "MultiplyChecked", InvocationsCount = 1
            },
                new FunctionTotalUsage {
                FunctionName = "Divide", InvocationsCount = 1
            });
        }
        public async Task Given_sink_and_flow_When_pushing_events_to_it_Then_they_should_be_projected()
        {
            var dep = Init(nameof(Given_sink_and_flow_When_pushing_events_to_it_Then_they_should_be_projected));

            var source = Source.From(new[]
            {
                new EventEnvelope(Offset.Sequence(1), "calcA", 1,
                                  new CalculatorActor.CalculationPerformed("calcA", "a+b+c+d", null, new[] { "add", "add", "add", "add" })),
                new EventEnvelope(Offset.Sequence(2), "calcB", 1,
                                  new CalculatorActor.CalculationPerformed("calcB", "a-b+c", null, new[] { "sub", "add" })),
                new EventEnvelope(Offset.Sequence(3), "calcA", 2,
                                  new CalculatorActor.CalculationPerformed("calcA", "a+b", null, new[] { "add" })),
                new EventEnvelope(Offset.Sequence(4), "calcC", 1,
                                  new CalculatorActor.CalculationPerformed("calcC", "a+b*e", null, new[] { "add", "mul" })),
            });
            var sink = FunctionTotalUsageSink.Create(Sys, "testEvent");
            var flow = FunctionTotalUsageFlow.Instance;

            source.Via(flow).To(sink).Run(Sys.Materializer());

            await Task.Delay(3000);

            var projection = dep.CreateFindProjectionQuery().Execute(KnownProjectionsNames.TotalFunctionUsage,
                                                                     nameof(FunctionsTotalUsageProjector), "testEvent");

            Assert.NotNull(projection);

            var projectedData = await new FunctionsTotalUsageQuery(dep.CreateFunctionUsageContext()).Execute("");

            projectedData.Should().BeEquivalentTo(
                new FunctionTotalUsage {
                FunctionName = "add", InvocationsCount = 7
            },
                new FunctionTotalUsage {
                FunctionName = "sub", InvocationsCount = 1
            },
                new FunctionTotalUsage {
                FunctionName = "mul", InvocationsCount = 1
            }
                );
        }
Esempio n. 4
0
        public async Task Given_sink_When_pushing_events_to_it_Then_they_should_be_projected()
        {
            var dep = Init(nameof(Given_sink_When_pushing_events_to_it_Then_they_should_be_projected));

            var source = Source.From(new[]
            {
                new SequencedFunctionTotalUsage {
                    FunctionName = "myFunc", InvocationsCount = 5, Sequence = 13
                },
                new SequencedFunctionTotalUsage {
                    FunctionName = "myFunc", InvocationsCount = 6, Sequence = 14
                },
                new SequencedFunctionTotalUsage {
                    FunctionName = "addition", InvocationsCount = 1, Sequence = 15
                },
            });

            var sink = FunctionTotalUsageSink.Create(Sys, "testEvent");

            source.RunWith(sink, Sys.Materializer());

            await Task.Delay(3000);

            var projection = dep.CreateFindProjectionQuery().Execute(KnownProjectionsNames.TotalFunctionUsage,
                                                                     nameof(FunctionsTotalUsageProjector), "testEvent");

            Assert.NotNull(projection);
            var projectedData = await new FunctionsTotalUsageQuery(dep.CreateFunctionUsageContext()).Execute("");

            projectedData.Should().BeEquivalentTo(
                new FunctionTotalUsage {
                FunctionName = "myFunc", InvocationsCount = 11
            },
                new FunctionTotalUsage {
                FunctionName = "addition", InvocationsCount = 1
            }
                );
        }