1
1
const ksqljs = require ( '../ksqljs/ksqlJS.js' ) ;
2
2
3
3
// Pre-requisite: start a docker container
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'
7
+ */
4
8
5
9
describe ( '--Integration Tests--' , ( ) => {
6
10
@@ -27,7 +31,7 @@ describe('--Integration Tests--', () => {
27
31
}
28
32
expect ( streamExists ) . toEqual ( true ) ;
29
33
} )
30
-
34
+
31
35
it ( '.push properly creates a push query' , ( ) => {
32
36
let pushActive = false ;
33
37
client . push ( 'SELECT * FROM TESTJESTSTREAM EMIT CHANGES LIMIT 1;' , async ( data ) => {
@@ -37,29 +41,29 @@ describe('--Integration Tests--', () => {
37
41
expect ( pushActive ) . toEqual ( true )
38
42
} ) ;
39
43
} )
40
-
44
+
41
45
it ( '.terminate properly terminates a push query' , ( ) => {
42
46
client . push ( 'SELECT * FROM TESTJESTSTREAM EMIT CHANGES LIMIT 3;' , async ( data ) => {
43
47
const terminateRes = await client . terminate ( JSON . parse ( data ) . queryId ) ;
44
48
expect ( terminateRes . wasTerminated ) . toEqual ( true ) ;
45
49
} )
46
50
} )
47
-
51
+
48
52
it ( '.insertStream properly inserts a row into a stream' , async ( ) => {
49
53
const response = await client . insertStream ( 'TESTJESTSTREAM' , [
50
54
{ "name" : "stab-rabbit" , "email" : "123@mail.com" , "age" : 100 }
51
55
] ) ;
52
56
console . log ( response ) ;
53
57
const data = [ ] ;
54
- await client . push ( 'SELECT * FROM TESTJESTSTREAM;' , async ( chunk ) => {
58
+ await client . push ( 'SELECT * FROM TESTJESTSTREAM EMIT CHANGES ;' , async ( chunk ) => {
55
59
data . push ( JSON . parse ( chunk ) ) ;
56
60
if ( data [ 1 ] ) {
57
61
client . terminate ( data [ 0 ] . queryId ) ;
58
62
expect ( data [ 1 ] ) . toEqual ( [ "stab-rabbit" , "123@mail.com" , 100 ] )
59
63
}
60
64
} ) ;
61
65
} )
62
-
66
+
63
67
it ( '.pull receives the correct data from a pull query' , async ( ) => {
64
68
const pullData = await client . pull ( "SELECT * FROM TESTJESTSTREAM;" ) ;
65
69
expect ( pullData [ 1 ] ) . toEqual ( [ 'stab-rabbit' , '123@mail.com' , 100 ] ) ;
@@ -73,20 +77,25 @@ describe('--Integration Tests--', () => {
73
77
expect ( expectPullData ) . toEqual ( expectData ) ;
74
78
} )
75
79
} )
76
-
77
80
describe ( '--Health Tests--' , ( ) => {
78
81
beforeAll ( ( done ) => {
79
82
client = new ksqljs ( { ksqldbURL : 'http://localhost:8088' } ) ;
80
83
done ( ) ;
81
84
} ) ;
82
-
83
- afterAll ( async ( ) => {
84
- await client . ksql ( 'DROP STREAM IF EXISTS TESTSTREAM2;' ) ;
85
- } )
86
85
87
- it ( '.inspectQueryStatus checks if a stream is created successfully' , async ( ) => {
88
- const streamName = 'TESTSTREAM2'
89
- const create = await client . ksql ( `CREATE STREAM IF NOT EXISTS ${ streamName }
86
+ describe ( '--Health Tests--' , ( ) => {
87
+ beforeAll ( ( done ) => {
88
+ client = new ksqljs ( { ksqldbURL : 'http://localhost:8088' } ) ;
89
+ done ( ) ;
90
+ } ) ;
91
+
92
+ afterAll ( async ( ) => {
93
+ await client . ksql ( 'DROP STREAM IF EXISTS TESTSTREAM2;' ) ;
94
+ } )
95
+
96
+ it ( '.inspectQueryStatus checks if a stream is created successfully' , async ( ) => {
97
+ const streamName = 'TESTSTREAM2'
98
+ const create = await client . ksql ( `CREATE STREAM IF NOT EXISTS ${ streamName }
90
99
(name VARCHAR,
91
100
email varchar,
92
101
age INTEGER)
@@ -95,92 +104,93 @@ describe('--Integration Tests--', () => {
95
104
VALUE_FORMAT = 'json',
96
105
PARTITIONS = 1
97
106
);` ) ;
98
- const commandId = create ? create . commandId : `stream/${ streamName } /create` ;
99
- const status = await client . inspectQueryStatus ( commandId ) ;
100
- // response should be { status: 'SUCCESS', message: 'Stream created', queryId: null }
101
- expect ( status . data ) . toEqual ( expect . objectContaining ( {
102
- status : expect . any ( String ) ,
103
- message : expect . any ( String ) ,
104
- queryId : null
105
- } ) ) ;
106
- } )
107
-
108
- it ( '.inspectServerInfo returns the server info and status' , async ( ) => {
109
- const status = await client . inspectServerInfo ( ) ;
110
- // should return something like: {
111
- // KsqlServerInfo: {
112
- // version: '0.25.1',
113
- // kafkaClusterId: '0Yxd6N5OSKGDUalltPWvXg',
114
- // ksqlServiceId: 'default_',
115
- // serverStatus: 'RUNNING'
116
- // }
117
- // }
118
- expect ( status . data ) . toEqual ( expect . objectContaining ( {
119
- KsqlServerInfo : expect . objectContaining ( {
120
- version : expect . any ( String ) ,
121
- kafkaClusterId : expect . any ( String ) ,
122
- serverStatus : expect . any ( String )
107
+ const commandId = create ? create . commandId : `stream/${ streamName } /create` ;
108
+ const status = await client . inspectQueryStatus ( commandId ) ;
109
+ // response should be { status: 'SUCCESS', message: 'Stream created', queryId: null }
110
+ expect ( status . data ) . toEqual ( expect . objectContaining ( {
111
+ status : expect . any ( String ) ,
112
+ message : expect . any ( String ) ,
113
+ queryId : null
114
+ } ) ) ;
115
+ } )
116
+
117
+ it ( '.inspectServerInfo returns the server info and status' , async ( ) => {
118
+ const status = await client . inspectServerInfo ( ) ;
119
+ // should return something like: {
120
+ // KsqlServerInfo: {
121
+ // version: '0.25.1',
122
+ // kafkaClusterId: '0Yxd6N5OSKGDUalltPWvXg',
123
+ // ksqlServiceId: 'default_',
124
+ // serverStatus: 'RUNNING'
125
+ // }
126
+ // }
127
+ expect ( status . data ) . toEqual ( expect . objectContaining ( {
128
+ KsqlServerInfo : expect . objectContaining ( {
129
+ version : expect . any ( String ) ,
130
+ kafkaClusterId : expect . any ( String ) ,
131
+ serverStatus : expect . any ( String )
132
+ } )
133
+ } ) ) ;
134
+ } )
135
+
136
+ it ( '.inspectServerHealth returns the server health' , async ( ) => {
137
+ const status = await client . inspectServerHealth ( ) ;
138
+ // should return something like: {
139
+ // isHealthy: true,
140
+ // details: {
141
+ // metastore: { isHealthy: true },
142
+ // kafka: { isHealthy: true },
143
+ // commandRunner: { isHealthy: true }
144
+ // }
145
+ // }
146
+ expect ( status . data ) . toEqual ( expect . objectContaining ( {
147
+ isHealthy : expect . any ( Boolean ) ,
148
+ details : expect . objectContaining ( {
149
+ metastore : expect . anything ( ) ,
150
+ kafka : expect . anything ( ) ,
151
+ commandRunner : expect . anything ( )
152
+ } )
123
153
} )
124
- } ) ) ;
125
- } )
126
-
127
- it ( '.inspectServerHealth returns the server health' , async ( ) => {
128
- const status = await client . inspectServerHealth ( ) ;
129
- // should return something like: {
130
- // isHealthy: true,
131
- // details: {
132
- // metastore: { isHealthy: true },
133
- // kafka: { isHealthy: true },
134
- // commandRunner: { isHealthy: true }
135
- // }
136
- // }
137
- expect ( status . data ) . toEqual ( expect . objectContaining ( {
138
- isHealthy : expect . any ( Boolean ) ,
139
- details : expect . objectContaining ( {
140
- metastore : expect . anything ( ) ,
141
- kafka : expect . anything ( ) ,
142
- commandRunner : expect . anything ( )
154
+ ) ;
155
+ } )
156
+
157
+ it ( '.inspectClusterStatus returns the cluster status' , async ( ) => {
158
+ const status = await client . inspectClusterStatus ( ) ;
159
+ // should return something like: {
160
+ // clusterStatus: {
161
+ // 'ksqldb-server:8088': {
162
+ // hostAlive: true,
163
+ // lastStatusUpdateMs: 1653164479237,
164
+ // activeStandbyPerQuery: [Object],
165
+ // hostStoreLags: [Object]
166
+ // }
167
+ // }}
168
+ expect ( status . data ) . toEqual ( expect . objectContaining ( {
169
+ clusterStatus : expect . anything ( )
143
170
} )
171
+ ) ;
144
172
} )
145
- ) ;
146
- } )
147
-
148
- it ( '.inspectClusterStatus returns the cluster status' , async ( ) => {
149
- const status = await client . inspectClusterStatus ( ) ;
150
- // should return something like: {
151
- // clusterStatus: {
152
- // 'ksqldb-server:8088': {
153
- // hostAlive: true,
154
- // lastStatusUpdateMs: 1653164479237,
155
- // activeStandbyPerQuery: [Object],
156
- // hostStoreLags: [Object]
157
- // }
158
- // }}
159
- expect ( status . data ) . toEqual ( expect . objectContaining ( {
160
- clusterStatus : expect . anything ( )
173
+
174
+ it ( '.isValidProperty returns true if a server configuration property is not prohibited from setting' , async ( ) => {
175
+ const status = await client . isValidProperty ( 'test' ) ;
176
+ // should return true
177
+ expect ( status . data ) . toEqual ( true ) ;
161
178
} )
162
- ) ;
163
- } )
164
-
165
- it ( '.isValidProperty returns true if a server configuration property is not prohibited from setting' , async ( ) => {
166
- const status = await client . isValidProperty ( 'test' ) ;
167
- // should return true
168
- expect ( status . data ) . toEqual ( true ) ;
179
+
180
+ // it('isValidProperty returns an error if the server property is prohibited from setting', async () => {
181
+ // const status = await client.isValidProperty('ksql.connect.url');
182
+ // // should return something like
183
+ // // {
184
+ // // "@type": "generic_error",
185
+ // // "error_code": 40000,
186
+ // // "message": "One or more properties overrides set locally are prohibited by the KSQL server (use UNSET to reset their default value): [ksql.service.id]"
187
+ // // }
188
+ // expect(status.data).toEqual(expect.objectContaining({
189
+ // type: expect.any(String),
190
+ // error_code: expect.any(Number),
191
+ // message: expect.any(String),
192
+ // }));
193
+ // })
169
194
} )
170
-
171
- // it('isValidProperty returns an error if the server property is prohibited from setting', async () => {
172
- // const status = await client.isValidProperty('ksql.connect.url');
173
- // // should return something like
174
- // // {
175
- // // "@type": "generic_error",
176
- // // "error_code": 40000,
177
- // // "message": "One or more properties overrides set locally are prohibited by the KSQL server (use UNSET to reset their default value): [ksql.service.id]"
178
- // // }
179
- // expect(status.data).toEqual(expect.objectContaining({
180
- // type: expect.any(String),
181
- // error_code: expect.any(Number),
182
- // message: expect.any(String),
183
- // }));
184
- // })
185
195
} )
186
196
} )
0 commit comments