예제 #1
0
        public void TestSetMonitorProtectionFromChange()
        {
            const int valueIndex   = 2;
            var       initialValue = InitialValues[valueIndex];
            var       key          = initialValue.Key;
            var       value        = initialValue.Value;

            const string changedValue = "ChangedValue";

            AssertStartup(TestMonitor);
            Assert.AreEqual(ChangeCount, 0);

            AssertValueChange(TestMonitor, key, changedValue);
            Assert.AreEqual(ChangeCount, 1);

            AssertValueChange(TestMonitor, key, value);
            Assert.AreEqual(ChangeCount, 2);

            // Setting the value to itself.
            TestMonitor.InnerSet[key] = value;
            TestMonitor.WaitOnUpdate();
            Assert.AreEqual(ChangeCount, 2);

            Assert.IsTrue(TestMonitor.Stop());
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRePlanAfterDataChangesFromAnEmptyDatabase() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRePlanAfterDataChangesFromAnEmptyDatabase()
        {
            // GIVEN
            TestMonitor monitor = new TestMonitor();

            Db.resolveDependency(typeof(Monitors)).addMonitorListener(monitor);
            // - setup schema -
            CreateIndex();
            // - execute the query without the existence data -
            ExecuteDistantFriendsCountQuery(USERS);

            long replanTime = DateTimeHelper.CurrentUnixTimeMillis() + 1_800;

            // - create data -
            CreateData(0, USERS, CONNECTIONS);

            // - after the query TTL has expired -
            while (DateTimeHelper.CurrentUnixTimeMillis() < replanTime)
            {
                Thread.Sleep(100);
            }

            // WHEN
            monitor.Reset();
            // - execute the query again -
            ExecuteDistantFriendsCountQuery(USERS);

            // THEN
            assertEquals("Query should have been replanned.", 1, monitor.Discards.get());
            assertThat("Replan should have occurred after TTL", monitor.WaitTime.get(), greaterThanOrEqualTo(1L));
        }
예제 #3
0
        public void GetLineCountTest()
        {
            MonitorTestSetUp();
            const int numLines = 10;
            var       monitor  = new TestMonitor(TestHelper.CreateOptions(), WriteToFile, new CancellationToken());

            AddAFile(numLines);
            Assert.AreEqual(2, AddedFiles.Count);
            Assert.AreEqual(numLines, monitor.GetLineCountPassThru(AddedFiles[1]).Result);

            var cts = new CancellationTokenSource();

            // lock the file on another task
            Task.Run(() =>
            {
                using (File.Open(AddedFiles[1], FileMode.Open, FileAccess.ReadWrite))
                {
                }
            },
                     cts.Token);

            // task that waits for GetLines to return
            var t = Task.Factory.StartNew(async() => { Assert.AreEqual(numLines, await monitor.GetLineCountPassThru(AddedFiles[1])); });

            // sleep the test thread for a second just for fun
            Thread.Sleep(1000);

            // now cancel the file locking task and the GetLines should proceed
            cts.Cancel(false);

            t.Wait();

            MonitorTestCleanUp();
        }
예제 #4
0
 private void SubmitFailureForRemainingPendingTasks()
 {
     foreach (string testId in testTasks.Keys)
     {
         TestMonitor testMonitor = GetTestMonitor(testId);
         testMonitor.SubmitFailureIfNotFinished();
     }
 }
예제 #5
0
 public void Update(TestMonitor monitor)
 {
     this.consoleError = UnitSerializer.XmlSerializerEscapeWorkAround(monitor.Console.Error);
     this.consoleOut   = UnitSerializer.XmlSerializerEscapeWorkAround(monitor.Console.Out);
     this.startTime    = monitor.Timer.StartTime.ToString("u");
     this.endTime      = monitor.Timer.EndTime.ToString("u");
     this.duration     = monitor.Timer.Duration;
     this.log          = monitor.GetLog();
 }
예제 #6
0
 public void ConstructorAndPropertiesTest()
 {
     Monitor = new TestMonitor(TestHelper.CreateOptions(), WriteToFile, new CancellationToken());
     Assert.IsNotNull(Monitor);
     Assert.IsNotNull(Monitor.CancellationToken);
     Assert.IsNotNull(Monitor.FileLineMap);
     Assert.IsNotNull(Monitor.FilePath);
     Assert.IsNotNull(Monitor.FilePattern);
 }
예제 #7
0
        private void TestStepFinished(object sender, TestStepFinishedEventArgs e)
        {
            TestMonitor testMonitor = GetTestMonitor(e.Test.Id);

            if (testMonitor != null)
            {
                testMonitor.TestStepFinished(e);
            }
        }
예제 #8
0
        private void TestStepLifecyclePhaseChanged(object sender, TestStepLifecyclePhaseChangedEventArgs e)
        {
            TestMonitor testMonitor = GetTestMonitor(e.Test.Id);

            if (testMonitor != null)
            {
                testMonitor.TestStepLifecyclePhaseChanged(e);
            }
        }
예제 #9
0
 public Result(string name)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     this.name    = name;
     this.monitor = new TestMonitor();
 }
        protected void OnTestProgressChanged(TestMonitor test, TestProgress progress)
        {
            var hub = GetHub();

            hub.Clients.All.testProgress(new
            {
                Key      = test.Key,
                Progress = progress
            });
        }
        protected void OnTestEvent(TestMonitor test, TestEvent ev)
        {
            var hub = GetHub();

            hub.Clients.All.testEvent(new
            {
                Key   = test.Key,
                Event = ev
            });
        }
        protected void OnTestCompleted(TestMonitor test)
        {
            var hub = GetHub();

            hub.Clients.All.testCompleted(new
            {
                test.Key,
                test.IsRunning,
                test.Result
            });
        }
