Exemplo n.º 1
0
        protected override ConfigurationOptions GetConfigurationOptions(HttpClientMock httpClientMock = null, int?eventsPushRate = null, int?eventsQueueSize = null, int?featuresRefreshRate = null, bool?ipAddressesEnabled = null)
        {
            _impressionListener = new IntegrationTestsImpressionListener(50);

            var cacheConfig = new CacheAdapterConfigurationOptions
            {
                Host     = Host,
                Port     = Port,
                Password = Password,
                Database = Database
            };

            return(new ConfigurationOptions
            {
                ImpressionListener = _impressionListener,
                FeaturesRefreshRate = featuresRefreshRate ?? 1,
                SegmentsRefreshRate = 1,
                ImpressionsRefreshRate = 1,
                MetricsRefreshRate = 1,
                EventsPushRate = eventsPushRate ?? 1,
                IPAddressesEnabled = ipAddressesEnabled,
                CacheAdapterConfig = cacheConfig,
                Mode = Mode.Consumer
            });
        }
Exemplo n.º 2
0
        protected override ConfigurationOptions GetConfigurationOptions(HttpClientMock httpClientMock = null, int?eventsPushRate = null, int?eventsQueueSize = null, int?featuresRefreshRate = null, bool?ipAddressesEnabled = null)
        {
            _impressionListener = new IntegrationTestsImpressionListener(50);

            var cacheConfig = new CacheAdapterConfigurationOptions
            {
                Type           = AdapterType.Redis,
                Host           = Host,
                Port           = Port,
                Password       = Password,
                Database       = Database,
                ConnectTimeout = 5000,
                ConnectRetry   = 3,
                SyncTimeout    = 1000,
                UserPrefix     = UserPrefix
            };

            return(new ConfigurationOptions
            {
                ReadTimeout = 20000,
                ConnectionTimeout = 20000,
                ImpressionListener = _impressionListener,
                FeaturesRefreshRate = featuresRefreshRate ?? 1,
                SegmentsRefreshRate = 1,
                ImpressionsRefreshRate = 1,
                MetricsRefreshRate = 1,
                EventsPushRate = eventsPushRate ?? 1,
                Mode = Mode.Consumer,
                CacheAdapterConfig = cacheConfig,
                IPAddressesEnabled = ipAddressesEnabled
            });
        }
Exemplo n.º 3
0
        private List <ImpressionCount> GetImpressionsCountsSentBackend(HttpClientMock httpClientMock = null)
        {
            var impressions = new List <ImpressionCount>();
            var logs        = httpClientMock.GetImpressionCountsLogs();

            foreach (var log in logs)
            {
                var _impression = JsonConvert.DeserializeObject <ImpressionCount>(log.RequestMessage.Body);

                impressions.Add(_impression);
            }

            return(impressions);
        }
Exemplo n.º 4
0
        protected override void AssertSentImpressions(int sentImpressionsCount, HttpClientMock httpClientMock = null, params KeyImpression[] expectedImpressions)
        {
            Thread.Sleep(1500);

            var redisImpressions = _redisAdapter.ListRange("SPLITIO.impressions");

            Assert.AreEqual(sentImpressionsCount, redisImpressions.Length);

            foreach (var item in redisImpressions)
            {
                var actualImp = JsonConvert.DeserializeObject <KeyImpressionRedis>(item);

                AssertImpression(actualImp, expectedImpressions.ToList());
            }
        }
Exemplo n.º 5
0
        protected override void AssertSentImpressions(int sentImpressionsCount, HttpClientMock httpClientMock = null, params KeyImpression[] expectedImpressions)
        {
            Thread.Sleep(1500);

            var sentImpressions = GetImpressionsSentBackend(httpClientMock);

            Assert.AreEqual(sentImpressionsCount, sentImpressions.Sum(si => si.KeyImpressions.Count));

            foreach (var expectedImp in expectedImpressions)
            {
                var keyImpressions = sentImpressions.First(si => si.TestName.Equals(expectedImp.feature)).KeyImpressions;

                AssertImpression(expectedImp, keyImpressions);
            }
        }
