-
Notifications
You must be signed in to change notification settings - Fork 234
feat: allow import into fle2 collections COMPASS-5810 #3101
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
Merged
alenakhineika
merged 5 commits into
main
from
COMPASS-5810-import-into-fle2-collections
May 17, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
06ca0ca
feat: allow import into fle2 collections COMPASS-5810
alenakhineika d650291
docs: move comment back to the function call
alenakhineika 784375d
Merge remote-tracking branch 'origin/main' into COMPASS-5810-import-i…
alenakhineika fb36f78
feat: stop on error option while inserting one by one
alenakhineika be40111
fix: batch.length ge BATCH_SIZE
alenakhineika File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
packages/compass-import-export/src/utils/collection-stream.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { createCollectionWriteStream } from './collection-stream'; | ||
const { expect } = require('chai'); | ||
|
||
const TEST_COLLECTION_NAME = 'db.testimport'; | ||
|
||
const runImport = (dataService, stopOnErrors) => { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
const dest = createCollectionWriteStream( | ||
dataService, | ||
TEST_COLLECTION_NAME, | ||
stopOnErrors | ||
); | ||
|
||
dest.once('progress', (stats) => { | ||
resolve(stats); | ||
}); | ||
|
||
dest.write({ phoneNumber: '+12874627836' }); | ||
dest.write({ phoneNumber: '+12874627811' }); | ||
dest.end({ phoneNumber: '+12874627222' }); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
}; | ||
|
||
describe('collection-stream', function () { | ||
describe('_executeBatch', function () { | ||
it('insert documents as bulk to regular collection', async function () { | ||
const dataService = { | ||
_collection: function () { | ||
return { | ||
bulkWrite: () => | ||
Promise.resolve({ | ||
nInserted: 3, | ||
nMatched: 0, | ||
nModified: 0, | ||
nRemoved: 0, | ||
nUpserted: 0, | ||
ok: 1, | ||
}), | ||
}; | ||
}, | ||
}; | ||
|
||
const stats = await runImport(dataService, false); | ||
|
||
expect(stats.docsProcessed).to.be.equal(3); | ||
expect(stats.docsWritten).to.be.equal(3); | ||
expect(stats.errors.length).to.be.equal(0); | ||
}); | ||
|
||
it('insert documents one by one to FLE2 collection', async function () { | ||
const dataService = { | ||
_collection: function () { | ||
return { | ||
bulkWrite: () => | ||
new Promise((resolve, reject) => { | ||
const error = new Error( | ||
'Only single insert batches are supported in FLE2' | ||
); | ||
error.code = 6371202; | ||
|
||
reject(error); | ||
}), | ||
insertOne: () => Promise.resolve({ acknowledged: true }), | ||
}; | ||
}, | ||
}; | ||
|
||
const stats = await runImport(dataService, false); | ||
|
||
expect(stats.docsProcessed).to.be.equal(3); | ||
expect(stats.docsWritten).to.be.equal(3); | ||
expect(stats.errors.length).to.be.equal(0); | ||
}); | ||
|
||
it('insert documents to FLE2 collection even one is failed', async function () { | ||
let i = 0; | ||
const dataService = { | ||
_collection: function () { | ||
return { | ||
bulkWrite: () => | ||
new Promise((resolve, reject) => { | ||
const error = new Error( | ||
'Only single insert batches are supported in FLE2' | ||
); | ||
error.code = 6371202; | ||
|
||
reject(error); | ||
}), | ||
insertOne: () => | ||
new Promise((resolve, reject) => { | ||
i += 1; | ||
|
||
if (i === 2) { | ||
return reject(new Error('foo')); | ||
} else { | ||
return resolve({ acknowledged: true }); | ||
} | ||
}), | ||
}; | ||
}, | ||
}; | ||
|
||
const stats = await runImport(dataService, false); | ||
|
||
expect(stats.docsProcessed).to.be.equal(3); | ||
expect(stats.docsWritten).to.be.equal(2); | ||
expect(stats.errors.length).to.be.equal(1); | ||
}); | ||
|
||
it('stops on error when inserting to FLE2 collection', async function () { | ||
let i = 0; | ||
const dataService = { | ||
_collection: function () { | ||
return { | ||
bulkWrite: () => | ||
new Promise((resolve, reject) => { | ||
const error = new Error( | ||
'Only single insert batches are supported in FLE2' | ||
); | ||
error.code = 6371202; | ||
|
||
reject(error); | ||
}), | ||
insertOne: () => | ||
new Promise((resolve, reject) => { | ||
i += 1; | ||
|
||
if (i === 2) { | ||
return reject(new Error('foo')); | ||
} else { | ||
return resolve({ acknowledged: true }); | ||
} | ||
}), | ||
}; | ||
}, | ||
}; | ||
|
||
const stats = await runImport(dataService, true); | ||
|
||
expect(stats.docsProcessed).to.be.equal(3); | ||
expect(stats.docsWritten).to.be.equal(1); | ||
expect(stats.errors.length).to.be.equal(1); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.