From 53dff0b2d1376d75d8aa623c005aaf9e7a00998d Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Wed, 10 Jun 2015 19:14:20 +0200 Subject: [PATCH] Added queue legacy test. --- .../apps/queue-legacy-test/controller.js | 27 +++++ .../apps/queue-legacy-test/exports.js | 15 +++ .../apps/queue-legacy-test/manifest.json | 13 +++ .../test-data/apps/queue-legacy-test/setup.js | 9 ++ .../apps/queue-legacy-test/teardown.js | 6 + js/server/modules/org/arangodb/testing.js | 105 +++++++++++++++++- 6 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 js/common/test-data/apps/queue-legacy-test/controller.js create mode 100644 js/common/test-data/apps/queue-legacy-test/exports.js create mode 100644 js/common/test-data/apps/queue-legacy-test/manifest.json create mode 100644 js/common/test-data/apps/queue-legacy-test/setup.js create mode 100644 js/common/test-data/apps/queue-legacy-test/teardown.js diff --git a/js/common/test-data/apps/queue-legacy-test/controller.js b/js/common/test-data/apps/queue-legacy-test/controller.js new file mode 100644 index 0000000000..deda18057e --- /dev/null +++ b/js/common/test-data/apps/queue-legacy-test/controller.js @@ -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()); +}); \ No newline at end of file diff --git a/js/common/test-data/apps/queue-legacy-test/exports.js b/js/common/test-data/apps/queue-legacy-test/exports.js new file mode 100644 index 0000000000..0c7380965e --- /dev/null +++ b/js/common/test-data/apps/queue-legacy-test/exports.js @@ -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; + } +}); \ No newline at end of file diff --git a/js/common/test-data/apps/queue-legacy-test/manifest.json b/js/common/test-data/apps/queue-legacy-test/manifest.json new file mode 100644 index 0000000000..18be7c1588 --- /dev/null +++ b/js/common/test-data/apps/queue-legacy-test/manifest.json @@ -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" +} \ No newline at end of file diff --git a/js/common/test-data/apps/queue-legacy-test/setup.js b/js/common/test-data/apps/queue-legacy-test/setup.js new file mode 100644 index 0000000000..d11a57c500 --- /dev/null +++ b/js/common/test-data/apps/queue-legacy-test/setup.js @@ -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); +} \ No newline at end of file diff --git a/js/common/test-data/apps/queue-legacy-test/teardown.js b/js/common/test-data/apps/queue-legacy-test/teardown.js new file mode 100644 index 0000000000..a7a552dbfd --- /dev/null +++ b/js/common/test-data/apps/queue-legacy-test/teardown.js @@ -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(); +} \ No newline at end of file diff --git a/js/server/modules/org/arangodb/testing.js b/js/server/modules/org/arangodb/testing.js index 5f8e70387b..7e9bd40eed 100644 --- a/js/server/modules/org/arangodb/testing.js +++ b/js/server/modules/org/arangodb/testing.js @@ -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;