Exemplo n.º 6
0
        public void GetTreatment_SegmentUpdate_ShouldFetch()
        {
            using (var httpClientMock = new HttpClientMock())
            {
                httpClientMock.SplitChangesSequence("splits_push.json", "-1", "First_Time_2");
                httpClientMock.SplitChangesSequence("splits_push2.json", "1585948850109", "First_Time");
                httpClientMock.SegmentChangesSequence("-1", "segment4", "split_segment4", "First_time", "1470947453878", "split_segment4_empty", "Second_time", "1470947453878", "split_segment4_updated", "Third_time");
                httpClientMock.SegmentChangesOk("1470947453879", "segment4", "split_segment4_updated_empty");


                var notification = "fb\r\nid: 123\nevent: message\ndata: {\"id\":\"1\",\"clientId\":\"emptyClientId\",\"connectionId\":\"1\",\"timestamp\":1582045421733,\"channel\":\"mauroc\",\"data\":\"{\\\"type\\\" : \\\"SEGMENT_UPDATE\\\",\\\"changeNumber\\\": 1470947453879, \\\"segmentName\\\" : \\\"segment4\\\"}\",\"name\":\"asdasd\"}\n\n\r\n";
                httpClientMock.SSE_Channels_Response_WithPath(EventSourcePath, notification);

                var authResponse = new AuthenticationResponse
                {
                    PushEnabled = true,
                    Token       = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ4LWFibHktY2FwYWJpbGl0eSI6IntcInh4eHhfeHh4eF9zZWdtZW50c1wiOltcInN1YnNjcmliZVwiXSxcInh4eHhfeHh4eF9zcGxpdHNcIjpbXCJzdWJzY3JpYmVcIl0sXCJjb250cm9sXCI6W1wic3Vic2NyaWJlXCJdfSJ9"
                };

                httpClientMock.AuthService_Response(JsonConvert.SerializeObject(authResponse));

                var url    = httpClientMock.GetUrl();
                var config = new ConfigurationOptions
                {
                    Endpoint            = url,
                    EventsEndpoint      = url,
                    FeaturesRefreshRate = 3000,
                    SegmentsRefreshRate = 3000,
                    AuthServiceURL      = $"{url}/api/auth",
                    StreamingServiceURL = $"{url}{EventSourcePath}",
                    StreamingEnabled    = true
                };

                var apikey = "apikey1";

                var splitFactory = new SplitFactory(apikey, config);
                var client       = splitFactory.Client();

                client.BlockUntilReady(1000000);
                Thread.Sleep(20000);

                var result = client.GetTreatment("test_in_segment", "feature_segment");

                Assert.AreEqual("def_test", result);

                client.Destroy();
            }
        }
Exemplo n.º 7
0
        public void ControlMessage_StreamingDisabled()
        {
            using (var httpClientMock = new HttpClientMock())
            {
                httpClientMock.SplitChangesSequence("splits_push.json", "-1", "First_Time_2");
                httpClientMock.SplitChangesSequence("splits_push2.json", "1585948850109", "First_Time", "splits_push3.json", "1585948850109", "Second_Time");
                httpClientMock.SplitChangesSequence("splits_push4.json", "1585948850111", "First_Time_1");
                httpClientMock.SegmentChangesOk("-1", "segment4");
                httpClientMock.SegmentChangesOk("1470947453878", "segment4", "split_segment4_empty");

                var notification = "d4\r\nevent: message\ndata: {\"id\":\"123\",\"clientId\":\"emptyClientId\",\"timestamp\":1582056812285,\"encoding\":\"json\",\"channel\":\"control_pri\",\"data\":\"{\\\"type\\\":\\\"CONTROL\\\",\\\"controlType\\\":\\\"STREAMING_DISABLED\\\"}\"}\n\n\r\n";
                httpClientMock.SSE_Channels_Response_WithPath(EventSourcePath, notification);

                var authResponse = new AuthenticationResponse
                {
                    PushEnabled = true,
                    Token       = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ4LWFibHktY2FwYWJpbGl0eSI6IntcInh4eHhfeHh4eF9zZWdtZW50c1wiOltcInN1YnNjcmliZVwiXSxcInh4eHhfeHh4eF9zcGxpdHNcIjpbXCJzdWJzY3JpYmVcIl0sXCJjb250cm9sXCI6W1wic3Vic2NyaWJlXCJdfSJ9"
                };

                httpClientMock.AuthService_Response(JsonConvert.SerializeObject(authResponse));

                var url    = httpClientMock.GetUrl();
                var config = new ConfigurationOptions
                {
                    Endpoint            = url,
                    EventsEndpoint      = url,
                    FeaturesRefreshRate = 3000,
                    SegmentsRefreshRate = 3000,
                    AuthServiceURL      = $"{url}/api/auth",
                    StreamingServiceURL = $"{url}{EventSourcePath}",
                    StreamingEnabled    = true
                };

                var apikey = "apikey1";

                var splitFactory = new SplitFactory(apikey, config);
                var client       = splitFactory.Client();

                client.BlockUntilReady(1000000);
                Thread.Sleep(20000);

                var result = client.GetTreatment("admin", "push_test");

                Assert.AreEqual("after_fetch", result);

                client.Destroy();
            }
        }
Exemplo n.º 8
0
        private List <EventBackend> GetEventsSentBackend(HttpClientMock httpClientMock = null)
        {
            var events = new List <EventBackend>();
            var logs   = httpClientMock.GetEventsLog();

            foreach (var log in logs)
            {
                var _events = JsonConvert.DeserializeObject <List <EventBackend> >(log.RequestMessage.Body);

                foreach (var item in _events)
                {
                    events.Add(item);
                }
            }

            return(events);
        }
