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."); }
public async Task GetJsonValue_Succeeded() { var value = new HazelcastJsonValue("{ \"age\": 20 }"); await _map.SetAsync("key-1", value); var result = await _map.GetAsync("key-1"); Assert.AreEqual(value, result); }
private static async Task RunTask(IHazelcastClient client, CancellationToken token, int id, int entryCount, ILogger logger) { logger.LogInformation($"Thread {id}: start"); IHMap <string, string> map = null; while (!token.IsCancellationRequested) { try { map = await client.GetMapAsync <string, string>("soak1").ConfigureAwait(false); break; } catch (Exception ex) { logger.LogError($"Thread {id} failed to acquire the map ({ex.GetType().Name}: {ex.Message}), abort"); return; } } logger.LogInformation($"Thread {id}: acquired the map"); while (!token.IsCancellationRequested) { try { var key = RandomProvider.Random.Next(0, entryCount).ToString(); var operation = RandomProvider.Random.Next(0, 100); if (operation < 30) { await map.GetAsync(key).ConfigureAwait(false); } else if (operation < 60) { await map.PutAsync(key, RandomProvider.Random.Next().ToString()).ConfigureAwait(false); } else if (operation < 80) { await map.GetValuesAsync(Predicates.Value().IsBetween(0, 10)).ConfigureAwait(false); } else { await map.ExecuteAsync(new UpdateEntryProcessor(key), key).ConfigureAwait(false); } _reports[id] += 1; } catch (Exception ex) { logger.LogError($"Thead {id} caught {ex.GetType().Name}: {ex.Message}"); } } }
private async Task GetTask(IHMap <string, string> dictionary, int id) { var n = 0; while (!_stop) { n++; // get the value var valueStr = await dictionary.GetAsync(Key).CfAwait(); // that should never happen! Assert.That(valueStr, Is.Not.Null); // parse the value (to get some CPU load) var valueInt = int.Parse(valueStr); Assert.AreEqual(valueInt.ToString(), valueStr); // slow down await Task.Delay(100).CfAwait(); } Logger.LogInformation($"Get task {id} performed {n} operations."); }
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"); } }
public async Task Setup() { _map = await Client.GetMapAsync <object, object>(CreateUniqueName()); _ = await _map.GetAsync(new object()); }