예제 #13
0
        private TestMonitor GetTestMonitor(string testId)
        {
            TestMonitor testMonitor;

            lock (testMonitors)
            {
                if (!testMonitors.TryGetValue(testId, out testMonitor))
                {
                    GallioTestItemTask testTask;
                    if (testTasks.TryGetValue(testId, out testTask))
                    {
                        testMonitor = new TestMonitor(facadeTaskServer, testTask);
                        testMonitors.Add(testId, testMonitor);
                    }
                }
            }

            return(testMonitor);
        }
예제 #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRePlanAfterDataChangesFromAPopulatedDatabase() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRePlanAfterDataChangesFromAPopulatedDatabase()
        {
            // GIVEN
            Config config = Db.DependencyResolver.resolveDependency(typeof(Config));
            double divergenceThreshold = config.Get(GraphDatabaseSettings.query_statistics_divergence_threshold);
            long   replanInterval      = config.Get(GraphDatabaseSettings.cypher_min_replan_interval).toMillis();

            TestMonitor monitor = new TestMonitor();

            Db.resolveDependency(typeof(Monitors)).addMonitorListener(monitor);
            // - setup schema -
            CreateIndex();
            //create some data
            CreateData(0, USERS, CONNECTIONS);
            ExecuteDistantFriendsCountQuery(USERS);

            long replanTime = DateTimeHelper.CurrentUnixTimeMillis() + replanInterval;

            assertTrue("Test does not work with edge setting for query_statistics_divergence_threshold: " + divergenceThreshold, divergenceThreshold > 0.0 && divergenceThreshold < 1.0);

            int usersToCreate = (( int )(Math.Ceiling((( double )USERS) / (1.0 - divergenceThreshold)))) - USERS + 1;

            //create more data
            CreateData(USERS, usersToCreate, CONNECTIONS);

            // - after the query TTL has expired -
            while (DateTimeHelper.CurrentUnixTimeMillis() <= replanTime)
            {
                Thread.Sleep(100);
            }

            // WHEN
            monitor.Reset();
            // - execute the query again -
            ExecuteDistantFriendsCountQuery(USERS);

            // THEN
            assertEquals("Query should have been replanned.", 1, monitor.Discards.get());
            assertThat("Replan should have occurred after TTL", monitor.WaitTime.get(), greaterThanOrEqualTo(replanInterval / 1000));
        }
