示例#1
0
 private void Configure(Event e)
 {
     this.Setup  = (SetupEvent)e;
     this.Buffer = new int[10000];
     this.Buffer[this.Buffer.Length - 1] = 1;
     this.Setup.Add(this.Buffer);
 }
        public void TestCreateActorIdFromName7()
        {
            this.TestWithError(async r =>
            {
                var setup = new SetupEvent();
                r.RegisterMonitor <TestMonitor>();
                r.Monitor <TestMonitor>(setup);
                var m = r.CreateActorIdFromName(typeof(M2), "M2");
                r.CreateActor(m, typeof(M2));

                // Make sure that the state machine halts.
                r.SendEvent(m, HaltEvent.Instance);

                await setup.Completed.Task;

                // Trying to bring up a halted state machine.
                r.CreateActor(m, typeof(M2));
            },
                               configuration: Configuration.Create().WithProductionMonitorEnabled(),
                               expectedErrors: new string[]
            {
                "Actor id '' is used by an existing or previously halted actor.",
                "An actor with id '0' was already created in generation '0'. This typically occurs if either the actor id was created by another runtime instance, or if a actor id from a previous runtime generation was deserialized, but the current runtime has not increased its generation value."
            },
                               replay: true);
        }
        protected override void WriteData(BinaryWriter w)
        {
            Texture.Write(w);

            w.Write((uint)Properties);
            w.Write((uint)Form);
            w.Write((uint)Anchors);
            w.Write((uint)Reactions);
            w.Write(Solidity);
            w.Write(Light);

            w.Write(Layer);
            w.Write(PartSize);
            w.Write(FramesCount);
            w.Write(FrameDelay);

            w.Write(OffsetX);
            w.Write(OffsetY);

            SetupEvent.Write(w);
            ReformEvent.Write(w);
            TouchEvent.Write(w);
            ActivateEvent.Write(w);
            RecieveEvent.Write(w);
            RemoveEvent.Write(w);

            w.Write(BackColor);
            w.Write(GridEnabled);
        }
示例#4
0
 protected override SystemTasks.Task OnInitializeAsync(Event e)
 {
     this.Setup = e as SetupEvent;
     this.Assert(this.CurrentEventGroup?.Name == EventGroup1);
     this.Child = this.CreateActor(typeof(M6B), e);
     return(base.OnInitializeAsync(e));
 }
        public void TestCreateActorIdFromName7()
        {
            if (this.SchedulingPolicy is SchedulingPolicy.None)
            {
                // Production runtime allows reuse of a machine id because it does not keep track
                // of halted machines.
                return;
            }

            this.TestWithError(async r =>
            {
                var setup = new SetupEvent();
                r.RegisterMonitor <TestMonitor>();
                r.Monitor <TestMonitor>(setup);
                var m = r.CreateActorIdFromName(typeof(M2), "M2");
                r.CreateActor(m, typeof(M2));

                // Make sure that the state machine halts.
                r.SendEvent(m, HaltEvent.Instance);

                await setup.Completed.Task;

                // Trying to bring up a halted state machine.
                r.CreateActor(m, typeof(M2));
            },
                               configuration: Configuration.Create().WithProductionMonitorEnabled(),
                               expectedErrors: new string[]
            {
                "Actor id '' is used by an existing or previously halted actor.",
                "An actor with id '0' was already created by another runtime instance."
            },
                               replay: true);
        }
示例#6
0
            protected override SystemTasks.Task OnInitializeAsync(Event e)
            {
                this.Setup = e as SetupEvent;
                var target = this.CreateActor(typeof(M8B));

                this.SendEvent(target, new E(this.Id));
                return(base.OnInitializeAsync(e));
            }
示例#7
0
        public async Task MeasurePushTransitionThroughput()
        {
            var tcs   = new TaskCompletionSource <bool>();
            var setup = new SetupEvent(tcs, NumTransitions);

            this.Runtime.CreateActor(typeof(M), null, setup);
            await tcs.Task;
        }
        public void MeasureGotoTransitionThroughput()
        {
            var tcs   = new TaskCompletionSource <bool>();
            var setup = new SetupEvent(tcs, NumTransitions);

            this.Runtime.CreateActor(typeof(M), null, setup);
            setup.Tcs.Task.Wait();
        }
示例#9
0
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     SetupClub.Setup(modelBuilder.Entity <Club>());
     SetupEntrant.Setup(modelBuilder.Entity <Entrant>());
     SetupMarshal.Setup(modelBuilder.Entity <Marshal>());
     SetupEvent.Setup(modelBuilder.Entity <Event>());
     SetupTestRun.Setup(modelBuilder.Entity <TestRun>());
     SetupProfile.Setup(modelBuilder.Entity <Profile>());
     SetupNotification.Setup(modelBuilder.Entity <Notification>());
 }
