-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support DedicatedGatewayRequestOptions and MaxIntegratedCacheStaleness #21240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| /** | ||
| * @beta Dedicated Gateway Request Options *Private feature* | ||
| */ | ||
| export interface DedicatedGatewayRequestOptions { | ||
|
||
| /** | ||
| * Sets the staleness value associated with the request in the Azure CosmosDB service. For requests where the {@link | ||
jay-most marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * com.azure.cosmos.ConsistencyLevel} is {@link com.azure.cosmos.ConsistencyLevel#EVENTUAL}, responses from the | ||
| * integrated cache are guaranteed to be no staler than value indicated by this maxIntegratedCacheStaleness. When the | ||
| * consistency level is not set, this property is ignored. | ||
| * | ||
| * <p>Default value is null</p> | ||
jay-most marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * <p>Cache Staleness is supported in milliseconds granularity. Anything smaller than milliseconds will be ignored.</p> | ||
jay-most marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| maxIntegratedCacheStalenessInMs?: number; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,96 @@ describe("New session token", function () { | |
| }); | ||
| }); | ||
|
|
||
| describe("Integrated Cache Staleness", async function (this: Suite) { | ||
| beforeEach(async function () { | ||
| await removeAllDatabases(); | ||
| }); | ||
| const dbId = addEntropy("maxIntegratedCacheTestDB"); | ||
| const containerId = addEntropy("maxIntegratedCacheTestContainer"); | ||
| const dedicatedGatewayMaxAge = 600000; | ||
| const client = new CosmosClient({ | ||
| endpoint, | ||
| key: masterKey, | ||
| consistencyLevel: ConsistencyLevel.Eventual, | ||
jay-most marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| plugins: [ | ||
| { | ||
| on: "request", | ||
| plugin: async (context, next) => { | ||
| it("Should check if the max integrated cache staleness header is set and the value is correct.", async function () { | ||
| if (context.headers["x-ms-consistency-level"]) { | ||
| if (context.resourceType === ResourceType.item) { | ||
| if (context.headers["x-ms-dedicatedgateway-max-age"]) { | ||
| assert.strictEqual( | ||
| context.headers["x-ms-dedicatedgateway-max-age"].valueOf(), | ||
| dedicatedGatewayMaxAge | ||
| ); | ||
| } else { | ||
| assert( | ||
| context.headers["x-ms-dedicatedgateway-max-age"], | ||
| "x-ms-dedicatedgateway-max-age is not set." | ||
| ); | ||
| assert.ifError(context.headers["x-ms-dedicatedgateway-max-age"]); | ||
| } | ||
| } else { | ||
| assert( | ||
| context.headers["x-ms-dedicatedgateway-max-age"], | ||
| "Attempt to use x-ms-dedicatedgateway-max-age on a non-item request." | ||
| ); | ||
| assert.ifError(context.headers["x-ms-dedicatedgateway-max-age"]); | ||
| } | ||
| } else { | ||
| assert( | ||
| context.headers["x-ms-consistency-level"], | ||
| "x-ms-consistency-level is not set." | ||
| ); | ||
| assert.ifError(context.headers["x-ms-consistency-level"]); | ||
| } | ||
| }); | ||
| const response = await next(context); | ||
| return response; | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
| const itemRequestFeedOptions = { | ||
| maxIntegratedCacheStalenessInMs: dedicatedGatewayMaxAge, | ||
jay-most marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| const { database } = await client.databases.createIfNotExists({ | ||
| id: dbId, | ||
| }); | ||
| const { container } = await database.containers.createIfNotExists({ | ||
| id: containerId, | ||
| }); | ||
|
|
||
| // Should pass with maxIntegratedCacheStalenessInMs and consistency level set. | ||
| await container.items.create({ id: "1" }); | ||
| await container.item("1").read(itemRequestFeedOptions); | ||
|
Comment on lines
+134
to
+136
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to split this test into different it() blocks? Even if you have to define a new client with a different plugin, I think it will help test readability and debugging. Something like this: it("readItem should pass with maxIntegratedCacheStalenessInMs and consistency level set", async () => {
const client = new CosmosClient({
endpoint,
key: masterKey,
consistencyLevel: ConsistencyLevel.Eventual,
plugins: [
{
on: "request",
plugin: async (context, next) => {/** Only check for the specific conditions to pass with maxIntegratedCacheStalenessInMs and consistency level set*/}
}]
});
await container.items.create({ id: "1" });
await container.item("1").read(itemRequestFeedOptions);
});
it("redDocument should pass with maxIntegratedCacheStalenessInMs and consistency level set. ", async () => {
const client = new CosmosClient({
endpoint,
key: masterKey,
consistencyLevel: ConsistencyLevel.Eventual,
plugins: [
{
on: "request",
plugin: async (context, next) => {/** Only check for the specific conditions to pass with maxIntegratedCacheStalenessInMs and consistency level set*/}
}]
});
await container.items.readAll(itemRequestFeedOptions).fetchAll();
})
// etc...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jay-most I'd like to hear what you think about the comment about splitting into individual describe("Test", () => {
it("should do something", () => {});
it("should do something else", () => {});
})However, the current test is executing the |
||
|
|
||
| // Should pass with maxIntegratedCacheStalenessInMs and consistency level set. | ||
| // read document. | ||
| await container.items.readAll(itemRequestFeedOptions).fetchAll(); | ||
jay-most marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Should pass with maxIntegratedCacheStalenessInMs and consistency level set. | ||
| // query documents | ||
| const querySpec = { | ||
| query: "SELECT * FROM root r WHERE r.id=@id", | ||
| parameters: [ | ||
| { | ||
| name: "@id", | ||
| value: "1", | ||
| }, | ||
| ], | ||
| }; | ||
| await container.items.query(querySpec, itemRequestFeedOptions).fetchAll(); | ||
|
|
||
| // Should fail: maxIntegratedCacheStalenessInMs should only be set at the item request level and query feed options | ||
| assert.doesNotThrow(async () => { | ||
| await container.read({ | ||
| maxIntegratedCacheStalenessInMs: dedicatedGatewayMaxAge, | ||
| }); | ||
| }, "maxIntegratedCacheStalenessInMs should only be set at the item request level and query feed options"); | ||
| }); | ||
|
|
||
| // For some reason this test does not pass against the emulator. Skipping it for now | ||
| describe.skip("Session Token", function (this: Suite) { | ||
| beforeEach(async function () { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.