Пример #1
0
        private static IDisposable StartLogStream(ApplicationManager appManager)
        {
            LogStreamWaitHandle waitHandle = null;
            Task task = null;

            if (Debugger.IsAttached)
            {
                // Set to verbose level
                appManager.SettingsManager.SetValue("SCM_TRACE_LEVEL", "4").Wait();

                RemoteLogStreamManager mgr = appManager.CreateLogStreamManager("kudu");
                waitHandle = new LogStreamWaitHandle(mgr.GetStream().Result);
                task       = Task.Factory.StartNew(() =>
                {
                    string line = null;
                    var trace   = new DefaultTraceListener();
                    while ((line = waitHandle.WaitNextLine(-1)) != null)
                    {
                        trace.WriteLine(line);
                    }
                });
            }

            return(new DisposableAction(() =>
            {
                if (waitHandle != null)
                {
                    waitHandle.Dispose();
                    task.Wait();
                }
            }));
        }
Пример #2
0
        public void TestLogStreamSubFolder()
        {
            string appName = "TestLogStreamFilter";

            ApplicationManager.Run(appName, appManager =>
            {
                // Act
                using (var localRepo = Git.Clone("LogTester"))
                {
                    appManager.GitDeploy(localRepo.PhysicalPath);
                }
                List<string> logFiles = new List<string>();
                List<LogStreamWaitHandle> waitHandles = new List<LogStreamWaitHandle>();
                for (int i = 0; i < 2; ++i)
                {
                    logFiles.Add(@"LogFiles\TestLogStreamFilter\Folder" + i + "\\temp.txt");
                    //Create the directory
                    CreateLogDirectory(appManager.SiteUrl, @"LogFiles\TestLogStreamFilter\Folder" + i);
                    RemoteLogStreamManager mgr = appManager.CreateLogStreamManager("TestLogStreamFilter/folder" + i);
                    var waitHandle = new LogStreamWaitHandle(mgr.GetStream().Result);
                    string line = waitHandle.WaitNextLine(10000);
                    Assert.True(!string.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);
                    waitHandles.Add(waitHandle);
                }

                using (LogStreamWaitHandle waitHandle = new LogStreamWaitHandle(appManager.CreateLogStreamManager("TestLogStreamFilter").GetStream().Result))
                {
                    try
                    {
                        string line = waitHandle.WaitNextLine(10000);
                        Assert.True(!string.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);

                        // write to folder0, we should not get any live stream for folder1 listener
                        string content = Guid.NewGuid().ToString();
                        WriteLogText(appManager.SiteUrl, logFiles[0], content);
                        line = waitHandle.WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[0].WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[1].WaitNextLine(1000);
                        Assert.True(line == null, "no more message: " + line);

                        // write to folder1, we should not get any live stream for folder0 listener
                        content = Guid.NewGuid().ToString();
                        WriteLogText(appManager.SiteUrl, logFiles[1], content);
                        line = waitHandle.WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[1].WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[0].WaitNextLine(1000);
                        Assert.True(line == null, "no more message: " + line);
                    }
                    finally
                    {
                        waitHandles[0].Dispose();
                        waitHandles[1].Dispose();
                    }
                }
            });
        }
Пример #3
0
        public void TestLogStreamBasic()
        {
            string repoName = "LogTester";
            string repoCloneUrl = "https://github.com/KuduApps/LogTester.git";
            string appName = KuduUtils.GetRandomWebsiteName("TestLogStreamBasic");

            ApplicationManager.Run(appName, appManager =>
            {
                // Act
                using (var localRepo = Git.Clone(repoName, repoCloneUrl))
                {
                    appManager.GitDeploy(localRepo.PhysicalPath);
                }

                CreateLogDirectory(appManager.SiteUrl, @"LogFiles");

                using (var waitHandle = new LogStreamWaitHandle(appManager.LogStreamManager.GetStream().Result))
                {
                    string line = waitHandle.WaitNextLine(10000);
                    Assert.True(!String.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);

                    string content = Guid.NewGuid().ToString();
                    WriteLogText(appManager.SiteUrl, @"LogFiles\temp.txt", content);
                    line = waitHandle.WaitNextLine(10000);
                    Assert.Equal(content, line);

                    content = Guid.NewGuid().ToString();
                    WriteLogText(appManager.SiteUrl, @"LogFiles\temp.log", content);
                    line = waitHandle.WaitNextLine(10000);
                    Assert.Equal(content, line);

                    // write to xml file, we should not get any live stream
                    content = Guid.NewGuid().ToString();
                    WriteLogText(appManager.SiteUrl, @"LogFiles\temp.xml", content);
                    line = waitHandle.WaitNextLine(1000);
                    Assert.Null(line);
                }
            });
        }
