public async Task PutEtcdProviderData_Currencies_ReturnsMockCurrencies() { // Arrange const string key = "currencies"; await _polly.ExecuteAsync(async() => { await _etcdClient.DeleteAsync(key); var value = await _etcdClient.GetValAsync(key); return(string.IsNullOrEmpty(value)); }); await WriteToEtcdAsync("currencies.json", key); var currencies = await ReadCurrencyFromEtcdAsync(key); var dataRetriever = _serviceProvider.GetRequiredService <IDataRetriever <IEnumerable <MockCurrency> > >(); var expectedData = currencies.ToList(); expectedData.First().Code = Guid.NewGuid().ToString(); // Act await _etcdClient.PutAsync(key, JsonSerializer.Serialize(expectedData)); // Arrange await _polly.ExecuteAsync(async() => { var actualData = await dataRetriever.GetAsync(); Assert.Equal(actualData.Select(l => l.Code), expectedData.Select(l => l.Code)); return(true); }); }
public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState) { var key = GetKeyName(grainType, grainReference); try { if (this.logger.IsEnabled(LogLevel.Trace)) { this.logger.Trace((int)MorsteadEtcdProviderErrorCode.MorsteadEtcdProvider_Storage_Reading, "Reading: GrainType={0} Grainid={1} ETag={2} from BlobName={3} in Container={4}", grainType, grainReference, grainState.ETag, key, name); } string json = await etcdClient.GetValAsync(key).ConfigureAwait(false); if (this.logger.IsEnabled(LogLevel.Trace)) { this.logger.Trace((int)MorsteadEtcdProviderErrorCode.MorsteadEtcdProvider_Storage_DataRead, "Read: GrainType={0} Grainid={1} ETag={2} from BlobName={3} in Container={4}", grainType, grainReference, grainState.ETag, key, name); } if (string.IsNullOrEmpty(json)) { return; } grainState.State = this.ConvertFromStorageFormat(json); grainState.ETag = key; } catch (Exception ex) { logger.Error((int)MorsteadEtcdProviderErrorCode.MorsteadEtcdProvider_ReadError, string.Format("Error reading: GrainType={0} Grainid={1} ETag={2} from Container={3} Exception={4}", grainType, grainReference, grainState.ETag, name, ex.Message), ex); throw; } return; }
/// <inheritdoc/> public async Task <T> GetAsync(params string[] keys) { var key = GetKey(keys); var value = await _etcdClient.GetValAsync(key, _metadata); return(_dataSerializer.Deserialize(value)); }
private void LoadData() { string result = _etcdClient.GetValAsync(_path).GetAwaiter().GetResult(); if (string.IsNullOrEmpty(result)) { return; } Data = ConvertData(result); }
public static async Task <int> GetPartitionCount(EtcdClient client, string topic) { var key = $"{TopicListPrefix}{topic}"; Console.WriteLine($"Requesting Topic partition count for {key}"); var partitionsString = await client.GetValAsync(key); if (int.TryParse(partitionsString, out var partitions)) { return(partitions); } throw new Exception("Topic does not exists"); }
public string GetValue(string key) { try { key = key.Replace('.', '/'); var value = client?.GetValAsync(nametag + key)?.Result; return(value); } catch { _logger.LogInformation($"Unable to get value of key '{nametag + key}'"); return(null); } }
public async Task <Response <FileConfiguration> > Get() { var config = _cache.Get(_configurationKey, _configurationKey); if (config != null) { return(new OkResponse <FileConfiguration>(config)); } var queryResult = await _etcdClient.GetValAsync($"/{_configurationKey}"); if (string.IsNullOrWhiteSpace(queryResult)) { return(new OkResponse <FileConfiguration>(null)); } var etcdConfig = JsonConvert.DeserializeObject <FileConfiguration>(queryResult); return(new OkResponse <FileConfiguration>(etcdConfig)); }
public Task <string> GetValAsync(string key) { Task <string> result = _etcdClient.GetValAsync(key); return(result); }