fix(core): update

This commit is contained in:
2024-06-14 16:33:00 +02:00
parent 07895c2767
commit 1aed44f035
12 changed files with 6433 additions and 4208 deletions

View File

@ -1,7 +1,8 @@
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
import { expect, tap } from '@push.rocks/tapbundle';
import * as smartclickhouse from '../ts/index.js';
let testClickhouseDb: smartclickhouse.SmartClickHouseDb;
let table: smartclickhouse.TimeDataTable;
tap.test('first test', async () => {
testClickhouseDb = new smartclickhouse.SmartClickHouseDb({
@ -16,9 +17,9 @@ tap.test('should start the clickhouse db', async () => {
});
tap.test('should create a timedatatable', async (toolsArg) => {
const table = await testClickhouseDb.getTable('analytics');
table = await testClickhouseDb.getTable('analytics');
let i = 0;
while (i < 5000) {
while (i < 1000) {
await table.addData({
timestamp: Date.now(),
message: `hello this is a message ${i}`,
@ -29,11 +30,57 @@ tap.test('should create a timedatatable', async (toolsArg) => {
},
});
i++;
console.log(`logged ${i} of 5000 lines.`);
await toolsArg.delayFor(1);
console.log(`logged ${i} of 1000 lines.`);
}
});
tap.skip.test('should write something to the clickhouse db', async () => {});
tap.test('should retrieve the last 10 entries', async () => {
const entries = await table.getLastEntries(10);
expect(entries.length).toEqual(10);
console.log(entries);
});
tap.start();
tap.test('should retrieve entries newer than a specific timestamp', async () => {
const timestamp = Date.now() - 60000; // 1 minute ago
const entries = await table.getEntriesNewerThan(timestamp);
expect(entries.length).toBeGreaterThan(0);
console.log(entries);
});
tap.test('should retrieve entries between two timestamps', async () => {
const startTimestamp = Date.now() - 120000; // 2 minutes ago
const endTimestamp = Date.now() - 60000; // 1 minute ago
const entries = await table.getEntriesBetween(startTimestamp, endTimestamp);
console.log(entries);
});
tap.test('should delete old entries', async () => {
await table.deleteOldEntries(0); // Delete all entries older than now
const entries = await table.getLastEntries(10);
expect(entries.length).toEqual(0);
});
tap.test('should delete the table', async () => {
await table.delete();
});
tap.test('should stream new entries', async (toolsArg) => {
const stream = table.streamNewEntries();
const subscription = stream.subscribe((entry) => {
console.log('New entry:', entry);
});
let i = 0;
while (i < 10) {
await table.addData({
timestamp: Date.now(),
message: `streaming message ${i}`,
});
i++;
await toolsArg.delayFor(1000); // Add a delay to simulate real-time data insertion
}
subscription.unsubscribe();
});
export default tap.start();