Пример #4
0
        private static IDisposable StartLogStream(ApplicationManager appManager)
        {
            LogStreamWaitHandle waitHandle = null;
            Task task = null;
            if (Debugger.IsAttached)
            {
                // Set to verbose level
                appManager.SettingsManager.SetValue("trace_level", "4").Wait();

                RemoteLogStreamManager mgr = appManager.CreateLogStreamManager("Git");
                waitHandle = new LogStreamWaitHandle(mgr.GetStream().Result);
                task = Task.Factory.StartNew(() =>
                {
                    string line = null;
                    var trace = new DefaultTraceListener();
                    while ((line = waitHandle.WaitNextLine(-1)) != null)
                    {
                        trace.WriteLine(line);
                    }
                });
            }

            return new DisposableAction(() =>
            {
                if (waitHandle != null)
                {
                    waitHandle.Dispose();
                    task.Wait();
                }
            });
        }
Пример #5
0
        public void TestLogStreamSubFolder()
        {
            string appName = KuduUtils.GetRandomWebsiteName("TestLogStreamFilter");
            string repoName = "LogTester";
            string repoCloneUrl = "https://github.com/KuduApps/LogTester.git";

            TestRepository testRepository = null;
            string localRepo = KuduUtils.GetCachedRepositoryPath(repoName);
            if (localRepo == null)
            {
                testRepository = Git.Clone(appName, repoCloneUrl);
                localRepo = testRepository.PhysicalPath;
            }

            ApplicationManager.Run(appName, appManager =>
            {
                // Act
                appManager.GitDeploy(localRepo);
                List<string> logFiles = new List<string>();
                List<LogStreamWaitHandle> waitHandles = new List<LogStreamWaitHandle>();
                for (int i = 0; i < 2; ++i)
                {
                    logFiles.Add(@"LogFiles\Folder" + i + "\\temp.txt");
                    //Create the directory
                    CreateLogDirectory(appManager.SiteUrl, @"LogFiles\Folder" + i);
                    RemoteLogStreamManager mgr = appManager.CreateLogStreamManager("folder" + i);
                    var waitHandle = new LogStreamWaitHandle(mgr.GetStream().Result);
                    string line = waitHandle.WaitNextLine(10000);
                    Assert.True(!string.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);
                    waitHandles.Add(waitHandle);
                }

                using (LogStreamWaitHandle waitHandle = new LogStreamWaitHandle(appManager.LogStreamManager.GetStream().Result))
                {
                    try
                    {
                        string line = waitHandle.WaitNextLine(10000);
                        Assert.True(!string.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);

                        // write to folder0, we should not get any live stream for folder1 listener
                        string content = Guid.NewGuid().ToString();
                        WriteLogText(appManager.SiteUrl, logFiles[0], content);
                        line = waitHandle.WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[0].WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[1].WaitNextLine(1000);
                        Assert.True(line == null, "no more message: " + line);

                        // write to folder1, we should not get any live stream for folder0 listener
                        content = Guid.NewGuid().ToString();
                        WriteLogText(appManager.SiteUrl, logFiles[1], content);
                        line = waitHandle.WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[1].WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[0].WaitNextLine(1000);
                        Assert.True(line == null, "no more message: " + line);
                    }
                    finally
                    {
                        waitHandles[0].Dispose();
                        waitHandles[1].Dispose();
                    }
                }
            });
        }
        public void TestLogStreamNotFound()
        {
            string appName = "TestLogStreamNotFound";

            ApplicationManager.Run(appName, appManager =>
            {
                RemoteLogStreamManager manager = new RemoteLogStreamManager(appManager.ServiceUrl + "/logstream/notfound");
                using (var waitHandle = new LogStreamWaitHandle(manager.GetStream().Result))
                {
                    string line = waitHandle.WaitNextLine(10000);
                    Assert.True(!String.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);
                }
            });
        }