Example #1
0
        public void LogSuccessfully()
        {
            //Arrange
            var queue            = new BlockingQueue <KeyImpression>(10);
            var impressionsCache = new InMemoryImpressionsCache(queue);
            var treatmentLog     = new SelfUpdatingTreatmentLog(null, 1, impressionsCache, 10);

            //Act
            var impression = new KeyImpression()
            {
                keyName = "GetTreatment", feature = "test", treatment = "on", time = 7000, changeNumber = 1, label = "test"
            };

            treatmentLog.Log(impression);

            //Assert
            KeyImpression element = null;

            while (element == null)
            {
                element = queue.Dequeue();
            }
            Assert.IsNotNull(element);
            Assert.AreEqual("GetTreatment", element.keyName);
            Assert.AreEqual("test", element.feature);
            Assert.AreEqual("on", element.treatment);
            Assert.AreEqual(7000, element.time);
        }
Example #2
0
        public void LogSuccessfullyUsingBucketingKey()
        {
            //Arrange
            var queue            = new BlockingQueue <KeyImpression>(10);
            var impressionsCache = new InMemoryImpressionsCache(queue);
            var treatmentLog     = new SelfUpdatingTreatmentLog(null, 1, impressionsCache, 10);

            //Act
            Key key        = new Key(bucketingKey: "a", matchingKey: "testkey");
            var impression = new KeyImpression()
            {
                keyName = key.matchingKey, feature = "test", treatment = "on", time = 7000, changeNumber = 1, label = "test-label", bucketingKey = key.bucketingKey
            };

            treatmentLog.Log(impression);

            //Assert
            KeyImpression element = null;

            while (element == null)
            {
                element = queue.Dequeue();
            }
            Assert.IsNotNull(element);
            Assert.AreEqual("testkey", element.keyName);
            Assert.AreEqual("a", element.bucketingKey);
            Assert.AreEqual("test", element.feature);
            Assert.AreEqual("on", element.treatment);
            Assert.AreEqual(7000, element.time);
        }
Example #3
0
 private void BuildTreatmentLog(ConfigurationOptions config)
 {
     impressionsCache   = new InMemoryImpressionsCache(new BlockingQueue <KeyImpression>(TreatmentLogSize));
     treatmentLog       = new SelfUpdatingTreatmentLog(treatmentSdkApiClient, TreatmentLogRefreshRate, impressionsCache);
     impressionListener = new AsynchronousImpressionListener();
     ((AsynchronousImpressionListener)impressionListener).AddListener(treatmentLog);
     if (config.ImpressionListener != null)
     {
         ((AsynchronousImpressionListener)impressionListener).AddListener(config.ImpressionListener);
     }
 }
Example #4
0
        public void ExecuteGetTreatmentWithDependencyMatcherImpressionOnChild()
        {
            //Arrange
            var queue            = new BlockingQueue <KeyImpression>(10);
            var impressionsCache = new InMemoryImpressionsCache(queue);
            var client           = new JSONFileClient(@"Resources\splits_staging_6.json", "", null, null, new SelfUpdatingTreatmentLog(null, 1000, impressionsCache));

            //Act
            var result = client.GetTreatment("test", "test_dependency_segment", null);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("V1", result);
            var item = queue.Dequeue();

            Assert.AreEqual(item.feature, "test_dependency_segment");
            Assert.IsNull(queue.Dequeue());
        }
Example #5
0
        public void AddImpressionSuccessfully()
        {
            //Arrange
            var queue = new BlockingQueue <KeyImpression>(2);
            var cache = new InMemoryImpressionsCache(queue);

            //Act
            cache.AddImpression(new KeyImpression()
            {
                feature = "test", changeNumber = 100, keyName = "date", label = "testdate", time = 10000000
            });
            var element  = queue.Dequeue();
            var element2 = queue.Dequeue();

            //Assert
            Assert.IsNotNull(element);
            Assert.IsNull(element2);
        }
Example #6
0
        public void FetchAllAndClearWithNullQueue()
        {
            //Arrange
            var cache = new InMemoryImpressionsCache(null);

            cache.AddImpression(new KeyImpression()
            {
                feature = "test", changeNumber = 100, keyName = "date", label = "testdate", time = 10000000
            });
            cache.AddImpression(new KeyImpression()
            {
                feature = "test2", changeNumber = 100, keyName = "date", label = "testdate", time = 10000000
            });

            //Act
            var result = cache.FetchAllAndClear();

            //Assert
            Assert.IsNull(result);
        }
Example #7
0
        public void LogSuccessfullyAndSendImpressions()
        {
            //Arrange
            var apiClientMock    = new Mock <ITreatmentSdkApiClient>();
            var queue            = new BlockingQueue <KeyImpression>(10);
            var impressionsCache = new InMemoryImpressionsCache(queue);
            var treatmentLog     = new SelfUpdatingTreatmentLog(apiClientMock.Object, 1, impressionsCache, 10);

            //Act
            treatmentLog.Start();
            var impression = new KeyImpression()
            {
                keyName = "GetTreatment", feature = "test", treatment = "on", time = 7000, changeNumber = 1, label = "test-label"
            };

            treatmentLog.Log(impression);

            //Assert
            Thread.Sleep(2000);
            apiClientMock.Verify(x => x.SendBulkImpressions(It.IsAny <string>()));
        }
Example #8
0
        public void HasReachedMaxSizeWithNullQueue()
        {
            //Arrange
            var queue = new BlockingQueue <KeyImpression>(3);
            var cache = new InMemoryImpressionsCache(queue);

            //Act
            cache.AddImpression(new KeyImpression()
            {
                feature = "test", changeNumber = 100, keyName = "date", label = "testdate", time = 10000000
            });
            cache.AddImpression(new KeyImpression()
            {
                feature = "test2", changeNumber = 100, keyName = "date", label = "testdate", time = 10000000
            });

            var result = cache.HasReachedMaxSize();

            //Assert
            Assert.IsFalse(result);
        }
Example #9
0
        public void FetchAllAndClearSuccessfully()
        {
            //Arrange
            var queue = new BlockingQueue <KeyImpression>(2);
            var cache = new InMemoryImpressionsCache(queue);

            cache.AddImpression(new KeyImpression()
            {
                feature = "test", changeNumber = 100, keyName = "date", label = "testdate", time = 10000000
            });
            cache.AddImpression(new KeyImpression()
            {
                feature = "test2", changeNumber = 100, keyName = "date", label = "testdate", time = 10000000
            });

            //Act
            var result  = cache.FetchAllAndClear();
            var element = queue.Dequeue();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count);
            Assert.IsNull(element);
        }