Skip to content

Commit 1884589

Browse files
Implement missing commands and add test
1 parent cba0289 commit 1884589

30 files changed

+1509
-43
lines changed

packages/time-series/lib/commands/CREATE.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ describe('CREATE', () => {
5151
it('with LABELS', () => {
5252
assert.deepEqual(
5353
transformArguments('key', {
54-
LABELS: { label: 'value' }
54+
LABELS: { label: 'value', label2: 'newValue' }
5555
}),
56-
['TS.CREATE', 'key', 'LABELS', 'label', 'value']
56+
['TS.CREATE', 'key', 'LABELS', 'label', 'value', 'label2', 'newValue']
5757
);
5858
});
5959

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './DECRBY';
4+
5+
describe('DECRBY', () => {
6+
describe('transformArguments', () => {
7+
it('without options', () => {
8+
assert.deepEqual(
9+
transformArguments('key', 1),
10+
['TS.DECRBY', 'key', '1']
11+
);
12+
});
13+
it('with TIMESTAMP', () => {
14+
assert.deepEqual(
15+
transformArguments('key', 1, {
16+
TIMESTAMP: '*'
17+
}),
18+
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*']
19+
);
20+
});
21+
it('with RETENTION', () => {
22+
assert.deepEqual(
23+
transformArguments('key', 1, {
24+
RETENTION: 100
25+
}),
26+
['TS.DECRBY', 'key', '1', 'RETENTION', '100']
27+
);
28+
});
29+
it('with UNCOMPRESSED', () => {
30+
assert.deepEqual(
31+
transformArguments('key', 1, {
32+
UNCOMPRESSED: true
33+
}),
34+
['TS.DECRBY', 'key', '1', 'UNCOMPRESSED']
35+
);
36+
});
37+
it('without UNCOMPRESSED', () => {
38+
assert.deepEqual(
39+
transformArguments('key', 1, {
40+
UNCOMPRESSED: false
41+
}),
42+
['TS.DECRBY', 'key', '1']
43+
);
44+
});
45+
it('with CHUNK_SIZE', () => {
46+
assert.deepEqual(
47+
transformArguments('key', 1, {
48+
CHUNK_SIZE: 100
49+
}),
50+
['TS.DECRBY', 'key', '1', 'CHUNK_SIZE', '100']
51+
);
52+
});
53+
it('with LABELS', () => {
54+
assert.deepEqual(
55+
transformArguments('key', 1, {
56+
LABELS: { label: 'value' }
57+
}),
58+
['TS.DECRBY', 'key', '1', 'LABELS', 'label', 'value']
59+
);
60+
});
61+
it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
62+
assert.deepEqual(
63+
transformArguments('key', 1, {
64+
TIMESTAMP: '*',
65+
RETENTION: 100,
66+
UNCOMPRESSED: true,
67+
CHUNK_SIZE: 1000,
68+
LABELS: { label: 'value', label2: 'new_value' }
69+
}),
70+
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '100', 'UNCOMPRESSED',
71+
'CHUNK_SIZE', '1000', 'LABELS', 'label', 'value', 'label2', 'new_value']
72+
);
73+
});
74+
});
75+
76+
testUtils.testWithClient('client.ts.decrBy', async client => {
77+
await Promise.all([
78+
client.ts.create('key'),
79+
]);
80+
81+
assert.equal(
82+
await client.ts.decrBy('key', 1, {
83+
TIMESTAMP: 1638267369476
84+
}),
85+
1638267369476
86+
);
87+
88+
assert.deepEqual(
89+
await client.ts.get('key'),
90+
{
91+
timestamp: 1638267369476,
92+
value: -1
93+
}
94+
);
95+
}, GLOBAL.SERVERS.OPEN);
96+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { strict as assert } from 'assert';
2+
import { TimeSeriesAggregationType } from '.';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { transformArguments } from './DEL';
5+
6+
describe('DEL', () => {
7+
it('transformArguments', () => {
8+
assert.deepEqual(
9+
transformArguments('key', 1, 10),
10+
['TS.DEL', 'key', '1', '10']
11+
);
12+
});
13+
14+
testUtils.testWithClient('client.ts.del', async client => {
15+
await Promise.all([
16+
client.ts.create('key'),
17+
client.ts.add('key', 1, 2),
18+
client.ts.add('key', 2, 3)
19+
]);
20+
21+
assert.equal(
22+
await client.ts.del('key', 1, 100),
23+
2
24+
);
25+
}, GLOBAL.SERVERS.OPEN);
26+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { strict as assert } from 'assert';
2+
import { TimeSeriesAggregationType } from '.';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { transformArguments } from './DELETERULE';
5+
6+
describe('DELETERULE', () => {
7+
it('transformArguments', () => {
8+
assert.deepEqual(
9+
transformArguments('source', 'destination'),
10+
['TS.DELETERULE', 'source', 'destination']
11+
);
12+
});
13+
14+
testUtils.testWithClient('client.ts.deleteRule', async client => {
15+
await Promise.all([
16+
client.ts.create('source'),
17+
client.ts.create('destination'),
18+
client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVARAGE, 1)
19+
]);
20+
21+
assert.equal(
22+
await client.ts.deleteRule('source', 'destination'),
23+
'OK'
24+
);
25+
}, GLOBAL.SERVERS.OPEN);
26+
});

packages/time-series/lib/commands/DELETERULE.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export function transformArguments(sourceKey: string,destinationKey: string,): Array<string> {
1+
export const FIRST_KEY_INDEX = 1;
2+
3+
export function transformArguments(sourceKey: string, destinationKey: string,): Array<string> {
24
return [
35
'TS.DELETERULE',
46
sourceKey,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './GET';
4+
5+
describe('GET', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments('key'),
9+
['TS.GET', 'key']
10+
);
11+
});
12+
13+
testUtils.testWithClient('client.ts.get', async client => {
14+
await Promise.all([
15+
client.ts.create('key'),
16+
client.ts.add('key', 1, 2)
17+
]);
18+
19+
assert.deepEqual(
20+
await client.ts.get('key'),
21+
{
22+
timestamp: 1,
23+
value: 2
24+
}
25+
);
26+
}, GLOBAL.SERVERS.OPEN);
27+
});
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './INCRBY';
4+
5+
describe('INCRBY', () => {
6+
describe('transformArguments', () => {
7+
it('without options', () => {
8+
assert.deepEqual(
9+
transformArguments('key', 1),
10+
['TS.INCRBY', 'key', '1']
11+
);
12+
});
13+
it('with TIMESTAMP', () => {
14+
assert.deepEqual(
15+
transformArguments('key', 1, {
16+
TIMESTAMP: '*'
17+
}),
18+
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*']
19+
);
20+
});
21+
it('with RETENTION', () => {
22+
assert.deepEqual(
23+
transformArguments('key', 1, {
24+
RETENTION: 100
25+
}),
26+
['TS.INCRBY', 'key', '1', 'RETENTION', '100']
27+
);
28+
});
29+
it('with UNCOMPRESSED', () => {
30+
assert.deepEqual(
31+
transformArguments('key', 1, {
32+
UNCOMPRESSED: true
33+
}),
34+
['TS.INCRBY', 'key', '1', 'UNCOMPRESSED']
35+
);
36+
});
37+
it('without UNCOMPRESSED', () => {
38+
assert.deepEqual(
39+
transformArguments('key', 1, {
40+
UNCOMPRESSED: false
41+
}),
42+
['TS.INCRBY', 'key', '1']
43+
);
44+
});
45+
it('with CHUNK_SIZE', () => {
46+
assert.deepEqual(
47+
transformArguments('key', 1, {
48+
CHUNK_SIZE: 100
49+
}),
50+
['TS.INCRBY', 'key', '1', 'CHUNK_SIZE', '100']
51+
);
52+
});
53+
it('with LABELS', () => {
54+
assert.deepEqual(
55+
transformArguments('key', 1, {
56+
LABELS: { label: 'value' }
57+
}),
58+
['TS.INCRBY', 'key', '1', 'LABELS', 'label', 'value']
59+
);
60+
});
61+
it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
62+
assert.deepEqual(
63+
transformArguments('key', 1, {
64+
TIMESTAMP: '*',
65+
RETENTION: 100,
66+
UNCOMPRESSED: true,
67+
CHUNK_SIZE: 1000,
68+
LABELS: { label: 'value', label2: 'new_value' }
69+
}),
70+
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '100', 'UNCOMPRESSED',
71+
'CHUNK_SIZE', '1000', 'LABELS', 'label', 'value', 'label2', 'new_value']
72+
);
73+
});
74+
});
75+
76+
testUtils.testWithClient('client.ts.decrBy', async client => {
77+
await Promise.all([
78+
client.ts.create('key'),
79+
]);
80+
81+
assert.equal(
82+
await client.ts.incrBy('key', 1, {
83+
TIMESTAMP: 1638267369476
84+
}),
85+
1638267369476
86+
);
87+
88+
assert.deepEqual(
89+
await client.ts.get('key'),
90+
{
91+
timestamp: 1638267369476,
92+
value: 1
93+
}
94+
);
95+
}, GLOBAL.SERVERS.OPEN);
96+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { strict as assert } from 'assert';
2+
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { transformArguments } from './INFO';
5+
6+
describe('INFO', () => {
7+
it('transformArguments', () => {
8+
assert.deepEqual(
9+
transformArguments('key'),
10+
['TS.INFO', 'key']
11+
);
12+
});
13+
14+
testUtils.testWithClient('client.ts.info', async client => {
15+
await Promise.all([
16+
client.ts.create('key', {
17+
LABELS: { id: "2" },
18+
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST
19+
}),
20+
client.ts.create('key2'),
21+
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5),
22+
client.ts.add('key', 1, 10)
23+
]);
24+
25+
assert.deepEqual(
26+
await client.ts.info('key'),
27+
{
28+
totalSamples: 1,
29+
memoryUsage: 4261,
30+
firstTimestamp: 1,
31+
lastTimestamp: 1,
32+
retentionTime: 0,
33+
chunkCount: 1,
34+
chunkSize: 4096,
35+
chunkType: 'compressed',
36+
duplicatePolicy: 'last',
37+
labels: [{
38+
name: 'id',
39+
value: '2'
40+
}],
41+
rules: [{
42+
aggregationType: 'COUNT',
43+
key: 'key2',
44+
timeBucket: 5
45+
}],
46+
sourceKey: null
47+
}
48+
);
49+
}, GLOBAL.SERVERS.OPEN);
50+
});

0 commit comments

Comments
 (0)