Пример #1
0
        public void TestHiPrioritySend()
        {
            string name = Guid.NewGuid().ToString();
            // Create the shared memory buffer
            SharedMemory readSharedMemory =
                new SharedMemory
                (
                    name,
                    SharedMemoryType.ReadOnly,
                    true
                );


            SharedMemory writeSharedMemory =
                new SharedMemory
                (
                    name,
                    SharedMemoryType.WriteOnly,
                    true
                );

            DualQueue <LocalCallDescriptor> queue      = new DualQueue <LocalCallDescriptor>();
            DualQueue <LocalCallDescriptor> hiPriQueue = new DualQueue <LocalCallDescriptor>();


            int numberOfEvents = 20;
            LocalCallDescriptorForPostLoggingMessagesToHost LargeLogEvent = CreatePostMessageCallDescriptor(numberOfEvents);

            queue.Enqueue(LargeLogEvent);
            LocalCallDescriptorForPostStatus nodeStatusExcept = new LocalCallDescriptorForPostStatus(new NodeStatus(new Exception("I am bad")));

            hiPriQueue.Enqueue(nodeStatusExcept);

            writeSharedMemory.Write(queue, hiPriQueue, true);
            IList localCallDescriptorList = readSharedMemory.Read();

            Assert.IsTrue(localCallDescriptorList.Count == 2);

            VerifyNodeStatus2((LocalCallDescriptorForPostStatus)localCallDescriptorList[0]);
            VerifyPostMessagesToHost((LocalCallDescriptorForPostLoggingMessagesToHost)localCallDescriptorList[1], numberOfEvents);
            writeSharedMemory.Reset();
            readSharedMemory.Reset();
            readSharedMemory  = null;
            writeSharedMemory = null;
        }
Пример #2
0
        public void TestLargeSharedMemorySend()
        {
            string name = Guid.NewGuid().ToString();
            // Create the shared memory buffer
            SharedMemory readSharedMemory =
                new SharedMemory
                (
                    name,
                    SharedMemoryType.ReadOnly,
                    true
                );


            SharedMemory writeSharedMemory =
                new SharedMemory
                (
                    name,
                    SharedMemoryType.WriteOnly,
                    true
                );

            DualQueue <LocalCallDescriptor> queue      = new DualQueue <LocalCallDescriptor>();
            DualQueue <LocalCallDescriptor> hiPriQueue = new DualQueue <LocalCallDescriptor>();

            int numberOfEvents = 2500;
            LocalCallDescriptorForPostLoggingMessagesToHost LargeLogEvent = CreatePostMessageCallDescriptor(numberOfEvents);

            queue.Enqueue(LargeLogEvent);
            writeSharedMemory.Write(queue, hiPriQueue, false);
            IList localCallDescriptorList = readSharedMemory.Read();

            while (localCallDescriptorList == null || localCallDescriptorList.Count == 0)
            {
                writeSharedMemory.Write(queue, hiPriQueue, false);
                localCallDescriptorList = readSharedMemory.Read();
            }
            VerifyPostMessagesToHost((LocalCallDescriptorForPostLoggingMessagesToHost)localCallDescriptorList[0], numberOfEvents);
            writeSharedMemory.Reset();
            readSharedMemory.Reset();
            readSharedMemory  = null;
            writeSharedMemory = null;
        }
