@@ -34,6 +34,7 @@ import { AwsMysqlPoolClient } from "../../mysql/lib/mysql_pool_client";
34
34
import { PoolKey } from "../../common/lib/utils/pool_key" ;
35
35
import { InternalPoolMapping } from "../../common/lib/utils/internal_pool_mapping" ;
36
36
import { SlidingExpirationCache } from "../../common/lib/utils/sliding_expiration_cache" ;
37
+ import { MySQL2DriverDialect } from "../../mysql/lib/dialect/mysql2_driver_dialect" ;
37
38
38
39
const internalPoolWithOneConnection = mock ( AwsMysqlPoolClient ) ;
39
40
const user1 = "user1" ;
@@ -67,6 +68,7 @@ const mockHostListProvider: HostListProvider = mock<HostListProvider>();
67
68
const mockClosedReaderClient : AwsClient = mock ( AwsMySQLClient ) ;
68
69
const mockClosedWriterClient : AwsClient = mock ( AwsMySQLClient ) ;
69
70
const mockDialect : MySQLDatabaseDialect = mock ( MySQLDatabaseDialect ) ;
71
+ const mockDriverDialect : MySQL2DriverDialect = mock ( MySQL2DriverDialect ) ;
70
72
const mockPoolConnection = mock ( AwsMysqlPoolClient ) ;
71
73
const mockAwsPoolClient = mock ( AwsMysqlPoolClient ) ;
72
74
const mockRdsUtils = mock ( RdsUtils ) ;
@@ -78,6 +80,9 @@ describe("reader write splitting test", () => {
78
80
when ( mockPluginService . getHostListProvider ( ) ) . thenReturn ( instance ( mockHostListProvider ) ) ;
79
81
when ( mockPluginService . getHosts ( ) ) . thenReturn ( defaultHosts ) ;
80
82
when ( mockPluginService . isInTransaction ( ) ) . thenReturn ( false ) ;
83
+ when ( mockPluginService . getDialect ( ) ) . thenReturn ( instance ( mockDialect ) ) ;
84
+ when ( mockPluginService . getDriverDialect ( ) ) . thenReturn ( instance ( mockDriverDialect ) ) ;
85
+ when ( mockDriverDialect . getAwsPoolClient ( anything ( ) ) ) . thenReturn ( mockAwsPoolClient ) ;
81
86
props . clear ( ) ;
82
87
} ) ;
83
88
@@ -106,14 +111,12 @@ describe("reader write splitting test", () => {
106
111
when ( mockRdsUtils . isRdsDns ( anything ( ) ) ) . thenReturn ( null ) ;
107
112
when ( mockRdsUtils . isGreenInstance ( anything ( ) ) ) . thenReturn ( null ) ;
108
113
when ( mockRdsUtils . isRdsInstance ( "instance1" ) ) . thenReturn ( true ) ;
109
- when ( mockPluginService . getDialect ( ) ) . thenReturn ( mockDialect ) ;
110
- when ( mockDialect . getAwsPoolClient ( anything ( ) ) ) . thenReturn ( mockAwsPoolClient ) ;
111
114
const config = {
112
115
maxConnection : 10 ,
113
116
idleTimeoutMillis : 10000 ,
114
117
connectionTimeoutMillis : 10000
115
118
} ;
116
- when ( mockDialect . preparePoolClientProperties ( anything ( ) , anything ( ) ) ) . thenReturn ( config ) ;
119
+ when ( mockDriverDialect . preparePoolClientProperties ( anything ( ) , anything ( ) ) ) . thenReturn ( config ) ;
117
120
const poolConfig : AwsPoolConfig = new AwsPoolConfig ( config ) ;
118
121
119
122
const provider = spy ( new InternalPooledConnectionProvider ( poolConfig ) ) ;
@@ -146,7 +149,6 @@ describe("reader write splitting test", () => {
146
149
when ( mockRdsUtils . isGreenInstance ( anything ( ) ) ) . thenReturn ( null ) ;
147
150
when ( mockRdsUtils . isRdsInstance ( "instance1" ) ) . thenReturn ( true ) ;
148
151
when ( mockPluginService . getDialect ( ) ) . thenReturn ( mockDialect ) ;
149
- when ( mockDialect . getAwsPoolClient ( anything ( ) ) ) . thenReturn ( mockAwsPoolClient ) ;
150
152
const config = {
151
153
maxConnection : 10 ,
152
154
idleTimeoutMillis : 10000 ,
@@ -157,7 +159,7 @@ describe("reader write splitting test", () => {
157
159
return hostInfo . url + "someKey" ;
158
160
}
159
161
} ;
160
- when ( mockDialect . preparePoolClientProperties ( anything ( ) , anything ( ) ) ) . thenReturn ( config ) ;
162
+ when ( mockDriverDialect . preparePoolClientProperties ( anything ( ) , anything ( ) ) ) . thenReturn ( config ) ;
161
163
const poolConfig : AwsPoolConfig = new AwsPoolConfig ( config ) ;
162
164
163
165
const provider = spy ( new InternalPooledConnectionProvider ( poolConfig , myKeyFunc ) ) ;
@@ -197,19 +199,14 @@ describe("reader write splitting test", () => {
197
199
when ( mockRdsUtils . isRdsDns ( anything ( ) ) ) . thenReturn ( null ) ;
198
200
when ( mockRdsUtils . isGreenInstance ( anything ( ) ) ) . thenReturn ( null ) ;
199
201
when ( mockRdsUtils . isRdsInstance ( "instance1" ) ) . thenReturn ( true ) ;
200
- when ( mockDialect . preparePoolClientProperties ( anything ( ) , anything ( ) ) ) . thenReturn ( props ) ;
201
- when ( mockDialect . getAwsPoolClient ( anything ( ) ) ) . thenThrow ( new Error ( "testError" ) ) ;
202
+ when ( mockDriverDialect . preparePoolClientProperties ( anything ( ) , anything ( ) ) ) . thenReturn ( props ) ;
203
+ when ( mockDriverDialect . getAwsPoolClient ( anything ( ) ) ) . thenThrow ( new Error ( "testError" ) ) ;
202
204
203
205
const provider = spy ( new InternalPooledConnectionProvider ( poolConfig ) ) ;
204
206
const providerSpy = instance ( provider ) ;
205
207
when ( await provider . getPoolConnection ( ) ) . thenReturn ( mockPoolConnection ) ;
206
208
207
- try {
208
- await providerSpy . connect ( hostInfo , mockPluginServiceInstance , props ) ;
209
- throw new Error ( "did not catch error" ) ;
210
- } catch ( error : any ) {
211
- expect ( error . message ) . toEqual ( "testError" ) ;
212
- }
209
+ await expect ( providerSpy . connect ( hostInfo , mockPluginServiceInstance , props ) ) . rejects . toThrow ( "testError" ) ;
213
210
await provider . releaseResources ( ) ;
214
211
ConnectionProviderManager . resetProvider ( ) ;
215
212
} ) ;
0 commit comments