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');
|
|
|
|
var JobStatus = require('../../../batch/job_status');
|
2016-01-08 22:47:59 +08:00
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
describe('batch happy cases', function() {
|
2015-12-14 17:36:16 +08:00
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
before(function() {
|
|
|
|
this.batchTestClient = new BatchTestClient();
|
2015-12-23 03:12:10 +08:00
|
|
|
});
|
2015-12-16 22:57:58 +08:00
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
after(function(done) {
|
|
|
|
this.batchTestClient.drain(done);
|
2016-01-06 00:42:28 +08:00
|
|
|
});
|
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
function jobPayload(query) {
|
|
|
|
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');
|
|
|
|
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) {
|
2016-10-19 02:01:11 +08:00
|
|
|
var payload = jobPayload('select * into batch_test_table from (select * from private_table) as job');
|
|
|
|
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');
|
|
|
|
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-03-19 01:12:01 +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',
|
|
|
|
'select * from private_table',
|
|
|
|
'select * from private_table',
|
|
|
|
'select * from private_table',
|
|
|
|
'select * from private_table',
|
|
|
|
'select * from private_table',
|
|
|
|
'select * from private_table',
|
|
|
|
'select * from private_table',
|
|
|
|
'select * from private_table'
|
|
|
|
];
|
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
var jobsQueue = queue(4);
|
2015-12-23 06:13:33 +08:00
|
|
|
|
|
|
|
jobs.forEach(function(job) {
|
2016-10-19 02:01:11 +08:00
|
|
|
jobsQueue.defer(function(payload, done) {
|
|
|
|
self.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
jobsCreated.forEach(function(job) {
|
|
|
|
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-22 00:27:57 +08:00
|
|
|
it.skip('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',
|
|
|
|
'select * from unexistent_table',
|
|
|
|
'select * from unexistent_table',
|
|
|
|
'select * from unexistent_table',
|
|
|
|
'select * from unexistent_table',
|
|
|
|
'select * from unexistent_table',
|
|
|
|
'select * from unexistent_table',
|
|
|
|
'select * from unexistent_table'
|
|
|
|
];
|
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
var jobsQueue = queue(4);
|
2016-01-25 21:51:37 +08:00
|
|
|
|
|
|
|
jobs.forEach(function(job) {
|
2016-10-19 02:01:11 +08:00
|
|
|
jobsQueue.defer(function(payload, done) {
|
|
|
|
self.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-10-19 02:01:11 +08:00
|
|
|
jobsCreated.forEach(function(job) {
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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
|
|
|
});
|