public void FetchAllCountMetricsSuccessfully()
        {
            //Arrange
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.IcrBy(metricsCountKeyPrefix + "counter_test", 150)).Returns(150);
            redisAdapterMock.Setup(x => x.IcrBy(metricsCountKeyPrefix + "counter_test_2", 123)).Returns(123);
            redisAdapterMock.Setup(x => x.IcrBy(metricsCountKeyPrefix + "counter_test_2", 1)).Returns(124);
            redisAdapterMock.Setup(x => x.Keys(metricsCountKeyPrefix + "*")).Returns(new RedisKey[] { metricsCountKeyPrefix + "counter_test", metricsCountKeyPrefix + "counter_test_2" });
            redisAdapterMock.Setup(x => x.Get(metricsCountKeyPrefix + "counter_test")).Returns("150");
            redisAdapterMock.Setup(x => x.Get(metricsCountKeyPrefix + "counter_test_2")).Returns("124");

            var cache = new RedisMetricsCache(redisAdapterMock.Object, "10.0.0.1", "net-1.0.2");

            cache.IncrementCount("counter_test", 150);
            cache.IncrementCount("counter_test_2", 123);
            cache.IncrementCount("counter_test_2", 1);

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

            //Assert
            Assert.IsNotNull(result);
            var result1 = result.First(x => x.Key == "counter_test");

            Assert.IsNotNull(result1);
            Assert.AreEqual(150, result1.Value.GetDelta());
            var result2 = result.First(x => x.Key == "counter_test_2");

            Assert.IsNotNull(result2);
            Assert.AreEqual(124, result2.Value.GetDelta());
        }
        public void IncrementCountShouldUpdateMetricWhenExisting()
        {
            //Arrange
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.IcrBy(metricsCountKeyPrefix + "counter_test", 150)).Returns(150);
            redisAdapterMock.Setup(x => x.IcrBy(metricsCountKeyPrefix + "counter_test", 10)).Returns(160);

            var cache = new RedisMetricsCache(redisAdapterMock.Object, "10.0.0.1", "net-1.0.2");

            //Act
            cache.IncrementCount("counter_test", 150);
            var result = cache.IncrementCount("counter_test", 10);

            //Assert
            Assert.AreEqual(160, result.GetDelta());
        }
Ejemplo n.º 3
0
        public void UseSplitioAndSdkMachineAndUserPrefix()
        {
            //Arrange
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.IcrBy("mycompany.SPLITIO/net-1.0.2/10.0.0.1/count.counter_test", 150)).Returns(150);
            var cache = new RedisMetricsCache(redisAdapterMock.Object, "10.0.0.1", "net-1.0.2", "mycompany");

            //Act
            var result = cache.IncrementCount("counter_test", 150);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.GetCount());
            Assert.AreEqual(150, result.GetDelta());
        }
Ejemplo n.º 4
0
        public void IncrementCountShouldAddNewMetricWhenNotExisting()
        {
            //Arrange
            var redisAdapterMock = new Mock <IRedisAdapter>();

            redisAdapterMock.Setup(x => x.IcrBy(metricsCountKeyPrefix + "counter_test", 150)).Returns(150);
            var cache = new RedisMetricsCache(redisAdapterMock.Object, "10.0.0.1", "net-1.0.2", "machine_name_test");

            //Act
            var result = cache.IncrementCount("counter_test", 150);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.GetCount());
            Assert.AreEqual(150, result.GetDelta());
        }