public void InitializeSegmentNotExistent() { //Arrange var gates = new InMemoryReadinessGatesCache(); var apiClient = new Mock <ISegmentSdkApiClient>(); apiClient .Setup(x => x.FetchSegmentChanges(It.IsAny <string>(), It.IsAny <long>())) .Returns(Task.FromResult(@"{ 'name': 'payed', 'added': [ 'abcdz', 'bcadz', 'xzydz' ], 'removed': [], 'since': -1, 'till': 10001 }")); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); var segments = new ConcurrentDictionary <string, Segment>(); var cache = new InMemorySegmentCache(segments); var segmentTaskQueue = new SegmentTaskQueue(); var segmentFetcher = new SelfRefreshingSegmentFetcher(apiFetcher, gates, 10, cache, 1, segmentTaskQueue); //Act segmentFetcher.InitializeSegment("payed"); //Assert Thread.Sleep(5000); Assert.IsTrue(gates.AreSegmentsReady(1)); Assert.IsTrue(cache.IsInSegment("payed", "abcdz")); }
public void ExecuteGetSuccessfulWithResults() { //Arrange var baseUrl = "https://sdk-aws-staging.split.io/api/"; var headers = new Dictionary <string, string> { { "SplitSDKMachineIP", "1.0.0.0" }, { "SplitSDKMachineName", "localhost" }, { "SplitSDKVersion", "1" } }; var telemetryStorage = new InMemoryTelemetryStorage(); var sdkApiClient = new SegmentSdkApiClient("///PUT API KEY HERE///", headers, baseUrl, 10000, 10000, telemetryStorage); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkApiClient); var gates = new InMemoryReadinessGatesCache(); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var segmentTaskQueue = new SegmentTaskQueue(); var wrapperAdapter = new WrapperAdapter(); var selfRefreshingSegmentFetcher = new SelfRefreshingSegmentFetcher(apiSegmentChangeFetcher, gates, 30, segmentCache, 4, segmentTaskQueue, new TasksManager(wrapperAdapter), wrapperAdapter); //Act var name = "payed"; selfRefreshingSegmentFetcher.InitializeSegment(name); //Assert Assert.IsTrue(segmentCache.IsInSegment(name, "abcdz")); }
public void InitializeSegmentNotExistent() { // Arrange var gates = new InMemoryReadinessGatesCache(); gates.SetReady(); var apiClient = new Mock <ISegmentSdkApiClient>(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); var segments = new ConcurrentDictionary <string, Segment>(); var cache = new InMemorySegmentCache(segments); var segmentTaskQueue = new SegmentTaskQueue(); var segmentFetcher = new SelfRefreshingSegmentFetcher(apiFetcher, gates, 1, cache, 1, segmentTaskQueue, new TasksManager(wrapperAdapter), wrapperAdapter); segmentFetcher.Start(); apiClient .Setup(x => x.FetchSegmentChanges(It.IsAny <string>(), It.IsAny <long>(), It.IsAny <FetchOptions>())) .Returns(Task.FromResult(PayedSplitJson)); // Act segmentFetcher.InitializeSegment("payed"); // Assert Thread.Sleep(5000); Assert.IsTrue(cache.IsInSegment("payed", "abcdz")); }
public void ExecuteGetSuccessfulWithResults() { //Arrange var baseUrl = "https://sdk-aws-staging.split.io/api/"; var httpHeader = new HTTPHeader() { authorizationApiKey = "///PUT API KEY HERE///", splitSDKMachineIP = "1.0.0.0", splitSDKMachineName = "localhost", splitSDKVersion = "net-0.0.0", splitSDKSpecVersion = "1.2", }; var sdkApiClient = new SegmentSdkApiClient(httpHeader, baseUrl, 10000, 10000); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkApiClient); var gates = new InMemoryReadinessGatesCache(); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var selfRefreshingSegmentFetcher = new SelfRefreshingSegmentFetcher(apiSegmentChangeFetcher, gates, 30, segmentCache, 4); //Act var name = "payed"; selfRefreshingSegmentFetcher.InitializeSegment(name); while (!gates.AreSegmentsReady(1000)) { Thread.Sleep(10); } //Assert Assert.IsTrue(segmentCache.IsInSegment(name, "abcdz")); }
public void RemoveKeyFromSegmentTest() { //Arrange var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var keys = new List <string> { "1234" }; var segmentName = "test"; //Act segmentCache.AddToSegment(segmentName, keys); var result = segmentCache.IsInSegment(segmentName, "1234"); segmentCache.RemoveFromSegment(segmentName, keys); var result2 = segmentCache.IsInSegment(segmentName, "1234"); //Assert Assert.IsTrue(result); Assert.IsFalse(result2); }
public void IsInSegmentWithInexistentSegmentTest() { //Arrange var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); //Act var result = segmentCache.IsInSegment("test", "abcd"); //Assert Assert.IsFalse(result); }
public void ExecuteGetSuccessfulWithResultsFromJSONFile() { //Arrange var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var segmentFetcher = new JSONFileSegmentFetcher($"{rootFilePath}segment_payed.json", segmentCache); //Act segmentFetcher.InitializeSegment("payed"); //Assert Assert.IsTrue(segmentCache.IsInSegment("payed", "abcdz")); }
public void IsNotInSegmentTest() { //Arrange var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>()); var keys = new List <string> { "1234" }; var segmentName = "test"; //Act segmentCache.AddToSegment(segmentName, keys); var result = segmentCache.IsInSegment(segmentName, "abcd"); //Assert Assert.IsFalse(result); }