예제 #1
0
 public void NetworkBehaviourCmdParamComponent()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: Cannot generate writer for component type MirrorTest.MirrorTestPlayer/ComponentClass. Use a supported type or provide a custom writer"));
 }
예제 #2
0
 public void TestRest()
 {
     Assert.Contains("a", new[] { "a", "b" });
     Assert.That(new[] { "a", "b" }, Contains.Item("a"));
     Assert.That(new[] { "a", "b" }, Does.Contain("b"));
 }
        public async Task ProcessJobsForMyDataCenter_XInQueueWithYConsumers_TakeNextApproach(int numberOfJobsToQueue, int numberOfConsumers)
        {
            var testStartTime    = DateTime.Now;
            var exampleQueueName = QueueId.Parse("ExampleQueue");

            await RunInMongoLand(async database =>
            {
                // Create two jobs that are relevant for my datacenter
                var creationService = new MongoJobCreationService(database);
                var jobsInQueue     = new List <JobId>();

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                for (int i = 0; i < numberOfJobsToQueue; i++)
                {
                    var newJobId = await creationService.Create(exampleQueueName, new JobAttributes
                    {
                        { "Name", "SpinWidget" },
                        { "DataCenter", "CAL01" },
                    }).ConfigureAwait(false);

                    jobsInQueue.Add(newJobId);
                }

                stopwatch.Stop();
                Console.WriteLine($"Creating {numberOfJobsToQueue} jobs took: {stopwatch.ElapsedMilliseconds} ms");

                var finishedJobs = new ConcurrentBag <Job>();

                var cancellationSource = new CancellationTokenSource();
                cancellationSource.CancelAfter(MaxTestTime);
                var cancellationToken = cancellationSource.Token;

                stopwatch.Reset();
                stopwatch.Start();

                for (int i = 0; i < numberOfConsumers; i++)
                {
                    var myDataCenter = new JobAttributes {
                        { "DataCenter", "CAL01" }
                    };

                    await SetupTakeNextWorkerWithSubscription(database, exampleQueueName, finishedJobs, myDataCenter, cancellationToken).ConfigureAwait(false);
                }

                do
                {
                    Thread.Sleep(100);
                } while (finishedJobs.Count < jobsInQueue.Count && DateTime.Now < testStartTime.Add(MaxTestTime));

                stopwatch.Stop();
                Console.WriteLine($"{numberOfConsumers} consumers processed {numberOfJobsToQueue} jobs in: {stopwatch.ElapsedMilliseconds} ms");

                cancellationSource.Cancel();

                var finishedJobIds = finishedJobs.Select(x => x.Id).ToList();
                foreach (var jobId in jobsInQueue)
                {
                    Assert.That(finishedJobIds, Contains.Item(jobId));
                }
            }).ConfigureAwait(false);
        }
예제 #4
0
 public void GotMissingInputWarnings()
 {
     Assert.That(_messages, Contains.Item("No input row found for block 2 of page 2"));
     Assert.That(_messages, Contains.Item("No input found for pages from 4 onwards."));
 }
        void AssertMessageIsLogged(string expectedMessage)
        {
            List <string> messages = messagesLogged.Select(m => m.ToString()).ToList();

            Assert.That(messages, Contains.Item(expectedMessage));
        }
예제 #6
0
 public void RecursionCount()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: MirrorTest.MirrorTestPlayer/Potato1 can't be serialized because it references itself"));
 }
예제 #7
0
 public void GotMissingBlockWarning()
 {
     Assert.That(_messages, Contains.Item("Input has 3 row(s) for page 2, but page 2 has only 1 place(s) for text"));
     Assert.That(_messages, Contains.Item("Input has 3 row(s) for page 5, but page 5 has only 2 place(s) for text"));
 }
예제 #8
0
 public void TargetRpcCantBeStatic()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: System.Void MirrorTest.MirrorTestPlayer::TargetCantBeStatic(Mirror.NetworkConnection) must not be static"));
 }
예제 #9
0
 public void SyncEventStartsWithEvent()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: MirrorTest.MirrorTestPlayer/MySyncEventDelegate MirrorTest.MirrorTestPlayer::DoCoolThingsWithExcitingPeople must start with Event.  Consider renaming it to EventDoCoolThingsWithExcitingPeople"));
 }
