@tdengine/websocket 3.2.0 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/example/all_type_query.js +26 -22
- package/lib/example/all_type_stmt.js +22 -20
- package/lib/example/basicBatchTmq.js +14 -14
- package/lib/example/basicSchemaless.js +11 -11
- package/lib/example/basicSql.js +10 -10
- package/lib/example/basicStmt.js +3 -3
- package/lib/example/basicTmq.js +8 -9
- package/lib/index.d.ts +0 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -7
- package/lib/src/client/wsClient.d.ts +2 -2
- package/lib/src/client/wsClient.d.ts.map +1 -1
- package/lib/src/client/wsClient.js +60 -37
- package/lib/src/client/wsConnector.d.ts.map +1 -1
- package/lib/src/client/wsConnector.js +40 -14
- package/lib/src/client/wsConnectorPool.d.ts.map +1 -1
- package/lib/src/client/wsConnectorPool.js +29 -14
- package/lib/src/client/wsEventCallback.d.ts.map +1 -1
- package/lib/src/client/wsEventCallback.js +6 -4
- package/lib/src/client/wsResponse.d.ts.map +1 -1
- package/lib/src/client/wsResponse.js +6 -2
- package/lib/src/common/config.d.ts +2 -2
- package/lib/src/common/config.d.ts.map +1 -1
- package/lib/src/common/config.js +5 -5
- package/lib/src/common/constant.d.ts.map +1 -1
- package/lib/src/common/constant.js +27 -27
- package/lib/src/common/log.d.ts +1 -1
- package/lib/src/common/log.d.ts.map +1 -1
- package/lib/src/common/log.js +9 -7
- package/lib/src/common/reqid.d.ts.map +1 -1
- package/lib/src/common/reqid.js +7 -7
- package/lib/src/common/taosResult.d.ts.map +1 -1
- package/lib/src/common/taosResult.js +46 -27
- package/lib/src/common/ut8Helper.d.ts.map +1 -1
- package/lib/src/common/ut8Helper.js +8 -8
- package/lib/src/common/utils.d.ts.map +1 -1
- package/lib/src/common/utils.js +17 -16
- package/lib/src/common/wsError.d.ts.map +1 -1
- package/lib/src/common/wsError.js +3 -3
- package/lib/src/common/wsOptions.d.ts +1 -1
- package/lib/src/index.d.ts +3 -3
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/sql/wsProto.d.ts.map +1 -1
- package/lib/src/sql/wsRows.d.ts +3 -3
- package/lib/src/sql/wsRows.d.ts.map +1 -1
- package/lib/src/sql/wsRows.js +4 -2
- package/lib/src/sql/wsSql.d.ts +5 -5
- package/lib/src/sql/wsSql.d.ts.map +1 -1
- package/lib/src/sql/wsSql.js +15 -16
- package/lib/src/stmt/FieldBindParams.d.ts.map +1 -1
- package/lib/src/stmt/wsColumnInfo.d.ts.map +1 -1
- package/lib/src/stmt/wsParams1.d.ts.map +1 -1
- package/lib/src/stmt/wsParams1.js +50 -24
- package/lib/src/stmt/wsParams2.d.ts.map +1 -1
- package/lib/src/stmt/wsParams2.js +30 -15
- package/lib/src/stmt/wsParamsBase.d.ts.map +1 -1
- package/lib/src/stmt/wsParamsBase.js +5 -3
- package/lib/src/stmt/wsProto.d.ts.map +1 -1
- package/lib/src/stmt/wsProto.js +22 -11
- package/lib/src/stmt/wsStmt.d.ts.map +1 -1
- package/lib/src/stmt/wsStmt1.d.ts +5 -5
- package/lib/src/stmt/wsStmt1.d.ts.map +1 -1
- package/lib/src/stmt/wsStmt1.js +14 -14
- package/lib/src/stmt/wsStmt2.d.ts +1 -1
- package/lib/src/stmt/wsStmt2.d.ts.map +1 -1
- package/lib/src/stmt/wsStmt2.js +18 -14
- package/lib/src/stmt/wsTableInfo.d.ts.map +1 -1
- package/lib/src/tmq/config.d.ts.map +1 -1
- package/lib/src/tmq/config.js +2 -2
- package/lib/src/tmq/constant.d.ts.map +1 -1
- package/lib/src/tmq/constant.js +28 -28
- package/lib/src/tmq/tmqResponse.d.ts.map +1 -1
- package/lib/src/tmq/tmqResponse.js +30 -16
- package/lib/src/tmq/wsTmq.d.ts +2 -2
- package/lib/src/tmq/wsTmq.d.ts.map +1 -1
- package/lib/src/tmq/wsTmq.js +32 -30
- package/lib/test/bulkPulling/cloud.tmq.test.js +11 -11
- package/lib/test/bulkPulling/decimal.test.js +50 -26
- package/lib/test/bulkPulling/log.test.js +8 -8
- package/lib/test/bulkPulling/queryTables.test.js +255 -49
- package/lib/test/bulkPulling/schemaless.test.js +34 -34
- package/lib/test/bulkPulling/sql.test.js +108 -69
- package/lib/test/bulkPulling/stmt1.func.test.js +96 -96
- package/lib/test/bulkPulling/stmt1.type.test.js +124 -48
- package/lib/test/bulkPulling/stmt2.func.test.js +116 -112
- package/lib/test/bulkPulling/stmt2.type.test.js +124 -48
- package/lib/test/bulkPulling/tmq.test.js +225 -31
- package/lib/test/bulkPulling/utils.test.js +2 -2
- package/lib/test/bulkPulling/wsConnectPool.test.js +18 -18
- package/lib/test/utils.d.ts.map +1 -1
- package/lib/test/utils.js +129 -129
- package/package.json +1 -1
- package/readme.md +1 -0
- package/lib/src/stmt/wsParams.d.ts +0 -41
- package/lib/src/stmt/wsParams.d.ts.map +0 -1
- package/lib/src/stmt/wsParams.js +0 -428
- package/lib/test/bulkPulling/stmt.func.test.d.ts +0 -2
- package/lib/test/bulkPulling/stmt.func.test.d.ts.map +0 -1
- package/lib/test/bulkPulling/stmt.func.test.js +0 -493
- package/lib/test/bulkPulling/stmt.type.test.d.ts +0 -2
- package/lib/test/bulkPulling/stmt.type.test.d.ts.map +0 -1
- package/lib/test/bulkPulling/stmt.type.test.js +0 -316
package/lib/src/tmq/wsTmq.js
CHANGED
|
@@ -18,7 +18,7 @@ class WsConsumer {
|
|
|
18
18
|
this._wsConfig = new config_1.TmqConfig(wsConfig);
|
|
19
19
|
log_1.default.debug(this._wsConfig);
|
|
20
20
|
if (wsConfig.size == 0 || !this._wsConfig.url) {
|
|
21
|
-
throw new wsError_1.WebSocketInterfaceError(wsError_1.ErrorCode.ERR_INVALID_URL,
|
|
21
|
+
throw new wsError_1.WebSocketInterfaceError(wsError_1.ErrorCode.ERR_INVALID_URL, "invalid url, password or username needed.");
|
|
22
22
|
}
|
|
23
23
|
this._wsClient = new wsClient_1.WsClient(this._wsConfig.url, this._wsConfig.timeout);
|
|
24
24
|
this._lastMessageID = BigInt(0);
|
|
@@ -33,12 +33,12 @@ class WsConsumer {
|
|
|
33
33
|
await this._wsClient.ready();
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
throw
|
|
36
|
+
throw new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_WEBSOCKET_CONNECTION_FAIL, `connection creation failed, url: ${this._wsConfig.url}`);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
catch (e) {
|
|
40
40
|
await this._wsClient.close();
|
|
41
|
-
throw
|
|
41
|
+
throw e;
|
|
42
42
|
}
|
|
43
43
|
finally {
|
|
44
44
|
if (wsSql) {
|
|
@@ -49,14 +49,14 @@ class WsConsumer {
|
|
|
49
49
|
}
|
|
50
50
|
static async newConsumer(wsConfig) {
|
|
51
51
|
if (wsConfig.size == 0 || !wsConfig.get(constant_1.TMQConstants.WS_URL)) {
|
|
52
|
-
throw new wsError_1.WebSocketInterfaceError(wsError_1.ErrorCode.ERR_INVALID_URL,
|
|
52
|
+
throw new wsError_1.WebSocketInterfaceError(wsError_1.ErrorCode.ERR_INVALID_URL, "invalid url, password or username needed.");
|
|
53
53
|
}
|
|
54
54
|
let wsConsumer = new WsConsumer(wsConfig);
|
|
55
55
|
return await wsConsumer.init();
|
|
56
56
|
}
|
|
57
57
|
async subscribe(topics, reqId) {
|
|
58
58
|
if (!topics || topics.length == 0) {
|
|
59
|
-
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS,
|
|
59
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "WsTmq Subscribe params is error!");
|
|
60
60
|
}
|
|
61
61
|
let queryMsg = {
|
|
62
62
|
action: constant_1.TMQMessageType.Subscribe,
|
|
@@ -70,7 +70,7 @@ class WsConsumer {
|
|
|
70
70
|
offset_rest: this._wsConfig.offset_rest,
|
|
71
71
|
auto_commit: this._wsConfig.auto_commit,
|
|
72
72
|
auto_commit_interval_ms: this._wsConfig.auto_commit_interval_ms,
|
|
73
|
-
config: this._wsConfig.otherConfigs
|
|
73
|
+
config: this._wsConfig.otherConfigs,
|
|
74
74
|
},
|
|
75
75
|
};
|
|
76
76
|
this._topics = topics;
|
|
@@ -120,20 +120,20 @@ class WsConsumer {
|
|
|
120
120
|
action: constant_1.TMQMessageType.Commit,
|
|
121
121
|
args: {
|
|
122
122
|
req_id: reqid_1.ReqId.getReqID(reqId),
|
|
123
|
-
message_id: 0
|
|
123
|
+
message_id: 0,
|
|
124
124
|
},
|
|
125
125
|
};
|
|
126
126
|
await this._wsClient.exec(JSON.stringify(queryMsg));
|
|
127
127
|
}
|
|
128
128
|
async committed(partitions, reqId) {
|
|
129
129
|
if (!partitions || partitions.length == 0) {
|
|
130
|
-
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS,
|
|
130
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "WsTmq Positions params is error!");
|
|
131
131
|
}
|
|
132
132
|
let offsets = new Array(partitions.length);
|
|
133
133
|
for (let i = 0; i < partitions.length; i++) {
|
|
134
134
|
offsets[i] = {
|
|
135
135
|
topic: partitions[i].topic,
|
|
136
|
-
vgroup_id: partitions[i].vgroup_id
|
|
136
|
+
vgroup_id: partitions[i].vgroup_id,
|
|
137
137
|
};
|
|
138
138
|
offsets[i].vgroup_id = partitions[i].vgroup_id;
|
|
139
139
|
}
|
|
@@ -141,7 +141,7 @@ class WsConsumer {
|
|
|
141
141
|
action: constant_1.TMQMessageType.Committed,
|
|
142
142
|
args: {
|
|
143
143
|
req_id: reqid_1.ReqId.getReqID(reqId),
|
|
144
|
-
topic_vgroup_ids: offsets
|
|
144
|
+
topic_vgroup_ids: offsets,
|
|
145
145
|
},
|
|
146
146
|
};
|
|
147
147
|
let resp = await this._wsClient.exec(json_bigint_1.default.stringify(queryMsg), false);
|
|
@@ -149,10 +149,10 @@ class WsConsumer {
|
|
|
149
149
|
}
|
|
150
150
|
async commitOffsets(partitions) {
|
|
151
151
|
if (!partitions || partitions.length == 0) {
|
|
152
|
-
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS,
|
|
152
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "WsTmq CommitOffsets params is error!");
|
|
153
153
|
}
|
|
154
154
|
const allp = [];
|
|
155
|
-
partitions.forEach(e => {
|
|
155
|
+
partitions.forEach((e) => {
|
|
156
156
|
allp.push(this.commitOffset(e));
|
|
157
157
|
});
|
|
158
158
|
await Promise.all(allp);
|
|
@@ -160,7 +160,7 @@ class WsConsumer {
|
|
|
160
160
|
}
|
|
161
161
|
async commitOffset(partition, reqId) {
|
|
162
162
|
if (!partition) {
|
|
163
|
-
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS,
|
|
163
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "WsTmq CommitOffsets params is error!");
|
|
164
164
|
}
|
|
165
165
|
let queryMsg = {
|
|
166
166
|
action: constant_1.TMQMessageType.CommitOffset,
|
|
@@ -175,13 +175,13 @@ class WsConsumer {
|
|
|
175
175
|
}
|
|
176
176
|
async positions(partitions, reqId) {
|
|
177
177
|
if (!partitions || partitions.length == 0) {
|
|
178
|
-
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS,
|
|
178
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "WsTmq Positions params is error!");
|
|
179
179
|
}
|
|
180
180
|
let offsets = new Array(partitions.length);
|
|
181
181
|
for (let i = 0; i < partitions.length; i++) {
|
|
182
182
|
offsets[i] = {
|
|
183
183
|
topic: partitions[i].topic,
|
|
184
|
-
vgroup_id: partitions[i].vgroup_id
|
|
184
|
+
vgroup_id: partitions[i].vgroup_id,
|
|
185
185
|
};
|
|
186
186
|
offsets[i].vgroup_id = partitions[i].vgroup_id;
|
|
187
187
|
}
|
|
@@ -189,7 +189,7 @@ class WsConsumer {
|
|
|
189
189
|
action: constant_1.TMQMessageType.Position,
|
|
190
190
|
args: {
|
|
191
191
|
req_id: reqid_1.ReqId.getReqID(reqId),
|
|
192
|
-
topic_vgroup_ids: offsets
|
|
192
|
+
topic_vgroup_ids: offsets,
|
|
193
193
|
},
|
|
194
194
|
};
|
|
195
195
|
let resp = await this._wsClient.exec(JSON.stringify(queryMsg), false);
|
|
@@ -197,7 +197,7 @@ class WsConsumer {
|
|
|
197
197
|
}
|
|
198
198
|
async seek(partition, reqId) {
|
|
199
199
|
if (!partition) {
|
|
200
|
-
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS,
|
|
200
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "WsTmq Seek params is error!");
|
|
201
201
|
}
|
|
202
202
|
let queryMsg = {
|
|
203
203
|
action: constant_1.TMQMessageType.Seek,
|
|
@@ -212,13 +212,13 @@ class WsConsumer {
|
|
|
212
212
|
}
|
|
213
213
|
async seekToBeginning(partitions) {
|
|
214
214
|
if (!partitions || partitions.length == 0) {
|
|
215
|
-
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS,
|
|
215
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "WsTmq SeekToBeginning params is error!");
|
|
216
216
|
}
|
|
217
217
|
return await this.seekToBeginOrEnd(partitions);
|
|
218
218
|
}
|
|
219
219
|
async seekToEnd(partitions) {
|
|
220
220
|
if (!partitions || partitions.length == 0) {
|
|
221
|
-
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS,
|
|
221
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "WsTmq SeekToEnd params is error!");
|
|
222
222
|
}
|
|
223
223
|
return await this.seekToBeginOrEnd(partitions, false);
|
|
224
224
|
}
|
|
@@ -227,19 +227,20 @@ class WsConsumer {
|
|
|
227
227
|
}
|
|
228
228
|
async fetchBlockData(pollResp, taosResult) {
|
|
229
229
|
let fetchMsg = {
|
|
230
|
-
action:
|
|
230
|
+
action: "fetch_raw_data",
|
|
231
231
|
args: {
|
|
232
232
|
req_id: reqid_1.ReqId.getReqID(),
|
|
233
233
|
message_id: pollResp.message_id,
|
|
234
234
|
},
|
|
235
235
|
};
|
|
236
236
|
let jsonStr = json_bigint_1.default.stringify(fetchMsg);
|
|
237
|
-
log_1.default.debug(
|
|
237
|
+
log_1.default.debug("[wsQueryInterface.fetch.fetchMsg]===>" + jsonStr);
|
|
238
238
|
let result = await this._wsClient.sendMsg(jsonStr);
|
|
239
239
|
let wsResponse = new wsResponse_1.WSFetchBlockResponse(result.msg);
|
|
240
240
|
if (wsResponse && wsResponse.data && wsResponse.blockLen > 0) {
|
|
241
241
|
let wsTmqResponse = new tmqResponse_1.WSTmqFetchBlockInfo(wsResponse.data, taosResult);
|
|
242
|
-
log_1.default.debug(
|
|
242
|
+
log_1.default.debug("[WSTmqFetchBlockInfo.fetchBlockData]===>" +
|
|
243
|
+
wsTmqResponse.taosResult);
|
|
243
244
|
if (wsTmqResponse.rows > 0) {
|
|
244
245
|
return true;
|
|
245
246
|
}
|
|
@@ -260,7 +261,8 @@ class WsConsumer {
|
|
|
260
261
|
let taosResult = new tmqResponse_1.TaosTmqResult(pollResp);
|
|
261
262
|
var taosResults = new Map();
|
|
262
263
|
taosResults.set(pollResp.topic, taosResult);
|
|
263
|
-
if (!pollResp.have_message ||
|
|
264
|
+
if (!pollResp.have_message ||
|
|
265
|
+
pollResp.message_type != constant_1.TMQMessageType.ResDataType) {
|
|
264
266
|
return taosResults;
|
|
265
267
|
}
|
|
266
268
|
this._lastMessageID = pollResp.message_id;
|
|
@@ -275,8 +277,8 @@ class WsConsumer {
|
|
|
275
277
|
action: constant_1.TMQMessageType.GetTopicAssignment,
|
|
276
278
|
args: {
|
|
277
279
|
req_id: reqid_1.ReqId.getReqID(),
|
|
278
|
-
topic: topic
|
|
279
|
-
}
|
|
280
|
+
topic: topic,
|
|
281
|
+
},
|
|
280
282
|
};
|
|
281
283
|
let resp = await this._wsClient.exec(JSON.stringify(queryMsg), false);
|
|
282
284
|
let assignmentInfo = new tmqResponse_1.AssignmentResp(resp, queryMsg.args.topic);
|
|
@@ -293,7 +295,7 @@ class WsConsumer {
|
|
|
293
295
|
allp.push(this.sendAssignmentReq(topics[i]));
|
|
294
296
|
}
|
|
295
297
|
let result = await Promise.all(allp);
|
|
296
|
-
result.forEach(e => {
|
|
298
|
+
result.forEach((e) => {
|
|
297
299
|
topicPartitions.push(...e);
|
|
298
300
|
});
|
|
299
301
|
}
|
|
@@ -301,18 +303,18 @@ class WsConsumer {
|
|
|
301
303
|
}
|
|
302
304
|
async seekToBeginOrEnd(partitions, bBegin = true) {
|
|
303
305
|
let topics = [];
|
|
304
|
-
partitions.forEach(e => {
|
|
306
|
+
partitions.forEach((e) => {
|
|
305
307
|
topics.push(e.topic);
|
|
306
308
|
});
|
|
307
309
|
let topicPartitions = await this.assignment(topics);
|
|
308
310
|
let itemMap = topicPartitions.reduce((map, obj) => {
|
|
309
|
-
map.set(obj.topic +
|
|
311
|
+
map.set(obj.topic + "_" + obj.vgroup_id, obj);
|
|
310
312
|
return map;
|
|
311
313
|
}, new Map());
|
|
312
314
|
const allp = [];
|
|
313
315
|
for (let i in partitions) {
|
|
314
|
-
if (itemMap.has(partitions[i].topic +
|
|
315
|
-
let topicPartition = itemMap.get(partitions[i].topic +
|
|
316
|
+
if (itemMap.has(partitions[i].topic + "_" + partitions[i].vgroup_id)) {
|
|
317
|
+
let topicPartition = itemMap.get(partitions[i].topic + "_" + partitions[i].vgroup_id);
|
|
316
318
|
if (topicPartition) {
|
|
317
319
|
if (bBegin) {
|
|
318
320
|
topicPartition.offset = topicPartition.begin;
|
|
@@ -11,8 +11,8 @@ beforeAll(async () => {
|
|
|
11
11
|
let wsSql = null;
|
|
12
12
|
try {
|
|
13
13
|
const conf = new config_1.WSConfig(url);
|
|
14
|
-
conf.setUser(
|
|
15
|
-
conf.setPwd(
|
|
14
|
+
conf.setUser("root");
|
|
15
|
+
conf.setPwd("taosdata");
|
|
16
16
|
wsSql = await wsSql_1.WsSql.open(conf);
|
|
17
17
|
let sql = `INSERT INTO dmeters.d1001 USING dmeters.meters (groupid, location) TAGS(2, 'SanFrancisco')
|
|
18
18
|
VALUES (NOW + 1a, 10.30000, 219, 0.31000) (NOW + 2a, 12.60000, 218, 0.33000) (NOW + 3a, 12.30000, 221, 0.31000)
|
|
@@ -31,21 +31,21 @@ beforeAll(async () => {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
-
describe(
|
|
34
|
+
describe("TDWebSocket.Tmq()", () => {
|
|
35
35
|
jest.setTimeout(20 * 1000);
|
|
36
|
-
test(
|
|
36
|
+
test("normal connect", async () => {
|
|
37
37
|
const url = `wss://${process.env.TDENGINE_CLOUD_URL}?token=${process.env.TDENGINE_CLOUD_TOKEN}`;
|
|
38
|
-
const topic =
|
|
38
|
+
const topic = "topic_meters";
|
|
39
39
|
const topics = [topic];
|
|
40
|
-
const groupId =
|
|
41
|
-
const clientId =
|
|
40
|
+
const groupId = "group1";
|
|
41
|
+
const clientId = "client1";
|
|
42
42
|
let configMap = new Map([
|
|
43
43
|
[constant_1.TMQConstants.GROUP_ID, groupId],
|
|
44
44
|
[constant_1.TMQConstants.CLIENT_ID, clientId],
|
|
45
|
-
[constant_1.TMQConstants.AUTO_OFFSET_RESET,
|
|
45
|
+
[constant_1.TMQConstants.AUTO_OFFSET_RESET, "earliest"],
|
|
46
46
|
[constant_1.TMQConstants.WS_URL, url],
|
|
47
|
-
[constant_1.TMQConstants.ENABLE_AUTO_COMMIT,
|
|
48
|
-
[constant_1.TMQConstants.AUTO_COMMIT_INTERVAL_MS,
|
|
47
|
+
[constant_1.TMQConstants.ENABLE_AUTO_COMMIT, "true"],
|
|
48
|
+
[constant_1.TMQConstants.AUTO_COMMIT_INTERVAL_MS, "1000"],
|
|
49
49
|
]);
|
|
50
50
|
(0, log_1.setLevel)("debug");
|
|
51
51
|
// create consumer
|
|
@@ -68,7 +68,7 @@ describe('TDWebSocket.Tmq()', () => {
|
|
|
68
68
|
// seek
|
|
69
69
|
let assignment = await consumer.assignment();
|
|
70
70
|
await consumer.seekToBeginning(assignment);
|
|
71
|
-
console.log(
|
|
71
|
+
console.log("Assignment seek to beginning successfully");
|
|
72
72
|
// clean
|
|
73
73
|
await consumer.unsubscribe();
|
|
74
74
|
await consumer.close();
|
|
@@ -7,45 +7,69 @@ const utils_1 = require("../utils");
|
|
|
7
7
|
const log_1 = require("../../src/common/log");
|
|
8
8
|
const constant_1 = require("../../src/tmq/constant");
|
|
9
9
|
const wsTmq_1 = require("../../src/tmq/wsTmq");
|
|
10
|
-
let dns =
|
|
10
|
+
let dns = "ws://localhost:6041";
|
|
11
11
|
let createTopic = `create topic if not exists topic_decimal_test as select * from power.decimal_test`;
|
|
12
12
|
let dropTopic = `DROP TOPIC IF EXISTS topic_decimal_test;`;
|
|
13
13
|
(0, log_1.setLevel)("debug");
|
|
14
14
|
beforeAll(async () => {
|
|
15
15
|
let conf = new config_1.WSConfig(dns);
|
|
16
|
-
conf.setUser(
|
|
17
|
-
conf.setPwd(
|
|
16
|
+
conf.setUser("root");
|
|
17
|
+
conf.setPwd("taosdata");
|
|
18
18
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
19
19
|
await wsSql.exec(dropTopic);
|
|
20
|
-
await wsSql.exec(
|
|
21
|
-
await wsSql.exec(
|
|
20
|
+
await wsSql.exec("drop database if exists power");
|
|
21
|
+
await wsSql.exec("create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;");
|
|
22
22
|
await (0, utils_1.Sleep)(100);
|
|
23
|
-
await wsSql.exec(
|
|
24
|
-
await wsSql.exec(
|
|
23
|
+
await wsSql.exec("use power");
|
|
24
|
+
await wsSql.exec("CREATE STABLE if not exists decimal_test (ts timestamp, dec64 decimal(10,6), dec128 decimal(24,10), int1 int) TAGS (location binary(64), groupId int);");
|
|
25
25
|
await wsSql.exec(createTopic);
|
|
26
26
|
await wsSql.close();
|
|
27
27
|
});
|
|
28
28
|
const expectedResultsMap = new Map([
|
|
29
|
-
[
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
[
|
|
30
|
+
"-1234.654321",
|
|
31
|
+
{
|
|
32
|
+
dec128: "-123456789012.0987654321",
|
|
33
|
+
int1: 3,
|
|
34
|
+
location: "California",
|
|
35
|
+
groupId: 3,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
"-0.000654",
|
|
40
|
+
{
|
|
41
|
+
dec128: "-0.0009876543",
|
|
42
|
+
int1: 2,
|
|
43
|
+
location: "California",
|
|
44
|
+
groupId: 3,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
"9876.123456",
|
|
49
|
+
{
|
|
50
|
+
dec128: "1234567890.0987654321",
|
|
51
|
+
int1: 1,
|
|
52
|
+
location: "California",
|
|
53
|
+
groupId: 3,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
32
56
|
]);
|
|
33
|
-
describe(
|
|
57
|
+
describe("TDWebSocket.WsSql()", () => {
|
|
34
58
|
jest.setTimeout(20 * 1000);
|
|
35
|
-
test(
|
|
59
|
+
test("insert recoder", async () => {
|
|
36
60
|
let conf = new config_1.WSConfig(dns);
|
|
37
|
-
conf.setUser(
|
|
38
|
-
conf.setPwd(
|
|
61
|
+
conf.setUser("root");
|
|
62
|
+
conf.setPwd("taosdata");
|
|
39
63
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
40
|
-
let taosResult = await wsSql.exec(
|
|
64
|
+
let taosResult = await wsSql.exec("use power");
|
|
41
65
|
console.log(taosResult);
|
|
42
66
|
expect(taosResult).toBeTruthy();
|
|
43
|
-
taosResult = await wsSql.exec(
|
|
67
|
+
taosResult = await wsSql.exec("describe decimal_test");
|
|
44
68
|
console.log(taosResult);
|
|
45
69
|
taosResult = await wsSql.exec('INSERT INTO d1001 USING decimal_test (location, groupid) TAGS ("California", 3) VALUES (NOW, "9876.123456", "1234567890.0987654321", 1) (NOW + 1a, "-0.000654", "-0.0009876543", 2) (NOW + 2a, "-1234.654321", "-123456789012.0987654321", 3)');
|
|
46
70
|
console.log(taosResult);
|
|
47
71
|
expect(taosResult.getAffectRows()).toBeGreaterThanOrEqual(3);
|
|
48
|
-
let wsRows = await wsSql.query(
|
|
72
|
+
let wsRows = await wsSql.query("select * from decimal_test");
|
|
49
73
|
expect(wsRows).toBeTruthy();
|
|
50
74
|
let meta = wsRows.getMeta();
|
|
51
75
|
expect(meta).toBeTruthy();
|
|
@@ -69,22 +93,22 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
69
93
|
expect(count).toBe(3);
|
|
70
94
|
});
|
|
71
95
|
});
|
|
72
|
-
test(
|
|
96
|
+
test("normal Subscribe", async () => {
|
|
73
97
|
let configMap = new Map([
|
|
74
98
|
[constant_1.TMQConstants.GROUP_ID, "gId"],
|
|
75
99
|
[constant_1.TMQConstants.CONNECT_USER, "root"],
|
|
76
100
|
[constant_1.TMQConstants.CONNECT_PASS, "taosdata"],
|
|
77
101
|
[constant_1.TMQConstants.AUTO_OFFSET_RESET, "earliest"],
|
|
78
|
-
[constant_1.TMQConstants.CLIENT_ID,
|
|
102
|
+
[constant_1.TMQConstants.CLIENT_ID, "test_tmq_client"],
|
|
79
103
|
[constant_1.TMQConstants.WS_URL, dns],
|
|
80
|
-
[constant_1.TMQConstants.ENABLE_AUTO_COMMIT,
|
|
81
|
-
[constant_1.TMQConstants.AUTO_COMMIT_INTERVAL_MS,
|
|
104
|
+
[constant_1.TMQConstants.ENABLE_AUTO_COMMIT, "true"],
|
|
105
|
+
[constant_1.TMQConstants.AUTO_COMMIT_INTERVAL_MS, "1000"],
|
|
82
106
|
["session.timeout.ms", "10000"],
|
|
83
107
|
["max.poll.interval.ms", "30000"],
|
|
84
|
-
["msg.with.table.name", "true"]
|
|
108
|
+
["msg.with.table.name", "true"],
|
|
85
109
|
]);
|
|
86
110
|
let consumer = await wsTmq_1.WsConsumer.newConsumer(configMap);
|
|
87
|
-
await consumer.subscribe([
|
|
111
|
+
await consumer.subscribe(["topic_decimal_test"]);
|
|
88
112
|
let assignment = await consumer.assignment();
|
|
89
113
|
console.log(assignment);
|
|
90
114
|
let useTime = [];
|
|
@@ -119,11 +143,11 @@ test('normal Subscribe', async () => {
|
|
|
119
143
|
});
|
|
120
144
|
afterAll(async () => {
|
|
121
145
|
let conf = new config_1.WSConfig(dns);
|
|
122
|
-
conf.setUser(
|
|
123
|
-
conf.setPwd(
|
|
146
|
+
conf.setUser("root");
|
|
147
|
+
conf.setPwd("taosdata");
|
|
124
148
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
125
149
|
await wsSql.exec(dropTopic);
|
|
126
|
-
await wsSql.exec(
|
|
150
|
+
await wsSql.exec("drop database power");
|
|
127
151
|
await wsSql.close();
|
|
128
152
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
129
153
|
});
|
|
@@ -34,20 +34,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
const log_1 = __importStar(require("../../src/common/log"));
|
|
37
|
-
describe(
|
|
38
|
-
test(
|
|
39
|
-
log_1.default.info(
|
|
40
|
-
log_1.default.debug(
|
|
41
|
-
log_1.default.error(
|
|
37
|
+
describe("log level print", () => {
|
|
38
|
+
test("normal connect", async () => {
|
|
39
|
+
log_1.default.info("log level is info");
|
|
40
|
+
log_1.default.debug("log level is debug");
|
|
41
|
+
log_1.default.error("log level is error");
|
|
42
42
|
let isLevel = log_1.default.isLevelEnabled("info");
|
|
43
43
|
expect(isLevel).toEqual(true);
|
|
44
44
|
(0, log_1.setLevel)("debug");
|
|
45
|
-
log_1.default.debug(
|
|
45
|
+
log_1.default.debug("log level is debug");
|
|
46
46
|
isLevel = log_1.default.isLevelEnabled("debug");
|
|
47
47
|
expect(isLevel).toEqual(true);
|
|
48
48
|
(0, log_1.setLevel)("error");
|
|
49
|
-
log_1.default.error(
|
|
50
|
-
log_1.default.debug(
|
|
49
|
+
log_1.default.error("log level is error");
|
|
50
|
+
log_1.default.debug("log level is debug");
|
|
51
51
|
isLevel = log_1.default.isLevelEnabled("error");
|
|
52
52
|
expect(isLevel).toEqual(true);
|
|
53
53
|
});
|