Skip to content
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

[App Config] updateSyncToken method #14507

Merged
11 commits merged into from
Mar 26, 2021
7 changes: 6 additions & 1 deletion sdk/appconfiguration/app-configuration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release History

## 1.2.0-beta.1 (Unreleased)

- Added `updateSyncToken` method to `AppConfigurationClient` to be able to provide external synchronization tokens.
[PR #14507](https://github.com/Azure/azure-sdk-for-js/pull/14507)

## 1.1.1 (Unreleased)

- Fix issues with `select`ing fields to be returned from `listConfigurationSettings`, `listConfigurationRevisions`
Expand All @@ -13,7 +18,7 @@
## 1.0.1 (2020-02-19)

- The underlying filter behavior has changed for `listConfigurationSettings` and `listRevisions`.
Inline documentation has been revised to accomodate it.
Inline documentation has been revised to accommodate it.

## 1.0.0 (2020-01-06)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface InternalAppConfigurationClientOptions extends AppConfigurationC
*/
export class AppConfigurationClient {
private client: AppConfiguration;
private _syncTokens: SyncTokens;
// (for tests)
private _trace = traceFromTracingHelpers;

Expand Down Expand Up @@ -164,13 +165,13 @@ export class AppConfigurationClient {
}
}

const syncTokens = appConfigOptions.syncTokens || new SyncTokens();
this._syncTokens = appConfigOptions.syncTokens || new SyncTokens();

this.client = new AppConfiguration(
appConfigCredential,
appConfigEndpoint,
apiVersion,
getGeneratedClientOptions(appConfigEndpoint, syncTokens, appConfigOptions)
getGeneratedClientOptions(appConfigEndpoint, this._syncTokens, appConfigOptions)
);
}

Expand Down Expand Up @@ -496,8 +497,11 @@ export class AppConfigurationClient {
}
});
}
}

updateSyncToken(syncToken: string): void {
this._syncTokens.addSyncTokenFromHeaderValue(syncToken);
}
}
/**
* Gets the options for the generated AppConfigurationClient
* @internal
Expand Down
32 changes: 32 additions & 0 deletions sdk/appconfiguration/app-configuration/test/internal/http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,38 @@ describe("http request related tests", function() {
assert.equal(syncTokens.getSyncTokenHeaderValue(), "clearReadOnly=value");
});
});

describe("syncToken", async () => {
it("update sync token", async () => {
const syncTokens = new SyncTokens();
syncTokens.addSyncTokenFromHeaderValue("a=value;sn=0");
const client = new AppConfigurationClient(
"Endpoint=https://endpoint.azconfig.io;Id=abc;Secret=123",
{ syncTokens } as InternalAppConfigurationClientOptions
);
assert.equal(
client["_syncTokens"]["_currentSyncTokens"].size,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You passed in syncTokens here so you don't need to delve into the object private fields to get it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client["_syncTokens"] -> syncTokens

1,
"Unexpected number of syncTokens before the `update` call"
);
client.updateSyncToken("b=value;sn=3");
assert.equal(
client["_syncTokens"]["_currentSyncTokens"].size,
2,
"Unexpected number of syncTokens after the `update` call"
);
assert.deepEqual(
client["_syncTokens"]["_currentSyncTokens"].get("a"),
{ id: "a", value: "value", sequenceNumber: 0 },
"Unexpected object present for key `a`"
);
assert.deepEqual(
client["_syncTokens"]["_currentSyncTokens"].get("b"),
{ id: "b", value: "value", sequenceNumber: 3 },
"Unexpected object present for key `b`"
);
});
});
});

function splitAndSort(syncTokens: string | undefined): string {
Expand Down
33 changes: 33 additions & 0 deletions sdk/appconfiguration/app-configuration/test/public/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,4 +1139,37 @@ describe("AppConfigurationClient", () => {
});
});
});

describe("syncToken", async () => {
it("update sync token with eventgrid example", async () => {
// Supposed to be a live test
// TODO:
// - Import eventgrid
// - get sync token from eventgrid event
// - call updateSyncToken
// - call getConfigurationSetting
// - assertion/check the retrieved setting

// get sync token from EventGrid event (example event shown, based on .net sample)
const eventGridEvent = {
key: "key for setting",
label: "label for setting",
syncToken: "opaque sync token"
};

// user treats token as an opaque value (note - this _does_ mutate the appconfigclient)
// however, this mutations happens regardless since the system can and does return
// sync token headers during normal operation.
client.updateSyncToken(eventGridEvent.syncToken);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to check - there's nothing to test here. I'd remove this test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


// and now retrieving the value should be consistent with what happened
// in EventGrid.
const retrievedSetting = await client.getConfigurationSetting({
key: eventGridEvent.key,
label: eventGridEvent.label
});

console.log(retrievedSetting);
});
});
});