2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-06 17:53:56 +08:00
|
|
|
require('../../helper');
|
2016-10-19 02:01:11 +08:00
|
|
|
|
2016-10-06 17:53:56 +08:00
|
|
|
var assert = require('../../support/assert');
|
2015-12-23 06:13:33 +08:00
|
|
|
var queue = require('queue-async');
|
2016-10-19 02:01:11 +08:00
|
|
|
var BatchTestClient = require('../../support/batch-test-client');
|
2019-10-04 00:24:39 +08:00
|
|
|
var JobStatus = require('../../../lib/batch/job-status');
|
2016-01-08 22:47:59 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('batch happy cases', function () {
|
|
|
|
before(function () {
|
2016-10-19 02:01:11 +08:00
|
|
|
this.batchTestClient = new BatchTestClient();
|
2015-12-23 03:12:10 +08:00
|
|
|
});
|
2015-12-16 22:57:58 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
after(function (done) {
|
2016-10-19 02:01:11 +08:00
|
|
|
this.batchTestClient.drain(done);
|
2016-01-06 00:42:28 +08:00
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
function jobPayload (query) {
|
2016-10-19 02:01:11 +08:00
|
|
|
return {
|
|
|
|
query: query
|
2016-05-16 07:22:47 +08:00
|
|
|
};
|
2015-12-23 03:12:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should perform job with select', function (done) {
|
2016-10-19 02:01:11 +08:00
|
|
|
var payload = jobPayload('select * from private_table');
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2015-12-23 03:12:10 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2015-12-23 03:12:10 +08:00
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
return done();
|
2015-12-23 03:12:10 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-12-17 01:13:48 +08:00
|
|
|
|
2015-12-23 03:12:10 +08:00
|
|
|
it('should perform job with select into', function (done) {
|
2019-09-13 17:28:37 +08:00
|
|
|
var payload = jobPayload(`
|
|
|
|
DROP TABLE IF EXISTS batch_test_table;
|
|
|
|
SELECT * INTO batch_test_table FROM (SELECT * from private_table) AS job`);
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2015-12-23 03:12:10 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2015-12-23 03:12:10 +08:00
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
return done();
|
2015-12-17 01:13:48 +08:00
|
|
|
});
|
|
|
|
});
|
2015-12-23 03:12:10 +08:00
|
|
|
});
|
2015-12-17 01:13:48 +08:00
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
it('should perform job with select from result table', function (done) {
|
|
|
|
var payload = jobPayload('select * from batch_test_table');
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2015-12-23 03:12:10 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2015-12-22 18:02:16 +08:00
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
return done();
|
2015-12-22 02:57:10 +08:00
|
|
|
});
|
2015-12-23 03:12:10 +08:00
|
|
|
});
|
2015-12-09 07:02:08 +08:00
|
|
|
});
|
2015-12-23 03:12:10 +08:00
|
|
|
|
2016-11-24 23:45:00 +08:00
|
|
|
it('should perform all enqueued jobs', function (done) {
|
2016-10-19 02:01:11 +08:00
|
|
|
var self = this;
|
|
|
|
|
2015-12-23 06:13:33 +08:00
|
|
|
var jobs = [
|
|
|
|
'select * from private_table',
|
|
|
|
'select * from private_table',
|
2019-12-24 01:19:08 +08:00
|
|
|
'select * from private_table'
|
2015-12-23 06:13:33 +08:00
|
|
|
];
|
|
|
|
|
2016-11-24 23:53:15 +08:00
|
|
|
var jobsQueue = queue(1);
|
2015-12-23 06:13:33 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
jobs.forEach(function (job) {
|
|
|
|
jobsQueue.defer(function (payload, done) {
|
|
|
|
self.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-10-19 02:01:11 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(done);
|
|
|
|
});
|
|
|
|
}, jobPayload(job));
|
2015-12-23 06:13:33 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
jobsQueue.awaitAll(function (err, jobsCreated) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
jobsCreated.forEach(function (job) {
|
2016-10-19 02:01:11 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
2015-12-23 06:13:33 +08:00
|
|
|
});
|
2016-10-19 02:01:11 +08:00
|
|
|
|
|
|
|
return done();
|
2015-12-23 06:13:33 +08:00
|
|
|
});
|
|
|
|
});
|
2016-01-25 21:51:37 +08:00
|
|
|
|
2016-11-24 23:45:00 +08:00
|
|
|
it('should set all job as failed', function (done) {
|
2016-10-19 02:01:11 +08:00
|
|
|
var self = this;
|
|
|
|
|
2016-01-25 21:51:37 +08:00
|
|
|
var jobs = [
|
|
|
|
'select * from unexistent_table',
|
|
|
|
'select * from unexistent_table',
|
|
|
|
'select * from unexistent_table'
|
|
|
|
];
|
|
|
|
|
2016-11-24 23:53:15 +08:00
|
|
|
var jobsQueue = queue(1);
|
2016-01-25 21:51:37 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
jobs.forEach(function (job) {
|
|
|
|
jobsQueue.defer(function (payload, done) {
|
|
|
|
self.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-10-19 02:01:11 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2016-01-25 21:51:37 +08:00
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
jobResult.getStatus(done);
|
2016-01-25 21:51:37 +08:00
|
|
|
});
|
2016-10-19 02:01:11 +08:00
|
|
|
}, jobPayload(job));
|
2016-01-25 21:51:37 +08:00
|
|
|
});
|
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
jobsQueue.awaitAll(function (err, jobsCreated) {
|
2016-01-25 21:51:37 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
jobsCreated.forEach(function (job) {
|
2016-10-19 02:01:11 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
});
|
2016-01-25 21:51:37 +08:00
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
return done();
|
2016-01-25 21:51:37 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-19 01:12:01 +08:00
|
|
|
it('should perform job with array of select', function (done) {
|
2016-05-16 07:22:47 +08:00
|
|
|
var queries = ['select * from private_table limit 1', 'select * from private_table'];
|
2016-03-31 18:39:03 +08:00
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
var payload = jobPayload(queries);
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-03-18 21:57:18 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2016-03-19 01:12:01 +08:00
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
return done();
|
|
|
|
});
|
2016-03-19 01:12:01 +08:00
|
|
|
});
|
|
|
|
});
|
2016-03-18 21:57:18 +08:00
|
|
|
|
2016-03-19 01:12:01 +08:00
|
|
|
it('should set job as failed if last query fails', function (done) {
|
|
|
|
var queries = ['select * from private_table', 'select * from undefined_table'];
|
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
var payload = jobPayload(queries);
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-03-19 01:12:01 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2016-03-18 21:57:18 +08:00
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
return done();
|
2016-03-18 21:57:18 +08:00
|
|
|
});
|
2016-03-19 01:12:01 +08:00
|
|
|
});
|
|
|
|
});
|
2016-03-18 21:57:18 +08:00
|
|
|
|
2016-03-19 01:12:01 +08:00
|
|
|
it('should set job as failed if first query fails', function (done) {
|
|
|
|
var queries = ['select * from undefined_table', 'select * from private_table'];
|
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
var payload = jobPayload(queries);
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-03-19 01:12:01 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2016-03-19 01:12:01 +08:00
|
|
|
}
|
2016-10-19 02:01:11 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
return done();
|
2016-03-19 01:12:01 +08:00
|
|
|
});
|
2016-03-18 21:57:18 +08:00
|
|
|
});
|
|
|
|
});
|
2015-12-09 07:02:08 +08:00
|
|
|
});
|