Source:
void multipleReceiverAndClientComplete(MessagingEntityType entityType, boolean isSessionEnabled) { setSenderAndReceiver(entityType, isSessionEnabled); int firstBatch = 2; int secondBatch = 2; final String messageId = UUID.randomUUID().toString(); final List<ServiceBusMessage> messages; if (isSessionEnabled) { messages = TestUtils.getServiceBusMessages(firstBatch, CONTENTS_BYTES, messageId, isSessionEnabled, sessionId); messages.addAll(TestUtils.getServiceBusMessages(secondBatch, CONTENTS_BYTES, messageId, isSessionEnabled, sessionId2)); } else { messages = TestUtils.getServiceBusMessages(firstBatch + secondBatch, CONTENTS_BYTES, messageId, isSessionEnabled, null); } final Duration smallDuration = Duration.ofSeconds(5); final ReceiveAsyncOptions options = new ReceiveAsyncOptions().setIsAutoCompleteEnabled(false); sendMessage(messages).block(TIMEOUT); StepVerifier.create(receiver.receive(options).limitRequest(firstBatch)) .assertNext(message -> { receiver.complete(message.getMessage()).block(smallDuration); messagesPending.decrementAndGet(); }) .assertNext(message -> { receiver.complete(message.getMessage()).block(smallDuration); messagesPending.decrementAndGet(); }) .verifyComplete(); StepVerifier.create(receiver2.receive(options).limitRequest(secondBatch)) .assertNext(message -> { receiver2.complete(message.getMessage()).block(smallDuration); messagesPending.decrementAndGet(); }) .assertNext(message -> { receiver2.complete(message.getMessage()).block(smallDuration); messagesPending.decrementAndGet(); }) .verifyComplete(); }

Target:
void multipleReceiverAndClientComplete(MessagingEntityType entityType, boolean isSessionEnabled) { setSenderAndReceiver(entityType, isSessionEnabled); int firstBatch = 2; int secondBatch = 2; final String messageId = UUID.randomUUID().toString(); final List<ServiceBusMessage> messages; if (isSessionEnabled) { messages = TestUtils.getServiceBusMessages(firstBatch, CONTENTS_BYTES, messageId, sessionId); messages.addAll(TestUtils.getServiceBusMessages(secondBatch, CONTENTS_BYTES, messageId, sessionId2)); } else { messages = TestUtils.getServiceBusMessages(firstBatch + secondBatch, messageId, CONTENTS_BYTES); } final Duration smallDuration = Duration.ofSeconds(5); final ReceiveAsyncOptions options = new ReceiveAsyncOptions().setIsAutoCompleteEnabled(false); sendMessage(messages).block(TIMEOUT); StepVerifier.create(receiver.receive(options)) .assertNext(message -> { assertMessageEquals(message, messageId, isSessionEnabled); receiver.complete(message.getMessage()).block(smallDuration); messagesPending.decrementAndGet(); }) .assertNext(message -> { assertMessageEquals(message, messageId, isSessionEnabled); receiver.complete(message.getMessage()).block(smallDuration); messagesPending.decrementAndGet(); }) .thenCancel() .verify(); receiver.close(); StepVerifier.create(receiver2.receive(options)) .assertNext(message -> { assertMessageEquals(message, messageId, isSessionEnabled); receiver2.complete(message.getMessage()).block(smallDuration); messagesPending.decrementAndGet(); }) .assertNext(message -> { assertMessageEquals(message, messageId, isSessionEnabled); receiver2.complete(message.getMessage()).block(smallDuration); messagesPending.decrementAndGet(); }) .thenCancel() .verify(); }