Пример #3
0
        public void TestQueueEnqueueMultipleWriterOneReader()
        {
            // Queue which will contain elements added using a single Enqueue per item
            DualQueue <string> stringQueue = new DualQueue <string>();
            // Queue which will contain elements added using an EnqueueArray for a group of Items
            DualQueue <string> stringQueueTwo = new DualQueue <string>();
            // List of strings which are supposed to be in the queue
            List <string> stringsSupposedToBeInQueue = new List <string>();
            // List of strings which are supposed to be in the queue which uses EnQueueArray
            List <string> stringsSupposedToBeInQueueTwo = new List <string>();

            // Array containing our set of ManualResetEvents which is the number of threads we are going to use
            ManualResetEvent[] waitHandles = new ManualResetEvent[50];
            for (int i = 0; i < waitHandles.Length; i++)
            {
                waitHandles[i] = new ManualResetEvent(false);
                ThreadPool.QueueUserWorkItem(
                    delegate(object state)
                {
                    // Create three non repeating strings to put in the the different queues
                    string string1 = System.Guid.NewGuid().ToString();
                    string string2 = System.Guid.NewGuid().ToString();
                    string string3 = System.Guid.NewGuid().ToString();

                    stringQueue.Enqueue(string1);
                    lock (stringsSupposedToBeInQueue)
                    {
                        stringsSupposedToBeInQueue.Add(string1);
                    }

                    stringQueueTwo.EnqueueArray(new string[] { string2, string3 });
                    lock (stringsSupposedToBeInQueueTwo)
                    {
                        stringsSupposedToBeInQueueTwo.Add(string2);
                        stringsSupposedToBeInQueueTwo.Add(string3);
                    }

                    // Say we are done the thread
                    ((ManualResetEvent)state).Set();
                }, waitHandles[i]);
            }

            // Wait for all of the threads to complete
            foreach (ManualResetEvent resetEvent in waitHandles)
            {
                resetEvent.WaitOne();
            }

            // Pop off items from the queue and make sure that we got all of out items back out
            int    numberOfItemsInQueue = 0;
            string result = null;

            while ((result = stringQueue.Dequeue()) != null)
            {
                Assert.IsTrue(stringsSupposedToBeInQueue.Contains(result), string.Format("Expected {0} to be in the queue but it was not", result));
                stringsSupposedToBeInQueue.Remove(result);
                numberOfItemsInQueue++;
            }
            Assert.IsTrue(stringsSupposedToBeInQueue.Count == 0, "Expected all strings to be removed but they were not");
            // The number of items we processed should be the same as the number of EnQueues we did
            Assert.IsTrue(numberOfItemsInQueue == waitHandles.Length, "Expected the number of items in the queue to be the same as the number of Enqueues but it was not");

            // Pop off items from the queue and make sure that we got all of out items back out
            int    numberOfItemsInQueueTwo = 0;
            string result2 = null;

            while ((result2 = stringQueueTwo.Dequeue()) != null)
            {
                Assert.IsTrue(stringsSupposedToBeInQueueTwo.Contains(result2), string.Format("Expected {0} to be in the queue number 2 but it was not", result2));
                stringsSupposedToBeInQueueTwo.Remove(result2);
                numberOfItemsInQueueTwo++;
            }
            Assert.IsTrue(stringsSupposedToBeInQueueTwo.Count == 0, "Expected all strings to be removed in queue 2 but they were not");
            // The number of items we processed should be the same as the number of EnQueues we did
            Assert.IsTrue(numberOfItemsInQueueTwo == waitHandles.Length * 2, "Expected the number of items in the queue 2 to be the same as the number of Enqueues but it was not");

            // Clear the queue
            stringQueue.Clear();
            Assert.IsTrue(stringQueue.Count == 0, "The count should be zero after clearing the queue");
        }
Пример #4
0
      public void TestQueueEnqueueMultipleWriterOneReader()
        {
            // Queue which will contain elements added using a single Enqueue per item
            DualQueue<string> stringQueue = new DualQueue<string>();
            // Queue which will contain elements added using an EnqueueArray for a group of Items
            DualQueue<string> stringQueueTwo = new DualQueue<string>();
            // List of strings which are supposed to be in the queue
            List<string> stringsSupposedToBeInQueue  = new List<string>();
            // List of strings which are supposed to be in the queue which uses EnQueueArray
            List<string> stringsSupposedToBeInQueueTwo = new List<string>();  
            
            // Array containing our set of ManualResetEvents which is the number of threads we are going to use
            ManualResetEvent[] waitHandles = new ManualResetEvent[50];
            for (int i = 0; i < waitHandles.Length; i++)
            {
                waitHandles[i] = new ManualResetEvent(false);
                ThreadPool.QueueUserWorkItem(
                              delegate(object state)
                              {
                                  // Create three non repeating strings to put in the the different queues
                                  string string1 = System.Guid.NewGuid().ToString();
                                  string string2 = System.Guid.NewGuid().ToString();
                                  string string3 = System.Guid.NewGuid().ToString();
                                  
                                  stringQueue.Enqueue(string1);
                                  lock (stringsSupposedToBeInQueue)
                                  {
                                      stringsSupposedToBeInQueue.Add(string1);
                                  }

                                  stringQueueTwo.EnqueueArray(new string[] { string2, string3 });
                                  lock (stringsSupposedToBeInQueueTwo)
                                  {
                                      stringsSupposedToBeInQueueTwo.Add(string2);
                                      stringsSupposedToBeInQueueTwo.Add(string3);
                                  }
                                  
                                  // Say we are done the thread
                                  ((ManualResetEvent)state).Set();
                              }, waitHandles[i]);
            }
            
          // Wait for all of the threads to complete
            foreach (ManualResetEvent resetEvent in waitHandles)
            {
                resetEvent.WaitOne();
            }
          
            // Pop off items from the queue and make ture that we got all of out items back out
            int numberOfItemsInQueue = 0;
            string result = null;
            while ((result = stringQueue.Dequeue()) != null)
            {
                Assert.IsTrue(stringsSupposedToBeInQueue.Contains(result),string.Format("Expected {0} to be in the queue but it was not",result));
                stringsSupposedToBeInQueue.Remove(result);
                numberOfItemsInQueue++;
            }
            Assert.IsTrue(stringsSupposedToBeInQueue.Count == 0, "Expected all strings to be removed but they were not");
            // The number of items we processed should be the same as the number of EnQueues we did
            Assert.IsTrue(numberOfItemsInQueue == waitHandles.Length,"Expected the number of items in the queue to be the same as the number of Enqueues but it was not");

            // Pop off items from the queue and make ture that we got all of out items back out
            int numberOfItemsInQueueTwo = 0;
            string result2 = null;
            while ((result2 = stringQueueTwo.Dequeue()) != null)
            {
                Assert.IsTrue(stringsSupposedToBeInQueueTwo.Contains(result2), string.Format("Expected {0} to be in the queue number 2 but it was not", result2));
                stringsSupposedToBeInQueueTwo.Remove(result2);
                numberOfItemsInQueueTwo++;
            }
            Assert.IsTrue(stringsSupposedToBeInQueueTwo.Count == 0, "Expected all strings to be removed in queue 2 but they were not");
            // The number of items we processed should be the same as the number of EnQueues we did
            Assert.IsTrue(numberOfItemsInQueueTwo == waitHandles.Length*2, "Expected the number of items in the queue 2 to be the same as the number of Enqueues but it was not");

            // Clear the queue
            stringQueue.Clear();
            Assert.IsTrue(stringQueue.Count == 0, "The count should be zero after clearing the queue");
        }
