示例#1
0
 public TestRingMaster(TestEvents ev, TestMarshaller marshaller)
     : base(string.Empty, 10, null)
 {
     this.ev         = ev;
     this.marshaller = marshaller;
 }
示例#2
0
        // [TestMethod]
        public void ValidateScheduler()
        {
            bool ok = false;

            TestEvents       ev         = new TestEvents();
            TestMarshaller   marshaller = new TestMarshaller(ev);
            TestRingMaster   testRM     = new TestRingMaster(ev, marshaller);
            ScheduledCommand scheduler  = null;

            try
            {
                foreach (string path in ScheduledCommand.GetPaths())
                {
                    testRM.Create(path, null, null, CreateMode.PersistentAllowPathCreation);
                }

                scheduler = new ScheduledCommand(() => { return(testRM.IsPrimary); }, testRM, marshaller);
                scheduler.InternalOnAbandon = new Action <Exception>(ex =>
                {
                    Assert.Fail("Scheduler Abandoned: " + ex);
                });

                scheduler.Start();

                this.VerifySetup(ev, TimeSpan.FromSeconds(15));

                string res = testRM.Create("/$metadata/scheduler/commands/c1", null, null, CreateMode.Persistent);

                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c1");
                this.VerifyCommandFailed(ev, TimeSpan.FromSeconds(10), "c1");

                List <Op> ops = new List <Op>();
                ops.Add(Op.Create("/$metadata/scheduler/commands/c2", null, null, CreateMode.Persistent));
                ops.Add(Op.Create("/$metadata/scheduler/commands/c4", null, null, CreateMode.Persistent));
                ops.Add(Op.Create("/$metadata/scheduler/commands/c3", null, null, CreateMode.Persistent));

                IReadOnlyList <OpResult> resL = testRM.Multi(ops.AsReadOnly(), completeSynchronously: true, scheduledName: null);

                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c2");
                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c3");
                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c4");
                this.VerifyCommandFailed(ev, TimeSpan.FromSeconds(10), "c2", "c3", "c4");

                ops.Clear();
                ops.Add(Op.Create("/test1", null, null, CreateMode.Persistent));
                resL = testRM.Multi(ops.AsReadOnly(), completeSynchronously: true, scheduledName: "c5");

                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c5");
                this.VerifyCommandSucceeded(ev, TimeSpan.FromSeconds(10), "c5");
                this.VerifyCreated(ev, TimeSpan.FromSeconds(10), "/test1");

                Assert.IsTrue(testRM.Exists("/test1", false, false) != null);
                Assert.IsTrue(testRM.Exists("/$metadata/scheduler/commands/c5", false, false) == null);

                ok = true;
            }
            finally
            {
                if (!ok)
                {
                    testRM.DumpNodes();
                }

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    if (scheduler != null)
                    {
                        scheduler.Close();
                    }

                    testRM.Close();
                });
            }
        }