예제 #10
0
 public void ClientRpcStartsWithRpc()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: System.Void MirrorTest.MirrorTestPlayer::DoesntStartWithRpc() must start with Rpc.  Consider renaming it to RpcDoesntStartWithRpc"));
 }
예제 #11
0
 public void TargetRpcStartsWithTarget()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: System.Void MirrorTest.MirrorTestPlayer::DoesntStartWithTarget(Mirror.NetworkConnection) must start with Target.  Consider renaming it to TargetDoesntStartWithTarget"));
 }
예제 #12
0
 public void CommandCantBeStatic()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: System.Void MirrorTest.MirrorTestPlayer::CmdCantBeStatic() cannot be static"));
 }
예제 #13
0
 public void NetworkBehaviourCmdDuplicateName()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: Duplicate Command name [MirrorTest.MirrorTestPlayer:CmdCantHaveSameName]"));
 }
예제 #14
0
 public void NetworkBehaviourCmdParamNetworkConnection()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: System.Void MirrorTest.MirrorTestPlayer::CmdCantHaveParamOptional(Mirror.NetworkConnection) has invalid parameer monkeyCon. Cannot pass NeworkConnections"));
 }
예제 #15
0
 public void MessageMemberGeneric()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: Cannot generate writer for generic type MirrorTest.HasGeneric`1<System.Int32>. Use a concrete type or provide a custom writer"));
 }
예제 #16
0
 public void SyncEventParamGeneric()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: MirrorTest.MirrorTestPlayer/MySyncEventDelegate`1<System.Int32> MirrorTest.MirrorTestPlayer::EventDoCoolThingsWithExcitingPeople must not have generic parameters.  Consider creating a new class that inherits from MirrorTest.MirrorTestPlayer/MySyncEventDelegate`1<System.Int32> instead"));
 }
예제 #17
0
 public void MessageMemberInterface()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: Cannot generate writer for interface MirrorTest.SuperCoolInterface. Use a concrete type or provide a custom writer"));
 }
예제 #18
0
 public void MonoBehaviourSyncVar()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: [SyncVar] System.Int32 MirrorTest.MirrorTestPlayer::potato must be inside a NetworkBehaviour.  MirrorTest.MirrorTestPlayer is not a NetworkBehaviour"));
 }
예제 #19
0
 public void GotMissingInputWarning()
 {
     Assert.That(_messages, Contains.Item("No input row found for block 2 of page 1"));
 }
예제 #20
0
 public void MonoBehaviourSyncList()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: Mirror.SyncListInt MirrorTest.MirrorTestPlayer::potato is a SyncObject and must be inside a NetworkBehaviour.  MirrorTest.MirrorTestPlayer is not a NetworkBehaviour"));
 }
예제 #21
0
 public void GotMissingPagesWarning()
 {
     Assert.That(_messages, Contains.Item("Input has rows for page 3, but document has no page 3 that can hold text"));
     Assert.That(_messages, Contains.Item("Input has rows for page 4, but document has no page 4 that can hold text"));
     Assert.That(_messages, Contains.Item("Input has rows for page 6, but document has no page 6 that can hold text"));
 }
예제 #22
0
 public void MonoBehaviourTargetRpc()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: [TargetRpc] System.Void MirrorTest.MirrorTestPlayer::TargetThisCantBeOutsideNetworkBehaviour(Mirror.NetworkConnection) must be declared inside a NetworkBehaviour"));
 }
예제 #23
0
        public void WaitEvent()
        {
            var pA = _cpu.CurrentProcess;

            Instructions.Movi(_cpu, Register.A, 1);
            Instructions.WaitEvent(_cpu, Register.A);

            Assert.That(_cpu.CurrentProcess, Is.Null);
            Assert.That(_cpu.DeviceQueue.Where(x => x.DeviceId == DeviceId.Event1).Select(x => x.Process), Contains.Item(pA));
        }
예제 #24
0
 public void MonoBehaviourClientCallback()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: [ClientCallback] System.Void MirrorTest.MirrorTestPlayer::ThisCantBeOutsideNetworkBehaviour() must be declared inside a NetworkBehaviour"));
 }
예제 #25
0
 public void PreferredLocalizations()
 {
     string [] locz = main.PreferredLocalizations;
     Assert.That(locz.Length, Is.GreaterThanOrEqualTo(1), "Length");
     Assert.That(locz, Contains.Item("Base"), "Base");
 }
예제 #26
0
 public void MessageSelfReferencing()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: MirrorTest.PrefabClone has field $MirrorTest.PrefabClone MirrorTest.PrefabClone::selfReference that references itself"));
 }
        private static Task SetupPeekThenAckWorkerWithSubscription(IMongoDatabase database, QueueId queueName, ConcurrentBag <Job> finishedJobs, JobAttributes attributesThatShouldWork, CancellationToken cancellationToken)
        {
            var standardAck = new JobAcknowledgment
            {
                { "RunnerId", Guid.NewGuid().ToString("N") }
            };

            var options = new PeekNextSubscriptionOptions()
            {
                Token           = cancellationToken,
                PeekNextOptions = new PeekNextOptions
                {
                    QueueId       = queueName,
                    HasAttributes = attributesThatShouldWork
                }
            };

            var subscriber = new TaskBasedPeekNextSubscriber(new MongoJobPeekNextService(new MongoJobQueryService(database)));

            return(subscriber.Subscribe(async nextJobs =>
            {
                var nextJob = nextJobs.First();
                // Acknowledge the job
                var acknowledgmentService = new MongoJobAcknowledgmentService(database);

                var ackResult = await acknowledgmentService.Ack(queueName, nextJob.Id, standardAck).ConfigureAwait(false);
                if (!ackResult.Success)
                {
                    return;
                }

                var exampleReportMessage1 = "FooBar";
                var exampleReportMessage2 = "WizBang";
                var exampleReportMessage3 = "PowPop";

                // Send Reports
                var reportService = new MongoJobReportService(database);
                await
                reportService.AddReport(queueName, nextJob.Id,
                                        new JobReport {
                    { "Timestamp", DateTime.UtcNow.ToString("O") }, { "Message", exampleReportMessage1 }
                }).ConfigureAwait(false);
                await
                reportService.AddReport(queueName, nextJob.Id,
                                        new JobReport {
                    { "Timestamp", DateTime.UtcNow.ToString("O") }, { "Message", exampleReportMessage2 }
                }).ConfigureAwait(false);
                await
                reportService.AddReport(queueName, nextJob.Id,
                                        new JobReport {
                    { "Timestamp", DateTime.UtcNow.ToString("O") }, { "Message", exampleReportMessage3 }
                }).ConfigureAwait(false);

                // Send Result
                var completionService = new MongoJobCompletionService(database);
                await completionService.Complete(queueName, nextJob.Id, new JobResult {
                    { "Result", "Success" }
                }).ConfigureAwait(false);

                // Finish Job
                var finishedJobFromDb =
                    await database.GetJobCollection().Find(Builders <Job> .Filter.Eq(x => x.Id, nextJob.Id)).FirstAsync(cancellationToken).ConfigureAwait(false);

                Assert.That(finishedJobFromDb, Is.Not.Null);
                Assert.That(finishedJobFromDb.Acknowledgment, Is.Not.Null);

                Assert.That(finishedJobFromDb.Reports, Has.Length.EqualTo(3));
                var valuesOfReports = finishedJobFromDb.Reports.SelectMany(x => x.Values).ToList();
                Assert.That(valuesOfReports, Contains.Item(exampleReportMessage1));
                Assert.That(valuesOfReports, Contains.Item(exampleReportMessage2));
                Assert.That(valuesOfReports, Contains.Item(exampleReportMessage3));

                Assert.That(finishedJobFromDb.Result, Is.Not.Null);
                finishedJobs.Add(finishedJobFromDb);
            }, options));
        }
예제 #28
0
 public void MessageInvalidDeserializeFieldType()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: System.AccessViolationException is not a supported type"));
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: System.AccessViolationException MirrorTest.PrefabClone::invalidField has unsupported type"));
 }
예제 #29
0
        public void TakesOnlyNameOfFullyQualifiedAssemblyName()
        {
            CsProj project = GetProject("FQAssemblyName");

            Assert.That(project.ReferencedAssemblyNames, Contains.Item("NHibernate"));
        }
예제 #30
0
 public void NetworkBehaviourCmdParamAbstract()
 {
     Assert.That(CompilationFinishedHook.WeaveFailed, Is.True);
     Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: MirrorTest.MirrorTestPlayer/AbstractClass can't be deserialized bcause i has no default constructor"));
 }