public async Task CounterCreationShouldFailInCaseCounterAlreadyExists()
        {
            var key     = Guid.NewGuid().ToString();
            var counter = new AerospikeAtomicCounter(GetClientFactory(), GetSettingsProvider());

            await counter.Create(key, TimeSpan.FromSeconds(_expirySeconds));

            await Assert.ThrowsAsync(typeof(AerospikeProviderException), async() => await counter.Create(key, TimeSpan.FromSeconds(1)));
        }
        public async Task CounterCreationShouldSucceedWithDefaultValueOfZero()
        {
            var key     = Guid.NewGuid().ToString();
            var counter = new AerospikeAtomicCounter(GetClientFactory(), GetSettingsProvider());

            await counter.Create(key, TimeSpan.FromSeconds(_expirySeconds));

            var val = await counter.GetCurrentValue(key);

            Assert.Equal(0, val);
        }
        public async Task TestDefaultCounterDecrementByOne()
        {
            var key     = Guid.NewGuid().ToString();
            var counter = new AerospikeAtomicCounter(GetClientFactory(), GetSettingsProvider());

            await counter.Create(key, TimeSpan.FromSeconds(_expirySeconds));

            var val = await counter.Increment(key);

            Assert.Equal(1, val);
            val = await counter.Increment(key);

            Assert.Equal(2, val);
        }
        public async Task TestCounterIncrementSpecifiedFactor()
        {
            var incrementFactor = 3;
            var currentValue    = 0;
            var key             = Guid.NewGuid().ToString();
            var counter         = new AerospikeAtomicCounter(GetClientFactory(), GetSettingsProvider());

            await counter.Create(key, TimeSpan.FromSeconds(_expirySeconds));

            currentValue += incrementFactor;
            var val = await counter.Increment(key, incrementFactor);

            Assert.Equal(currentValue, val);

            currentValue += incrementFactor;
            val           = await counter.Increment(key, incrementFactor);

            Assert.Equal(currentValue, val);
        }
        public async Task TestCouncurrentIncrementOperationsAtomicity()
        {
            var key     = Guid.NewGuid().ToString();
            var counter = new AerospikeAtomicCounter(GetClientFactory(), GetSettingsProvider());

            await counter.Create(key, TimeSpan.FromSeconds(_expirySeconds));

            var incrementTasks = new List <Task>();

            for (var i = 0; i < 100; i++)
            {
                incrementTasks.Add(Task.Run(() => counter.Increment(key)));
            }

            await Task.WhenAll(incrementTasks.ToArray());

            var counterVal = await counter.GetCurrentValue(key);

            Assert.Equal(incrementTasks.Count, counterVal);
        }