Skip to content

Commit e1aac93

Browse files
Resolving merge conflicts
2 parents 69f0734 + 58fbee1 commit e1aac93

File tree

9 files changed

+1758
-698
lines changed

9 files changed

+1758
-698
lines changed

.gitignore

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,17 @@ dist
103103
# TernJS port file
104104
.tern-port
105105

106+
<<<<<<< HEAD
106107
# Local
107-
./ksqljsTest.js
108+
ksqljsTest.js
109+
package-lock.json
110+
local_ignore/
111+
.gitignore
112+
113+
# KSQLDB docker server settings
114+
ksqldb_server_config/
115+
116+
=======
117+
# Local files
118+
./ksqljs.js
119+
>>>>>>> jonTest

__tests__/integrationtests.js

Lines changed: 142 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
const { default: waitForExpect } = require('wait-for-expect');
12
const ksqljs = require('../ksqljs/ksqlJS.js');
2-
33
// Pre-requisite: start a docker container
44
/* 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.
78
*/
89

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)
1015

16+
describe('--Integration Tests--', () => {
1117
describe('--Method Tests--', () => {
1218
beforeAll(async () => {
1319
client = new ksqljs({ ksqldbURL: 'http://localhost:8088' });
@@ -53,6 +59,7 @@ describe('--Integration Tests--', () => {
5359
const response = await client.insertStream('TESTJESTSTREAM', [
5460
{ "name": "stab-rabbit", "email": "123@mail.com", "age": 100 }
5561
]);
62+
console.log(response);
5663
const data = [];
5764
await client.push('SELECT * FROM TESTJESTSTREAM EMIT CHANGES;', async (chunk) => {
5865
data.push(JSON.parse(chunk));
@@ -65,7 +72,8 @@ describe('--Integration Tests--', () => {
6572

6673
it('.pull receives the correct data from a pull query', async () => {
6774
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]);
6977
})
7078

7179
it('.pullFromTo receives all the data', async () => {
@@ -105,26 +113,65 @@ describe('--Integration Tests--', () => {
105113
});
106114
})
107115
})
116+
<<<<<<< HEAD
108117

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
109162
describe('--Health Tests--', () => {
110163
beforeAll((done) => {
111164
client = new ksqljs({ ksqldbURL: 'http://localhost:8088' });
112165
done();
113166
});
114167

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+
})
124171

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}
128175
(name VARCHAR,
129176
email varchar,
130177
age INTEGER)
@@ -133,93 +180,92 @@ describe('--Integration Tests--', () => {
133180
VALUE_FORMAT = 'json',
134181
PARTITIONS = 1
135182
);`);
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+
})
164192

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)
182208
})
183-
);
184-
})
209+
}));
210+
})
185211

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()
199228
})
200-
);
201229
})
230+
);
231+
})
202232

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()
207246
})
247+
);
248+
})
208249

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);
223254
})
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+
// })
224270
})
225271
})

docker-compose.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
version: "2"
2+
version: "3.2"
33

44
services:
55
zookeeper:
@@ -34,6 +34,10 @@ services:
3434
image: confluentinc/ksqldb-server:0.25.1
3535
hostname: ksqldb-server
3636
container_name: ksqldb-server
37+
volumes:
38+
- type: bind
39+
source: ./
40+
target: /home/appuser
3741
depends_on:
3842
- broker
3943
ports:
@@ -43,6 +47,16 @@ services:
4347
KSQL_BOOTSTRAP_SERVERS: broker:9092
4448
KSQL_KSQL_LOGGING_PROCESSING_STREAM_AUTO_CREATE: "true"
4549
KSQL_KSQL_LOGGING_PROCESSING_TOPIC_AUTO_CREATE: "true"
50+
# KSQL_KSQL_OPTS: "-Djava.security.auth.login.config=/jaas_config.file"
51+
# KSQL_AUTHENTICATION_METHOD: BASIC
52+
# KSQL_AUTHENTICATION_REALM: KsqlServer-Props
53+
# KSQL_AUTHENTICATION_ROLES: admin,developer,user
54+
# KSQL_SSL_CLIENT_AUTHENTICATION: NONE
55+
# KSQL_SSL_TRUSTSTORE_LOCATION: ksqldb_server_config/kafka.server.truststore.jks
56+
# KSQL_SSL_TRUSTSTORE_PASSWORD: ${SSL_PASSWORD}
57+
# KSQL_SSL_KEYSTORE_LOCATION: ksqldb_server_config/kafka.server.keystore.jks
58+
# KSQL_SSL_KEYSTORE_PASSWORD: ${SSL_PASSWORD}
59+
# KSQL_SSL_KEY_PASSWORD: ${SSL_PASSWORD}
4660
KSQL_KSQL_HEARTBEAT_ENABLE: "true"
4761
KSQL_KSQL_LAG_REPORTING_ENABLE: "true"
4862

ksqldbJS_classTest.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const ksqljs = require('./ksqljs/ksqldbJS_class');
2+
3+
const client = new ksqljs('http://localhost:8088');
4+
5+
//---------------------Test PUll Queries-------------------
6+
/* const pullTest = async () => {
7+
const result = await client.pull('SELECT * FROM riderlocations;');
8+
console.log('this is the result', result);
9+
}
10+
11+
pullTest(); */
12+
13+
//---------------------Test Push Queries-------------------
14+
/* const pushTest = async () => {
15+
metadata = await client.push('SELECT * FROM riderlocations EMIT CHANGES LIMIT 1;', (row) => console.log(row));
16+
console.log('this is the metadata returned ', metadata);
17+
};
18+
19+
pushTest();
20+
21+
//---------------------Test Termination of Queries-------------------
22+
const terminateTest = async () => {
23+
client.terminate(metadata);
24+
};
25+
26+
setTimeout(() => terminateTest(metadata), 2000); */
27+
28+
//---------------------Test List Queries-------------------
29+
/* // const listQueries = async () => {
30+
// console.log(await client.ksql('LIST QUERIES;'));
31+
// console.log(await client.ksql('LIST STREAMS;'));
32+
// console.log(await client.ksql('LIST TABLES;'));
33+
// console.log(await client.ksql('LIST TOPICS;'));
34+
// }
35+
36+
// listQueries(); */
37+
38+
//---------------------Test Stream Creation-------------------
39+
/* const createStreamTest = () => {
40+
client.createStream('AnotherTestStream', ['name VARCHAR','email varchar','age INTEGER'], 'testTopic', 'json', 1);
41+
}
42+
43+
createStreamTest(); */
44+
45+
//---------------------Test Table Creation-------------------
46+
/* const createTableTest = () => {
47+
client.createTable();
48+
} */

0 commit comments

Comments
 (0)