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