Skip to content

Commit

Permalink
feat: Set LAR as False (#1883)
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhigarg92 committed Jul 21, 2023
1 parent 74a54b0 commit ed510e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Expand Up @@ -108,8 +108,8 @@ export type GetInstanceConfigOperationsCallback = PagedCallback<

/**
* Session pool configuration options.
* @property {boolean} [routeToLeaderEnabled=True] If set to false leader aware routing will be disabled.
* Disabling leader aware routing would route all requests in RW/PDML transactions to any region.
* @property {boolean} [routeToLeaderEnabled=False] If set to true leader aware routing will be enabled.
* Enabling leader aware routing would route all requests in RW/PDML transactions to leader region.
*/
export interface SpannerOptions extends GrpcClientOptions {
apiEndpoint?: string;
Expand Down Expand Up @@ -216,7 +216,7 @@ class Spanner extends GrpcService {
projectIdReplaced_: boolean;
projectFormattedName_: string;
resourceHeader_: {[k: string]: string};
routeToLeaderEnabled = true;
routeToLeaderEnabled = false;

/**
* Placeholder used to auto populate a column with the commit timestamp.
Expand Down Expand Up @@ -318,8 +318,8 @@ class Spanner extends GrpcService {
} as {} as GrpcServiceConfig;
super(config, options);

if (options.routeToLeaderEnabled === false) {
this.routeToLeaderEnabled = false;
if (options.routeToLeaderEnabled === true) {
this.routeToLeaderEnabled = true;
}

this.options = options;
Expand Down
18 changes: 9 additions & 9 deletions test/spanner.ts
Expand Up @@ -1491,33 +1491,33 @@ describe('Spanner with mock server', () => {
});

describe('LeaderAwareRouting', () => {
let spannerWithLARDisabled: Spanner;
let instanceWithLARDisabled: Instance;
let spannerWithLAREnabled: Spanner;
let instanceWithLAREnabled: Instance;

function newTestDatabaseWithLARDisabled(
function newTestDatabaseWithLAREnabled(
options?: SessionPoolOptions,
queryOptions?: IQueryOptions
): Database {
return instanceWithLARDisabled.database(
return instanceWithLAREnabled.database(
`database-${dbCounter++}`,
options,
queryOptions
);
}

before(() => {
spannerWithLARDisabled = new Spanner({
spannerWithLAREnabled = new Spanner({
servicePath: 'localhost',
port,
sslCreds: grpc.credentials.createInsecure(),
routeToLeaderEnabled: false,
routeToLeaderEnabled: true,
});
// Gets a reference to a Cloud Spanner instance and database
instanceWithLARDisabled = spannerWithLARDisabled.instance('instance');
instanceWithLAREnabled = spannerWithLAREnabled.instance('instance');
});

it('should execute with leader aware routing enabled in a read/write transaction', async () => {
const database = newTestDatabase();
const database = newTestDatabaseWithLAREnabled();
await database.runTransactionAsync(async tx => {
await tx!.runUpdate({
sql: insertSql,
Expand All @@ -1539,7 +1539,7 @@ describe('Spanner with mock server', () => {
});

it('should execute with leader aware routing disabled in a read/write transaction', async () => {
const database = newTestDatabaseWithLARDisabled();
const database = newTestDatabase();
await database.runTransactionAsync(async tx => {
await tx!.runUpdate({
sql: insertSql,
Expand Down

0 comments on commit ed510e8

Please sign in to comment.