Skip to content

Commit 8dad3c4

Browse files
Merge pull request #63 from atc-net/feature/release-delete-partition
Release DeletePartitionAsync
2 parents e9bde2d + 2cc393a commit 8dad3c4

File tree

9 files changed

+12
-50
lines changed

9 files changed

+12
-50
lines changed

README.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -249,40 +249,6 @@ az cosmosdb update --resource-group $ResourceGroup --name $AccountName --enable
249249

250250
See [MS Learn](https://learn.microsoft.com/en-us/azure/cosmos-db/priority-based-execution) for more details.
251251
252-
### Delete resources by partition key
253-
254-
The preview version of the library extends the `ICosmosWriter` and `ILowPriorityCosmosWriter` with and additional method `DeletePartitionAsync` to delete all resources in a container based on a partition key. The deletion will be executed in a CosmosDB background service using a percentage of the RU's available. The effect are available immediatly as all resources in the partition will not be available through reads or queries.
255-
256-
In order to use this new method the "Delete All Items By Partition Key" feature needs to be enabled on the CosmosDB account.
257-
258-
This can be done through Azure CLI:
259-
260-
```bash
261-
# Delete All Items By Partition Key
262-
az cosmosdb update --resource-group $ResourceGroup --name $AccountName --capabilities DeleteAllItemsByPartitionKey
263-
```
264-
265-
or wih bicep:
266-
267-
```bicep
268-
resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2024-05-15' = {
269-
name: cosmosName
270-
properties: {
271-
databaseAccountOfferType: 'Standard'
272-
locations: location
273-
capabilities: [
274-
{
275-
name: 'DeleteAllItemsByPartitionKey'
276-
}
277-
]
278-
}
279-
}
280-
```
281-
282-
If the feature is not enabled when calling this method then a `CosmosException` will be thrown.
283-
284-
See [MS Learn](https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-delete-by-partition-key) for more details.
285-
286252
## Unit Testing
287253
The reader and writer interfaces can easily be mocked, but in some cases it is nice to have a fake version of a reader or writer to mimic the behavior of the read and write operations. For this purpose the `Atc.Cosmos.Testing` namespace contains the following fakes:
288254

global.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"sdk": {
3-
"rollForward": "latestMajor",
4-
"allowPrerelease": false
3+
"version": "8.0.0",
4+
"rollForward": "latestMinor",
5+
"allowPrerelease": false
56
}
67
}

src/Atc.Cosmos/Atc.Cosmos.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
1313
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
1414
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
15+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1516
<PackageReference Include="System.Text.Json" Version="8.0.5" />
16-
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.45.0-preview.0" Condition="$(IsPreview)" />
17-
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.44.1" Condition="!$(IsPreview)" />
17+
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.47.0-preview.0" Condition="$(IsPreview)" />
18+
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.46.0" Condition="!$(IsPreview)" />
1819
</ItemGroup>
1920

2021
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">

src/Atc.Cosmos/ICosmosWriter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public Task<bool> TryDeleteAsync(
149149
string documentId,
150150
string partitionKey,
151151
CancellationToken cancellationToken = default);
152-
#if PREVIEW
153152

154153
/// <summary>
155154
/// Preview Feature DeleteAllItemsByPartitionKey.<br/>
@@ -168,7 +167,6 @@ public Task<bool> TryDeleteAsync(
168167
public Task DeletePartitionAsync(
169168
string partitionKey,
170169
CancellationToken cancellationToken = default);
171-
#endif
172170

173171
/// <summary>
174172
/// Updates a <typeparamref name="T"/> resource that is read from the configured

src/Atc.Cosmos/Internal/CosmosWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ await container
175175

176176
return true;
177177
}
178-
#if PREVIEW
179178

180179
public Task DeletePartitionAsync(
181180
string partitionKey,
@@ -185,11 +184,12 @@ public Task DeletePartitionAsync(
185184
new PartitionKey(partitionKey),
186185
new ItemRequestOptions
187186
{
187+
#if PREVIEW
188188
PriorityLevel = PriorityLevel,
189+
#endif
189190
},
190191
cancellationToken: cancellationToken)
191192
.ProcessResponseMessage();
192-
#endif
193193

194194
public Task<T> UpdateAsync(
195195
string documentId,

src/Atc.Cosmos/Testing/FakeCosmos.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ Task<bool> ICosmosWriter<T>.TryDeleteAsync(
481481
documentId,
482482
partitionKey,
483483
cancellationToken);
484-
#if PREVIEW
485484

486485
Task ICosmosWriter<T>.DeletePartitionAsync(
487486
string partitionKey,
@@ -490,7 +489,6 @@ Task ICosmosWriter<T>.DeletePartitionAsync(
490489
.DeletePartitionAsync(
491490
partitionKey,
492491
cancellationToken);
493-
#endif
494492

495493
Task<T> ICosmosWriter<T>.UpdateAsync(
496494
string documentId,

src/Atc.Cosmos/Testing/FakeCosmosWriter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ await DeleteAsync(
153153

154154
return true;
155155
}
156-
#if PREVIEW
157156

158157
public virtual Task DeletePartitionAsync(
159158
string partitionKey,
@@ -164,7 +163,6 @@ public virtual Task DeletePartitionAsync(
164163

165164
return Task.CompletedTask;
166165
}
167-
#endif
168166

169167
public virtual Task<T> UpdateAsync(
170168
string documentId,

test/Atc.Cosmos.Tests/CosmosWriterTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ public async Task Should_Return_False_When_Trying_To_Delete_NonExisting_Resource
296296
#endif
297297
cancellationToken: cancellationToken);
298298
}
299-
#if PREVIEW
300299

301300
[Theory, AutoNSubstituteData]
302301
public async Task DeletePartitionAsync_Calls_DeleteAllItemsByPartitionKeyStreamAsync_On_Container(
@@ -307,7 +306,11 @@ public async Task DeletePartitionAsync_Calls_DeleteAllItemsByPartitionKeyStreamA
307306
.Received(1)
308307
.DeleteAllItemsByPartitionKeyStreamAsync(
309308
new PartitionKey(record.Pk),
309+
#if PREVIEW
310310
Arg.Is<ItemRequestOptions>(o => o.PriorityLevel == PriorityLevel.High),
311+
#else
312+
Arg.Any<ItemRequestOptions>(),
313+
#endif
311314
cancellationToken: cancellationToken);
312315
}
313316

@@ -323,7 +326,6 @@ public Task DeletePartitionAsync_Throws_CosmosException_If_ResponseMessage_Is_No
323326
Func<Task> act = () => sut.DeletePartitionAsync(record.Pk, cancellationToken);
324327
return act.Should().ThrowAsync<CosmosException>();
325328
}
326-
#endif
327329

328330
[Theory, AutoNSubstituteData]
329331
public async Task UpdateAsync_Reads_The_Resource(

test/Atc.Cosmos.Tests/Testing/FakeCosmosWriterTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ public async Task DeleteAsync_Should_Replace_Existing_Document(
211211
.Should()
212212
.NotContain(existingDocument);
213213
}
214-
#if PREVIEW
215214

216215
[Theory, AutoNSubstituteData]
217216
public async Task DeletePartitionAsyncAsync_Should_Delete_Existing_Documents(
@@ -249,7 +248,6 @@ public async Task DeletePartitionAsyncAsync_Should_Delete_Existing_Documents(
249248
.And
250249
.Contain(existingDocument3);
251250
}
252-
#endif
253251

254252
[Theory, AutoNSubstituteData]
255253
public void UpdateAsync_Should_Throw_If_Document_Does_Not_Exists(

0 commit comments

Comments
 (0)