示例#10
0
        public void MeasurePushTransitionThroughput()
        {
            var configuration = Configuration.Create();
            var runtime       = RuntimeFactory.Create(configuration);
            var tcs           = new TaskCompletionSource <bool>();
            var e             = new SetupEvent(tcs, this.NumTransitions);

            runtime.CreateActor(typeof(M), null, e);
            tcs.Task.Wait();
        }
示例#11
0
 public void TestEventGroupClearedBySend()
 {
     this.Test(async r =>
     {
         var e = new SetupEvent();
         r.CreateActor(typeof(M5A), e, new EventGroup(name: EventGroup1));
         var result = await this.GetResultAsync(e.Tcs);
         Assert.True(result is null);
     });
 }
示例#12
0
 public void TestEventGroupTwoActorsSendBack()
 {
     this.Test(async r =>
     {
         var e = new SetupEvent();
         r.CreateActor(typeof(M7A), e, new EventGroup(name: EventGroup1));
         var result = await this.GetResultAsync(e.Tcs);
         Assert.Equal(EventGroup2, result);
     });
 }
示例#13
0
 public void TestGetEventGroupIdSet()
 {
     this.Test(async r =>
     {
         var e = new SetupEvent();
         r.CreateActor(typeof(M2), e);
         var result = await this.GetResultAsync(e.Tcs);
         Assert.Equal(EventGroupId, result);
     });
 }
示例#14
0
 public void TestNullEventGroup()
 {
     this.Test(async r =>
     {
         var e = new SetupEvent();
         r.CreateActor(typeof(M1), e);
         var result = await this.GetResultAsync(e.Tcs);
         Assert.True(result is null);
     });
 }
示例#15
0
 public void TestNullEventGroupPropagation()
 {
     this.Test(async r =>
     {
         var e = new SetupEvent();
         var a = r.CreateActor(typeof(M6A), e, new EventGroup(name: EventGroup1));
         r.SendEvent(a, new E(), EventGroup.Null); // clear the event group!
         var result = await this.GetResultAsync(e.Tcs);
         Assert.True(result is "ok", string.Format("result is {0}", result));
     });
 }
 public void TestCreateActorIdFromName11()
 {
     this.Test(async r =>
     {
         var setup = new SetupEvent();
         r.RegisterMonitor <TestMonitor>();
         r.Monitor <TestMonitor>(setup);
         r.CreateActor(typeof(M7));
         await setup.Completed.Task;
     }, Configuration.Create().WithProductionMonitorEnabled());
 }
        public void MeasureCreationThroughput()
        {
            var tcs   = new TaskCompletionSource <bool>();
            var setup = new SetupEvent(tcs, NumMachines, this.DoHalt);

            for (int idx = 0; idx < NumMachines; idx++)
            {
                this.Runtime.CreateActor(typeof(M), null, setup);
            }

            setup.Tcs.Task.Wait();
        }
示例#18
0
 public void TestEventGroupChangedBySend()
 {
     this.Test(async r =>
     {
         var e = new SetupEvent()
         {
             Name = EventGroup1
         };
         r.CreateActor(typeof(M3), e, new EventGroup(name: EventGroup2));
         var result = await this.GetResultAsync(e.Tcs);
         Assert.Equal(EventGroup1, result);
     });
 }
示例#19
0
 public void TestEventGroupSetByHand()
 {
     this.Test(async r =>
     {
         var e = new SetupEvent()
         {
             Name = EventGroup1
         };
         r.CreateActor(typeof(M3), e);
         var result = await this.GetResultAsync(e.Tcs);
         Assert.Equal(EventGroup1, result);
     });
 }
示例#20
0
        public void TestNoMemoryLeakInEventSending()
        {
            this.Test(async r =>
            {
                var setup = new SetupEvent();
                r.CreateActor(typeof(M), setup);

                await this.WaitAsync(setup.Tcs.Task, 10000);

                (r as ActorRuntime).Stop();

                AssertNoLeaks(setup);
            });
        }
示例#21
0
        public void MeasureMachineCreation()
        {
            var runtime = new ProductionRuntime();

            var tcs = new TaskCompletionSource <bool>();
            var e   = new SetupEvent(tcs, NumMachines, DoHalt);

            for (int idx = 0; idx < NumMachines; idx++)
            {
                runtime.CreateMachine(typeof(M), null, e, null);
            }

            tcs.Task.Wait();
        }
 public void TestCreateActorIdFromName1()
 {
     this.Test(async r =>
     {
         var setup = new SetupEvent(2);
         r.RegisterMonitor <TestMonitor>();
         r.Monitor <TestMonitor>(setup);
         var m1 = r.CreateActor(typeof(M));
         var m2 = r.CreateActorIdFromName(typeof(M), "M");
         r.Assert(!m1.Equals(m2));
         r.CreateActor(m2, typeof(M));
         await setup.Completed.Task;
     },
               Configuration.Create().WithProductionMonitorEnabled());
 }
