Skip to content

Commit 5f165a3

Browse files
committed
add tests for stream-json coping with negative etags
1 parent c7d595d commit 5f165a3

File tree

5 files changed

+96
-16
lines changed

5 files changed

+96
-16
lines changed

src/Http/RavenCommandResponsePipeline.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,7 @@ export class RavenCommandResponsePipeline<TStreamResult> extends EventEmitter {
166166

167167
if (opts.jsonAsync) {
168168
const parser = new Parser({
169-
packKeys: true,
170-
packStrings: true,
171-
packValues: true,
172-
packNumbers: true,
173-
streamNumbers: false,
174-
streamValues: false,
175-
streamKeys: false,
176-
streamStrings: false
169+
packKeys: true
177170
});
178171
streams.push(parser);
179172

src/Mapping/Json/Streams/Pipelines.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ export function getDocumentResultsPipeline(
2727
return RavenCommandResponsePipeline.create<object[]>()
2828
.parseJsonAsync([
2929
new TransformKeysJsonStream(getTransformJsonKeysProfile("DocumentLoad", conventions)),
30-
// .on("data", x => console.log("TRANSF", x)),
31-
// .on("end", () => console.log("TRANSF END")),
32-
stringer({
33-
useValues: true
34-
})
35-
// .on("data", x => console.log("STRINGER", x.toString()))
36-
// .on("end", () => console.log("STRINGER END"))
30+
stringer({ useValues: true })
3731
]);
3832
}
3933

test/Assets/queryResult.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"ResultEtag":-7405531408361930253,"IsStale":false,"IndexName":"Users/ByName","TotalResults":10,"IndexTimestamp":"2018-10-08T07:02:43.9804130Z","Results":[{"name":"jon0","lastName":"snow0","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:2-Y7BIYp5+C024MXyo68JUfQ","@id":"users/1-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9350760Z"}},{"name":"jon1","lastName":"snow1","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:3-Y7BIYp5+C024MXyo68JUfQ","@id":"users/2-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9407694Z"}},{"name":"jon2","lastName":"snow2","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:4-Y7BIYp5+C024MXyo68JUfQ","@id":"users/3-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9407980Z"}},{"name":"jon3","lastName":"snow3","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:5-Y7BIYp5+C024MXyo68JUfQ","@id":"users/4-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9408069Z"}},{"name":"jon4","lastName":"snow4","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:6-Y7BIYp5+C024MXyo68JUfQ","@id":"users/5-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9408172Z"}},{"name":"jon5","lastName":"snow5","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:7-Y7BIYp5+C024MXyo68JUfQ","@id":"users/6-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9408252Z"}},{"name":"jon6","lastName":"snow6","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:8-Y7BIYp5+C024MXyo68JUfQ","@id":"users/7-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9408326Z"}},{"name":"jon7","lastName":"snow7","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:9-Y7BIYp5+C024MXyo68JUfQ","@id":"users/8-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9408404Z"}},{"name":"jon8","lastName":"snow8","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:10-Y7BIYp5+C024MXyo68JUfQ","@id":"users/9-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9408478Z"}},{"name":"jon9","lastName":"snow9","@metadata":{"@collection":"Users","@nested-object-types":{},"Raven-Node-Type":"User","@change-vector":"A:11-Y7BIYp5+C024MXyo68JUfQ","@id":"users/10-A","@index-score":1,"@last-modified":"2018-10-08T07:02:43.9408566Z"}}]}

test/Mapping/StreamJsonTests.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
import * as stream from "readable-stream";
4+
import * as assert from "assert";
5+
import * as Parser from "stream-json/Parser";
6+
import { stringer } from "stream-json/Stringer";
7+
8+
describe("stream-json parser and stringer", function () {
9+
10+
it("stringer using values can stringify negative numbers when parser packing keys", (done) => {
11+
12+
const content = `{"test":-1}`;
13+
const readable = new stream.Readable();
14+
readable.push(content);
15+
readable.push(null);
16+
17+
const parser = new Parser({
18+
packKeys: true
19+
});
20+
21+
let hasNumberChunk = false;
22+
parser.on("data", x => hasNumberChunk = hasNumberChunk || x.name === "numberChunk");
23+
24+
const stringerInstance = stringer({ useValues: true });
25+
let output = "";
26+
stringerInstance.on("data", data => output += data.toString());
27+
28+
stream.pipeline(
29+
readable,
30+
parser,
31+
stringerInstance,
32+
(err) => {
33+
err ? done(err) : done();
34+
assert.strictEqual(output, content);
35+
});
36+
});
37+
38+
// TODO waiting for resolution of https://github.com/uhop/stream-json/issues/44
39+
it.skip("parser with streamNumbers turned off should not emit 'numberChunk' tokens", (done) => {
40+
41+
const content = `{ "test": -1 }`;
42+
const readable = new stream.Readable();
43+
readable.push(content);
44+
readable.push(null);
45+
46+
const parser = new Parser({
47+
packKeys: true,
48+
packStrings: true,
49+
packValues: true,
50+
packNumbers: true,
51+
streamNumbers: false,
52+
streamValues: false,
53+
streamKeys: false,
54+
streamStrings: false
55+
});
56+
57+
let hasNumberChunk = false;
58+
parser.on("data", x => hasNumberChunk = hasNumberChunk || x.name === "numberChunk");
59+
60+
stream.pipeline(
61+
readable,
62+
parser,
63+
(err) => {
64+
err ? done(err) : done();
65+
assert.ok(!hasNumberChunk);
66+
});
67+
});
68+
69+
it("stringer for query result response with negative result etag", (done) => {
70+
const content = fs.readFileSync(path.join(__dirname, "../Assets/queryResult.json"), "utf-8");
71+
const readable = new stream.Readable();
72+
readable.push(content);
73+
readable.push(null);
74+
75+
const parser = new Parser({
76+
packKeys: true
77+
});
78+
79+
const stringerInstance = stringer({ useValues: true });
80+
let output = "";
81+
stringerInstance.on("data", data => output += data.toString());
82+
83+
stream.pipeline(
84+
readable,
85+
parser,
86+
stringerInstance,
87+
(err) => {
88+
err ? done(err) : done();
89+
assert.strictEqual(output, content);
90+
});
91+
});
92+
});

test/Ported/Core/Streaming/QueryStreaming.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ describe("query streaming", function () {
220220
session.advanced.streamInto(query, targetStream);
221221
await StreamUtil.finishedAsync(targetStream);
222222

223-
const result: string = targetStream["string"];
223+
const result: string = targetStream["string"];
224224
assert.ok(result);
225225
const json = parseJsonVerbose(result);
226226
assert.ok(json);

0 commit comments

Comments
 (0)