1
+ const { default : waitForExpect } = require ( 'wait-for-expect' ) ;
1
2
const ksqljs = require ( '../ksqljs/ksqlJS.js' ) ;
2
-
3
3
// Pre-requisite: start a docker container
4
4
/* To add to README: Prior to running test with 'npm test', please start the ksqlDB
5
- server using the command 'docker compose-up'. This will spin up a ksqlDB server on
6
- 'http://localhost:8088'
5
+ server using the command 'docker-compose up'. This will spin up a ksqlDB server on
6
+ 'http://localhost:8088'. If the command was run before, the created container might
7
+ need to be removed first.
7
8
*/
8
9
9
- describe ( '--Integration Tests--' , ( ) => {
10
+ // ** INTEGRATION TEST INSTRUCTIONS **
11
+
12
+ // Prior to running the test files, please ensure an instance of the ksqldb server is running
13
+ // Steps to starting the ksqldb server can be found here: (https://ksqldb.io/quickstart.html)
14
+ // Once the ksqlDB server is running, tests can be run with terminal line: (npm test)
10
15
16
+ describe ( '--Integration Tests--' , ( ) => {
11
17
describe ( '--Method Tests--' , ( ) => {
12
18
beforeAll ( async ( ) => {
13
19
client = new ksqljs ( { ksqldbURL : 'http://localhost:8088' } ) ;
@@ -53,6 +59,7 @@ describe('--Integration Tests--', () => {
53
59
const response = await client . insertStream ( 'TESTJESTSTREAM' , [
54
60
{ "name" : "stab-rabbit" , "email" : "123@mail.com" , "age" : 100 }
55
61
] ) ;
62
+ console . log ( response ) ;
56
63
const data = [ ] ;
57
64
await client . push ( 'SELECT * FROM TESTJESTSTREAM EMIT CHANGES;' , async ( chunk ) => {
58
65
data . push ( JSON . parse ( chunk ) ) ;
@@ -65,7 +72,8 @@ describe('--Integration Tests--', () => {
65
72
66
73
it ( '.pull receives the correct data from a pull query' , async ( ) => {
67
74
const pullData = await client . pull ( "SELECT * FROM TESTJESTSTREAM;" ) ;
68
- expect ( pullData [ 1 ] ) . toEqual ( [ 'stab-rabbit' , '123@mail.com' , 100 ] ) ;
75
+ console . log ( pullData [ 1 ] ) ;
76
+ expect ( pullData [ 1 ] ) . toEqual ( [ "stab-rabbit" , "123@mail.com" , 100 ] ) ;
69
77
} )
70
78
71
79
it ( '.pullFromTo receives all the data' , async ( ) => {
@@ -105,26 +113,65 @@ describe('--Integration Tests--', () => {
105
113
} ) ;
106
114
} )
107
115
} )
116
+ << < << << HEAD
108
117
118
+ === = ===
119
+
120
+ // describe('--Materialized Views Test--', () => {
121
+ // beforeAll( async () => {
122
+ // client = new ksqljs({ ksqldbURL: 'http://localhost:8088'});
123
+ // const waitForExpect = require('wait-for-expect');
124
+ // await client.ksql('CREATE STREAM NEWTESTSTREAM (NAME VARCHAR, AGE INTEGER, LOCATION VARCHAR, WEIGHT INTEGER) WITH (kafka_topic= \'testJestTopic2\', value_format=\'json\', partitions=1);')
125
+ // });
126
+ // afterAll(async () => {
127
+ // await client.ksql('DROP TABLE IF EXISTS TABLEOFSTREAM DELETE TOPIC;')
128
+ // await client.ksql('DROP STREAM IF EXISTS NEWTESTSTREAM DELETE TOPIC;')
129
+ // })
130
+ // it('creates a materialized table view of a stream', async () => {
131
+ // await client.createTableAs('TABLEOFSTREAM', 'NEWTESTSTREAM', ['name', 'LATEST_BY_OFFSET(age) AS recentAge', 'LATEST_BY_OFFSET(weight) AS recentweight'], {topic:'newTopic'},{WHERE: 'age >= 21', GROUP_BY: 'name'});
132
+ // const tables = await client.ksql('LIST TABLES;');
133
+ // const allTables = tables.tables;
134
+ // let tableCheck = false;
135
+ // for (let i = 0; i < allTables.length; i++){
136
+ // if (allTables[i].name === 'TABLEOFSTREAM') {
137
+ // tableCheck = true;
138
+ // break;
139
+ // }
140
+ // }
141
+ // expect(tableCheck).toEqual(true);
142
+
143
+ // })
144
+ // it('materialized table view updates with source stream', async () => {
145
+ // let rowCheck = false;
146
+ // // push query for the table
147
+ // // console.log('testing materialized view')
148
+ // await client.push('SELECT * FROM TABLEOFSTREAM EMIT CHANGES LIMIT 1;', async (data) => {
149
+ // console.log('QUERY INFO',data)
150
+ // if (Array.isArray(JSON.parse(data))){
151
+ // if (JSON.parse(data)[0] === "firstTester" && JSON.parse(data)[1] === 25 && JSON.parse(data)[2] === 130){
152
+ // rowCheck = true;
153
+ // }
154
+ // }
155
+ // })
156
+ // await client.insertStream('NEWTESTSTREAM', [{"NAME":"firstTester", "AGE":25, "LOCATION": "Seattle", "WEIGHT": 130}]);
157
+ // await waitForExpect(() => expect(rowCheck).toEqual(true))
158
+ // })
159
+ // })
160
+
161
+ >>> > >>> dev
109
162
describe ( '--Health Tests--' , ( ) => {
110
163
beforeAll ( ( done ) => {
111
164
client = new ksqljs ( { ksqldbURL : 'http://localhost:8088' } ) ;
112
165
done ( ) ;
113
166
} ) ;
114
167
115
- describe ( '--Health Tests--' , ( ) => {
116
- beforeAll ( ( done ) => {
117
- client = new ksqljs ( { ksqldbURL : 'http://localhost:8088' } ) ;
118
- done ( ) ;
119
- } ) ;
120
-
121
- afterAll ( async ( ) => {
122
- await client . ksql ( 'DROP STREAM IF EXISTS TESTSTREAM2;' ) ;
123
- } )
168
+ afterAll ( async ( ) => {
169
+ await client . ksql ( 'DROP STREAM IF EXISTS TESTSTREAM2;' ) ;
170
+ } )
124
171
125
- it ( '.inspectQueryStatus checks if a stream is created successfully' , async ( ) => {
126
- const streamName = 'TESTSTREAM2'
127
- const create = await client . ksql ( `CREATE STREAM IF NOT EXISTS ${ streamName }
172
+ it ( '.inspectQueryStatus checks if a stream is created successfully' , async ( ) => {
173
+ const streamName = 'TESTSTREAM2'
174
+ const create = await client . ksql ( `CREATE STREAM IF NOT EXISTS ${ streamName }
128
175
(name VARCHAR,
129
176
email varchar,
130
177
age INTEGER)
@@ -133,93 +180,92 @@ describe('--Integration Tests--', () => {
133
180
VALUE_FORMAT = 'json',
134
181
PARTITIONS = 1
135
182
);` ) ;
136
- const commandId = create ? create . commandId : `stream/${ streamName } /create` ;
137
- const status = await client . inspectQueryStatus ( commandId ) ;
138
- // response should be { status: 'SUCCESS', message: 'Stream created', queryId: null }
139
- expect ( status . data ) . toEqual ( expect . objectContaining ( {
140
- status : expect . any ( String ) ,
141
- message : expect . any ( String ) ,
142
- queryId : null
143
- } ) ) ;
144
- } )
145
-
146
- it ( '.inspectServerInfo returns the server info and status' , async ( ) => {
147
- const status = await client . inspectServerInfo ( ) ;
148
- // should return something like: {
149
- // KsqlServerInfo: {
150
- // version: '0.25.1',
151
- // kafkaClusterId: '0Yxd6N5OSKGDUalltPWvXg',
152
- // ksqlServiceId: 'default_',
153
- // serverStatus: 'RUNNING'
154
- // }
155
- // }
156
- expect ( status . data ) . toEqual ( expect . objectContaining ( {
157
- KsqlServerInfo : expect . objectContaining ( {
158
- version : expect . any ( String ) ,
159
- kafkaClusterId : expect . any ( String ) ,
160
- serverStatus : expect . any ( String )
161
- } )
162
- } ) ) ;
163
- } )
183
+ const commandId = create ? create . commandId : `stream/${ streamName } /create` ;
184
+ const status = await client . inspectQueryStatus ( commandId ) ;
185
+ // response should be { status: 'SUCCESS', message: 'Stream created', queryId: null }
186
+ expect ( status . data ) . toEqual ( expect . objectContaining ( {
187
+ status : expect . any ( String ) ,
188
+ message : expect . any ( String ) ,
189
+ queryId : null
190
+ } ) ) ;
191
+ } )
164
192
165
- it ( '.inspectServerHealth returns the server health' , async ( ) => {
166
- const status = await client . inspectServerHealth ( ) ;
167
- // should return something like: {
168
- // isHealthy: true,
169
- // details: {
170
- // metastore: { isHealthy: true },
171
- // kafka: { isHealthy: true },
172
- // commandRunner: { isHealthy: true }
173
- // }
174
- // }
175
- expect ( status . data ) . toEqual ( expect . objectContaining ( {
176
- isHealthy : expect . any ( Boolean ) ,
177
- details : expect . objectContaining ( {
178
- metastore : expect . anything ( ) ,
179
- kafka : expect . anything ( ) ,
180
- commandRunner : expect . anything ( )
181
- } )
193
+ it ( '.inspectServerInfo returns the server info and status' , async ( ) => {
194
+ const status = await client . inspectServerInfo ( ) ;
195
+ // should return something like: {
196
+ // KsqlServerInfo: {
197
+ // version: '0.25.1',
198
+ // kafkaClusterId: '0Yxd6N5OSKGDUalltPWvXg',
199
+ // ksqlServiceId: 'default_',
200
+ // serverStatus: 'RUNNING'
201
+ // }
202
+ // }
203
+ expect ( status . data ) . toEqual ( expect . objectContaining ( {
204
+ KsqlServerInfo : expect . objectContaining ( {
205
+ version : expect . any ( String ) ,
206
+ kafkaClusterId : expect . any ( String ) ,
207
+ serverStatus : expect . any ( String )
182
208
} )
183
- ) ;
184
- } )
209
+ } ) ) ;
210
+ } )
185
211
186
- it ( '.inspectClusterStatus returns the cluster status' , async ( ) => {
187
- const status = await client . inspectClusterStatus ( ) ;
188
- // should return something like: {
189
- // clusterStatus: {
190
- // 'ksqldb-server:8088': {
191
- // hostAlive: true,
192
- // lastStatusUpdateMs: 1653164479237,
193
- // activeStandbyPerQuery: [Object],
194
- // hostStoreLags: [Object]
195
- // }
196
- // }}
197
- expect ( status . data ) . toEqual ( expect . objectContaining ( {
198
- clusterStatus : expect . anything ( )
212
+ it ( '.inspectServerHealth returns the server health' , async ( ) => {
213
+ const status = await client . inspectServerHealth ( ) ;
214
+ // should return something like: {
215
+ // isHealthy: true,
216
+ // details: {
217
+ // metastore: { isHealthy: true },
218
+ // kafka: { isHealthy: true },
219
+ // commandRunner: { isHealthy: true }
220
+ // }
221
+ // }
222
+ expect ( status . data ) . toEqual ( expect . objectContaining ( {
223
+ isHealthy : expect . any ( Boolean ) ,
224
+ details : expect . objectContaining ( {
225
+ metastore : expect . anything ( ) ,
226
+ kafka : expect . anything ( ) ,
227
+ commandRunner : expect . anything ( )
199
228
} )
200
- ) ;
201
229
} )
230
+ ) ;
231
+ } )
202
232
203
- it ( '.isValidProperty returns true if a server configuration property is not prohibited from setting' , async ( ) => {
204
- const status = await client . isValidProperty ( 'test' ) ;
205
- // should return true
206
- expect ( status . data ) . toEqual ( true ) ;
233
+ it ( '.inspectClusterStatus returns the cluster status' , async ( ) => {
234
+ const status = await client . inspectClusterStatus ( ) ;
235
+ // should return something like: {
236
+ // clusterStatus: {
237
+ // 'ksqldb-server:8088': {
238
+ // hostAlive: true,
239
+ // lastStatusUpdateMs: 1653164479237,
240
+ // activeStandbyPerQuery: [Object],
241
+ // hostStoreLags: [Object]
242
+ // }
243
+ // }}
244
+ expect ( status . data ) . toEqual ( expect . objectContaining ( {
245
+ clusterStatus : expect . anything ( )
207
246
} )
247
+ ) ;
248
+ } )
208
249
209
- // it('isValidProperty returns an error if the server property is prohibited from setting', async () => {
210
- // const status = await client.isValidProperty('ksql.connect.url');
211
- // // should return something like
212
- // // {
213
- // // "@type": "generic_error",
214
- // // "error_code": 40000,
215
- // // "message": "One or more properties overrides set locally are prohibited by the KSQL server (use UNSET to reset their default value): [ksql.service.id]"
216
- // // }
217
- // expect(status.data).toEqual(expect.objectContaining({
218
- // type: expect.any(String),
219
- // error_code: expect.any(Number),
220
- // message: expect.any(String),
221
- // }));
222
- // })
250
+ it ( '.isValidProperty returns true if a server configuration property is not prohibited from setting' , async ( ) => {
251
+ const status = await client . isValidProperty ( 'test' ) ;
252
+ // should return true
253
+ expect ( status . data ) . toEqual ( true ) ;
223
254
} )
255
+
256
+ // it('isValidProperty returns an error if the server property is prohibited from setting', async () => {
257
+ // const status = await client.isValidProperty('ksql.connect.url');
258
+ // // should return something like
259
+ // // {
260
+ // // "@type": "generic_error",
261
+ // // "error_code": 40000,
262
+ // // "message": "One or more properties overrides set locally are prohibited by the KSQL server (use UNSET to reset their default value): [ksql.service.id]"
263
+ // // }
264
+ // expect(status.data).toEqual(expect.objectContaining({
265
+ // type: expect.any(String),
266
+ // error_code: expect.any(Number),
267
+ // message: expect.any(String),
268
+ // }));
269
+ // })
224
270
} )
225
271
} )
0 commit comments