示例#23
0
        public void MeasureThroughputMachineCreation()
        {
            var configuration = Configuration.Create();
            var runtime       = new ProductionRuntime(configuration);

            var tcs = new TaskCompletionSource <bool>();
            var e   = new SetupEvent(tcs, this.NumMachines, this.DoHalt);

            for (int idx = 0; idx < this.NumMachines; idx++)
            {
                runtime.CreateMachine(typeof(M), null, e);
            }

            tcs.Task.Wait();
        }
示例#24
0
        protected override Task OnInitializeAsync(Event initialEvent)
        {
            var setup = initialEvent as SetupEvent;

            this.ClientInfo   = setup;
            this.NumResponses = 0;

            // Start by sending the first request.
            this.SendNextRequest();

            // Create a periodic timer to retry sending requests, if needed.
            // The chosen time does not matter, as the client will run under
            // test mode, and thus the time is controlled by the runtime.
            this.StartPeriodicTimer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
            return(Task.CompletedTask);
        }
示例#25
0
        public void TestStateMachineFinalizerInvoked()
        {
            var tracker = new GCTracker();

            var           config = this.GetConfiguration().WithTestingIterations(2);
            TestingEngine engine = TestingEngine.Create(config, (IActorRuntime r) =>
            {
                var setup = new SetupEvent(tracker);
                r.CreateActor(typeof(M), setup);
            });

            engine.Run();

            // Force a full GC.
            GC.Collect(2);
            GC.WaitForFullGCComplete();
            GC.WaitForPendingFinalizers();
            Assert.True(tracker.IsFinalized, "Finalizer was not called.");
        }
示例#26
0
        public void TestNoMemoryLeakAfterHalt()
        {
            this.Test(async r =>
            {
                // test that actors don't leak after they've been halted and that
                // subsequent events that are dropped also don't leak.
                var setup = new SetupEvent()
                {
                    HaltTest = true
                };
                r.CreateActor(typeof(M), setup);

                await this.WaitAsync(setup.Tcs.Task, 10000);

                (r as ActorRuntime).Stop();

                AssertNoLeaks(setup);
            });
        }
示例#27
0
        protected override void ReadData(BinaryReader r)
        {
            if (Type != CurrentType)
            {
                throw new Exception(
                          "Resource have wrong type [" + TypeToString(Type) + "]. [" +
                          TypeToString(CurrentType) + "] required.");
            }
            if (Version != CurrentVersion)
            {
                throw new Exception(
                          "Resource have wrong version \"" + Version +
                          "]. [" + CurrentVersion + "] required.");
            }

            Texture.Read(r);

            Properties = (Property)r.ReadUInt32();
            Form       = (Shape)r.ReadUInt32();
            Anchors    = (Anchor)r.ReadUInt32();
            Reactions  = (Reaction)r.ReadUInt32();
            Solidity   = r.ReadInt32();
            Light      = r.ReadUInt32();

            Layer       = r.ReadInt32();
            PartSize    = r.ReadInt32();
            FramesCount = r.ReadInt32();
            FrameDelay  = r.ReadInt32();

            OffsetX = r.ReadInt32();
            OffsetY = r.ReadInt32();

            SetupEvent.Read(r);
            ReformEvent.Read(r);
            TouchEvent.Read(r);
            ActivateEvent.Read(r);
            RecieveEvent.Read(r);
            RemoveEvent.Read(r);

            BackColor   = r.ReadInt32();
            GridEnabled = r.ReadBoolean();
        }
示例#28
0
        private static void AssertNoLeaks(SetupEvent e)
        {
            int retries = 10;
            int count   = 0;

            do
            {
                GC.Collect(3);
                count = 0;
                foreach (WeakReference <int[]> item in e.Buffers)
                {
                    if (item.TryGetTarget(out int[] buffer))
                    {
                        count++;
                    }
                }
            }while (retries-- > 0 && count > 1);

            // MacOs really doesn't want to let go of the last one for some reason (perhaps
            // because we are also grabbing references in the above foreach statement).
            Assert.True(count <= 1);
        }
示例#29
0
 protected override SystemTasks.Task OnInitializeAsync(Event e)
 {
     this.Setup = e as SetupEvent;
     this.SendEvent(this.Id, new E(), new EventGroup(name: this.Setup.Name));
     return(base.OnInitializeAsync(e));
 }
示例#30
0
 protected override SystemTasks.Task OnInitializeAsync(Event e)
 {
     this.Setup = e as SetupEvent;
     this.Assert(this.CurrentEventGroup?.Name == EventGroup1);
     return(base.OnInitializeAsync(e));
 }