Пример #5
0
        public void TestItemsInandOutOfSharedMemory()
        {
            string name = Guid.NewGuid().ToString();
            // Create the shared memory buffer
            SharedMemory readSharedMemory =
                new SharedMemory
                (
                    name,
                    SharedMemoryType.ReadOnly,
                    true
                );


            SharedMemory writeSharedMemory =
                new SharedMemory
                (
                    name,
                    SharedMemoryType.WriteOnly,
                    true
                );

            DualQueue <LocalCallDescriptor> queue      = new DualQueue <LocalCallDescriptor>();
            DualQueue <LocalCallDescriptor> hiPriQueue = new DualQueue <LocalCallDescriptor>();
            LocalCallDescriptorForPostLoggingMessagesToHost LargeLogEvent      = CreatePostMessageCallDescriptor(1);
            LocalCallDescriptorForUpdateNodeSettings        updateNodeSettings = new LocalCallDescriptorForUpdateNodeSettings(true, true, true);
            LocalCallDescriptorForPostBuildResult           buildResult        = new LocalCallDescriptorForPostBuildResult(CreateBuildResult());
            LocalCallDescriptorForPostBuildRequests         buildRequests      = new LocalCallDescriptorForPostBuildRequests(CreateBuildRequest());
            LocalCallDescriptorForRequestStatus             requestStatus      = new LocalCallDescriptorForRequestStatus(4);
            LocalCallDescriptorForPostStatus             nodeStatusNoExcept    = new LocalCallDescriptorForPostStatus(new NodeStatus(1, true, 2, 3, 4, true));
            LocalCallDescriptorForPostStatus             nodeStatusExcept      = new LocalCallDescriptorForPostStatus(new NodeStatus(new Exception("I am bad")));
            LocalCallDescriptorForShutdownNode           shutdownNode          = new LocalCallDescriptorForShutdownNode(Node.NodeShutdownLevel.BuildCompleteSuccess, true);
            LocalCallDescriptorForShutdownComplete       shutdownComplete      = new LocalCallDescriptorForShutdownComplete(Node.NodeShutdownLevel.BuildCompleteFailure, 0);
            LocalCallDescriptorForInitializationComplete initializeComplete    = new LocalCallDescriptorForInitializationComplete(99);

            BuildPropertyGroup propertyGroup = new BuildPropertyGroup();
            BuildProperty      propertyToAdd = new BuildProperty("PropertyName", "Value");

            propertyGroup.SetProperty(propertyToAdd);
            CacheEntry[] entries = CreateCacheEntries();
            LocalCallDescriptorForGettingCacheEntriesFromHost getCacheEntries  = new LocalCallDescriptorForGettingCacheEntriesFromHost(new string[] { "Hi", "Hello" }, "Name", propertyGroup, "3.5", CacheContentType.Properties);
            LocalCallDescriptorForPostingCacheEntriesToHost   postCacheEntries = new LocalCallDescriptorForPostingCacheEntriesToHost(entries, "ScopeName", propertyGroup, "3.5", CacheContentType.BuildResults);
            LocalReplyCallDescriptor replyDescriptor1 = new LocalReplyCallDescriptor(1, entries);
            LocalReplyCallDescriptor replyDescriptor2 = new LocalReplyCallDescriptor(6, "Foo");

            IDictionary environmentVariables          = Environment.GetEnvironmentVariables();
            Hashtable   environmentVariablesHashtable = new Hashtable(environmentVariables);

            string            className                         = "Class";
            string            loggerAssemblyName                = "Class";
            string            loggerFileAssembly                = null;
            string            loggerSwitchParameters            = "Class";
            LoggerVerbosity   verbosity                         = LoggerVerbosity.Detailed;
            LoggerDescription description                       = new LoggerDescription(className, loggerAssemblyName, loggerFileAssembly, loggerSwitchParameters, verbosity);
            LocalCallDescriptorForInitializeNode initializeNode = new LocalCallDescriptorForInitializeNode(environmentVariablesHashtable, new LoggerDescription[] { description }, 4, propertyGroup, ToolsetDefinitionLocations.ConfigurationFile, 5, String.Empty);

            queue.Enqueue(LargeLogEvent);
            queue.Enqueue(updateNodeSettings);
            queue.Enqueue(buildResult);
            queue.Enqueue(buildRequests);
            queue.Enqueue(requestStatus);
            queue.Enqueue(nodeStatusNoExcept);
            queue.Enqueue(nodeStatusExcept);
            queue.Enqueue(shutdownNode);
            queue.Enqueue(shutdownComplete);
            queue.Enqueue(initializeComplete);
            queue.Enqueue(getCacheEntries);
            queue.Enqueue(postCacheEntries);
            queue.Enqueue(replyDescriptor1);
            queue.Enqueue(replyDescriptor2);
            queue.Enqueue(initializeNode);
            writeSharedMemory.Write(queue, hiPriQueue, false);

            IList localCallDescriptorList = readSharedMemory.Read();

            Assert.IsTrue(localCallDescriptorList.Count == 15);

            LocalCallDescriptorForPostLoggingMessagesToHost messageCallDescriptor = localCallDescriptorList[0] as LocalCallDescriptorForPostLoggingMessagesToHost;

            VerifyPostMessagesToHost(messageCallDescriptor, 1);

            LocalCallDescriptorForUpdateNodeSettings updateSettingsCallDescriptor = localCallDescriptorList[1] as LocalCallDescriptorForUpdateNodeSettings;

            VerifyUpdateSettings(updateSettingsCallDescriptor);

            LocalCallDescriptorForPostBuildResult buildResultCallDescriptor = localCallDescriptorList[2] as LocalCallDescriptorForPostBuildResult;

            CompareBuildResult(buildResultCallDescriptor);

            LocalCallDescriptorForPostBuildRequests buildRequestsCallDescriptor = localCallDescriptorList[3] as LocalCallDescriptorForPostBuildRequests;

            ComparebuildRequests(buildRequestsCallDescriptor);

            LocalCallDescriptorForRequestStatus requestStatusCallDescriptor = localCallDescriptorList[4] as LocalCallDescriptorForRequestStatus;

            Assert.IsTrue(requestStatusCallDescriptor.RequestId == 4);

            LocalCallDescriptorForPostStatus nodeStatus1CallDescriptor = localCallDescriptorList[5] as LocalCallDescriptorForPostStatus;

            VerifyNodeStatus1(nodeStatus1CallDescriptor);

            LocalCallDescriptorForPostStatus nodeStatus2CallDescriptor = localCallDescriptorList[6] as LocalCallDescriptorForPostStatus;

            VerifyNodeStatus2(nodeStatus2CallDescriptor);

            LocalCallDescriptorForShutdownNode shutdownNodeCallDescriptor = localCallDescriptorList[7] as LocalCallDescriptorForShutdownNode;

            Assert.IsTrue(shutdownNodeCallDescriptor.ShutdownLevel == Node.NodeShutdownLevel.BuildCompleteSuccess);
            Assert.IsTrue(shutdownNodeCallDescriptor.ExitProcess);

            LocalCallDescriptorForShutdownComplete shutdownNodeCompleteCallDescriptor = localCallDescriptorList[8] as LocalCallDescriptorForShutdownComplete;

            Assert.IsTrue(shutdownNodeCompleteCallDescriptor.ShutdownLevel == Node.NodeShutdownLevel.BuildCompleteFailure);

            LocalCallDescriptorForInitializationComplete initializeCompleteCallDescriptor = localCallDescriptorList[9] as LocalCallDescriptorForInitializationComplete;

            Assert.IsTrue(initializeCompleteCallDescriptor.ProcessId == 99);

            LocalCallDescriptorForGettingCacheEntriesFromHost getCacheEntriesCallDescriptor = localCallDescriptorList[10] as LocalCallDescriptorForGettingCacheEntriesFromHost;

            VerifyGetCacheEntryFromHost(getCacheEntriesCallDescriptor);

            LocalCallDescriptorForPostingCacheEntriesToHost postCacheEntriesCallDescriptor = localCallDescriptorList[11] as LocalCallDescriptorForPostingCacheEntriesToHost;

            Assert.IsTrue(string.Compare(postCacheEntriesCallDescriptor.ScopeName, "ScopeName", StringComparison.OrdinalIgnoreCase) == 0);
            Assert.IsTrue(string.Compare(postCacheEntriesCallDescriptor.ScopeProperties["PropertyName"].Value, "Value", StringComparison.OrdinalIgnoreCase) == 0);
            Assert.IsTrue(string.Compare(postCacheEntriesCallDescriptor.ScopeToolsVersion, "3.5", StringComparison.OrdinalIgnoreCase) == 0);
            Assert.IsTrue(postCacheEntriesCallDescriptor.ContentType == CacheContentType.BuildResults);
            VerifyGetCacheEntries(postCacheEntriesCallDescriptor.Entries);

            LocalReplyCallDescriptor reply1CallDescriptor = localCallDescriptorList[12] as LocalReplyCallDescriptor;

            Assert.IsTrue(reply1CallDescriptor.RequestingCallNumber == 1);
            VerifyGetCacheEntries((CacheEntry[])reply1CallDescriptor.ReplyData);

            LocalReplyCallDescriptor reply2CallDescriptor = localCallDescriptorList[13] as LocalReplyCallDescriptor;

            Assert.IsTrue(reply2CallDescriptor.RequestingCallNumber == 6);
            Assert.IsTrue(string.Compare("Foo", (string)reply2CallDescriptor.ReplyData, StringComparison.OrdinalIgnoreCase) == 0);

            LocalCallDescriptorForInitializeNode initializeCallDescriptor = localCallDescriptorList[14] as LocalCallDescriptorForInitializeNode;

            Assert.IsTrue(initializeCallDescriptor.ParentProcessId == 5);
            Assert.IsTrue(initializeCallDescriptor.NodeId == 4);
            Assert.IsTrue(initializeCallDescriptor.ToolsetSearchLocations == ToolsetDefinitionLocations.ConfigurationFile);
            Assert.IsTrue(string.Compare(initializeCallDescriptor.ParentGlobalProperties["PropertyName"].Value, "Value", StringComparison.OrdinalIgnoreCase) == 0);
            Assert.IsTrue(string.Compare(initializeCallDescriptor.NodeLoggers[0].Name, "Class", StringComparison.OrdinalIgnoreCase) == 0);

            IDictionary variables = Environment.GetEnvironmentVariables();

            Assert.IsTrue(variables.Count == initializeCallDescriptor.EnvironmentVariables.Count);
            foreach (string key in variables.Keys)
            {
                Assert.IsTrue(string.Compare((string)initializeCallDescriptor.EnvironmentVariables[key], (string)variables[key], StringComparison.OrdinalIgnoreCase) == 0);
            }

            writeSharedMemory.Reset();
            readSharedMemory.Reset();
            readSharedMemory  = null;
            writeSharedMemory = null;
        }
