Example #1
0
        public void CreateANewSlowCloseToxicShouldWork()
        {
            var client = _connection.Client();

            var proxy = new Proxy
            {
                Name     = "testingProxy",
                Enabled  = true,
                Listen   = "127.0.0.1:9090",
                Upstream = "google.com"
            };

            var newProxy = client.AddAsync(proxy).Result;

            var toxic = new SlowCloseToxic
            {
                Name     = "SlowCloseToxicTest",
                Stream   = ToxicDirection.UpStream,
                Toxicity = 0.5
            };

            toxic.Attributes.Delay = 100;
            var newToxic = newProxy.AddAsync(toxic).Result;

            // Need to retrieve the proxy and check the toxic's values
            Assert.Equal(toxic.Name, newToxic.Name);
            Assert.Equal(toxic.Stream, newToxic.Stream);
            Assert.Equal(toxic.Attributes.Delay, newToxic.Attributes.Delay);
        }
Example #2
0
        public void GetAllToxicsFromAProxyShouldWork()
        {
            // Add two toxics to a proxy and check if they are present in the list
            // of the toxies for the given proxy
            var client = _connection.Client();
            var proxy  = new Proxy
            {
                Name     = "testingProxy",
                Enabled  = true,
                Listen   = "127.0.0.1:9090",
                Upstream = "google.com"
            };

            var newProxy = client.AddAsync(proxy).Result;

            var slicerToxic = new SlicerToxic
            {
                Name   = "SlicerToxicTest",
                Stream = ToxicDirection.UpStream
            };

            slicerToxic.Attributes.AverageSize   = 10;
            slicerToxic.Attributes.Delay         = 5;
            slicerToxic.Attributes.SizeVariation = 1;
            newProxy.AddAsync(slicerToxic).Wait();

            var slowCloseToxic = new SlowCloseToxic
            {
                Name     = "slowCloseToxic",
                Stream   = ToxicDirection.DownStream,
                Toxicity = 80
            };

            slowCloseToxic.Attributes.Delay = 50;
            newProxy.AddAsync(slowCloseToxic).Wait();

            // Retrieve the proxy and check the toxics
            var toxics = newProxy.GetAllToxicsAsync().Result;

            Assert.Equal(2, toxics.Count());

            var slicerToxicInTheProxy = toxics.OfType <SlicerToxic>().Single();

            Assert.Equal(slicerToxic.Name, slicerToxicInTheProxy.Name);
            Assert.Equal(slicerToxic.Stream, slicerToxicInTheProxy.Stream);
            Assert.Equal(slicerToxic.Attributes.AverageSize, slicerToxicInTheProxy.Attributes.AverageSize);
            Assert.Equal(slicerToxic.Attributes.Delay, slicerToxicInTheProxy.Attributes.Delay);
            Assert.Equal(slicerToxic.Attributes.SizeVariation, slicerToxicInTheProxy.Attributes.SizeVariation);

            var slowCloseToxicInTheProxy = toxics.OfType <SlowCloseToxic>().Single();

            Assert.Equal(slowCloseToxic.Name, slowCloseToxicInTheProxy.Name);
            Assert.Equal(slowCloseToxic.Stream, slowCloseToxicInTheProxy.Stream);
            Assert.Equal(slowCloseToxic.Attributes.Delay, slowCloseToxicInTheProxy.Attributes.Delay);
        }
Example #3
0
        public void DeleteAToxicShouldWork()
        {
            // Add two toxics to a proxy.
            // After delete the first one and check that
            // there is still the second toxic in the proxy
            var client = _connection.Client();
            var proxy  = new Proxy
            {
                Name     = "testingProxy",
                Enabled  = true,
                Listen   = "127.0.0.1:9090",
                Upstream = "google.com"
            };

            var newProxy = client.AddAsync(proxy).Result;

            var firstToxic = new SlicerToxic
            {
                Name   = "SlicerToxicTest",
                Stream = ToxicDirection.UpStream
            };

            firstToxic.Attributes.AverageSize   = 10;
            firstToxic.Attributes.Delay         = 5;
            firstToxic.Attributes.SizeVariation = 1;
            newProxy.AddAsync(firstToxic).Wait();

            var secondToxic = new SlowCloseToxic
            {
                Name     = "slowCloseToxic",
                Stream   = ToxicDirection.DownStream,
                Toxicity = 80
            };

            secondToxic.Attributes.Delay = 50;
            newProxy.AddAsync(secondToxic).Wait();

            // Delete the first toxic
            newProxy.RemoveToxicAsync(firstToxic.Name).Wait();

            // Retrieve the proxy and check that there is the
            // correct toxics
            var toxicsInProxy = newProxy.GetAllToxicsAsync().Result;

            Assert.True(1 == toxicsInProxy.Count());
            Assert.IsType <SlowCloseToxic>(toxicsInProxy.First());
            var singleToxicInProxy = (SlowCloseToxic)toxicsInProxy.First();

            Assert.Equal(secondToxic.Name, singleToxicInProxy.Name);
            Assert.Equal(secondToxic.Stream, singleToxicInProxy.Stream);
            Assert.Equal(secondToxic.Toxicity, singleToxicInProxy.Toxicity);
            Assert.Equal(secondToxic.Attributes.Delay, singleToxicInProxy.Attributes.Delay);
        }