private async Task FillAsync()
 {
     for (var i = 1; i < 30; i++)
     {
         await _map.SetAsync("key-" + i, new HazelcastJsonValue("{ \"age\": " + i + " }"));
     }
 }
예제 #2
0
        public async Task TestSequenceFixIfKeyRemoveAtServer()
        {
            const string theKey = "key";

            await _map.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(_map) 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(_map.Name, theKey);

            await AssertEx.SucceedsEventually(() =>
            {
                Assert.That(metadata.Sequence, Is.EqualTo(2));
                Assert.That(cache.Count, Is.EqualTo(0));
            }, 2000, 200);
        }
 private static async Task Fill <T>(IHMap <string, T> dictionary, Func <int, T> convert)
 {
     for (var i = 0; i < 10; i++)
     {
         var key = TestUtils.RandomString();
         await dictionary.SetAsync(key, convert(i));
     }
 }
        private async Task SetTask(IHMap <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()).CfAwait();

                _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).CfAwait();

                if (valueStr == null)
                {
                    continue;                   // not found
                }
                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).CfAwait();

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

                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.");
        }
예제 #5
0
        private async Task UseClientOnce(IHMap <string, string> map)
        {
            var stopwatch = Stopwatch.StartNew();

            string key, value;

            try
            {
                key = value = RandomValue;
                stopwatch.Restart();
                await map.SetAsync(key, value);

                HConsole.WriteLine(this, $"Set map value ({(int)stopwatch.Elapsed.TotalSeconds}s)");
            }
            catch (TargetUnreachableException)
            {
                HConsole.WriteLine(this, "Failed to set map value: target unreachable");
            }

            try
            {
                key = RandomValue;
                stopwatch.Restart();
                value = await map.GetAsync(key);

                HConsole.WriteLine(this, $"Got map value ({(int)stopwatch.Elapsed.TotalSeconds}s)");
                if (value != null)
                {
                    Assert.That(value, Is.EqualTo(key));
                }
            }
            catch (TargetUnreachableException)
            {
                HConsole.WriteLine(this, "Failed to get map value: target unreachable");
            }
        }