CK.Monitoring.Tests.TestHelper.WaitForCkmonFilesInDirectory C# (CSharp) Method

WaitForCkmonFilesInDirectory() public static method

public static WaitForCkmonFilesInDirectory ( string directoryPath, int minFileCount ) : string[]
directoryPath string
minFileCount int
return string[]
        public static string[] WaitForCkmonFilesInDirectory( string directoryPath, int minFileCount )
        {
            string[] files;
            for( ; ; )
            {
                files = Directory.GetFiles( directoryPath, "*.ckmon", SearchOption.TopDirectoryOnly );
                if( files.Length >= minFileCount ) break;
                Thread.Sleep( 200 );
            }
            foreach( var f in files )
            {
                if( !FileUtil.CheckForWriteAccess( f, 3000 ) )
                {
                    throw new CKException( "CheckForWriteAccess exceeds 3000 milliseconds..." );
                }
            }
            return files;
        }

Usage Example

Example #1
0
        public void GrandOutputHasSameCompressedAndUncompressedLogs()
        {
            string rootPath = SystemActivityMonitor.RootLogPath + @"\GrandOutputGzip";

            TestHelper.CleanupFolder(rootPath);

            GrandOutputConfiguration c = new GrandOutputConfiguration();

            Assert.That(c.Load(XDocument.Parse(@"
                <GrandOutputConfiguration GlobalDefaultFilter=""Release"" >
                    <Channel>
                        <Add Type=""BinaryFile"" Name=""GzipGlobalCatch"" Path=""" + rootPath + @"\OutputGzip"" MaxCountPerFile=""200000"" UseGzipCompression=""True"" />
                        <Add Type=""BinaryFile"" Name=""RawGlobalCatch"" Path=""" + rootPath + @"\OutputRaw"" MaxCountPerFile=""200000"" UseGzipCompression=""False"" />
                    </Channel>
                </GrandOutputConfiguration>"
                                               ).Root, TestHelper.ConsoleMonitor));
            Assert.That(c.ChannelsConfiguration.Configurations.Count, Is.EqualTo(2));

            using (GrandOutput g = new GrandOutput())
            {
                Assert.That(g.SetConfiguration(c, TestHelper.ConsoleMonitor), Is.True);

                var taskA = Task.Factory.StartNew <int>(() => { DumpMonitorOutput(CreateMonitorAndRegisterGrandOutput("Task A", g)); return(1); });
                var taskB = Task.Factory.StartNew <int>(() => { DumpMonitorOutput(CreateMonitorAndRegisterGrandOutput("Task B", g)); return(1); });
                var taskC = Task.Factory.StartNew <int>(() => { DumpMonitorOutput(CreateMonitorAndRegisterGrandOutput("Task C", g)); return(1); });

                Task.WaitAll(taskA, taskB, taskC);
            }

            string[] gzipCkmons = TestHelper.WaitForCkmonFilesInDirectory(rootPath + @"\OutputGzip", 1);
            string[] rawCkmons  = TestHelper.WaitForCkmonFilesInDirectory(rootPath + @"\OutputRaw", 1);

            Assert.That(gzipCkmons, Has.Length.EqualTo(1));
            Assert.That(rawCkmons, Has.Length.EqualTo(1));

            FileInfo gzipCkmonFile = new FileInfo(gzipCkmons.Single());
            FileInfo rawCkmonFile  = new FileInfo(rawCkmons.Single());

            Assert.That(gzipCkmonFile.Exists, Is.True);
            Assert.That(rawCkmonFile.Exists, Is.True);

            // Test file size
            Assert.That(gzipCkmonFile.Length, Is.LessThan(rawCkmonFile.Length));

            // Test de-duplication between Gzip and non-Gzip
            MultiLogReader mlr      = new MultiLogReader();
            var            fileList = mlr.Add(new string[] { gzipCkmonFile.FullName, rawCkmonFile.FullName });

            Assert.That(fileList, Has.Count.EqualTo(2));

            var map = mlr.GetActivityMap();

            Assert.That(map.Monitors.Count, Is.EqualTo(3));
        }