1
0
Fork 0

Added queue legacy test.

This commit is contained in:
Alan Plum 2015-06-10 19:14:20 +02:00
parent e79088c528
commit 53dff0b2d1
6 changed files with 174 additions and 1 deletions

View File

@ -0,0 +1,27 @@
'use strict';
var Foxx = require('org/arangodb/foxx');
var queue = Foxx.queues.get('default');
var ctrl = new Foxx.Controller(applicationContext);
ctrl.post('/', function (req, res) {
try {
var jobId = queue.push('queue-legacy-test', req.body(), {
allowUnknown: req.parameters.allowUnknown,
success: function (id, data) {
var collectionName = 'test__queue_test_data';
var db = require('org/arangodb').db;
db._collection(collectionName).save(data);
}
});
res.json({success: true, job: jobId});
} catch (e) {
res.status = 418;
res.json({success: false, error: e.name, stacktrace: e.stack});
}
});
ctrl.get('/', function (req, res) {
var db = require('org/arangodb').db;
var collectionName = 'test__queue_test_data';
res.json(db._collection(collectionName).all().toArray());
});

View File

@ -0,0 +1,15 @@
'use strict';
var joi = require('joi');
var schema = joi.object().required();
var queues = require('org/arangodb/foxx').queues;
queues.registerJobType('queue-legacy-test', {
schema: schema,
execute: function (data) {
var result = schema.validate(data);
if (result.error) {
throw result.error;
}
return result.data;
}
});

View File

@ -0,0 +1,13 @@
{
"name": "queue-legacy-test",
"version": "0.0.0",
"defaultDocument": "",
"controllers": {
"/": "controller.js"
},
"exports": {
"legacyJobType": "exports.js"
},
"setup": "setup.js",
"teardown": "teardown.js"
}

View File

@ -0,0 +1,9 @@
'use strict';
var db = require('org/arangodb').db;
var collectionName = 'test__queue_test_data';
if (db._collection(collectionName)) {
require('console').warn('Collection already exists:', collectionName);
db._collection(collectionName).truncate();
} else {
db._createDocumentCollection(collectionName);
}

View File

@ -0,0 +1,6 @@
'use strict';
var db = require('org/arangodb').db;
var collectionName = 'test__queue_test_data';
if (db._collection(collectionName)) {
db._collection(collectionName).drop();
}

View File

@ -149,7 +149,8 @@ var allTests =
"importing",
"upgrade",
"authentication",
"authentication_parameters"
"authentication_parameters",
"queue_legacy"
];
@ -1631,6 +1632,108 @@ testFuncs.foxx_manager = function (options) {
return results;
};
testFuncs.queue_legacy = function (options) {
// TODO
var startTime;
var queueAppMountPath = '/test-queue-legacy'
print("Testing legacy queue job types");
var instanceInfo = startInstance("tcp", options, [], "queue_legacy");
if (instanceInfo === false) {
return {status: false, message: "failed to start server!"};
}
var data = {
naive: {_key: 'potato', hello: 'world'},
forced: {_key: 'tomato', hello: 'world'},
plain: {_key: 'banana', hello: 'world'}
};
var results = {};
results.install = runArangoshCmd(options, instanceInfo, {"configuration": "etc/relative/foxx-manager.conf"}, [
"install",
"js/common/test-data/apps/queue-legacy-test",
queueAppMountPath
]);
print("Restarting without foxx-queues-warmup-exports...");
shutdownInstance(instanceInfo, options);
instanceInfo = startInstance("tcp", options, {
"server.foxx-queues-warmup-exports": "false"
}, "queue_legacy", instanceInfo.flatTmpDataDir);
if (instanceInfo === false) {
return {status: false, message: "failed to restart server!"};
}
print("done.");
var res, body;
startTime = time();
try {
res = download(instanceInfo.url + queueAppMountPath + '/', JSON.stringify(data.naive), {method: 'POST'});
body = JSON.parse(res.body);
results.naive = {status: body.success === false, message: JSON.stringify({body: res.body, code: res.code})};
} catch (e) {
results.naive = {status: true, message: JSON.stringify({body: res.body, code: res.code})};
}
results.naive.duration = time() - startTime;
startTime = time();
try {
res = download(instanceInfo.url + queueAppMountPath + '/?allowUnknown=true', JSON.stringify(data.forced), {method: 'POST'});
body = JSON.parse(res.body);
results.forced = body.success ? {status: true} : {status: false, message: body.error, stacktrace: body.stacktrace};
} catch (e) {
results.forced = {status: false, message: JSON.stringify({body: res.body, code: res.code})};
}
results.forced.duration = time() - startTime;
print("Restarting with foxx-queues-warmup-exports...");
shutdownInstance(instanceInfo, options);
instanceInfo = startInstance("tcp", options, {
"server.foxx-queues-warmup-exports": "true"
}, "queue_legacy", instanceInfo.flatTmpDataDir);
if (instanceInfo === false) {
return {status: false, message: "failed to restart server!"};
}
print("done.");
startTime = time();
try {
res = download(instanceInfo.url + queueAppMountPath + '/', JSON.stringify(data.plain), {method: 'POST'});
body = JSON.parse(res.body);
results.plain = body.success ? {status: true} : {status: false, message: JSON.stringify({body: res.body, code: res.code})};
} catch (e) {
results.plain = {status: false, message: JSON.stringify({body: res.body, code: res.code})};
}
results.plain.duration = time() - startTime;
startTime = time();
try {
for (var i = 0; i < 60; i++) {
wait(1);
res = download(instanceInfo.url + queueAppMountPath + '/');
body = JSON.parse(res.body);
if (body.length === 2) {
break;
}
}
results.final = (
body.length === 2 && body[0]._key === data.forced._key && body[1]._key === data.plain._key
? {status: true}
: {status: false, message: JSON.stringify({body: res.body, code: res.code})}
);
} catch (e) {
results.final = {status: false, message: JSON.stringify({body: res.body, code: res.code})};
}
results.final.duration = time() - startTime;
results.uninstall = runArangoshCmd(options, instanceInfo, {"configuration": "etc/relative/foxx-manager.conf"}, [
"uninstall",
queueAppMountPath
]);
print("Shutting down...");
shutdownInstance(instanceInfo, options);
print("done.");
return results;
};
testFuncs.dump = function (options) {
var cluster;