Пример #6
0
        public void TestHiPrioritySend()
        {
            string name = Guid.NewGuid().ToString();
            // Create the shared memory buffer
            SharedMemory readSharedMemory =
                  new SharedMemory
                  (
                        name,
                        SharedMemoryType.ReadOnly,
                        true
                  );


            SharedMemory writeSharedMemory =
                new SharedMemory
                (
                    name,
                    SharedMemoryType.WriteOnly,
                    true
                );

            DualQueue<LocalCallDescriptor> queue = new DualQueue<LocalCallDescriptor>();
            DualQueue<LocalCallDescriptor> hiPriQueue = new DualQueue<LocalCallDescriptor>();


            int numberOfEvents = 20;
            LocalCallDescriptorForPostLoggingMessagesToHost LargeLogEvent = CreatePostMessageCallDescriptor(numberOfEvents);
            queue.Enqueue(LargeLogEvent);
            LocalCallDescriptorForPostStatus nodeStatusExcept = new LocalCallDescriptorForPostStatus(new NodeStatus(new Exception("I am bad")));
            hiPriQueue.Enqueue(nodeStatusExcept);

            writeSharedMemory.Write(queue, hiPriQueue, true);
            IList localCallDescriptorList = readSharedMemory.Read();

            Assert.IsTrue(localCallDescriptorList.Count == 2);

            VerifyNodeStatus2((LocalCallDescriptorForPostStatus)localCallDescriptorList[0]);
            VerifyPostMessagesToHost((LocalCallDescriptorForPostLoggingMessagesToHost)localCallDescriptorList[1], numberOfEvents);
            writeSharedMemory.Reset();
            readSharedMemory.Reset();
            readSharedMemory = null;
            writeSharedMemory = null;
        }
