[ServiceBus] workaround a service issue by using page size of 100 (#22142)

Testing reveals that if we use max int as maxCount, and also use top then
service will return InternalServerError.

This PR workarounds around that by defaulting to 100 as maxPageSize.
This commit is contained in:
Jeremy Meng 2022-06-07 16:29:25 -07:00 коммит произвёл GitHub
Родитель a027f18338
Коммит 1a59ad1de8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 85 добавлений и 2 удалений

Просмотреть файл

@ -190,7 +190,7 @@ export class ServiceBusRuleManagerImpl implements ServiceBusRuleManager {
do {
const rules = await this.getRules({
skip: Number(marker),
maxCount: options.maxPageSize,
maxCount: options.maxPageSize ?? 100,
...options,
});
yield rules;

Просмотреть файл

@ -147,7 +147,48 @@ describe("RuleManager tests", () => {
assert.deepStrictEqual(correlationFilter.applicationProperties, applicationProperties);
});
it("list rules by page", async () => {
it("list rules", async () => {
const ruleManager = serviceBusClient.createRuleManager(topic, subscription);
const sqlRuleName = "sqlRule";
const correlationRuleName = "correlationRule";
const rules = await getRules(ruleManager);
assert.equal(rules.length, 1); // default rule
const firstRule = rules[0];
assert.equal(firstRule.name, defaultRuleName);
await ruleManager.createRule(sqlRuleName, {
sqlExpression: "price > 10",
});
const applicationProperties = {
key1: "value1",
};
const correlationRuleFilter: CorrelationRuleFilter = {
correlationId: "correlationId",
subject: "label",
messageId: "messageId",
applicationProperties,
replyTo: "replyTo",
replyToSessionId: "replyToSessionId",
sessionId: "sessionId",
to: "to",
};
const action: SqlRuleAction = {
sqlExpression: "Set CorrelationId = 'newValue'",
};
await ruleManager.createRule(correlationRuleName, correlationRuleFilter, action);
const iterator = ruleManager.listRules();
const result: RuleProperties[] = [];
for await (const rule of iterator) {
result.push(rule);
}
assert.equal(result.length, 3, "Expecting three rules");
});
it("list rules by page specifying page size", async () => {
const ruleManager = serviceBusClient.createRuleManager(topic, subscription);
const sqlRuleName = "sqlRule";
@ -196,6 +237,48 @@ describe("RuleManager tests", () => {
assert.equal(result.value, undefined, "Not expecting any more pages");
});
it("list rules by page without specifying page size", async () => {
const ruleManager = serviceBusClient.createRuleManager(topic, subscription);
const sqlRuleName = "sqlRule";
const correlationRuleName = "correlationRule";
const rules = await getRules(ruleManager);
assert.equal(rules.length, 1); // default rule
const firstRule = rules[0];
assert.equal(firstRule.name, defaultRuleName);
await ruleManager.createRule(sqlRuleName, {
sqlExpression: "price > 10",
});
const applicationProperties = {
key1: "value1",
};
const correlationRuleFilter: CorrelationRuleFilter = {
correlationId: "correlationId",
subject: "label",
messageId: "messageId",
applicationProperties,
replyTo: "replyTo",
replyToSessionId: "replyToSessionId",
sessionId: "sessionId",
to: "to",
};
const action: SqlRuleAction = {
sqlExpression: "Set CorrelationId = 'newValue'",
};
await ruleManager.createRule(correlationRuleName, correlationRuleFilter, action);
const iterator = ruleManager.listRules().byPage();
let result = await iterator.next();
assert.equal(result.value.length, 3, "Expecting one rule in first page");
result = await iterator.next();
assert.equal(result.value.length, 0, "Not expecting any result in last page");
result = await iterator.next();
assert.equal(result.value, undefined, "Not expecting any more pages");
});
it("throws if add rule with same name twice", async () => {
const ruleManager = serviceBusClient.createRuleManager(topic, subscription);
const ruleName = "ruleName";