From f58d9256cb29c576a5201b1d570e48c71a1148e5 Mon Sep 17 00:00:00 2001 From: Mohsin Mehmood Date: Fri, 23 Oct 2020 03:33:17 +0800 Subject: [PATCH] [servicebus]scheduleMessages method swap enqueedTime and messages order (#11994) Co-authored-by: Mohsin Mehmood --- sdk/servicebus/service-bus/CHANGELOG.md | 1 + .../service-bus/review/service-bus.api.md | 2 +- sdk/servicebus/service-bus/src/sender.ts | 6 ++--- .../service-bus/test/internal/sender.spec.ts | 4 ++-- .../test/invalidParameters.spec.ts | 2 +- .../service-bus/test/managementClient.spec.ts | 8 +++---- .../service-bus/test/retries.spec.ts | 2 +- .../service-bus/test/sendAndSchedule.spec.ts | 24 +++++++++---------- .../service-bus/test/serviceBusClient.spec.ts | 2 +- 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/sdk/servicebus/service-bus/CHANGELOG.md b/sdk/servicebus/service-bus/CHANGELOG.md index c7f29e498dc..76b36fc02c6 100644 --- a/sdk/servicebus/service-bus/CHANGELOG.md +++ b/sdk/servicebus/service-bus/CHANGELOG.md @@ -31,6 +31,7 @@ - "properties" renamed to "applicationProperties" - "label" renamed to "subject" - `SqlRuleFilter` interface "sqlExpression" changed from optional to required +- `ServiceBusSender.scheduleMessages` method signature updated: `scheduledEnqueueTimeUtc` and `messages` parameters are swapped. ## 7.0.0-preview.7 (2020-10-07) diff --git a/sdk/servicebus/service-bus/review/service-bus.api.md b/sdk/servicebus/service-bus/review/service-bus.api.md index c4728ea349c..0a10c3db594 100644 --- a/sdk/servicebus/service-bus/review/service-bus.api.md +++ b/sdk/servicebus/service-bus/review/service-bus.api.md @@ -468,7 +468,7 @@ export interface ServiceBusSender { entityPath: string; isClosed: boolean; open(options?: OperationOptionsBase): Promise; - scheduleMessages(scheduledEnqueueTimeUtc: Date, messages: ServiceBusMessage | ServiceBusMessage[], options?: OperationOptionsBase): Promise; + scheduleMessages(messages: ServiceBusMessage | ServiceBusMessage[], scheduledEnqueueTimeUtc: Date, options?: OperationOptionsBase): Promise; sendMessages(messages: ServiceBusMessage | ServiceBusMessage[] | ServiceBusMessageBatch, options?: OperationOptionsBase): Promise; } diff --git a/sdk/servicebus/service-bus/src/sender.ts b/sdk/servicebus/service-bus/src/sender.ts index 0b51b4e2f61..2bf64f5aa4c 100644 --- a/sdk/servicebus/service-bus/src/sender.ts +++ b/sdk/servicebus/service-bus/src/sender.ts @@ -89,8 +89,8 @@ export interface ServiceBusSender { /** * Schedules given messages to appear on Service Bus Queue/Subscription at a later time. * - * @param scheduledEnqueueTimeUtc - The UTC time at which the messages should be enqueued. * @param messages - Message or an array of messages that need to be scheduled. + * @param scheduledEnqueueTimeUtc - The UTC time at which the messages should be enqueued. * @param options - Options bag to pass an abort signal or tracing options. * @returns Promise - The sequence numbers of messages that were scheduled. * You will need the sequence number if you intend to cancel the scheduling of the messages. @@ -100,8 +100,8 @@ export interface ServiceBusSender { * @throws MessagingError if the service returns an error while scheduling messages. */ scheduleMessages( - scheduledEnqueueTimeUtc: Date, messages: ServiceBusMessage | ServiceBusMessage[], + scheduledEnqueueTimeUtc: Date, options?: OperationOptionsBase ): Promise; @@ -244,8 +244,8 @@ export class ServiceBusSenderImpl implements ServiceBusSender { } async scheduleMessages( - scheduledEnqueueTimeUtc: Date, messages: ServiceBusMessage | ServiceBusMessage[], + scheduledEnqueueTimeUtc: Date, options: OperationOptionsBase = {} ): Promise { this._throwIfSenderOrConnectionClosed(); diff --git a/sdk/servicebus/service-bus/test/internal/sender.spec.ts b/sdk/servicebus/service-bus/test/internal/sender.spec.ts index 0daea584fe1..bb13459df1a 100644 --- a/sdk/servicebus/service-bus/test/internal/sender.spec.ts +++ b/sdk/servicebus/service-bus/test/internal/sender.spec.ts @@ -77,9 +77,9 @@ describe("sender unit tests", () => { try { await sender.scheduleMessages( - new Date(), // @ts-expect-error - invalidValue + invalidValue, + new Date() ); } catch (err) { assert.equal(err.name, "TypeError"); diff --git a/sdk/servicebus/service-bus/test/invalidParameters.spec.ts b/sdk/servicebus/service-bus/test/invalidParameters.spec.ts index 1a02c4578d6..28b72da4680 100644 --- a/sdk/servicebus/service-bus/test/invalidParameters.spec.ts +++ b/sdk/servicebus/service-bus/test/invalidParameters.spec.ts @@ -399,7 +399,7 @@ describe("invalid parameters", () => { it("ScheduledMessages: Missing messages in Sender", async function(): Promise { let caughtError: Error | undefined; try { - await sender.scheduleMessages(new Date(), undefined as any); + await sender.scheduleMessages(undefined as any, new Date()); } catch (error) { caughtError = error; } diff --git a/sdk/servicebus/service-bus/test/managementClient.spec.ts b/sdk/servicebus/service-bus/test/managementClient.spec.ts index ca00481c25d..5e2840d9e0f 100644 --- a/sdk/servicebus/service-bus/test/managementClient.spec.ts +++ b/sdk/servicebus/service-bus/test/managementClient.spec.ts @@ -78,8 +78,8 @@ describe("ManagementClient - disconnects", function(): void { // Send a message so we have something to peek. const deliveryIds = await sender.scheduleMessages( - new Date("2020-04-25T12:00:00Z"), - TestMessage.getSample() + TestMessage.getSample(), + new Date("2020-04-25T12:00:00Z") ); deliveryIds.length.should.equal(1, "Unexpected number of scheduled messages."); @@ -97,8 +97,8 @@ describe("ManagementClient - disconnects", function(): void { // peek additional messages const [deliveryId] = await sender.scheduleMessages( - new Date("2020-04-25T12:00:00Z"), - TestMessage.getSample() + TestMessage.getSample(), + new Date("2020-04-25T12:00:00Z") ); deliveryIds.push(deliveryId); deliveryIds.length.should.equal(2, "Unexpected number of scheduled messages."); diff --git a/sdk/servicebus/service-bus/test/retries.spec.ts b/sdk/servicebus/service-bus/test/retries.spec.ts index 8c10ed7fb90..bf301703bc9 100644 --- a/sdk/servicebus/service-bus/test/retries.spec.ts +++ b/sdk/servicebus/service-bus/test/retries.spec.ts @@ -102,7 +102,7 @@ describe("Retries - ManagementClient", () => { it("Unpartitioned Queue: scheduleMessages", async function(): Promise { await beforeEachTest(TestClientType.UnpartitionedQueue); await mockManagementClientAndVerifyRetries(async () => { - await sender.scheduleMessages(new Date(), [TestMessage.getSample()]); + await sender.scheduleMessages([TestMessage.getSample()], new Date()); }); }); diff --git a/sdk/servicebus/service-bus/test/sendAndSchedule.spec.ts b/sdk/servicebus/service-bus/test/sendAndSchedule.spec.ts index 765221ffd9f..0715a569620 100644 --- a/sdk/servicebus/service-bus/test/sendAndSchedule.spec.ts +++ b/sdk/servicebus/service-bus/test/sendAndSchedule.spec.ts @@ -155,7 +155,7 @@ describe("Sender Tests", () => { : TestMessage.getSample(); const scheduleTime = new Date(Date.now() + 10000); // 10 seconds from - await sender.scheduleMessages(scheduleTime, testMessage); + await sender.scheduleMessages(testMessage, scheduleTime); const msgs = await receiver.receiveMessages(1); const msgEnqueueTime = msgs[0].enqueuedTimeUtc ? msgs[0].enqueuedTimeUtc.valueOf() : 0; @@ -180,7 +180,7 @@ describe("Sender Tests", () => { ? [TestMessage.getSessionSample(), TestMessage.getSessionSample()] : [TestMessage.getSample(), TestMessage.getSample()]; const scheduleTime = new Date(Date.now() + 10000); // 10 seconds from now - await sender.scheduleMessages(scheduleTime, testMessages); + await sender.scheduleMessages(testMessages, scheduleTime); const msgs = await receiver.receiveMessages(2); should.equal(Array.isArray(msgs), true, "`ReceivedMessages` is not an array"); @@ -232,7 +232,7 @@ describe("Sender Tests", () => { ? TestMessage.getSessionSample() : TestMessage.getSample(); const scheduleTime = new Date(Date.now() + 30000); // 30 seconds from now as anything less gives inconsistent results for cancelling - const [sequenceNumber] = await sender.scheduleMessages(scheduleTime, testMessage); + const [sequenceNumber] = await sender.scheduleMessages(testMessage, scheduleTime); await delay(2000); @@ -249,10 +249,10 @@ describe("Sender Tests", () => { : TestMessage.getSample; const scheduleTime = new Date(Date.now() + 30000); // 30 seconds from now as anything less gives inconsistent results for cancelling - const [sequenceNumber1, sequenceNumber2] = await sender.scheduleMessages(scheduleTime, [ - getTestMessage(), - getTestMessage() - ]); + const [sequenceNumber1, sequenceNumber2] = await sender.scheduleMessages( + [getTestMessage(), getTestMessage()], + scheduleTime + ); await delay(2000); @@ -293,9 +293,9 @@ describe("Sender Tests", () => { ]; const [result1, result2, result3] = await Promise.all([ // Schedule messages in parallel - sender.scheduleMessages(date, messages[0]), - sender.scheduleMessages(date, messages[1]), - sender.scheduleMessages(date, messages[2]) + sender.scheduleMessages(messages[0], date), + sender.scheduleMessages(messages[1], date), + sender.scheduleMessages(messages[2], date) ]); const sequenceNumbers = [result1[0], result2[0], result3[0]]; compareSequenceNumbers(sequenceNumbers[0], sequenceNumbers[1]); @@ -354,7 +354,7 @@ describe("Sender Tests", () => { const controller = new AbortController(); setTimeout(() => controller.abort(), 1); try { - await sender.scheduleMessages(new Date(), [TestMessage.getSample()], { + await sender.scheduleMessages([TestMessage.getSample()], new Date(), { abortSignal: controller.signal }); throw new Error(`Test failure`); @@ -521,7 +521,7 @@ describe("ServiceBusMessage validations", function(): void { it("ScheduleMessages() throws if " + testInput.title, async function(): Promise { let actualErrorMsg = ""; let actualErr; - await sender.scheduleMessages(new Date(), testInput.message).catch((err) => { + await sender.scheduleMessages(testInput.message, new Date()).catch((err) => { actualErr = err; actualErrorMsg = err.message; }); diff --git a/sdk/servicebus/service-bus/test/serviceBusClient.spec.ts b/sdk/servicebus/service-bus/test/serviceBusClient.spec.ts index ca7b6247fbf..7964b16ad39 100644 --- a/sdk/servicebus/service-bus/test/serviceBusClient.spec.ts +++ b/sdk/servicebus/service-bus/test/serviceBusClient.spec.ts @@ -511,7 +511,7 @@ describe("Errors after close()", function(): void { should.equal(errorSendBatch, expectedErrorMsg, "Expected error not thrown for sendBatch()"); let errorScheduleMsgs: string = ""; - await sender.scheduleMessages(new Date(Date.now() + 30000), [testMessage]).catch((err) => { + await sender.scheduleMessages([testMessage], new Date(Date.now() + 30000)).catch((err) => { errorScheduleMsgs = err.message; }); should.equal(