Esempio n. 1
0
        public void SerializeEvent()
        {
            var eventsString = "{\"body\":\"eyJrZXkxIjoidmFsdWUxIiwgImtleTIiOiJ2YWx1ZTIifQ==\",\"content-type\":\"plain/text\",\"headers\":{\"testkey\":\"testvalue\"},\"fields\":{\"testkey\":\"testvalue\"},\"size\":9223372036854775807,\"id\":\"123\",\"method\":\"testmethod\",\"path\":\"testpath\",\"url\":\"http://localhost\",\"version\":1234,\"timestamp\":15187716610000000,\"trigger\":{\"class\":\"testclass\",\"kind\":\"testkind\"}}";

            var eve = new Event();

            eve.SetBody("{\"key1\":\"value1\", \"key2\":\"value2\"}");
            eve.ContentType = "plain/text";
            eve.Headers.Add("testkey", "testvalue");
            eve.Fields.Add("testkey", "testvalue");
            eve.Id            = "123";
            eve.Method        = "testmethod";
            eve.Path          = "testpath";
            eve.Size          = long.MaxValue;
            eve.Timestamp     = new System.DateTime(2018, 02, 16, 09, 01, 01, System.DateTimeKind.Utc);
            eve.Trigger.Class = "testclass";
            eve.Trigger.Kind  = "testkind";
            eve.Url           = "http://localhost";
            eve.Version       = 1234;

            var serialized = NuclioSerializationHelpers <Event> .Serialize(eve);

            Assert.IsFalse(string.IsNullOrEmpty(serialized));
            serialized.Should().BeEquivalentTo(eventsString);
        }
Esempio n. 2
0
        private void MessageReceived(object sender, EventArgs e)
        {
            var msgArgs = e as MessageEventArgs;

            if (msgArgs != null)
            {
                var      st       = new System.Diagnostics.Stopwatch();
                Response response = null;
                var      context  = new Context();
                try
                {
                    st.Start();
                    var eve = NuclioSerializationHelpers <Event> .Deserialize(msgArgs.Message);

                    context.Logger.LogEvent += LogEvent;
                    var result = InvokeFunction(context, eve);
                    response = CreateResponse(result);
                }
                catch (Exception ex)
                {
                    response = CreateResponse(ex);
                }
                finally
                {
                    st.Stop();
                    context.Logger.LogEvent -= LogEvent;
                    var metric = new Metric()
                    {
                        Duration = st.Elapsed.TotalSeconds
                    };
                    socketHandler.SendMessage(string.Join(String.Empty, "m", NuclioSerializationHelpers <Metric> .Serialize(metric), Environment.NewLine));
                    socketHandler.SendMessage(string.Join(String.Empty, "r", NuclioSerializationHelpers <Response> .Serialize(response), Environment.NewLine));
                }
            }
        }
Esempio n. 3
0
        private void LogEvent(object sender, EventArgs e)
        {
            var logger       = (Logger)sender;
            var loggerString = new StringBuilder("l");

            loggerString.Append(NuclioSerializationHelpers <Logger> .Serialize(logger));
            loggerString.AppendLine();
            socketHandler.SendMessage(loggerString.ToString());
        }
Esempio n. 4
0
        public void SerializeResponse()
        {
            var responseString = "{\"body\":\"test\",\"content_type\":\"plain/text\",\"status_code\":200,\"headers\":{\"testkey\":\"testvalue\"},\"body_encoding\":\"text\"}";

            var response = new Response();

            response.Body         = "test";
            response.BodyEncoding = "text";
            response.ContentType  = "plain/text";
            response.StatusCode   = 200;
            response.Headers.Add("testkey", "testvalue");

            var serialized = NuclioSerializationHelpers <Response> .Serialize(response);

            Assert.IsFalse(string.IsNullOrEmpty(serialized));
            serialized.Should().BeEquivalentTo(responseString);
        }
Esempio n. 5
0
        public void SerializeMissingPropertiesEvent()
        {
            var eventsString = "{\"body\":\"eyJrZXkxIjoidmFsdWUxIiwgImtleTIiOiJ2YWx1ZTIifQ==\",\"content-type\":\"plain/text\",\"headers\":{\"testkey\":\"testvalue\"},\"fields\":{\"testkey\":\"testvalue\"},\"size\":0,\"id\":\"123\",\"method\":null,\"path\":null,\"url\":null,\"version\":0,\"timestamp\":-62135596800,\"trigger\":{\"class\":null,\"kind\":null}}";

            var eve = new Event();

            eve.SetBody("{\"key1\":\"value1\", \"key2\":\"value2\"}");
            eve.ContentType = "plain/text";
            eve.Headers.Add("testkey", "testvalue");
            eve.Fields.Add("testkey", "testvalue");
            eve.Id = "123";

            var serialized = NuclioSerializationHelpers <Event> .Serialize(eve);

            Assert.IsFalse(string.IsNullOrEmpty(serialized));
            serialized.Should().BeEquivalentTo(eventsString);
        }
Esempio n. 6
0
        private void LogEvent(object sender, EventArgs e)
        {
            var logger = (Logger)sender;

            socketHandler.SendMessage(string.Join(String.Empty, "l", NuclioSerializationHelpers <Logger> .Serialize(logger), Environment.NewLine));
        }