public void RecentWebSocketOpen() { using (ShimsContext.Create()) { var openEvent = default(EventHandler<EventArgs>); var state = ConnectionState.None; var openEventFired = new ManualResetEvent(false); ShimLogyardWebSocket.AllInstances.StreamOpenedAddEventHandlerOfEventArgs = (@this, h) => openEvent = h; ShimLogyardWebSocket.AllInstances.StateGet = (@this) => { return state; }; ShimLogyardWebSocket.AllInstances.OpenUriStringUriBoolean = (@this, appLogEndpoint, authenticationToken, proxy, skipCertValidation) => { state = ConnectionState.Open; }; LogyardLog log = new LogyardLog(logyardEndpoint, string.Empty); log.StreamOpened += delegate(object sender, EventArgs e) { openEventFired.Set(); }; log.StartLogStream(Guid.NewGuid().ToString(), 50); openEvent(this, EventArgs.Empty); Assert.IsTrue(openEventFired.WaitOne(100)); Assert.AreEqual(log.State, ConnectionState.Open); } }
public void RecentWebSocketMessage() { using (ShimsContext.Create()) { var openEvent = default(EventHandler<EventArgs>); var messageEvent = default(EventHandler<StringEventArgs>); var messageEventFired = new ManualResetEvent(false); Guid appGuid = Guid.NewGuid(); string text = "This is a log entry"; string source = "app"; string json = string.Format(@"{{""value"":{{""source"":""{0}"", ""app_guid"":""{1}"", ""text"":""{2}"", ""syslog"":{{ }} }} }}", source, appGuid.ToString(), text); Message msg = new Message(); msg.Value = new MessageValue(); msg.Value.AppGuid = appGuid; msg.Value.Text = text; msg.Value.Source = source; msg.Value.Syslog = new ValueSyslog(); ShimLogyardWebSocket.AllInstances.StreamOpenedAddEventHandlerOfEventArgs = (@this, h) => openEvent = h; ShimLogyardWebSocket.AllInstances.DataReceivedAddEventHandlerOfStringEventArgs = (@this, h) => messageEvent = h; ShimLogyardWebSocket.AllInstances.OpenUriStringUriBoolean = (@this, appLogEndpoint, authenticationToken, proxy, skipCertValidation) => { }; LogyardLog log = new LogyardLog(logyardEndpoint, string.Empty); log.MessageReceived += delegate(object sender, MessageEventArgs e) { Assert.AreEqual(msg.Value.Source, e.Message.Value.Source); Assert.AreEqual(msg.Value.AppGuid, e.Message.Value.AppGuid); Assert.AreEqual(msg.Value.Text, e.Message.Value.Text); messageEventFired.Set(); }; log.StartLogStream(msg.Value.AppGuid.ToString()); messageEvent(this, new StringEventArgs() { Data = json }); Assert.IsTrue(messageEventFired.WaitOne(100)); } }
public void LogsTest() { CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; client.Apps.Push(appGuid, tempAppPath, true).Wait(); while (true) { var appSummary = client.Apps.GetAppSummary(appGuid).Result; var packageState = appSummary.PackageState.ToLowerInvariant(); if (packageState != "pending") { Assert.AreEqual(packageState, "staged"); var instances = client.Apps.GetInstanceInformationForStartedApp(appGuid).Result; if (instances.Count > 0) { if (instances[0].State.ToLower() == "running") { break; } } } } var logyardClient = new LogyardLog( new Uri(client.Info.GetV1Info().Result.AppLogEndpoint), string.Format("bearer {0}", client.AuthorizationToken), null, true); var logs = new List<string>(); logyardClient.MessageReceived += delegate(object sender, MessageEventArgs e) { Assert.IsTrue(string.IsNullOrEmpty(e.Message.Error)); logs.Add(e.Message.Value.Text); }; logyardClient.ErrorReceived += delegate(object sender, Logyard.Client.ErrorEventArgs e) { Assert.Fail("Logyard error: {0}", e.Error.ToString()); }; var stopevent = new EventWaitHandle(false, EventResetMode.ManualReset); logyardClient.StreamClosed += delegate { stopevent.Set(); }; // Just wait a bit to get the latest logs Thread.Sleep(1000); logyardClient.StartLogStream(appGuid.ToString(), 100, false); stopevent.WaitOne(); var conatainsPushedContent = logs.Any((line) => line.Contains("dummy content")); Assert.IsTrue(conatainsPushedContent, "Pushed content was not dumped in the output stream: {0}", string.Join(Environment.NewLine, logs)); var conatainsEnvContent = logs.Any((line) => line.Contains("env-test-1234")); Assert.IsTrue(conatainsEnvContent, "Pushed env variable was not dumped in the output stream: {0}", string.Join(Environment.NewLine, logs)); client.Apps.DeleteApp(appGuid).Wait(); Directory.Delete(tempAppPath, true); }
public void RecentWebSockerError() { using (ShimsContext.Create()) { var errorEvent = default(EventHandler<ErrorEventArgs>); var errorEventFired = new ManualResetEvent(false); ShimLogyardWebSocket.AllInstances.ErrorReceivedAddEventHandlerOfErrorEventArgs = (@this, h) => errorEvent = h; ShimLogyardWebSocket.AllInstances.OpenUriStringUriBoolean = (@this, appLogEndpoint, authenticationToken, proxy, skipCertValidation) => { }; LogyardLog logyard = new LogyardLog(logyardEndpoint, string.Empty); logyard.ErrorReceived += delegate(object sender, ErrorEventArgs e) { Assert.AreEqual("Test error", e.Error.Message); errorEventFired.Set(); }; logyard.StartLogStream(Guid.NewGuid().ToString()); errorEvent(this, new ErrorEventArgs() { Error = new LogyardException("Test error") }); Assert.IsTrue(errorEventFired.WaitOne(100)); } }
public void RecentWebSocketErrorMessage() { using (ShimsContext.Create()) { var openEvent = default(EventHandler<EventArgs>); var messageEvent = default(EventHandler<StringEventArgs>); var messageEventFired = new ManualResetEvent(false); Guid appGuid = Guid.NewGuid(); string error = "This is a error"; string json = string.Format(@"{{""error"":""{0}""}}", error); Message msg = new Message(); msg.Error = error; ShimLogyardWebSocket.AllInstances.StreamOpenedAddEventHandlerOfEventArgs = (@this, h) => openEvent = h; ShimLogyardWebSocket.AllInstances.DataReceivedAddEventHandlerOfStringEventArgs = (@this, h) => messageEvent = h; ShimLogyardWebSocket.AllInstances.OpenUriStringUriBoolean = (@this, appLogEndpoint, authenticationToken, proxy, skipCertValidation) => { }; LogyardLog log = new LogyardLog(logyardEndpoint, string.Empty); log.ErrorReceived += delegate(object sender, ErrorEventArgs e) { Assert.AreEqual(msg.Error, e.Error.Message); messageEventFired.Set(); }; log.StartLogStream(appGuid.ToString()); messageEvent(this, new StringEventArgs() { Data = json }); Assert.IsTrue(messageEventFired.WaitOne(100)); } }
public void RecentTwiceTest() { using (ShimsContext.Create()) { ShimLogyardWebSocket.AllInstances.OpenUriStringUriBoolean = (@this, appLogEndpoint, authenticationToken, proxy, skipCertValidation) => { }; LogyardLog logyard = new LogyardLog(logyardEndpoint, string.Empty); string appGuid = Guid.NewGuid().ToString(); logyard.StartLogStream(appGuid); try { logyard.StartLogStream(appGuid); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(InvalidOperationException)); Assert.IsTrue(ex.Message.Contains("The log stream has already been started.")); } } }
public void RecentNullAppIdTest() { using (ShimsContext.Create()) { ShimLogyardWebSocket.AllInstances.OpenUriStringUriBoolean = (@this, appLogEndpoint, authenticationToken, proxy, skipCertValidation) => { }; LogyardLog logyard = new LogyardLog(logyardEndpoint, string.Empty); try { logyard.StartLogStream(null); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentNullException)); } } }
public void StopRecentTest() { using (ShimsContext.Create()) { var closedEvent = default(EventHandler<EventArgs>); var closedEventFired = new ManualResetEvent(false); ShimLogyardWebSocket.AllInstances.StreamClosedAddEventHandlerOfEventArgs = (@this, h) => closedEvent = h; ShimLogyardWebSocket.AllInstances.OpenUriStringUriBoolean = (@this, appLogEndpoint, authenticationToken, proxy, skipCertValidation) => { }; ShimLogyardWebSocket.AllInstances.Close = (@this) => { closedEvent(this, EventArgs.Empty); }; ShimLogyardWebSocket.AllInstances.Dispose = (@this) => { }; LogyardLog logyard = new LogyardLog(logyardEndpoint, string.Empty); logyard.StreamClosed += delegate(object sender, EventArgs e) { closedEventFired.Set(); }; logyard.StartLogStream(Guid.NewGuid().ToString(), 50, false); logyard.StopLogStream(); Assert.IsTrue(closedEventFired.WaitOne(100)); Assert.AreEqual(ConnectionState.None, logyard.State); } }