public async Task TestSequenceFixIfKeyRemoveAtServer()
        {
            const string theKey = "key";

            await _dictionary.SetAsync(theKey, "value1");

            var partitioner = ((HazelcastClient)_client).Cluster.Partitioner;
            var keyData     = ((HazelcastClient)_client).SerializationService.ToData(theKey);
            var partitionId = partitioner.GetPartitionId(keyData.PartitionHash);

            var cache    = GetNearCache(_dictionary) as NearCaching.NearCache;
            var metadata = cache.RepairingHandler.GetMetadata(partitionId);

            await AssertEx.SucceedsEventually(() =>
            {
                Assert.That(metadata.Sequence, Is.EqualTo(1));
            }, 2000, 200);

            metadata.Sequence -= 2; //distort the sequence

            await RemoveKeyAtServerAsync(_dictionary.Name, theKey);

            await AssertEx.SucceedsEventually(() =>
            {
                Assert.That(metadata.Sequence, Is.EqualTo(2));
                Assert.That(cache.Count, Is.EqualTo(0));
            }, 2000, 200);
        }
Example #2
0
 private async Task FillAsync()
 {
     for (var i = 1; i < 30; i++)
     {
         await _dictionary.SetAsync("key-" + i, new HazelcastJsonValue("{ \"age\": " + i + " }"));
     }
 }
        private async Task SetTask(IHDictionary <string, string> dictionary, SemaphoreSlim started, int id)
        {
            var i = 0;

            while (!_stop)
            {
                i++;
                // put new value and update last state
                // note: the value in the map/Near Cache is *always* larger or equal to valuePut
                // assertion: valueMap >= valuePut
                await dictionary.SetAsync(Key, i.ToString()).CAF();

                _valuePut = i;

                // ensure we have a value
                if (i == 1)
                {
                    started.Release();
                }

                // check if we see our last update
                var valueStr = await dictionary.GetAsync(Key).CAF();

                if (valueStr == null)
                {
                    continue;                   // ignore nulls (?)
                }
                var valueInt = int.Parse(valueStr);
                if (valueInt == i)
                {
                    continue;                // match = ok
                }
                _assertionViolationCount++;
                Logger.LogWarning($"Err: set {i} but got {valueInt}.");

                // maybe it needs a bit of time?
                await Task.Delay(200).CAF();

                // test again and stop if really lost
                valueStr = await dictionary.GetAsync(Key).CAF();

                valueInt = int.Parse(valueStr);
                if (valueInt == i)
                {
                    continue;                // fixed
                }
                Logger.LogWarning($"Err: still getting {valueInt} instead of {i}.");

                // maybe it needs a lot of time?
                // in non-strict, we'll give it plenty

                // abort all
                _stop = true;
            }
            Logger.LogInformation($"AddOrUpdate task {id} performed {i} operations.");
        }