Skip to content

Commit

Permalink
Restore integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Mar 29, 2024
1 parent 2bd6485 commit 0da727b
Show file tree
Hide file tree
Showing 6 changed files with 534 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.node-version }}
parallel: true
- name: Run integration tests
run: npx lerna run integration --concurrency 1

coveralls:
needs: test
Expand Down
3 changes: 2 additions & 1 deletion engines/query-sparql-hdt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"scripts": {
"build": "npm run build:ts",
"build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
"prepare": "comunica-compile-config config/config-default.json > engine-default.js"
"prepare": "comunica-compile-config config/config-default.json > engine-default.js",
"integration": "rdf-test-suite-ldf spec/sparql-engine.js https://comunica.github.io/manifest-ldf-tests/sparql-hdt/hdt-manifest.ttl -d 200000 -c ../../.rdf-test-suite-ldf-cache/"
},
"dependencies": {
"@comunica/actor-context-preprocess-convert-shortcuts": "^3.0.1",
Expand Down
68 changes: 68 additions & 0 deletions engines/query-sparql-hdt/spec/sparql-engine-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const ProxyHandlerStatic = require('@comunica/actor-http-proxy').ProxyHandlerStatic;
const { KeysInitQuery } = require('@comunica/context-entries');
const { ActionContext } = require('@comunica/core');
const RdfStore = require('rdf-stores').RdfStore;
const RdfTestSuite = require('rdf-test-suite');

module.exports = function(engine) {
return {
parse(query, options) {
return engine.actorInitQuery.mediatorQueryProcess.bus.actors[0].parse(query, new ActionContext({ [KeysInitQuery.baseIRI.name]: options.baseIRI }));
},
query(data, queryString, options) {
return this.queryLdf([{ type: 'rdfjs', value: source(data) }], null, queryString, options);
},
async queryLdf(sources, proxyUrl, queryString, options) {
sources = sources.map((source) => {
if (source.type === 'rdfjsSource') {
source.type = 'rdfjs';
}
if (source.type === 'hdtFile') {
source.type = 'hdt';
}
return source;
});
const result = await engine.query(queryString, {
baseIRI: options.baseIRI,
sources,
httpProxyHandler: proxyUrl ? new ProxyHandlerStatic(proxyUrl) : null,
httpRetryOnServerError: true,
httpRetryCount: 3,
httpRetryDelay: 10,
});
if (result.resultType === 'boolean') {
return new RdfTestSuite.QueryResultBoolean(await result.execute());
}
if (result.resultType === 'quads') {
return new RdfTestSuite.QueryResultQuads(await require('arrayify-stream').default(await result.execute()));
}
if (result.resultType === 'bindings') {
return new RdfTestSuite.QueryResultBindings(
(await result.metadata()).variables.map(variable => `?${variable.value}`),
(await require('arrayify-stream').default(await result.execute()))
.map(binding => Object.fromEntries([ ...binding ]
.map(([ key, value ]) => [ `?${key.value}`, value ]))),
);
}
throw new Error(`Invalid query result type: ${result.resultType}`);
},
async update(data, queryString, options) {
const store = await source(data);
const result = await engine.query(queryString, {
baseIRI: options.baseIRI,
sources: [{ type: 'rdfjs', value: store }],
destination: store,
});
await result.execute();
return store.getQuads();
},
};
};

function source(data) {
const store = RdfStore.createDefault();
for (quad of data) {
store.addQuad(quad);
}
return store;
}
2 changes: 2 additions & 0 deletions engines/query-sparql-hdt/spec/sparql-engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const QueryEngine = require('@comunica/query-sparql-hdt').QueryEngine;
module.exports = require('./sparql-engine-base.js')(new QueryEngine());
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"pre-commit": "^1.2.2",
"rdf-data-factory": "^1.1.0",
"rdf-quad": "^1.5.0",
"rdf-test-suite-ldf": "^1.5.0",
"sparqlalgebrajs": "^4.0.0",
"stream-to-string": "^1.1.0",
"streamify-array": "^1.0.0",
Expand Down
Loading

0 comments on commit 0da727b

Please sign in to comment.