Skip to content

Commit

Permalink
[App Config] updateSyncToken method (Azure#14507)
Browse files Browse the repository at this point in the history
### TODOs
- [x] Add the new `updateSyncToken` method to `AppConfigurationClient` 
  (Picked up pieces from @richardpark-msft's work here Azure#14342.)
- [x] Add a unit test
- [x] ~~Hoping to add a live test by leveraging the eventgrid SDK~~
- [x] Changelog
- [x] Hold off merging - wait for 1.1.1 to be released
- [x] What's the new version number for preview? - `1.2.0-beta.1` fine?
  
Reference: PR from .NET Azure/azure-sdk-for-net#18487
  • Loading branch information
HarshaNalluru authored and vindicatesociety committed Apr 26, 2021
1 parent 06b167f commit a89dc8d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
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 (2021-03-25)

- 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 @@ -33,7 +33,8 @@ export class AppConfigurationClient {
listRevisions(options?: ListRevisionsOptions): PagedAsyncIterableIterator<ConfigurationSetting, ListRevisionsPage>;
setConfigurationSetting(configurationSetting: SetConfigurationSettingParam, options?: SetConfigurationSettingOptions): Promise<SetConfigurationSettingResponse>;
setReadOnly(id: ConfigurationSettingId, readOnly: boolean, options?: SetReadOnlyOptions): Promise<SetReadOnlyResponse>;
}
updateSyncToken(syncToken: string): void;
}

// @public
export interface AppConfigurationClientOptions {
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,16 @@ export class AppConfigurationClient {
}
});
}
}

/**
* Adds an external synchronization token to ensure service requests receive up-to-date values.
*
* @param syncToken The synchronization token value.
*/
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 @@ -292,6 +292,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(
syncTokens["_currentSyncTokens"].size,
1,
"Unexpected number of syncTokens before the `update` call"
);
client.updateSyncToken("b=value;sn=3");
assert.equal(
syncTokens["_currentSyncTokens"].size,
2,
"Unexpected number of syncTokens after the `update` call"
);
assert.deepEqual(
syncTokens["_currentSyncTokens"].get("a"),
{ id: "a", value: "value", sequenceNumber: 0 },
"Unexpected object present for key `a`"
);
assert.deepEqual(
syncTokens["_currentSyncTokens"].get("b"),
{ id: "b", value: "value", sequenceNumber: 3 },
"Unexpected object present for key `b`"
);
});
});
});

function splitAndSort(syncTokens: string | undefined): string {
Expand Down

0 comments on commit a89dc8d

Please sign in to comment.