Пример #7
0
        public void TestItemsInandOutOfSharedMemory()
        {
            string name = Guid.NewGuid().ToString();
            // Create the shared memory buffer
            SharedMemory readSharedMemory =
                  new SharedMemory
                  (
                        name,
                        SharedMemoryType.ReadOnly,
                        true
                  );


            SharedMemory writeSharedMemory =
                new SharedMemory
                (
                    name,
                    SharedMemoryType.WriteOnly,
                    true
                );

            DualQueue<LocalCallDescriptor> queue = new DualQueue<LocalCallDescriptor>();
            DualQueue<LocalCallDescriptor> hiPriQueue = new DualQueue<LocalCallDescriptor>();
            LocalCallDescriptorForPostLoggingMessagesToHost LargeLogEvent = CreatePostMessageCallDescriptor(1);
            LocalCallDescriptorForUpdateNodeSettings updateNodeSettings = new LocalCallDescriptorForUpdateNodeSettings(true, true, true);
            LocalCallDescriptorForPostBuildResult buildResult = new LocalCallDescriptorForPostBuildResult(CreateBuildResult());
            LocalCallDescriptorForPostBuildRequests buildRequests = new LocalCallDescriptorForPostBuildRequests(CreateBuildRequest());
            LocalCallDescriptorForRequestStatus requestStatus = new LocalCallDescriptorForRequestStatus(4);
            LocalCallDescriptorForPostStatus nodeStatusNoExcept = new LocalCallDescriptorForPostStatus(new NodeStatus(1, true, 2, 3, 4, true));
            LocalCallDescriptorForPostStatus nodeStatusExcept = new LocalCallDescriptorForPostStatus(new NodeStatus(new Exception("I am bad")));
            LocalCallDescriptorForShutdownNode shutdownNode = new LocalCallDescriptorForShutdownNode(Node.NodeShutdownLevel.BuildCompleteSuccess, true);
            LocalCallDescriptorForShutdownComplete shutdownComplete = new LocalCallDescriptorForShutdownComplete(Node.NodeShutdownLevel.BuildCompleteFailure, 0);
            LocalCallDescriptorForInitializationComplete initializeComplete = new LocalCallDescriptorForInitializationComplete(99);

            BuildPropertyGroup propertyGroup = new BuildPropertyGroup();
            BuildProperty propertyToAdd = new BuildProperty("PropertyName", "Value");
            propertyGroup.SetProperty(propertyToAdd);
            CacheEntry[] entries = CreateCacheEntries();
            LocalCallDescriptorForGettingCacheEntriesFromHost getCacheEntries = new LocalCallDescriptorForGettingCacheEntriesFromHost(new string[] { "Hi", "Hello" }, "Name", propertyGroup, "3.5", CacheContentType.Properties);
            LocalCallDescriptorForPostingCacheEntriesToHost postCacheEntries = new LocalCallDescriptorForPostingCacheEntriesToHost(entries, "ScopeName", propertyGroup, "3.5", CacheContentType.BuildResults);
            LocalReplyCallDescriptor replyDescriptor1 = new LocalReplyCallDescriptor(1, entries);
            LocalReplyCallDescriptor replyDescriptor2 = new LocalReplyCallDescriptor(6, "Foo");

            IDictionary environmentVariables = Environment.GetEnvironmentVariables();
            Hashtable environmentVariablesHashtable = new Hashtable(environmentVariables);

            string className = "Class";
            string loggerAssemblyName = "Class";
            string loggerFileAssembly = null;
            string loggerSwitchParameters = "Class";
            LoggerVerbosity verbosity = LoggerVerbosity.Detailed;
            LoggerDescription description = new LoggerDescription(className, loggerAssemblyName, loggerFileAssembly, loggerSwitchParameters, verbosity);
            LocalCallDescriptorForInitializeNode initializeNode = new LocalCallDescriptorForInitializeNode(environmentVariablesHashtable, new LoggerDescription[] { description }, 4, propertyGroup, ToolsetDefinitionLocations.ConfigurationFile, 5, String.Empty);

            queue.Enqueue(LargeLogEvent);
            queue.Enqueue(updateNodeSettings);
            queue.Enqueue(buildResult);
            queue.Enqueue(buildRequests);
            queue.Enqueue(requestStatus);
            queue.Enqueue(nodeStatusNoExcept);
            queue.Enqueue(nodeStatusExcept);
            queue.Enqueue(shutdownNode);
            queue.Enqueue(shutdownComplete);
            queue.Enqueue(initializeComplete);
            queue.Enqueue(getCacheEntries);
            queue.Enqueue(postCacheEntries);
            queue.Enqueue(replyDescriptor1);
            queue.Enqueue(replyDescriptor2);
            queue.Enqueue(initializeNode);
            writeSharedMemory.Write(queue, hiPriQueue, false);

            IList localCallDescriptorList = readSharedMemory.Read();
            Assert.IsTrue(localCallDescriptorList.Count == 15);

            LocalCallDescriptorForPostLoggingMessagesToHost messageCallDescriptor = localCallDescriptorList[0] as LocalCallDescriptorForPostLoggingMessagesToHost;
            VerifyPostMessagesToHost(messageCallDescriptor, 1);

            LocalCallDescriptorForUpdateNodeSettings updateSettingsCallDescriptor = localCallDescriptorList[1] as LocalCallDescriptorForUpdateNodeSettings;
            VerifyUpdateSettings(updateSettingsCallDescriptor);

            LocalCallDescriptorForPostBuildResult buildResultCallDescriptor = localCallDescriptorList[2] as LocalCallDescriptorForPostBuildResult;
            CompareBuildResult(buildResultCallDescriptor);

            LocalCallDescriptorForPostBuildRequests buildRequestsCallDescriptor = localCallDescriptorList[3] as LocalCallDescriptorForPostBuildRequests;
            ComparebuildRequests(buildRequestsCallDescriptor);

            LocalCallDescriptorForRequestStatus requestStatusCallDescriptor = localCallDescriptorList[4] as LocalCallDescriptorForRequestStatus;
            Assert.IsTrue(requestStatusCallDescriptor.RequestId == 4);

            LocalCallDescriptorForPostStatus nodeStatus1CallDescriptor = localCallDescriptorList[5] as LocalCallDescriptorForPostStatus;
            VerifyNodeStatus1(nodeStatus1CallDescriptor);

            LocalCallDescriptorForPostStatus nodeStatus2CallDescriptor = localCallDescriptorList[6] as LocalCallDescriptorForPostStatus;
            VerifyNodeStatus2(nodeStatus2CallDescriptor);

            LocalCallDescriptorForShutdownNode shutdownNodeCallDescriptor = localCallDescriptorList[7] as LocalCallDescriptorForShutdownNode;
            Assert.IsTrue(shutdownNodeCallDescriptor.ShutdownLevel == Node.NodeShutdownLevel.BuildCompleteSuccess);
            Assert.IsTrue(shutdownNodeCallDescriptor.ExitProcess);

            LocalCallDescriptorForShutdownComplete shutdownNodeCompleteCallDescriptor = localCallDescriptorList[8] as LocalCallDescriptorForShutdownComplete;
            Assert.IsTrue(shutdownNodeCompleteCallDescriptor.ShutdownLevel == Node.NodeShutdownLevel.BuildCompleteFailure);

            LocalCallDescriptorForInitializationComplete initializeCompleteCallDescriptor = localCallDescriptorList[9] as LocalCallDescriptorForInitializationComplete;
            Assert.IsTrue(initializeCompleteCallDescriptor.ProcessId == 99);

            LocalCallDescriptorForGettingCacheEntriesFromHost getCacheEntriesCallDescriptor = localCallDescriptorList[10] as LocalCallDescriptorForGettingCacheEntriesFromHost;
            VerifyGetCacheEntryFromHost(getCacheEntriesCallDescriptor);

            LocalCallDescriptorForPostingCacheEntriesToHost postCacheEntriesCallDescriptor = localCallDescriptorList[11] as LocalCallDescriptorForPostingCacheEntriesToHost;
            Assert.IsTrue(string.Compare(postCacheEntriesCallDescriptor.ScopeName, "ScopeName", StringComparison.OrdinalIgnoreCase) == 0);
            Assert.IsTrue(string.Compare(postCacheEntriesCallDescriptor.ScopeProperties["PropertyName"].Value, "Value", StringComparison.OrdinalIgnoreCase) == 0);
            Assert.IsTrue(string.Compare(postCacheEntriesCallDescriptor.ScopeToolsVersion, "3.5", StringComparison.OrdinalIgnoreCase) == 0);
            Assert.IsTrue(postCacheEntriesCallDescriptor.ContentType == CacheContentType.BuildResults);
            VerifyGetCacheEntries(postCacheEntriesCallDescriptor.Entries);

            LocalReplyCallDescriptor reply1CallDescriptor = localCallDescriptorList[12] as LocalReplyCallDescriptor;
            Assert.IsTrue(reply1CallDescriptor.RequestingCallNumber == 1);
            VerifyGetCacheEntries((CacheEntry[])reply1CallDescriptor.ReplyData);

            LocalReplyCallDescriptor reply2CallDescriptor = localCallDescriptorList[13] as LocalReplyCallDescriptor;
            Assert.IsTrue(reply2CallDescriptor.RequestingCallNumber == 6);
            Assert.IsTrue(string.Compare("Foo", (string)reply2CallDescriptor.ReplyData, StringComparison.OrdinalIgnoreCase) == 0);

            LocalCallDescriptorForInitializeNode initializeCallDescriptor = localCallDescriptorList[14] as LocalCallDescriptorForInitializeNode;
            Assert.IsTrue(initializeCallDescriptor.ParentProcessId == 5);
            Assert.IsTrue(initializeCallDescriptor.NodeId == 4);
            Assert.IsTrue(initializeCallDescriptor.ToolsetSearchLocations == ToolsetDefinitionLocations.ConfigurationFile);
            Assert.IsTrue(string.Compare(initializeCallDescriptor.ParentGlobalProperties["PropertyName"].Value, "Value", StringComparison.OrdinalIgnoreCase) == 0);
            Assert.IsTrue(string.Compare(initializeCallDescriptor.NodeLoggers[0].Name, "Class", StringComparison.OrdinalIgnoreCase) == 0);

            IDictionary variables = Environment.GetEnvironmentVariables();

            Assert.IsTrue(variables.Count == initializeCallDescriptor.EnvironmentVariables.Count);
            foreach (string key in variables.Keys)
            {
                Assert.IsTrue(string.Compare((string)initializeCallDescriptor.EnvironmentVariables[key], (string)variables[key], StringComparison.OrdinalIgnoreCase) == 0);
            }

            writeSharedMemory.Reset();
            readSharedMemory.Reset();
            readSharedMemory = null;
            writeSharedMemory = null;
        }