Exemplo n.º 9
0
        private List <KeyImpressionBackend> GetImpressionsSentBackend(HttpClientMock httpClientMock = null)
        {
            var impressions = new List <KeyImpressionBackend>();
            var logs        = httpClientMock.GetImpressionLogs();

            foreach (var log in logs)
            {
                var _impressions = JsonConvert.DeserializeObject <List <KeyImpressionBackend> >(log.RequestMessage.Body);

                foreach (var _imp in _impressions)
                {
                    impressions.Add(_imp);
                }
            }

            return(impressions);
        }
Exemplo n.º 10
0
        protected override HttpClientMock GetHttpClientMock()
        {
            var httpClientMock = new HttpClientMock();

            httpClientMock.SplitChangesOk("split_changes.json", "-1");
            httpClientMock.SplitChangesOk("split_changes_1.json", "1506703262916");

            httpClientMock.SegmentChangesOk("-1", "segment1");
            httpClientMock.SegmentChangesOk("1470947453877", "segment1");

            httpClientMock.SegmentChangesOk("-1", "segment2");
            httpClientMock.SegmentChangesOk("1470947453878", "segment2");

            httpClientMock.SegmentChangesOk("-1", "segment3");
            httpClientMock.SegmentChangesOk("1470947453879", "segment3");

            return(httpClientMock);
        }
Exemplo n.º 11
0
        protected override ConfigurationOptions GetConfigurationOptions(HttpClientMock httpClientMock = null, int?eventsPushRate = null, int?eventsQueueSize = null, int?featuresRefreshRate = null, bool?ipAddressesEnabled = null)
        {
            _impressionListener = new IntegrationTestsImpressionListener(50);

            return(new ConfigurationOptions
            {
                Endpoint = $"http://localhost:{httpClientMock.GetPort()}",
                EventsEndpoint = $"http://localhost:{httpClientMock.GetPort()}",
                ReadTimeout = 20000,
                ConnectionTimeout = 20000,
                ImpressionListener = _impressionListener,
                FeaturesRefreshRate = featuresRefreshRate ?? 1,
                SegmentsRefreshRate = 1,
                ImpressionsRefreshRate = 1,
                MetricsRefreshRate = 1,
                EventsPushRate = eventsPushRate ?? 1,
                EventsQueueSize = eventsQueueSize,
                IPAddressesEnabled = ipAddressesEnabled
            });
        }
Exemplo n.º 12
0
        protected override void AssertSentEvents(List <EventBackend> eventsExpected, HttpClientMock httpClientMock = null, int sleepTime = 15000, int?eventsCount = null, bool validateEvents = true)
        {
            Thread.Sleep(sleepTime);

            var sentEvents = GetEventsSentBackend(httpClientMock);

            Assert.AreEqual(eventsCount ?? eventsExpected.Count, sentEvents.Count);

            if (validateEvents)
            {
                foreach (var expected in eventsExpected)
                {
                    Assert.IsTrue(sentEvents
                                  .Where(ee => ee.Key == expected.Key)
                                  .Where(ee => ee.EventTypeId == expected.EventTypeId)
                                  .Where(ee => ee.Value == expected.Value)
                                  .Where(ee => ee.TrafficTypeName == expected.TrafficTypeName)
                                  .Where(ee => ee.Properties?.Count == expected.Properties?.Count)
                                  .Any());
                }
            }
        }
Exemplo n.º 13
0
 protected override void ShutdownServer(HttpClientMock httpClientMock = null)
 {
     _redisAdapter.Flush();
 }
Exemplo n.º 14
0
 protected override void ShutdownServer(HttpClientMock httpClientMock = null)
 {
     httpClientMock.ShutdownServer();
 }
Exemplo n.º 15
0
 protected abstract void AssertSentEvents(List <EventBackend> eventsExcpected, HttpClientMock httpClientMock = null, int sleepTime = 15000, int?eventsCount = null, bool validateEvents = true);
Exemplo n.º 16
0
 protected abstract void AssertSentImpressions(int sentImpressionsCount, HttpClientMock httpClientMock = null, params KeyImpression[] expectedImpressions);
Exemplo n.º 17
0
 protected abstract void ShutdownServer(HttpClientMock httpClientMock = null);
Exemplo n.º 18
0
 protected abstract ConfigurationOptions GetConfigurationOptions(HttpClientMock httpClientMock = null, int?eventsPushRate = null, int?eventsQueueSize = null, int?featuresRefreshRate = null, bool?ipAddressesEnabled = null);
Exemplo n.º 19
0
        protected override void AssertSentEvents(List <EventBackend> eventsExcpected, HttpClientMock httpClientMock = null, int sleepTime = 15000, int?eventsCount = null, bool validateEvents = true)
        {
            Thread.Sleep(sleepTime);

            var redisEvents = _redisAdapter.ListRange("SPLITIO.events");

            Assert.AreEqual(eventsExcpected.Count, redisEvents.Length);

            foreach (var item in redisEvents)
            {
                var actualEvent = JsonConvert.DeserializeObject <EventRedis>(item);

                AssertEvent(actualEvent, eventsExcpected);
            }
        }