private Telemetry.Domain.Config GetMetricsConfigSentBackend(HttpClientMock httpClientMock) { var logs = httpClientMock.GetMetricsConfigLog(); if (logs.FirstOrDefault() == null) { return(null); } return(JsonConvert.DeserializeObject <Telemetry.Domain.Config>(logs.FirstOrDefault().RequestMessage.Body)); }
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); }
private List <Telemetry.Domain.Stats> GetMetricsStatsSentBackend(HttpClientMock httpClientMock) { var stats = new List <Telemetry.Domain.Stats>(); var logs = httpClientMock.GetMetricsUsageLog(); foreach (var item in logs) { var stat = JsonConvert.DeserializeObject <Telemetry.Domain.Stats>(item.RequestMessage.Body); stats.Add(stat); } return(stats); }
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); impressions.AddRange(_impressions); } return(impressions); }
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"); httpClientMock.Post_Response("/api/testImpressions/bulk", 200, "ok"); httpClientMock.Post_Response("/api/events/bulk", 200, "ok"); var notification = "d4\r\nevent: message\ndata: {\"id\":\"123\",\"clientId\":\"emptyClientId\",\"timestamp\":1582056812285,\"encoding\":\"json\",\"channel\":\"[?occupancy=metrics.publishers]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(10000); Thread.Sleep(500); var result = client.GetTreatment("admin", "push_test"); Assert.AreEqual("on", result); client.Destroy(); } }
public void GetTreatment_SplitKill_ShouldFetch() { 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"); httpClientMock.Post_Response("/api/testImpressions/bulk", 200, "ok"); httpClientMock.Post_Response("/api/events/bulk", 200, "ok"); var notification = "fb\r\nid: 123\nevent: message\ndata: {\"id\":\"1\",\"clientId\":\"emptyClientId\",\"connectionId\":\"1\",\"timestamp\":1582045421733,\"channel\":\"mauroc\",\"data\":\"{\\\"type\\\" : \\\"SPLIT_KILL\\\",\\\"changeNumber\\\": 1585948850111, \\\"defaultTreatment\\\" : \\\"off_kill\\\", \\\"splitName\\\" : \\\"push_test\\\"}\",\"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(10000); Thread.Sleep(5000); var result = client.GetTreatment("admin", "push_test"); Assert.AreEqual("after_fetch", result); client.Destroy(); } }
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()); } }
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); }
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"); httpClientMock.Post_Response("/api/testImpressions/bulk", 200, "ok"); httpClientMock.Post_Response("/api/events/bulk", 200, "ok"); return(httpClientMock); }
protected override void AssertSentEvents(List <EventBackend> eventsExpected, HttpClientMock httpClientMock = null, int sleepTime = 5000, 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()); } } }
protected override void AssertSentImpressions(int sentImpressionsCount, HttpClientMock httpClientMock = null, params KeyImpression[] expectedImpressions) { if (sentImpressionsCount <= 0) { return; } var sentImpressions = GetImpressionsSentBackend(httpClientMock); var time = 1000; while (sentImpressionsCount != sentImpressions.Sum(si => si.I.Count)) { if (time >= 10000) { break; } Thread.Sleep(time); time = time + 100; sentImpressions = GetImpressionsSentBackend(httpClientMock); } Assert.AreEqual(sentImpressionsCount, sentImpressions.Sum(si => si.I.Count)); foreach (var expectedImp in expectedImpressions) { var impressions = new List <ImpressionData>(); foreach (var ki in sentImpressions.Where(si => si.F.Equals(expectedImp.feature))) { impressions.AddRange(ki.I); } AssertImpression(expectedImp, impressions); } }
protected abstract void AssertSentEvents(List <EventBackend> eventsExcpected, HttpClientMock httpClientMock = null, int sleepTime = 15000, int?eventsCount = null, bool validateEvents = true);
protected abstract void AssertSentImpressions(int sentImpressionsCount, HttpClientMock httpClientMock = null, params KeyImpression[] expectedImpressions);
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); } }