Пример #8
0
        public void TestLargeSharedMemorySend()
        {
            string name = Guid.NewGuid().ToString();
            // Create the shared memory buffer
            SharedMemory readSharedMemory =
                  new SharedMemory
                  (
                        name,
                        SharedMemoryType.ReadOnly,
                        true
                  );


            SharedMemory writeSharedMemory =
                new SharedMemory
                (
                    name,
                    SharedMemoryType.WriteOnly,
                    true
                );

            DualQueue<LocalCallDescriptor> queue = new DualQueue<LocalCallDescriptor>();
            DualQueue<LocalCallDescriptor> hiPriQueue = new DualQueue<LocalCallDescriptor>();

            int numberOfEvents = 2500;
            LocalCallDescriptorForPostLoggingMessagesToHost LargeLogEvent = CreatePostMessageCallDescriptor(numberOfEvents);
            queue.Enqueue(LargeLogEvent);
            writeSharedMemory.Write(queue, hiPriQueue, false);
            IList localCallDescriptorList = readSharedMemory.Read();
            while (localCallDescriptorList == null || localCallDescriptorList.Count == 0)
            {
                writeSharedMemory.Write(queue, hiPriQueue, false);
                localCallDescriptorList = readSharedMemory.Read();
            }
            VerifyPostMessagesToHost((LocalCallDescriptorForPostLoggingMessagesToHost)localCallDescriptorList[0], numberOfEvents);
            writeSharedMemory.Reset();
            readSharedMemory.Reset();
            readSharedMemory = null;
            writeSharedMemory = null;
        }