本文整理汇总了TypeScript中long.fromNumber函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fromNumber函数的具体用法?TypeScript fromNumber怎么用?TypeScript fromNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromNumber函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("should correctly dispatch receiveMetrics with an unmatching nextRequest", function() {
const response = new protos.cockroach.ts.tspb.TimeSeriesQueryResponse({
results: [
{
datapoints: [],
},
],
});
const request = new protos.cockroach.ts.tspb.TimeSeriesQueryRequest({
start_nanos: Long.fromNumber(0),
end_nanos: Long.fromNumber(10),
queries: [
{
name: "test.metric.1",
},
],
});
state = metrics.metricsReducer(state, metrics.receiveMetrics(componentID, request, response));
assert.isDefined(state.queries);
assert.isDefined(state.queries[componentID]);
assert.lengthOf(_.keys(state.queries), 1);
assert.equal(state.queries[componentID].data, null);
assert.equal(state.queries[componentID].request, null);
assert.isUndefined(state.queries[componentID].nextRequest);
assert.isUndefined(state.queries[componentID].error);
});
示例2: randomStats
function randomStats(sensitiveInfo?: ISensitiveInfo): StatementStatistics {
const count = randomInt(1000);
// tslint:disable:variable-name
const first_attempt_count = randomInt(count);
const max_retries = randomInt(count - first_attempt_count);
// tslint:enable:variable-name
return {
count: Long.fromNumber(count),
first_attempt_count: Long.fromNumber(first_attempt_count),
max_retries: Long.fromNumber(max_retries),
num_rows: randomStat(100),
parse_lat: randomStat(),
plan_lat: randomStat(),
run_lat: randomStat(),
service_lat: randomStat(),
overhead_lat: randomStat(),
sensitive_info: sensitiveInfo || makeSensitiveInfo(null, null),
};
}
示例3: randomStats
function randomStats(): StatementStatistics {
const count = randomInt(1000);
// tslint:disable:variable-name
const first_attempt_count = randomInt(count);
const max_retries = randomInt(count - first_attempt_count);
// tslint:enable:variable-name
return {
count: Long.fromNumber(count),
first_attempt_count: Long.fromNumber(first_attempt_count),
max_retries: Long.fromNumber(max_retries),
num_rows: randomStat(100),
parse_lat: randomStat(),
plan_lat: randomStat(),
run_lat: randomStat(),
service_lat: randomStat(),
overhead_lat: randomStat(),
last_err: "",
last_err_redacted: "",
};
}
示例4: it
it("handles non-string values", function () {
const testValues: { [k: string]: any } = {
boolean: true,
number: 1,
emptyObject: {},
emptyArray: [],
objectWithProps: { a: 1, b: 2 },
arrayWithElts: [1, 2, 3],
long: Long.fromNumber(1),
};
const querystring = api.propsToQueryString(testValues);
assert.deepEqual(_.mapValues(testValues, _.toString), decodeQueryString(querystring));
});
示例5: describe
describe("saga functions", function() {
type timespan = [Long, Long];
const shortTimespan: timespan = [Long.fromNumber(400), Long.fromNumber(500)];
const longTimespan: timespan = [Long.fromNumber(0), Long.fromNumber(500)];
// Helper function to generate metrics request.
function createRequest(ts: timespan, ...names: string[]): TSRequest {
return new protos.cockroach.ts.tspb.TimeSeriesQueryRequest({
start_nanos: ts[0],
end_nanos: ts[1],
queries: _.map(names, (s) => {
return {
name: s,
};
}),
});
}
function createResponse(
queries: protos.cockroach.ts.tspb.IQuery[],
datapoints: protos.cockroach.ts.tspb.TimeSeriesDatapoint[] = [],
) {
return new protos.cockroach.ts.tspb.TimeSeriesQueryResponse({
results: queries.map(query => {
return {
query,
datapoints,
};
}),
});
}
function createDatapoints(val: number) {
const result: protos.cockroach.ts.tspb.TimeSeriesDatapoint[] = [];
for (let i = 0; i < val; i++) {
result.push(new protos.cockroach.ts.tspb.TimeSeriesDatapoint({
timestamp_nanos: new Long(val),
value: val,
}));
}
return result;
}
describe("queryMetricsSaga plan", function() {
it("initially waits for incoming request objects", function () {
testSaga(metrics.queryMetricsSaga)
.next()
.take(metrics.REQUEST);
});
it("correctly accumulates batches", function () {
const requestAction = metrics.requestMetrics("id", createRequest(shortTimespan, "short.1"));
const beginAction = metrics.beginMetrics(requestAction.payload.id, requestAction.payload.data);
return expectSaga(metrics.queryMetricsSaga)
// Stub out calls to batchAndSendRequests.
.provide([
[matchers.call.fn(metrics.batchAndSendRequests), null],
])
// Dispatch six requests, with delays inserted in order to trigger
// batch sends.
.dispatch(requestAction)
.dispatch(requestAction)
.dispatch(requestAction)
.delay(0)
.dispatch(requestAction)
.delay(0)
.dispatch(requestAction)
.dispatch(requestAction)
.run()
.then((result) => {
const { effects } = result;
// Verify the order of call dispatches.
assert.deepEqual(
effects.call,
[
call(delay, 0),
call(metrics.batchAndSendRequests, [requestAction.payload, requestAction.payload, requestAction.payload]),
call(delay, 0),
call(metrics.batchAndSendRequests, [requestAction.payload]),
call(delay, 0),
call(metrics.batchAndSendRequests, [requestAction.payload, requestAction.payload]),
],
);
// Verify that all beginAction puts were dispatched.
assert.deepEqual(
effects.put,
[
put(beginAction),
put(beginAction),
put(beginAction),
put(beginAction),
put(beginAction),
put(beginAction),
],
);
});
});
});
//.........这里部分代码省略.........
示例6: it
it ("correctly responds to errors.", function () {
this.timeout(1000);
// Mock out fetch server; send a positive reply to the first request, and
// an error to the second request.
let successSent = false;
fetchMock.mock({
matcher: "ts/query",
method: "POST",
response: (_url: string, requestObj: RequestInit) => {
// Assert that metric store's "inFlight" is 1.
assert.equal(mockMetricsState.inFlight, 1);
if (successSent) {
return { throws: new Error() };
}
successSent = true;
const request = protos.cockroach.ts.tspb.TimeSeriesQueryRequest.decode(new Uint8Array(requestObj.body as ArrayBuffer));
const encodedResponse = protos.cockroach.ts.tspb.TimeSeriesQueryResponse.encode({
results: _.map(request.queries, (q) => {
return {
query: q,
datapoints: [],
};
}),
}).finish();
return {
body: api.toArrayBuffer(encodedResponse),
};
},
});
// Dispatch several requests. Requests are divided among two timespans,
// which should result in two batches.
let shortTimespan: timespan = [Long.fromNumber(400), Long.fromNumber(500)];
let longTimespan: timespan = [Long.fromNumber(0), Long.fromNumber(500)];
queryMetrics("id.1", createRequest(shortTimespan, "short.1", "short.2"));
let p = queryMetrics("id.2", createRequest(longTimespan, "long.1"));
// Queries should already be present, but unfulfilled.
assert.lengthOf(_.keys(mockMetricsState.queries), 2);
_.each(mockMetricsState.queries, (q) => {
assert.isDefined(q.nextRequest);
assert.isUndefined(q.data);
});
return p.then(() => {
// Assert that the server got the correct number of requests (2).
assert.lengthOf(fetchMock.calls("ts/query"), 2);
// Assert that the mock metrics state has 2 queries.
assert.lengthOf(_.keys(mockMetricsState.queries), 2);
// Assert query with id.1 has results.
let q1 = mockMetricsState.queries["id.1"];
assert.isDefined(q1);
assert.isDefined(q1.data);
assert.isUndefined(q1.error);
// Assert query with id.2 has an error.
let q2 = mockMetricsState.queries["id.2"];
assert.isDefined(q2);
assert.isDefined(q2.error);
assert.isUndefined(q2.data);
// Assert that inFlight is 0.
assert.equal(mockMetricsState.inFlight, 0);
});
});
示例7: describe
describe("saga functions", function() {
type timespan = [Long, Long];
const shortTimespan: timespan = [Long.fromNumber(400), Long.fromNumber(500)];
const longTimespan: timespan = [Long.fromNumber(0), Long.fromNumber(500)];
// Helper function to generate metrics request.
function createRequest(ts: timespan, ...names: string[]): TSRequest {
return new protos.cockroach.ts.tspb.TimeSeriesQueryRequest({
start_nanos: ts[0],
end_nanos: ts[1],
queries: _.map(names, (s) => {
return {
name: s,
};
}),
});
}
function createResponse(queries: protos.cockroach.ts.tspb.Query$Properties[]) {
return new protos.cockroach.ts.tspb.TimeSeriesQueryResponse({
results: queries.map(q => {
return {
query: q,
datapoints: [],
};
}),
});
}
describe("queryMetricsSaga", function() {
it("initially waits for incoming request objects", function () {
const saga = metrics.queryMetricsSaga();
assert.deepEqual(saga.next().value, take(metrics.REQUEST));
});
it("correctly accumulates batches", function () {
const requestAction = metrics.requestMetrics("id", createRequest(shortTimespan, "short.1"));
const saga = metrics.queryMetricsSaga();
saga.next();
// Pass in a request, the generator should put the request to the
// redux store, fork "sendBatches" process, then await another request.
assert.deepEqual(saga.next(requestAction).value, put(requestAction));
const sendBatchesFork = saga.next().value as ForkEffect;
assert.isDefined(sendBatchesFork.FORK);
assert.deepEqual(saga.next().value, take(metrics.REQUEST));
// Pass in two additional requests, the generator should not yield another
// fork.
for (let i = 0; i < 2; i++) {
assert.deepEqual(saga.next(requestAction).value, put(requestAction));
assert.deepEqual(saga.next().value, take(metrics.REQUEST));
}
// Run the fork function. It should initially call delay (to defer to the
// event queue), then call sendRequestBatches with the currently
// accumulated batches, then complete.
const accumulateBatch = sendBatchesFork.FORK.fn() as IterableIterator<any>;
assert.deepEqual(accumulateBatch.next().value, call(delay, 0));
assert.deepEqual(
accumulateBatch.next().value,
call(
metrics.batchAndSendRequests,
[requestAction.payload, requestAction.payload, requestAction.payload],
),
);
assert.isTrue(accumulateBatch.next().done);
// Pass in a request, the generator should again yield a "fork" followed
// by another take for request objects.
assert.deepEqual(saga.next(requestAction).value, put(requestAction));
assert.isDefined((saga.next().value as ForkEffect).FORK);
assert.deepEqual(saga.next().value, take(metrics.REQUEST));
});
});
describe("batchAndSendRequests", function() {
it("sendBatches correctly batches multiple requests", function () {
const shortRequests = [
metrics.requestMetrics("id", createRequest(shortTimespan, "short.1")).payload,
metrics.requestMetrics("id", createRequest(shortTimespan, "short.2", "short.3")).payload,
metrics.requestMetrics("id", createRequest(shortTimespan, "short.4")).payload,
];
const longRequests = [
metrics.requestMetrics("id", createRequest(longTimespan, "long.1")).payload,
metrics.requestMetrics("id", createRequest(longTimespan, "long.2", "long.3")).payload,
metrics.requestMetrics("id", createRequest(longTimespan, "long.4", "long.5")).payload,
];
// Mix the requests together and send the combined request set.
const mixedRequests = _.flatMap(shortRequests, (short, i) => [short, longRequests[i]]);
const sendBatches = metrics.batchAndSendRequests(mixedRequests);
// sendBatches next puts a "fetchMetrics" action into the store.
assert.deepEqual(sendBatches.next().value, put(metrics.fetchMetrics()));
// Next, sendBatches dispatches a "all" effect with a "call" for each
// batch; there should be two batches in total, one containing the
// short requests and one containing the long requests. The order
// of requests in each batch is maintained.
//.........这里部分代码省略.........