Skip to content

Commit 40551c6

Browse files
ChangeFeedProcessor: Removes eager stream expandability validation
Remove SetLength validation from WithInMemoryLeaseContainer. Non-expandable stream errors will propagate naturally from ShutdownAsync when it tries to write. Also reorders validation so state-check runs before stream inspection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1b2c508 commit 40551c6

2 files changed

Lines changed: 2 additions & 35 deletions

File tree

Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/ChangeFeedProcessorBuilder.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,28 +258,13 @@ public virtual ChangeFeedProcessorBuilder WithInMemoryLeaseContainer(MemoryStrea
258258
throw new ArgumentNullException(nameof(leaseState));
259259
}
260260

261+
this.ValidateNoLeaseContainerConfigured();
262+
261263
if (!leaseState.CanWrite)
262264
{
263265
throw new ArgumentException("The lease state stream must be writable so that state can be persisted on shutdown.", nameof(leaseState));
264266
}
265267

266-
// Verify the stream is expandable. A MemoryStream created via
267-
// new MemoryStream(byte[]) is writable but not expandable and will
268-
// throw NotSupportedException when ShutdownAsync tries to resize it.
269-
try
270-
{
271-
leaseState.SetLength(leaseState.Length);
272-
}
273-
catch (NotSupportedException)
274-
{
275-
throw new ArgumentException(
276-
"The lease state stream must be resizable. Use 'new MemoryStream()' and write bytes into it "
277-
+ "instead of 'new MemoryStream(byte[])' to create a resizable stream.",
278-
nameof(leaseState));
279-
}
280-
281-
this.ValidateNoLeaseContainerConfigured();
282-
283268
if (string.IsNullOrEmpty(this.InstanceName))
284269
{
285270
this.InstanceName = ChangeFeedProcessorBuilder.InMemoryDefaultHostName;

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/ChangeFeedProcessorBuilderTests.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -551,24 +551,6 @@ public void WithInMemoryLeaseContainerWithCorruptedStreamThrowsInvalidOperation(
551551
Assert.IsNotNull(ex.InnerException);
552552
}
553553

554-
[TestMethod]
555-
public void WithInMemoryLeaseContainerWithNonResizableStreamThrows()
556-
{
557-
// new MemoryStream(byte[]) creates a writable but non-expandable stream
558-
byte[] data = System.Text.Encoding.UTF8.GetBytes("[]");
559-
MemoryStream nonResizableStream = new MemoryStream(data);
560-
561-
ChangeFeedProcessorBuilder builder = new ChangeFeedProcessorBuilder("workflowName",
562-
ChangeFeedProcessorBuilderTests.GetMockedContainer(),
563-
ChangeFeedProcessorBuilderTests.GetMockedProcessor(),
564-
ChangeFeedProcessorBuilderTests.GetEmptyInitialization());
565-
566-
ArgumentException ex = Assert.ThrowsException<ArgumentException>(
567-
() => builder.WithInMemoryLeaseContainer(nonResizableStream));
568-
569-
Assert.IsTrue(ex.Message.Contains("resizable"));
570-
}
571-
572554
#endregion
573555

574556
private static ContainerInternal GetMockedContainer(string containerName = null)

0 commit comments

Comments
 (0)