@@ -22,6 +22,7 @@ globalCallbacks.onSocketClose = () => {
2222 logger . info ( "socket closed" ) ;
2323 return undefined ;
2424} ;
25+
2526const regions : BDAWSRegion [ ] = [
2627 "eu-west-1" ,
2728 "eu-north-1" ,
@@ -36,95 +37,95 @@ const regions: BDAWSRegion[] = [
3637 // "ca-central-1",
3738] ;
3839
40+ // Create connection to each region
41+ const bdAllRegions = regions . map ( region => ( {
42+ region,
43+ bd : new BoilingData ( { username, password, globalCallbacks, logLevel, region } ) ,
44+ } ) ) ;
45+ const connMap = new Map < string , BoilingData > ( ) ;
46+ bdAllRegions . forEach ( conn => connMap . set ( conn . region , conn . bd ) ) ;
47+
3948describe ( "BD can switch the WebSocket connection endpoint dynamically" , ( ) => {
40- it ( "run single query from 4 different supported regions" , async ( ) => {
41- const expected = [
42- {
43- DOLocationID : 1 ,
44- PULocationID : 1 ,
45- RatecodeID : 5 ,
46- VendorID : 1 ,
47- congestion_surcharge : 0 ,
48- extra : 0 ,
49- fare_amount : 121 ,
50- improvement_surcharge : 0.3 ,
51- mta_tax : 0 ,
52- passenger_count : 2 ,
53- payment_type : 1 ,
54- store_and_fwd_flag : "N" ,
55- tip_amount : 0 ,
56- tolls_amount : 0 ,
57- total_amount : 121.3 ,
58- tpep_dropoff_datetime : 1551410222000 ,
59- tpep_pickup_datetime : 1551410199000 ,
60- trip_distance : 0 ,
61- } ,
62- {
63- DOLocationID : 1 ,
64- PULocationID : 1 ,
65- RatecodeID : 5 ,
66- VendorID : 1 ,
67- congestion_surcharge : 0 ,
68- extra : 0 ,
69- fare_amount : 110 ,
70- improvement_surcharge : 0.3 ,
71- mta_tax : 0 ,
72- passenger_count : 1 ,
73- payment_type : 1 ,
74- store_and_fwd_flag : "N" ,
75- tip_amount : 10 ,
76- tolls_amount : 0 ,
77- total_amount : 120.3 ,
78- tpep_dropoff_datetime : 1551415659000 ,
79- tpep_pickup_datetime : 1551415597000 ,
80- trip_distance : 18.4 ,
81- } ,
82- ] ;
49+ const expected = [
50+ {
51+ DOLocationID : 1 ,
52+ PULocationID : 1 ,
53+ RatecodeID : 5 ,
54+ VendorID : 1 ,
55+ congestion_surcharge : 0 ,
56+ extra : 0 ,
57+ fare_amount : 121 ,
58+ improvement_surcharge : 0.3 ,
59+ mta_tax : 0 ,
60+ passenger_count : 2 ,
61+ payment_type : 1 ,
62+ store_and_fwd_flag : "N" ,
63+ tip_amount : 0 ,
64+ tolls_amount : 0 ,
65+ total_amount : 121.3 ,
66+ tpep_dropoff_datetime : 1551410222000 ,
67+ tpep_pickup_datetime : 1551410199000 ,
68+ trip_distance : 0 ,
69+ } ,
70+ {
71+ DOLocationID : 1 ,
72+ PULocationID : 1 ,
73+ RatecodeID : 5 ,
74+ VendorID : 1 ,
75+ congestion_surcharge : 0 ,
76+ extra : 0 ,
77+ fare_amount : 110 ,
78+ improvement_surcharge : 0.3 ,
79+ mta_tax : 0 ,
80+ passenger_count : 1 ,
81+ payment_type : 1 ,
82+ store_and_fwd_flag : "N" ,
83+ tip_amount : 10 ,
84+ tolls_amount : 0 ,
85+ total_amount : 120.3 ,
86+ tpep_dropoff_datetime : 1551415659000 ,
87+ tpep_pickup_datetime : 1551415597000 ,
88+ trip_distance : 18.4 ,
89+ } ,
90+ ] ;
91+
92+ beforeAll ( async ( ) => await Promise . all ( bdAllRegions . map ( conn => conn . bd . connect ( ) ) ) ) ;
93+
94+ afterAll ( async ( ) => await Promise . all ( bdAllRegions . map ( conn => conn . bd . close ( ) ) ) ) ;
8395
96+ it ( "run a local query in all supported regions" , async ( ) => {
97+ // Run all in parallel
98+ await Promise . all (
99+ regions . map ( async region => {
100+ const rows : any [ ] = [ ] ;
101+ const bucket = region == "eu-west-1" ? "boilingdata-demo" : `${ region } -boilingdata-demo` ;
102+ const sql = `SELECT * FROM parquet_scan('s3://${ bucket } /test.parquet') LIMIT 1;` ;
103+ rows . push ( await connMap . get ( region ) ?. execQueryPromise ( { sql } ) ) ;
104+ const sorted = rows . sort ( ) ;
105+ console . log ( sorted ) ;
106+ expect ( sorted ) . toMatchSnapshot ( ) ;
107+ } ) ,
108+ ) ;
109+ } ) ;
110+ it ( "run single query to eu-west-1 from all supported regions" , async ( ) => {
84111 // Run all queries in parallel
85112 await Promise . all (
86113 regions . map ( async region => {
87114 const sql = `SELECT * FROM parquet_scan('s3://boilingdata-demo/demo2.parquet') ORDER BY DOLocationID, PULocationID, tpep_dropoff_datetime, tpep_pickup_datetime, trip_distance LIMIT 2;` ;
88- const bd = new BoilingData ( {
89- username,
90- password,
91- globalCallbacks,
92- logLevel,
93- region,
94- } ) ;
95- await bd . connect ( ) ;
96115 // The JSON is bigint JSON, thus converting back to "normal", to get Object properties inherited, like toString()
97- const rows = JSON . parse ( JSON . stringify ( await bd . execQueryPromise ( { sql } ) ) ) ;
116+ const rows = JSON . parse ( JSON . stringify ( await connMap . get ( region ) ? .execQueryPromise ( { sql } ) ) ) ;
98117 expect ( rows . sort ( ) ) . toEqual ( expected ) ;
99- await bd . close ( ) ;
100118 } ) ,
101119 ) ;
102120 } ) ;
103- } ) ;
104-
105- describe ( "BoilingData in all North-America and Europe AWS Regions" , ( ) => {
106- it ( "runs query succesfully in other regions too" , async ( ) => {
107- // Run all in parallel
121+ it ( "run single query to us-east-2 from all supported regions" , async ( ) => {
122+ // Run all queries in parallel
108123 await Promise . all (
109124 regions . map ( async region => {
110- const rows : any [ ] = [ ] ;
111- const bdInstance = new BoilingData ( {
112- username,
113- password,
114- globalCallbacks,
115- logLevel,
116- region,
117- } ) ;
118- await bdInstance . connect ( ) ;
119- logger . info ( `connected to region ${ region } ` ) ;
120- const bucket = region == "eu-west-1" ? "boilingdata-demo" : `${ region } -boilingdata-demo` ;
121- const sql = `SELECT * FROM parquet_scan('s3://${ bucket } /test.parquet') LIMIT 1;` ;
122- rows . push ( await bdInstance . execQueryPromise ( { sql } ) ) ;
123- await bdInstance . close ( ) ;
124- logger . info ( `connection closed to region ${ region } ` ) ;
125- const sorted = rows . sort ( ) ;
126- console . log ( sorted ) ;
127- expect ( sorted ) . toMatchSnapshot ( ) ;
125+ const sql = `SELECT * FROM parquet_scan('s3://us-east-2-boilingdata-demo/demo2.parquet') ORDER BY DOLocationID, PULocationID, tpep_dropoff_datetime, tpep_pickup_datetime, trip_distance LIMIT 2;` ;
126+ // The JSON is bigint JSON, thus converting back to "normal", to get Object properties inherited, like toString()
127+ const rows = JSON . parse ( JSON . stringify ( await connMap . get ( region ) ?. execQueryPromise ( { sql } ) ) ) ;
128+ expect ( rows . sort ( ) ) . toEqual ( expected ) ;
128129 } ) ,
129130 ) ;
130131 } ) ;
0 commit comments