Пример #1
0
        public void parsing_dependent_token_and_start_and_create_messages_with_time_collision()
        {
            ActivityMonitor m = new ActivityMonitor(false);

            m.Output.CreateBridgeTo(TestHelper.ConsoleMonitor.Output.BridgeTarget);
            StupidStringClient cLaunch = m.Output.RegisterClient(new StupidStringClient());

            // Generates a token with time collision.
            int loopNeeded = 0;

            ActivityMonitor.DependentToken token;
            while ((token = m.DependentActivity().CreateTokenWithTopic("Test...")).CreationDate.Uniquifier == 0)
            {
                ++loopNeeded;
            }
            Assert.That(token.Topic, Is.EqualTo("Test..."));
            m.Trace().Send("Generating time collision required {0} loops.", loopNeeded);

            string launchMessage = cLaunch.Entries[loopNeeded].Text;
            {
                bool   launched;
                bool   launchWithTopic;
                string launchDependentTopic;
                Assert.That(ActivityMonitor.DependentToken.TryParseLaunchOrCreateMessage(launchMessage, out launched, out launchWithTopic, out launchDependentTopic));
                Assert.That(!launched, "We used CreateToken.");
                Assert.That(launchWithTopic);
                Assert.That(launchDependentTopic, Is.EqualTo("Test..."));
            }

            string tokenToString = token.ToString();

            {
                ActivityMonitor.DependentToken t2 = ActivityMonitor.DependentToken.Parse(tokenToString);
                Assert.That(t2.OriginatorId, Is.EqualTo(((IUniqueId)m).UniqueId));
                Assert.That(t2.CreationDate, Is.EqualTo(cLaunch.Entries[loopNeeded].LogTime));
                Assert.That(t2.Topic, Is.EqualTo("Test..."));
            }

            StupidStringClient.Entry[] logs = RunDependentActivity(token);
            {
                Assert.That(logs[0].Text, Is.EqualTo(ActivityMonitor.SetTopicPrefix + "Test..."));
                Guid          id;
                DateTimeStamp time;
                Assert.That(ActivityMonitor.DependentToken.TryParseStartMessage(logs[1].Text, out id, out time));
                Assert.That(id, Is.EqualTo(((IUniqueId)m).UniqueId));
                Assert.That(time, Is.EqualTo(cLaunch.Entries[loopNeeded].LogTime));
            }
        }
Пример #2
0
        private static StupidStringClient.Entry[] RunDependentActivity(ActivityMonitor.DependentToken token)
        {
            string depMonitorTopic = null;

            StupidStringClient.Entry[] dependentLogs = null;
            var task = Task.Factory.StartNew(t =>
            {
                StupidStringClient cStarted = new StupidStringClient();
                using (var depMonitor = token.CreateDependentMonitor(mD => mD.Output.RegisterClient(cStarted)))
                {
                    depMonitorTopic = depMonitor.Topic;
                    depMonitor.Trace().Send("Hello!");
                }
                dependentLogs = cStarted.Entries.ToArray();
            }, token);

            task.Wait();
            Assert.That(depMonitorTopic, Is.EqualTo(token.Topic));
            return(dependentLogs);
        }