Skip to content

Commit

Permalink
Add filter argument to ringbuffer readMany() method and a test for it…
Browse files Browse the repository at this point in the history
… API-1294 (hazelcast#1414)

* add filter argument to ringbuffer readMany() method and a test for it

* fix some typos
  • Loading branch information
fatihozer0 committed Nov 20, 2022
1 parent 2daa58a commit 8f17e50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/proxy/Ringbuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,22 @@ export interface Ringbuffer<E> extends DistributedObject {
* until further items become available, and it can read at least the
* minimum number of items.
*
* `filter` argument is provided to select only the items that are needed
* to be read. If the filter is not provided, all items will be read.
* Otherwise, only the items where the filter function returns true are returned.
* Using filters is a good way to prevent getting items that are of no value
* to the receiver. This reduces the amount of IO and the number of operations being executed,
* and can result in a significant performance improvement. Note that,
* filtering logic must be defined on the server-side.
*
* @param startSequence sequence number of the first item to be read.
* @param minCount minimum number of items to be read.
* @param maxCount maximum number of items to be read.
* @param filter optional filter to be applied to the items
* @throws RangeError if `startSequence` is smaller than `0`,
* or if `minCount` smaller than `0`,
* or if `minCount` larger than `maxCount`,
* or if `maxCount` larger than `1000` (to prevent overloading)
*/
readMany(startSequence: number | Long, minCount: number, maxCount: number): Promise<ReadResultSet<E>>;
readMany(startSequence: number | Long, minCount: number, maxCount: number, filter?: any): Promise<ReadResultSet<E>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,13 @@ describe('RingbufferProxyTest', function () {
const size = await rb.size();
expect(size.toNumber()).to.equal(2);
});

it('readMany correctly works with a filter', async function () {
await rb.addAll(['item1', 'prefixedItem2', 'prefixedItem3']);
const items = await rb.readMany(0, 1, 3, new PrefixFilter('prefixed'));
expect(items.get(0)).to.equal('prefixedItem2');
expect(items.get(1)).to.equal('prefixedItem3');
expect(items.getReadCount()).to.equal(3);
expect(items.size()).to.equal(2);
});
});

0 comments on commit 8f17e50

Please sign in to comment.