public async Task List(string nameSpace, CancellationToken token) { nameSpace.VerifyNotEmpty(nameof(nameSpace)); using IDisposable scope = _logger.BeginScope(new { Command = nameof(List), Namespace = nameSpace }); BatchSetCursor <string> batch = _artifactClient.List(null !); int index = 0; var list = new List <string> { $"Listing artifacts from Namespace {nameSpace}...", "", }; while (true) { BatchSet <string> batchSet = await batch.ReadNext(token); if (batchSet.IsEndSignaled) { break; } batchSet.Records.ForEach(x => list.Add($"({index++}) {nameSpace + "/" + x}")); } list.Add($"Completed, {index} listed"); _logger.LogInformation(list.Aggregate(string.Empty, (a, x) => a += x + Environment.NewLine)); }
public async Task GivenMultiLinkRecord_WhenPagedWithContinuationUrl_ShouldComplete() { TestWebsiteHost host = await TestApplication.DefaultHost.GetHost(); const string testPrefix = "metadata-test03-"; await DeleteAll(host, testPrefix); const int max = 100; const int pageSize = 10; IReadOnlyList <MetadataRecord> records = Enumerable.Range(0, max) .Select(x => new MetadataRecord { Id = $"{testPrefix}meta_{x}", Properties = new[] { new KeyValue("key1", "value1"), new KeyValue("key2", "value2"), }, }) .ToArray(); foreach (var item in records) { await host.PathFinderClient.Metadata.Set(item); } var aggList = new List <MetadataRecord>(); BatchSetCursor <MetadataRecord> cursor = host.PathFinderClient.Metadata.List(new QueryParameters { Id = testPrefix, Index = 0, Count = pageSize }); while (aggList.Count < max) { BatchSet <MetadataRecord> list = await cursor.ReadNext(); list.Should().NotBeNull(); list !.Records.Count.Should().Be(pageSize); aggList.AddRange(list.Records); } aggList.Count.Should().Be(max); BatchSet <MetadataRecord> lastList = await cursor.ReadNext(); lastList.Should().NotBeNull(); lastList.Records.Should().NotBeNull(); lastList.Records.Count.Should().Be(0); records .Zip(aggList, (o, i) => (o, i)) .All(x => x.o == x.i) .Should().BeTrue(); }
public async Task GivenMultiLinkRecord_WhenPagedWithContinuationUrl_ShouldComplete() { TestWebsiteHost host = await TestApplication.DefaultHost.GetHost(); const string testPrefix = "test03-"; await DeleteAll(host, testPrefix); const int max = 100; const int pageSize = 10; const string redirectUrl = "http://localhost:5003/Document"; IReadOnlyList <LinkRecord> records = Enumerable.Range(0, max) .Select(x => new LinkRecord { Id = $"{testPrefix}lnk_{x}", RedirectUrl = redirectUrl }) .ToArray(); foreach (var item in records) { await host.PathFinderClient.Link.Set(item); } var aggList = new List <LinkRecord>(); BatchSetCursor <LinkRecord> cursor = host.PathFinderClient.Link.List(new QueryParameters { Id = testPrefix, Index = 0, Count = pageSize }); while (aggList.Count < max) { BatchSet <LinkRecord> list = await cursor.ReadNext(); list.Should().NotBeNull(); list !.Records.Count.Should().Be(pageSize); aggList.AddRange(list.Records); } aggList.Count.Should().Be(max); BatchSet <LinkRecord> lastList = await cursor.ReadNext(); lastList.Should().NotBeNull(); lastList.Records.Should().NotBeNull(); lastList.Records.Count.Should().Be(0); records .Zip(aggList, (o, i) => (o, i)) .All(x => x.o == x.i) .Should().BeTrue(); }
public async Task WriteFile(string file, string path, bool recursive, CancellationToken token) { file.VerifyNotEmpty(nameof(file)); using IDisposable scope = _logger.BeginScope(new { Command = nameof(WriteFile), File = file, Path = path, Recursive = recursive }); _logger.LogInformation($"Reading directory at {path}, recursive={recursive}..."); var query = new QueryParameter() { Filter = path, Recursive = recursive, }; BatchSetCursor <DatalakePathItem> batch = _directoryClient.Search(query); var list = new List <DirectoryEntry>(); while (true) { BatchSet <DatalakePathItem> batchSet = await batch.ReadNext(token); if (batchSet.IsEndSignaled) { break; } foreach (var entry in batchSet.Records) { var documentId = new DocumentId(entry.Name); DirectoryEntry?directoryEntry = await _directoryClient.Get(documentId, token); if (directoryEntry == null) { _logger.LogWarning($"Directory entry for {entry.Name} was not found"); continue; } list.Add(directoryEntry); } } string json = Json.Default.SerializeFormat(list); File.WriteAllText(path, json); _logger.LogInformation($"{list.Count} directory entries written to {file}"); }
public async Task List(string path, bool recursive, CancellationToken token) { path.VerifyNotEmpty(nameof(path)); using IDisposable scope = _logger.BeginScope(new { Command = nameof(List), Path = path }); var query = new QueryParameter() { Filter = path, Recursive = recursive, }; BatchSetCursor <DatalakePathItem> batch = _directoryClient.Search(query); int index = 0; var list = new List <string> { $"Listing directory from path {path}, recursive={recursive}...", "", }; while (true) { BatchSet <DatalakePathItem> batchSet = await batch.ReadNext(token); if (batchSet.IsEndSignaled) { break; } batchSet.Records .Where(x => !(x.IsDirectory == true)) .ForEach(x => list.Add($"({index++}) {x.Name}")); } list.Add(""); list.Add($"Completed, {index} listed"); _logger.LogInformation(list.Join(Environment.NewLine)); }
public async Task GivenAccount_WhenRoundTrip_ShouldSucceed() { BankAccountClient client = TestApplication.GetBankAccountClient(); DocumentId documentId = (DocumentId)"test/bank/bankAccount1"; await client.Delete(documentId); BankAccount entry = new BankAccount { AccountId = documentId.Path, AccountName = "testBankAccount", AccountNumber = Guid.NewGuid().ToString(), }; await client.Set(entry); BankAccount?account = await client.Get(documentId); account.Should().NotBeNull(); account !.AccountId.Should().Be(entry.AccountId); account.AccountName.Should().Be(entry.AccountName); account.AccountNumber.Should().Be(entry.AccountNumber); account.Transactions.Count.Should().Be(0); account = account with { AccountName = "newBankAccount", Transactions = new[] { new TrxRecord { Type = TrxType.Credit, Amount = 100.0m }, new TrxRecord { Type = TrxType.Debit, Amount = 41.0m }, }.ToList() }; await client.Set(account); BankAccount?account1 = await client.Get(documentId); account1.Should().NotBeNull(); account1 !.AccountId.Should().Be(account.AccountId); account1.AccountName.Should().Be(account.AccountName); account1.AccountNumber.Should().Be(account.AccountNumber); account1.Transactions.Count.Should().Be(2); (account1.Transactions[0] == account.Transactions[0]).Should().BeTrue(); (account1.Transactions[1] == account.Transactions[1]).Should().BeTrue(); var query = new QueryParameter { Filter = "test/bank" }; BatchSetCursor <DatalakePathItem> cursor = client.Search(query); cursor.Should().NotBeNull(); BatchSet <DatalakePathItem> batchSet = await cursor.ReadNext(); batchSet.Should().NotBeNull(); batchSet.Records.Any(x => x.Name.EndsWith(documentId.Path)).Should().BeTrue(); await client.Delete(documentId); } }