예제 #15
0
        private TestMonitor GetTestMonitor(string testId)
        {
            TestMonitor testMonitor;
            lock (testMonitors)
            {
                if (!testMonitors.TryGetValue(testId, out testMonitor))
                {
                    GallioTestItemTask testTask;
                    if (testTasks.TryGetValue(testId, out testTask))
                    {
                        testMonitor = new TestMonitor(facadeTaskServer, testTask);
                        testMonitors.Add(testId, testMonitor);
                    }
                }
            }

            return testMonitor;
        }
예제 #16
0
        public void MonitorTests(int worldScale)
        {
            var tree = new QuadTree <object>(worldScale);

            // test a monitor on an initially empty tree, add an object to the tree and ensure that
            // the monitor contains it, update the monitor to a position that doesn't contain the
            // item in the tree, ensure the monitor is empty, update the monitor so that it contains
            // the item again, ensure the monitor contains the item, update the monitor so that it
            // still contains the item & verify, then remove the monitor and ensure it is empty
            {
                var monitor = new TestMonitor <object>();

                // inserting a monitor into an empty tree should result in an empty monitor
                tree.AddMonitor(monitor, new Bound(0, 0, 25));
                Assert.Empty(monitor.Contained);

                // add an object to (0,0)
                var added = new object();
                tree.AddItem(added, new Vector2r());
                Assert.Contains(added, monitor.Contained);

                // update the position of the monitor so that it doesn't contain anything
                tree.UpdateMonitor(monitor, new Bound(0, 0, 25), new Bound(100, 100, 25));
                Assert.Empty(monitor.Contained);

                // update the position of the monitor so that it contains the item
                tree.UpdateMonitor(monitor, new Bound(100, 100, 25), new Bound(5, 5, 25));
                Assert.Contains(added, monitor.Contained);

                // update it back to its original position so that it contains everything
                tree.UpdateMonitor(monitor, new Bound(5, 5, 25), new Bound(0, 0, 25));
                Assert.Contains(added, monitor.Contained);

                // remove the monitor
                tree.RemoveMonitor(monitor, new Bound(0, 0, 25));
                Assert.Empty(monitor.Contained);
            }

            // test a monitor on a non-empty tree
            {
                var monitor = new TestMonitor <object>();

                // the monitor should have the object already in the tree added to it
                tree.AddMonitor(monitor, new Bound(0, 0, 25));
                Assert.NotEmpty(monitor.Contained);

                // add an object to (0,0)
                var added = new object();
                tree.AddItem(added, new Vector2r());
                Assert.Contains(added, monitor.Contained);

                // remove the monitor
                tree.RemoveMonitor(monitor, new Bound(0, 0, 25));
                Assert.Empty(monitor.Contained);
            }

            // test a monitor on a non-empty tree that doesn't contain the objects already in the
            // tree
            {
                var monitor = new TestMonitor <object>();

                // the monitor should remain empty when being added to the tree
                tree.AddMonitor(monitor, new Bound(100, 100, 25));
                Assert.Empty(monitor.Contained);

                // add an object to (0,0); it should not be added to the monitor
                var added = new object();
                tree.AddItem(added, new Vector2r());
                Assert.Empty(monitor.Contained);

                // remove the monitor
                tree.RemoveMonitor(monitor, new Bound(100, 100, 25));
                Assert.Empty(monitor.Contained);
            }
        }
