Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bfetch (2) #53711

Merged
merged 59 commits into from
Jan 16, 2020
Merged
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
cfcb181
feat: 🎸 implement ItemBuffer
streamich Dec 15, 2019
44e0ccc
test: 💍 add tests for ItemBuffer
streamich Dec 15, 2019
d052f0a
feat: 🎸 add TimedItemBuffer
streamich Dec 15, 2019
7f528f6
test: 💍 add TimedItemBuffer tests
streamich Dec 15, 2019
fb93abb
feat: 🎸 add createBatchedFunction
streamich Dec 16, 2019
19689b9
chore: 🤖 save wip on higher level batching
streamich Dec 19, 2019
7381ead
test: 💍 add createBatchedFunction tests
streamich Dec 20, 2019
ed621b9
feat: 🎸 implement createStreamingBatchedFunction() method
streamich Dec 20, 2019
35b27c6
refactor: 💡 rename "data" key to "result"
streamich Dec 20, 2019
5ae7e38
feat: 🎸 return error in "error" key in legacy protocol
streamich Dec 20, 2019
a0eb554
feat: 🎸 add server-side to Expressions plugin
streamich Dec 20, 2019
889028a
refactor: 💡 move interpreter server-side registries to NP
streamich Dec 20, 2019
c900fe4
feat: 🎸 implement bfetch.addBatchProcessingRoute
streamich Dec 27, 2019
5bc501b
feat: 🎸 improve streaming and batching func to pass request
streamich Dec 27, 2019
f08a2b3
feat: 🎸 initial setup of new expressions batching endpoint
streamich Dec 27, 2019
772dea7
feat: 🎸 expose bfetch.batchedFunction() function
streamich Dec 30, 2019
a59fd6d
feat: 🎸 add of() function
streamich Dec 30, 2019
32eaaba
refactor: 💡 move normalizeError() to /common
streamich Dec 30, 2019
7d9507f
feat: 🎸 improve createStreamingBatchedFunction() function
streamich Dec 30, 2019
0cd860e
refactor: 💡 move GET /api/interpreter/fns to the New Platform
streamich Dec 30, 2019
2a938f5
feat: 🎸 move batched_fetch to the New Platform
streamich Dec 30, 2019
a9e0433
feat: 🎸 implement legacy interpreter batching on server in NP
streamich Dec 30, 2019
8ee6ad9
feat: 🎸 switch legacy interpreter server functions to NP
streamich Jan 3, 2020
ba0b31f
chore: 🤖 remove unused import
streamich Jan 3, 2020
901c875
fix: 🐛 correct expressions mocks
streamich Jan 3, 2020
0c10810
test: 💍 fix batching tests after refactor
streamich Jan 3, 2020
c8d7b92
test: 💍 stub bfetch plugin explorer
streamich Jan 6, 2020
87c5893
test: 💍 add routing and app structure to bfetch_explorer
streamich Jan 6, 2020
cc972ec
test: 💍 add server-side to bfetch_explorer
streamich Jan 6, 2020
259c43f
test: 💍 create <DoubleInteger> component in bfetch_explorer
streamich Jan 6, 2020
2547749
test: 💍 improve bfetch_explorer
streamich Jan 6, 2020
f8788fd
test: 💍 add <CountUntil> demo to bfetch_explorer
streamich Jan 6, 2020
476d6d0
test: 💍 by default redirect to first bfetch_explorer example
streamich Jan 6, 2020
2d0c5e7
test: 💍 add error example to bfetch_explorer
streamich Jan 7, 2020
7306c26
docs: ✏️ improve bfetch docs
streamich Jan 7, 2020
88faebd
docs: ✏️ improve bfetch server-side docs
streamich Jan 7, 2020
90ec2fa
chore: 🤖 address self-review comments
streamich Jan 8, 2020
9d56ac5
fix: 🐛 use new core ES data client, remove unuseed import
streamich Jan 9, 2020
148c936
fix: 🐛 remove unused interface import
streamich Jan 9, 2020
4d727d8
Update examples/bfetch_explorer/public/components/count_until/index.tsx
streamich Jan 9, 2020
2f77faa
Update examples/bfetch_explorer/public/components/double_integers/ind…
streamich Jan 9, 2020
f56a327
Update src/plugins/bfetch/common/buffer/item_buffer.ts
streamich Jan 9, 2020
eaf01bb
Update src/plugins/kibana_utils/common/of.ts
streamich Jan 9, 2020
20efbb2
docs: ✏️ add batchedFunction params to README
streamich Jan 10, 2020
3b02bd1
refactor: 💡 rename onflush to onFlush
streamich Jan 10, 2020
2b12c47
feat: 🎸 make maxItemAge optional in TimedItemBuffer
streamich Jan 10, 2020
c32d821
refactor: 💡 remove promise from fetchStreaming
streamich Jan 10, 2020
643fa67
test: 💍 add bfetch_explorer functional tests
streamich Jan 10, 2020
0bae4eb
Merge remote-tracking branch 'upstream/master' into bfetch-2
streamich Jan 10, 2020
3ac588d
test: 💍 rename test plugin to kbn_tp_bfetch_explorer
streamich Jan 10, 2020
552f026
Merge branch 'master' into bfetch-2
streamich Jan 10, 2020
809f566
Merge branch 'master' into bfetch-2
elasticmachine Jan 10, 2020
c87291f
Merge branch 'master' into bfetch-2
elasticmachine Jan 10, 2020
c90111f
Merge remote-tracking branch 'upstream/master' into bfetch-2
streamich Jan 13, 2020
364826c
fix: 🐛 use stream instead of removed promise
streamich Jan 13, 2020
6f76117
fix: 🐛 use correct tsconfig.json in bfetch test plugin
streamich Jan 13, 2020
549eaae
feat: 🎸 add kbn_tp_bfetch_explorer server-side files to tsconfi
streamich Jan 14, 2020
62cd03a
Merge remote-tracking branch 'upstream/master' into bfetch-2
streamich Jan 14, 2020
bd75508
Merge branch 'master' into bfetch-2
elasticmachine Jan 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: 💍 add createBatchedFunction tests
  • Loading branch information
