Icard/angular-clarity-master(work.../node_modules/hdr-histogram-js/dist/encoding.spec.js

94 lines
12 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/*
* This is a TypeScript port of the original Java version, which was written by
* Gil Tene as described in
* https://github.com/HdrHistogram/HdrHistogram
* and released to the public domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const index_1 = require("./index");
const wasm_1 = require("./wasm");
const encoding_1 = require("./encoding");
describe("Histogram encoding", () => {
it("should encode and decode an histogram", () => {
// given
const histogram = new index_1.Int32Histogram(1, 2, 3);
histogram.autoResize = true;
histogram.recordValue(32415);
// when
const b64 = encoding_1.encodeIntoCompressedBase64(histogram);
// then
const decodedHistogram = encoding_1.decodeFromCompressedBase64(b64);
expect(decodedHistogram.toJSON()).toStrictEqual(histogram.toJSON());
});
it("should decode and decompress reading a base64 string", () => {
// given
const base64String = "HISTFAAAAB542pNpmSzMwMDAxAABzFCaEUoz2X+AMIKZAEARAtM=";
// when
const histogram = encoding_1.decodeFromCompressedBase64(base64String);
// then
expect(histogram.mean).toBe(42);
expect(histogram.totalCount).toBe(1);
});
it("should decode and decompress a big base64 string", () => {
// given
const base64String = "HISTFAAACGB42j1WQY4cuRGks7KzWWwOh1NTGo1GEmzBWCx0EAxjsdiTsdiTD4ZPfoa/4R/4o/7BOiKSrWnNVBWLzIyMiMzWp//897mUA7/62db1D/n3999//V8umBW74POTPds7+4In2/xq722zv9huj/bRbvZH+2oPdrV3vtu//AOeP9if8Ra7H7DlhlcPePyo+w1xrrh+84uZFzd7QkyEL/ZXJPgN295jC5bsii0FN084/BXXDQH+jqPMlhn5eYf1D/beb9h7BdSfseMJGG5C94h3BRFveibyZ9x9wR1KeaebR0P8J/vVfsCbHevv7DOxPxt2/1MrLOQz3j8BH2DjhOHpA/ZfEILRWaD9bZHyb7z60X6xRxByMzxsQEJsCPlNoP/BFI849WQP/iy+cHJHqG+4veIAWcf+DQ9Y51MRBRueHlRqEbOPXqQR74Ec28Dab9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Lf208c87XPlBEsLVeZ5/HGfWIAwyjodoJwmYMR6HH2SfcVnGnsYbTfPiENP316K8Dr8+K4hpIgdlHBUdgox3jBSk6K0YP9qMBzZzRX0CQgwTYPXBw1IHCQDLeI1kDG/0E0nqOA5+O8EA+XhFytKO1E5MJlZ4dvNY5zzpeHFkhH9K8sS/npFjIZZ8aM4e/NGjUx/BjvCHA0QnkBTHwFqGO2Y+jw24T0rNF/oT3/Zx06P8BChhtKw==";
// when
const histogram = encoding_1.decodeFromCompressedBase64(base64String);
// then
expect(histogram.totalCount).toBe(10000);
});
it("should encode and compress an histogram to a base64 string", () => {
// given
const histogram = new index_1.Int32Histogram(1, 2, 3);
histogram.recordValue(42);
// when
const base64Histogram = encoding_1.encodeIntoCompressedBase64(histogram);
// then
expect(base64Histogram).toBe("HISTFAAAAB94nJNpmSzMwMDABMSMQMzMAAGMUJoJxg9mAgA1TQGm");
});
it("should throw an error when trying to decompress an histogram using V1 encoding", () => {
// given
const base64V1EncodingString = "HISTIgAAAFd42pNpmazIwMAYxgABTBDKT4GBgdnNYMcCBvsPUBkeBkYGZqA8MwMbAzsDC5DFBCTZgJCDQY1BjkGLQZRBlUEPCB8zWDCYMxgDZZkZhgJgHDibAY8JB/A=";
// when & then
expect(() => encoding_1.decodeFromCompressedBase64(base64V1EncodingString)).toThrowError("Encoding not supported");
});
});
describe("WASM Histogram encoding", () => {
let histogram;
beforeAll(wasm_1.initWebAssembly);
afterEach(() => {
if (histogram) {
histogram.destroy();
}
});
it("should decode and decompress a big base64 string", () => {
// given
const base64String = "HISTFAAACGB42j1WQY4cuRGks7KzWWwOh1NTGo1GEmzBWCx0EAxjsdiTsdiTD4ZPfoa/4R/4o/7BOiKSrWnNVBWLzIyMiMzWp//897mUA7/62db1D/n3999//V8umBW74POTPds7+4In2/xq722zv9huj/bRbvZH+2oPdrV3vtu//AOeP9if8Ra7H7DlhlcPePyo+w1xrrh+84uZFzd7QkyEL/ZXJPgN295jC5bsii0FN084/BXXDQH+jq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+CDoS3xt5wqjSpJhHjtjZr1OCA+Ys5ZDzYx/DL6iI4eG8dr6bOPA7hnbccc53gbPNJHqzgx5zE6/ImJQKMN3OFYe5mQ9qxv/RyvzY854QpIM/AX2/w8xoluoETnnONtvowxZjuPjiLbS61vwydCAu4x2tlfz47U3A75zonNmEHgZbzM3pAIaNuJQYbFMY8GaMjjAyv1PNtLf208c87XPlBEsLVeZ5/HGfWIAwyjodoJwmYMR6HH2SfcVnGnsYbTfPiENP316K8Dr8+K4hpIgdlHBUdgox3jBSk6K0YP9qMBzZzRX0CQgwTYPXBw1IHCQDLeI1kDG/0E0nqOA5+O8EA+XhFytKO1E5MJlZ4dvNY5zzpeHFkhH9K8sS/npFjIZZ8aM4e/NGjUx/BjvCHA0QnkBTHwFqGO2Y+jw24T0rNF/oT3/Zx06P8BChhtKw==";
// when
histogram = encoding_1.decodeFromCompressedBase64(base64String, 32, true);
// then
//console.log(histogram);
expect(histogram.totalCount).toBe(10000);
});
it("should decode and decompress a big base64 string to a wasm packed histogram", () => {
// given
const base64String = "HISTFAAACGB42j1WQY4cuRGks7KzWWwOh1NTGo1GEmzBWCx0EAxjsdiTsdiTD4ZPfoa/4R/4o/7BOiKSrWnNVBWLzIyMiMzWp//897mUA7/62db1D/n3999//V8umBW74POTPds7+4In2/xq722zv9huj/bRbvZH+2oPdrV3vtu//AOeP9if8Ra7H7DlhlcPePyo+w1xrrh+84uZFzd7QkyEL/ZXJPgN295jC5bsii0FN084/BXXDQH+jqPMlhn5eYf1D/beb9h7BdSfseMJGG5C94h3BRFveibyZ9x9wR1KeaebR0P8J/vVfsCbHevv7DOxPxt2/1MrLOQz3j8BH2DjhOHpA/ZfEILRWaD9bZHyb7z60X6xRxByMzxsQEJsCPlNoP/BFI849WQP/iy+cHJHqG+4veIAWcf+DQ9Y51MRBRueHlRqEbOPXqQR74Ec28Dab9pseLpqI7na/bPCPuBz0xskIIAvUqVIpQdTcr7/Afje68RHpPwsBrXnUYE3UVy0AYubljZTggshU+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IgdlHBUdgox3jBSk6K0YP9qMBzZzRX0CQgwTYPXBw1IHCQDLeI1kDG/0E0nqOA5+O8EA+XhFytKO1E5MJlZ4dvNY5zzpeHFkhH9K8sS/npFjIZZ8aM4e/NGjUx/BjvCHA0QnkBTHwFqGO2Y+jw24T0rNF/oT3/Zx06P8BChhtKw==";
// when
histogram = encoding_1.decodeFromCompressedBase64(base64String, "packed", true);
// then
expect(histogram.totalCount).toBe(10000);
});
it("should encode and decode an histogram", () => {
// given
histogram = index_1.WasmHistogram.build();
histogram.recordValue(32415482);
// when
const b64 = encoding_1.encodeIntoCompressedBase64(histogram);
// then
const decodedHistogram = encoding_1.decodeFromCompressedBase64(b64);
expect(decodedHistogram.getValueAtPercentile(50)).toBe(histogram.getValueAtPercentile(50));
});
});
//# sourceMappingURL=encoding.spec.js.map