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
Merge from concat -> aleph nodes #152
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d89b45e
move broadly useful fns to src/common/utils.js
yusefnapora e201273
add Datastore.has method
yusefnapora 5c35c2b
statement verification
yusefnapora 2330c2e
merge: basically working, (no partial successes)
yusefnapora b132a12
integration-test: use separate namespace for each test, delete statem…
yusefnapora 29ac66b
merge: separate key filtering and batching fns
yusefnapora 4046ba9
add (failing) test for partially successful merge
yusefnapora d423061
merge: support partial success
yusefnapora 2e16b7a
validate object hashes before merging
yusefnapora 8e77303
use random object ids instead of wiping datastore after tests
yusefnapora 8197f40
separate `makeStatement` code from MediachainNode
yusefnapora fe46bd6
tests for statement signature verification
yusefnapora File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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,86 @@ | ||
// @flow | ||
/* eslint-env mocha */ | ||
|
||
const assert = require('assert') | ||
const { describe, it, before, after } = require('mocha') | ||
const uuid = require('node-uuid') | ||
|
||
const { getTestNodeId } = require('../test/util') | ||
const { MediachainNode: AlephNode } = require('../src/peer/node') | ||
const { concatNodeClient, concatNodePeerInfo } = require('./util') | ||
|
||
const TEST_NAMESPACE = 'scratch.merge-test' | ||
const INVALID_STATEMENT_NAMESPACE = 'scratch.merge-test.invalid-stmt' | ||
|
||
const seedObjects = [ | ||
{id: uuid.v4(), hello: 'world'}, | ||
{id: uuid.v4(), foo: 'bar'}, | ||
{id: uuid.v4(), etc: 'and so on'} | ||
] | ||
|
||
describe('Merge (concat -> aleph)', () => { | ||
let objectIds | ||
let seedStatements | ||
let concatClient | ||
let concatPeerInfo | ||
|
||
before(() => { | ||
return concatNodeClient() | ||
.then(_client => { concatClient = _client }) | ||
.then(() => concatNodePeerInfo()) | ||
.then(_pInfo => { concatPeerInfo = _pInfo }) | ||
.then(() => concatClient.setStatus('online')) | ||
.then(() => concatClient.putData(...seedObjects)) | ||
.then(_objectIds => { objectIds = _objectIds }) | ||
.then(() => { | ||
seedStatements = objectIds.map((object, idx) => ({ | ||
object, | ||
refs: [`test:obj:${idx.toString()}`], | ||
tags: ['test'], | ||
deps: [] | ||
})) | ||
return concatClient.publish({namespace: TEST_NAMESPACE}, ...seedStatements) | ||
}) | ||
.then(() => | ||
// add a statement with a reference to a non-existent object | ||
concatClient.publish({namespace: INVALID_STATEMENT_NAMESPACE}, { | ||
object: 'QmNLftPEMzsadpbTsGaVP3haETYJb4GfnCgQiaFj5Red9G', | ||
refs: ['test:invalid:ref'], | ||
tags: [], | ||
deps: [] | ||
})) | ||
}) | ||
|
||
after(() => | ||
concatClient.delete(`DELETE FROM ${TEST_NAMESPACE}`) | ||
.then(() => concatClient.delete(`DELETE FROM ${INVALID_STATEMENT_NAMESPACE}`)) | ||
) | ||
|
||
it('merges statements from a concat node', () => { | ||
let alephNode | ||
return getTestNodeId().then(peerId => { alephNode = new AlephNode({ peerId }) }) | ||
.then(() => alephNode.start()) | ||
.then(() => alephNode.merge(concatPeerInfo, `SELECT * FROM ${TEST_NAMESPACE}`)) | ||
.then(results => { | ||
assert.notEqual(results, null, 'merge did not return a result') | ||
assert.equal(results.statementCount, seedStatements.length, 'aleph node merged an unexpected number of statements') | ||
assert.equal(results.objectCount, objectIds.length, 'aleph node merged an unexpected number of objects') | ||
}) | ||
}) | ||
|
||
it('returns counts + error message for partially successful merge', () => { | ||
let alephNode | ||
return getTestNodeId() | ||
.then(peerId => { alephNode = new AlephNode({ peerId }) }) | ||
.then(() => alephNode.start()) | ||
.then(() => alephNode.merge(concatPeerInfo, `SELECT * FROM ${TEST_NAMESPACE}.* ORDER BY counter`)) | ||
.catch(err => { | ||
assert.fail(err, 'no error', '', '!==') | ||
}) | ||
.then(result => { | ||
assert.notEqual(result, null, 'partially-successful merge should return a result') | ||
assert(typeof result.error === 'string' && result.error.length > 0, | ||
'partially successful merge should return an error message') | ||
}) | ||
}) | ||
}) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, was there a specific reason for doing this? Are the tests noticeably faster this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make sure that data from one test wouldn't "contaminate" the results for a subsequent test, since I'm asserting on e.g. the number of objects merged, and if I unthinkingly reuse the same
{foo: "bar"}
object in multiple tests, I might get the wrong result if the node already had it in the store from a previous test.I tried doing a garbage collection pass on the datastore after each test, but you have to take the node offline first, and I was getting weird connection reset errors. So I figured I'd just make sure that all the data objects had a random component, so there's no chance of a duplicate object throwing things off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, that makes sense