streamich committed Jan 9, 2020
commit 7381eadf0eab69901fb772d447331899d7a41d05
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ import { TimedItemBufferParams, TimedItemBuffer } from './timed_item_buffer';
type Fn = (...args: any) => any;

export interface BatchedFunctionParams<Func extends Fn, BatchEntry> {
onCall: (...args: Parameters<Func>) => [Func, BatchEntry];
onCall: (...args: Parameters<Func>) => [ReturnType<Func>, BatchEntry];
onBatch: (items: BatchEntry[]) => void;
flushOnMaxItems?: ItemBufferParams<any>['flushOnMaxItems'];
maxItemAge?: TimedItemBufferParams<any>['maxItemAge'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { createBatchedFunction } from '../create_batched_function';

describe('createBatchedFunction', () => {
test('calls onCall every time fn is called, calls onBatch once flushOnMaxItems reached', async () => {
const onBatch = jest.fn();
const onCall = jest.fn(() => [1, 2] as any);
const [fn] = createBatchedFunction({
onBatch,
onCall,
flushOnMaxItems: 2,
maxItemAge: 10,
});

expect(onCall).toHaveBeenCalledTimes(0);
expect(onBatch).toHaveBeenCalledTimes(0);

fn(123);

expect(onCall).toHaveBeenCalledTimes(1);
expect(onCall).toHaveBeenCalledWith(123);
expect(onBatch).toHaveBeenCalledTimes(0);

fn(456);

expect(onCall).toHaveBeenCalledTimes(2);
expect(onCall).toHaveBeenCalledWith(456);
expect(onBatch).toHaveBeenCalledTimes(1);
expect(onBatch).toHaveBeenCalledWith([2, 2]);
});

test('calls onBatch once timeout is reached', async () => {
const onBatch = jest.fn();
const onCall = jest.fn(() => [4, 3] as any);
const [fn] = createBatchedFunction({
onBatch,
onCall,
flushOnMaxItems: 2,
maxItemAge: 10,
});

expect(onCall).toHaveBeenCalledTimes(0);
expect(onBatch).toHaveBeenCalledTimes(0);

fn(123);

expect(onCall).toHaveBeenCalledTimes(1);
expect(onCall).toHaveBeenCalledWith(123);
expect(onBatch).toHaveBeenCalledTimes(0);

await new Promise(r => setTimeout(r, 15));

expect(onCall).toHaveBeenCalledTimes(1);
expect(onBatch).toHaveBeenCalledTimes(1);
expect(onBatch).toHaveBeenCalledWith([3]);
});
});