chore: support for common interface to get a session to support multiplexed session#2204
chore: support for common interface to get a session to support multiplexed session#2204gcf-merge-on-green[bot] merged 12 commits intomainfrom
Conversation
bddd1d4 to
421a5a1
Compare
6061d99 to
df92e41
Compare
21394ef to
3730a8a
Compare
e49f2a4 to
3f2117a
Compare
e24245d to
be238ed
Compare
a5fa3d0 to
4024beb
Compare
| /** | ||
| * Retrieves the session, either the regular session or the multiplexed session based upon the environment varibale | ||
| * If the environment variable GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is set to `true` the method will attempt to | ||
| * retrieve the multiplexed session. Otherwise it will retrieve the session from the pool. | ||
| * | ||
| * The session is returned asynchronously via the provided callback, which will receive either an error or the session object. | ||
| * @param callback | ||
| */ |
There was a problem hiding this comment.
| /** | |
| * Retrieves the session, either the regular session or the multiplexed session based upon the environment varibale | |
| * If the environment variable GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is set to `true` the method will attempt to | |
| * retrieve the multiplexed session. Otherwise it will retrieve the session from the pool. | |
| * | |
| * The session is returned asynchronously via the provided callback, which will receive either an error or the session object. | |
| * @param callback | |
| */ | |
| /** | |
| * Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration. | |
| * | |
| * If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `true`, the method will attempt to | |
| * retrieve a multiplexed session. Otherwise, it will retrieve a session from the regular pool. | |
| * | |
| * @param {GetSessionCallback} callback The callback function. | |
| */ |
| /** | ||
| * Returns the SessionPoolInterface used by the current instance, which provide access to the session pool | ||
| * for obtaining database sessions. | ||
| * | ||
| * @returns {SessionPoolInterface} The session pool used by current instance. | ||
| * This object allows interaction with the pool for acquiring and managing sessions. | ||
| */ | ||
|
|
There was a problem hiding this comment.
| /** | |
| * Returns the SessionPoolInterface used by the current instance, which provide access to the session pool | |
| * for obtaining database sessions. | |
| * | |
| * @returns {SessionPoolInterface} The session pool used by current instance. | |
| * This object allows interaction with the pool for acquiring and managing sessions. | |
| */ | |
| /** | |
| * Returns the regular session pool object. | |
| * | |
| * @returns {SessionPoolInterface} The session pool used by current instance. | |
| */ | |
src/session-factory.ts
Outdated
| * @throws {Error} Throws an error if the session is invalid or cannot be released. | ||
| */ | ||
| release(session: Session): void { | ||
| if (!this.isMuxCreated) { |
There was a problem hiding this comment.
isMultiplexedEnabled
| if (!this.isMuxCreated) { | |
| if (!this.isMultiplexedEnabled) { |
| /** | ||
| * Releases the session back to the pool. | ||
| * | ||
| * This method is used to return the session back to the pool after it is no longer needed. | ||
| * | ||
| * It only performs the operation if the Multiplexed Session is disabled which is controlled via the | ||
| * env variable GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS. | ||
| * | ||
| * @param session The session to be released. This should be an instance of `Session` that was previously | ||
| * acquired from the session pool. | ||
| * | ||
| * @throws {Error} Throws an error if the session is invalid or cannot be released. | ||
| */ |
There was a problem hiding this comment.
| /** | |
| * Releases the session back to the pool. | |
| * | |
| * This method is used to return the session back to the pool after it is no longer needed. | |
| * | |
| * It only performs the operation if the Multiplexed Session is disabled which is controlled via the | |
| * env variable GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS. | |
| * | |
| * @param session The session to be released. This should be an instance of `Session` that was previously | |
| * acquired from the session pool. | |
| * | |
| * @throws {Error} Throws an error if the session is invalid or cannot be released. | |
| */ | |
| /** | |
| * Releases a session back to the session pool. | |
| * | |
| * This method returns a session to the pool after it is no longer needed. | |
| * It is a no-op for multiplexed sessions. | |
| * | |
| * @param {Session} session - The session to be released. This should be an instance of `Session` that was | |
| * previously acquired from the session pool. | |
| * | |
| * @throws {Error} If the session is invalid or cannot be released. | |
| */ |
test/session-factory.ts
Outdated
| import {ReleaseError} from '../src/session-pool'; | ||
|
|
||
| describe('SessionFactory', () => { | ||
| process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'true'; |
There was a problem hiding this comment.
Can we initialize this in before block and clear in after block
There was a problem hiding this comment.
we need to keep this in after block so that others test which will be running after this test don't fail on because of the change in env configuration
test/session-factory.ts
Outdated
| assert.strictEqual(openStub.callCount, 1); | ||
| }); | ||
|
|
||
| describe('when env GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is enabled', () => { |
There was a problem hiding this comment.
| describe('when env GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is enabled', () => { | |
| describe('when GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is enabled', () => { |
test/session-factory.ts
Outdated
| }); | ||
|
|
||
| describe('getSession', () => { | ||
| describe('for regular session', () => { |
There was a problem hiding this comment.
| describe('for regular session', () => { | |
| describe('when GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is disabled', () => { |
test/session-factory.ts
Outdated
| process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'false'; | ||
| }); | ||
|
|
||
| it('should return the regular session if GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS env is disabled', done => { |
There was a problem hiding this comment.
| it('should return the regular session if GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS env is disabled', done => { | |
| it('should retrieve a regular session from the pool', done => { |
test/session-factory.ts
Outdated
| }); | ||
| }); | ||
|
|
||
| it('should return the error from getSession if GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS env is disabled and regular session creation get failed', done => { |
There was a problem hiding this comment.
| it('should return the error from getSession if GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS env is disabled and regular session creation get failed', done => { | |
| it('should propagate errors when regular session retrieval fails', done => { |
There was a problem hiding this comment.
I have given a few examples on how the test cases should be named. Please updated others as well
There was a problem hiding this comment.
modified other tests as well
ae9c1fe to
56c53c0
Compare
56c53c0 to
5509f01
Compare
* e2eTracing * context propagation * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Add end to end tracing header and refactore resource header * Add end to end tracing header and refactore resource header --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
…taleness (#2207) * chore: integration test fix * chore: Improve error message for Read-only transaction with bounded staleness * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * review comments * review comments * review comment --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
deef307 to
346008a
Compare
| * | ||
| * @param {Database} database Database object. | ||
| * @param {String} name Name of the database. | ||
| * @param {SessionPoolOptions|SessionPoolInterface} options Session pool |
There was a problem hiding this comment.
SessionPoolConstructor right
| * @param {SessionPoolOptions|SessionPoolInterface} options Session pool | |
| * @param {SessionPoolOptions| SessionPoolConstructor} options Session pool |
There was a problem hiding this comment.
Please let me know if my understanding is incorrect ?
There was a problem hiding this comment.
Since, the SessionPoolConstructor is eventually creating SessionPoolInterface object, hence we can keep SessionPoolInterface here in the documentation
This PR contains the common interface class SessionFactory which will be responsible for the creation of the Session Pool and the Multiplexed Session(if the env variable would be set to true) upon client initialization.
This PR also contains the getSession method which will return the session(multiplexed/regular) based upon the env variable value.