private async Task ClientThread(CancellationToken token) { var created = new List <string>(); while (!token.IsCancellationRequested) { var result = await client.CreateAsync(new CreateRequest(path, CreateMode.PersistentSequential)); if (result.IsSuccessful) { created.Add(result.NewPath); } await SleepRandom(); } client.Dispose(); Log.Info("Created thread nodes: " + string.Join(", ", created.OrderBy(x => x))); }
public static void AddApiKey(string apiKey, string zooKeeperConnectionString, ILog log) { using (var client = new ZooKeeperClient(new ZooKeeperClientSettings(zooKeeperConnectionString), log)) { try { foreach (var accessRight in new[] { "read", "write", "manage" }) { var path = $"/hercules/auth/rules/{apiKey}.*.{accessRight}"; client.CreateAsync(new CreateRequest(path, CreateMode.Persistent)) .GetAwaiter() .GetResult() .EnsureSuccess(); } } catch (Exception error) { throw new Exception($"Failed to add api key '{apiKey}'.", error); } } }
public async Task Should_return_NotConnected() { Ensemble.Stop(); WaitForDisconnectedState(client); var result = await client.CreateAsync("/return_connection_loss", CreateMode.Persistent); result.Status.Should().Be(ZooKeeperStatus.NotConnected); }
public async Task CreatedZxId_CreatedTime_should_increase() { var result1 = await client.CreateAsync("/create/a", CreateMode.Persistent); var result2 = await client.CreateAsync("/create/b", CreateMode.Persistent); var stat1 = await GetNodeStat(result1.NewPath); var stat2 = await GetNodeStat(result2.NewPath); stat2.CreatedZxId.Should().Be(stat1.CreatedZxId + 1); stat2.CreatedTime.Should().BeOnOrAfter(stat1.CreatedTime); }