예제 #17
0
        public void TestMassiveStoreEntries()
        {
            var iteration = 1000;
            var entries   = new List <TestEntry>(3000);

            for (int i = 0; i < iteration; ++i)
            {
                for (int n = 0; n < 10; ++n)
                {
                    var entry = CreateTestEntry("massive-test-entry", i);
                    entry.StringValue += " :" + n;
                    entries.Add(entry);
                }
            }
            entries.Sort(delegate(TestEntry x, TestEntry y) { return(x.IntValue.CompareTo(y.IntValue)); });            // shuffle randomly

            var CouchConveyor = new OrderedPooledCouchConveyor <TestEntry>(HOSTNAME, DATABASE, 1024);

            CouchConveyor.StartAll();

            var monitor = new TestMonitor <TestEntry>();

            foreach (var entry in entries)
            {
                CouchConveyor.Convey(entry.Id, entry, monitor.StartOne());
            }
            ;

            monitor.WaitToFinish();

            Trace.WriteLine(string.Format("Completed to store all test entries. Start checking it now"));
            var mycouch_pool      = new ConcurrentBag <MyCouchStore>(Enumerable.Range(0, 100).Select((i) => new MyCouchStore(HOSTNAME, DATABASE)));
            var entries_to_remove = new ConcurrentBag <TestEntry>();

            // Async tasks are suppressing Assert exceptions
            Parallel.ForEach(entries, new ParallelOptions {
                MaxDegreeOfParallelism = 100
            }, (entry) =>
            {
                MyCouchStore couchdb;
                if (false == mycouch_pool.TryTake(out couchdb))                 // Actually, this condition is not required. Just to avoid CS0165
                {
                    SpinWait.SpinUntil(() => mycouch_pool.TryTake(out couchdb));
                }
                var task    = couchdb.GetByIdAsync <TestEntry>(entry.Id);
                var dbentry = task.Result;
                mycouch_pool.Add(couchdb);
                couchdb = null;

                Assert.IsNotNull(dbentry);

                var last_entry = entries.Where((e) => e.Id == entry.Id).Last();
                if (last_entry.IntValue != dbentry.IntValue)
                {
                    var es = entries.Where((e) => e.Id == entry.Id);
                    Trace.WriteLine(string.Format("Entry '{0}' has stored incorrectly: {1} for {2}", entry.Id, dbentry.IntValue, string.Join(",", es.Select((e) => e.IntValue))));
                }
                Assert.AreEqual(entry.Id, dbentry.Id);
                Assert.AreEqual(last_entry.IntValue, dbentry.IntValue);
                Assert.AreEqual(last_entry.IntNullValue, dbentry.IntNullValue);
                Assert.AreEqual(last_entry.StringValue, dbentry.StringValue);
                Assert.AreEqual(last_entry.StringNullValue, dbentry.StringNullValue);
                Assert.AreEqual(last_entry.CustomValue, dbentry.CustomValue);
                Assert.AreEqual(last_entry.CustomNullValue, dbentry.CustomNullValue);
                Assert.AreEqual(last_entry.DateTimeValue.ToString(), dbentry.DateTimeValue.ToString());
                CollectionAssert.AreEqual(last_entry.ListValue, dbentry.ListValue);

                if (last_entry.IntValue == entry.IntValue)
                {
                    entries_to_remove.Add(entry);
                }
            });

            var delete_monitor = new TestMonitorForDelete <TestEntry>();

            Parallel.ForEach(entries_to_remove, (entry) => CouchConveyor.Convey(entry.Id, null, delete_monitor.StartOne()));
            delete_monitor.WaitToFinish();
            CouchConveyor.StopAll();

            Parallel.ForEach(entries, new ParallelOptions {
                MaxDegreeOfParallelism = 100
            }, (entry) =>
            {
                MyCouchStore couchdb;
                if (false == mycouch_pool.TryTake(out couchdb))
                {
                    SpinWait.SpinUntil(() => mycouch_pool.TryTake(out couchdb));
                }
                var task    = couchdb.GetByIdAsync <TestEntry>(entry.Id);
                var dbentry = task.Result;
                mycouch_pool.Add(couchdb);
                couchdb = null;

                Assert.IsNull(dbentry);
            });

            foreach (var c in mycouch_pool)
            {
                c.Dispose();
            }
        }
예제 #18
0
 public XmlMonitor(TestMonitor monitor)
 {
     this.Update(monitor);
 }