Skip to content

Commit 3d751a2

Browse files
feat(shell-api): add options in stream processor start, stop, and drop MONGOSH-1920 (#2274)
1 parent dce0b68 commit 3d751a2

File tree

2 files changed

+69
-26
lines changed

2 files changed

+69
-26
lines changed

packages/shell-api/src/stream-processor.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,30 @@ export default class StreamProcessor extends ShellApiWithMongoClass {
2626
}
2727

2828
@returnsPromise
29-
async start() {
29+
async start(options: Document = {}) {
3030
return await this._streams._runStreamCommand({
3131
startStreamProcessor: this.name,
32+
...options,
3233
});
3334
}
3435

3536
@returnsPromise
36-
async stop() {
37+
async stop(options: Document = {}) {
3738
return await this._streams._runStreamCommand({
3839
stopStreamProcessor: this.name,
40+
...options,
3941
});
4042
}
4143

4244
@returnsPromise
43-
async drop() {
44-
return this._drop();
45+
async drop(options: Document = {}) {
46+
return this._drop(options);
4547
}
4648

47-
async _drop() {
49+
async _drop(options: Document = {}) {
4850
return await this._streams._runStreamCommand({
4951
dropStreamProcessor: this.name,
52+
...options,
5053
});
5154
}
5255

packages/shell-api/src/streams.spec.ts

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,67 @@ describe('Streams', function () {
164164
});
165165
});
166166

167+
// Create a stream processor.
168+
const createProcessor = async (name: string) => {
169+
const runCmdStub = sinon
170+
.stub(mongo._serviceProvider, 'runCommand')
171+
.resolves({ ok: 1 });
172+
const pipeline = [{ $match: { foo: 'bar' } }];
173+
const processor = await streams.createStreamProcessor(name, pipeline);
174+
expect(processor).to.eql(streams.getProcessor(name));
175+
const cmd = { createStreamProcessor: name, pipeline };
176+
expect(runCmdStub.calledOnceWithExactly('admin', cmd, {})).to.be.true;
177+
return { runCmdStub, processor };
178+
};
179+
180+
// Validate supplying options in start,stop, and drop commands.
181+
describe('options', function () {
182+
it('supplies options in start, stop, and drop', async function () {
183+
const name = 'testOptions';
184+
const { runCmdStub, processor } = await createProcessor(name);
185+
186+
// Start the stream processor with an extra option.
187+
await processor.start({ resumeFromCheckpoint: false });
188+
expect(
189+
runCmdStub.calledWithExactly(
190+
'admin',
191+
{ startStreamProcessor: name, resumeFromCheckpoint: false },
192+
{}
193+
)
194+
).to.be.true;
195+
196+
// Stop the stream processor with an extra option.
197+
await processor.stop({ force: true });
198+
expect(
199+
runCmdStub.calledWithExactly(
200+
'admin',
201+
{ stopStreamProcessor: name, force: true },
202+
{}
203+
)
204+
).to.be.true;
205+
206+
// Drop the stream processor with a few extra options.
207+
const opts = {
208+
force: true,
209+
ttl: { unit: 'day', size: 30 },
210+
};
211+
await processor.drop(opts);
212+
expect(
213+
runCmdStub.calledWithExactly(
214+
'admin',
215+
{
216+
dropStreamProcessor: name,
217+
...opts,
218+
},
219+
{}
220+
)
221+
).to.be.true;
222+
});
223+
});
224+
167225
describe('modify', function () {
168226
it('throws with invalid parameters', async function () {
169-
// Create the stream processor.
170-
const runCmdStub = sinon
171-
.stub(mongo._serviceProvider, 'runCommand')
172-
.resolves({ ok: 1 });
173-
const name = 'p1';
174-
const pipeline = [{ $match: { foo: 'bar' } }];
175-
const processor = await streams.createStreamProcessor(name, pipeline);
176-
expect(processor).to.eql(streams.getProcessor(name));
177-
const cmd = { createStreamProcessor: name, pipeline };
178-
expect(runCmdStub.calledOnceWithExactly('admin', cmd, {})).to.be.true;
227+
const { processor } = await createProcessor('testModify');
179228

180229
// No arguments to modify.
181230
const caught = await processor
@@ -206,17 +255,8 @@ describe('Streams', function () {
206255
});
207256

208257
it('works with pipeline and options arguments', async function () {
209-
const runCmdStub = sinon
210-
.stub(mongo._serviceProvider, 'runCommand')
211-
.resolves({ ok: 1 });
212-
213-
// Create the stream processor.
214-
const name = 'p1';
215-
const pipeline = [{ $match: { foo: 'bar' } }];
216-
const processor = await streams.createStreamProcessor(name, pipeline);
217-
expect(processor).to.eql(streams.getProcessor(name));
218-
const cmd = { createStreamProcessor: name, pipeline };
219-
expect(runCmdStub.calledOnceWithExactly('admin', cmd, {})).to.be.true;
258+
const name = 'testModify';
259+
const { runCmdStub, processor } = await createProcessor(name);
220260

221261
// Start the stream processor.
222262
await processor.start();

0 commit comments

Comments
 (0)