예제 #1
0
        public void StartTest()
        {
            //Test 1: double start
            using (SyslogUdpReceiver target = new SyslogUdpReceiver())
            {
                try
                {
                    target.SetConfigurationParameter("port", "37888");
                    target.SetConfigurationParameter("ip", "127.0.0.1");
                    //target.Configuration.Add(new KeyValuePair<string, string>("port", "37888"));
                    //target.Configuration.Add(new KeyValuePair<string, string>("ip", "127.0.0.1"));
                    target.Start();
                    target.Start();
                    Assert.Fail("It should have thrown LogbusException");
                }
                catch (InvalidOperationException)
                {
                    //OK
                }
                catch (Exception ex)
                {
                    Assert.Fail("I expected InvalidOperationException, found {0}", ex.GetType());
                }
            }

            //OK test
            using (SyslogUdpReceiver target = new SyslogUdpReceiver())
            {
                target.SetConfigurationParameter("port", "37889");
                target.SetConfigurationParameter("ip", "127.0.0.1");
                target.Start();
            }
            //OK
        }
        public void RuntimeTest()
        {
            using (SyslogUdpReceiver target = new SyslogUdpReceiver())
            {
                TestContext.BeginTimer("RunTimer");

                target.SetConfigurationParameter("port", port.ToString());
                //target.Configuration["ip"] = "127.0.0.1";
                target.Start();
                target.MessageReceived += target_MessageReceived;
                target.ParseError      += target_ParseError; //Most interesting

                injector_thread.Start();
                test_finished.WaitOne();

                target.Stop();

                TestContext.EndTimer("RunTimer");

                TestContext.WriteLine("Summary of SyslogUdpRuntimeTest:\r\nTotal messages: {0}\r\nSuccessfully parsed: {1}\r\nFailed parsing: {2}",
                                      logs_sent, logs_received, logs_error);

                Assert.AreEqual(logs_sent, logs_received + logs_error); //Integrity
                Assert.AreEqual(0, logs_error);                         //Correctness
            }
        }
예제 #3
0
        public void StopTest()
        {
            //Test 1: stop but not started
            try
            {
                using (SyslogUdpReceiver target = new SyslogUdpReceiver())
                {
                    //target.Configuration["port"] = "37889";
                    //target.Configuration["ip"] = "127.0.0.1";
                    //target.Start();
                    target.Stop();
                }
                Assert.Fail("I expected InvalidOperationException");
            }
            catch (InvalidOperationException)
            {
                //OK
            }
            catch (Exception ex)
            {
                Assert.Fail("Something went wrong: [{0}]", ex);
            }


            //Test 2: start and stop
            try
            {
                using (SyslogUdpReceiver target = new SyslogUdpReceiver())
                {
                    target.SetConfigurationParameter("port", "37889");
                    target.SetConfigurationParameter("ip", "127.0.0.1");
                    target.Start();
                    target.Stop();
                }
                //OK
            }
            catch (Exception ex)
            {
                Assert.Fail("Something went wrong: [{0}]", ex);
            }
        }
예제 #4
0
        public void ConfigurationTest()
        {
            //Test 1: empty configuration
            using (SyslogUdpReceiver target = new SyslogUdpReceiver())
            {
                try
                {
                    target.Start();
                    Assert.Fail("Collector not initialized but started");
                }
                catch (LogbusException)
                {
                    //OK
                }
                catch (Exception)
                {
                    Assert.Fail("I expected InvalidOperationException");
                }
            }

            //Test 2: bad data
            using (SyslogUdpReceiver target = new SyslogUdpReceiver())
            {
                try
                {
                    target.SetConfigurationParameter("port", "HELL0");
                    target.SetConfigurationParameter("ip", "656.33.21.0");
                    //target.Configuration.Add(new KeyValuePair<string, string>("port", "37888"));
                    //target.Configuration.Add(new KeyValuePair<string, string>("ip", "127.0.0.1"));
                    target.Start();
                    Assert.Fail("It should never have started");
                }
                catch (LogbusException)
                {
                    //OK
                }
                catch (Exception ex)
                {
                    Assert.Fail("Listener should have started... [{0}]", ex.ToString());
                }
            }

            //Test 3: IP and port filled (it should start)
            using (SyslogUdpReceiver target = new SyslogUdpReceiver())
            {
                try
                {
                    target.SetConfigurationParameter("port", "37888");
                    target.SetConfigurationParameter("ip", "127.0.0.1");
                    //target.Configuration.Add(new KeyValuePair<string, string>("port", "37888"));
                    //target.Configuration.Add(new KeyValuePair<string, string>("ip", "127.0.0.1"));
                    target.Start();
                    target.Stop();
                }
                catch (Exception ex)
                {
                    Assert.Fail("Listener should have started... [{0}]", ex.ToString());
                }
            }


            //Test 4: start & stop twice
            using (SyslogUdpReceiver target = new SyslogUdpReceiver())
            {
                try
                {
                    target.SetConfigurationParameter("port", "37888");
                    target.SetConfigurationParameter("ip", "127.0.0.1");
                    //target.Configuration.Add(new KeyValuePair<string, string>("port", "37888"));
                    //target.Configuration.Add(new KeyValuePair<string, string>("ip", "127.0.0.1"));
                    target.Start();
                    target.Stop();
                    target.Start();
                    target.Stop();
                }
                catch (Exception ex)
                {
                    Assert.Fail("It shouldn't fail... [{0}]", ex.ToString());
                }
            }
        }