public async Task UpdateCheckpointLogsStartAndCompleteWhenTheBlobExists() { var blobInfo = BlobsModelFactory.BlobInfo(new ETag($@"""{MatchingEtag}"""), DateTime.UtcNow); var blobList = new List <BlobItem> { BlobsModelFactory.BlobItem($"{FullyQualifiedNamespace}/{EventHubName}/{ConsumerGroup}/ownership/{Guid.NewGuid().ToString()}", false, BlobsModelFactory.BlobItemProperties(true, lastModified: DateTime.UtcNow, eTag: new ETag(MatchingEtag)), "snapshot", new Dictionary <string, string> { { BlobMetadataKey.OwnerIdentifier, Guid.NewGuid().ToString() } }) }; var mockContainerClient = new MockBlobContainerClient() { Blobs = blobList }; mockContainerClient.AddBlobClient($"{FullyQualifiedNamespace}/{EventHubName}/{ConsumerGroup}/checkpoint/1", client => { client.BlobInfo = blobInfo; client.UploadBlobException = new Exception("Upload should not be called"); }); var target = new BlobCheckpointStoreInternal(mockContainerClient); var mockLog = new Mock <BlobEventStoreEventSource>(); target.Logger = mockLog.Object; await target.UpdateCheckpointAsync(FullyQualifiedNamespace, EventHubName, ConsumerGroup, PartitionId, 0, default, CancellationToken.None);
public async Task ClaimOwnershipForExistingPartitionWithWrongEtagLogsOwnershipNotClaimable() { var blobInfo = BlobsModelFactory.BlobInfo(new ETag($@"""{WrongEtag}"""), DateTime.UtcNow); var partitionOwnership = new List <EventProcessorPartitionOwnership> { new EventProcessorPartitionOwnership { FullyQualifiedNamespace = FullyQualifiedNamespace, EventHubName = EventHubName, ConsumerGroup = ConsumerGroup, OwnerIdentifier = OwnershipIdentifier, PartitionId = PartitionId, LastModifiedTime = DateTime.UtcNow, Version = MatchingEtag } }; var mockContainerClient = new MockBlobContainerClient().AddBlobClient($"{FullyQualifiedNamespace}/{EventHubName}/{ConsumerGroup}/ownership/1", client => client.BlobInfo = blobInfo); var target = new BlobsCheckpointStore(mockContainerClient, DefaultRetryPolicy); var mockLog = new Mock <BlobEventStoreEventSource>(); target.Logger = mockLog.Object; var result = await target.ClaimOwnershipAsync(partitionOwnership, CancellationToken.None); mockLog.Verify(m => m.OwnershipNotClaimable(PartitionId, FullyQualifiedNamespace, EventHubName, ConsumerGroup, OwnershipIdentifier, It.Is <string>(e => e.Contains(BlobErrorCode.ConditionNotMet.ToString())))); }
public async Task ClaimOwnershipForExistingPartitionLogsOwnershipClaimed() { var blobInfo = BlobsModelFactory.BlobInfo(new ETag($@"""{MatchingEtag}"""), DateTime.UtcNow); var partitionOwnership = new List <EventProcessorPartitionOwnership> { new EventProcessorPartitionOwnership { FullyQualifiedNamespace = FullyQualifiedNamespace, EventHubName = EventHubName, ConsumerGroup = ConsumerGroup, OwnerIdentifier = OwnershipIdentifier, PartitionId = PartitionId, LastModifiedTime = DateTime.UtcNow, Version = MatchingEtag } }; var mockContainerClient = new MockBlobContainerClient().AddBlobClient($"{FullyQualifiedNamespace}/{EventHubName}/{ConsumerGroup}/ownership/1", client => client.BlobInfo = blobInfo); var target = new BlobCheckpointStoreInternal(mockContainerClient); var mockLog = new Mock <BlobEventStoreEventSource>(); target.Logger = mockLog.Object; var result = await target.ClaimOwnershipAsync(partitionOwnership, CancellationToken.None); mockLog.Verify(m => m.OwnershipClaimed(PartitionId, FullyQualifiedNamespace, EventHubName, ConsumerGroup, OwnershipIdentifier)); }
public async Task ClaimOwnershipForExistingPartitionWithWongEtagLogsOwnershipNotClaimable() { var blobInfo = BlobsModelFactory.BlobInfo(new ETag($@"""{WrongEtag}"""), DateTime.UtcNow); var partitionOwnerships = new List <PartitionOwnership> { new PartitionOwnership(FullyQualifiedNamespace, EventHubName, ConsumerGroup, OwnershipIdentifier, PartitionId, DateTime.UtcNow, MatchingEtag) }; var target = new BlobsCheckpointStore(new MockBlobContainerClient { BlobInfo = blobInfo }, new BasicRetryPolicy(new EventHubsRetryOptions())); var mockLog = new Mock <BlobEventStoreEventSource>(); target.Logger = mockLog.Object; var result = (await target.ClaimOwnershipAsync(partitionOwnerships, new CancellationToken())).ToList(); CollectionAssert.IsEmpty(result); mockLog.Verify(m => m.OwnershipNotClaimable(PartitionId, OwnershipIdentifier, It.Is <string>(e => e.Contains(BlobErrorCode.ConditionNotMet.ToString())))); }