2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-06 17:53:56 +08:00
|
|
|
require('../../helper');
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-10-06 17:53:56 +08:00
|
|
|
var assert = require('../../support/assert');
|
2019-10-04 00:24:39 +08:00
|
|
|
var JobStatus = require('../../../lib/batch/job-status');
|
2016-11-24 02:22:24 +08:00
|
|
|
var BatchTestClient = require('../../support/batch-test-client');
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2019-02-27 18:57:36 +08:00
|
|
|
describe('Batch API fallback job', function () {
|
2019-12-24 01:19:08 +08:00
|
|
|
before(function () {
|
2016-11-24 02:22:24 +08:00
|
|
|
this.batchTestClient = new BatchTestClient();
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
after(function (done) {
|
2016-11-24 02:22:24 +08:00
|
|
|
this.batchTestClient.drain(done);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" on first query should be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-05-17 07:00:27 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-11-24 02:22:24 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onerror" on first query should not be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'skipped'
|
2016-11-24 02:22:24 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onerror" on first query should be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
2016-05-19 22:58:14 +08:00
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-05-17 07:00:27 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'done',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" on first query should not be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
2016-05-19 22:58:14 +08:00
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-05-17 07:00:27 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'skipped',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" should be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
status: 'done'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" should not be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
2016-05-19 22:58:14 +08:00
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */'
|
2016-05-17 07:00:27 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */',
|
|
|
|
status: 'failed',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.SKIPPED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onerror" should be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */',
|
|
|
|
status: 'failed',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onerror" should not be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
status: 'done'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.SKIPPED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" & "onsuccess" on query should be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" for each query should be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-05-17 07:00:27 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 3'
|
2016-05-17 07:00:27 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-11-24 02:22:24 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" for each query should not be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM nonexistent_table /* should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 3'
|
2016-05-18 00:51:02 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM nonexistent_table /* should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'skipped',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
status: 'skipped',
|
|
|
|
fallback_status: 'skipped'
|
2016-11-24 02:22:24 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" for second query should not be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM nonexistent_table /* should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 3'
|
2016-05-18 00:51:02 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-05-25 23:00:27 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM nonexistent_table /* should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'skipped',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-11-24 02:22:24 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-25 23:00:27 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-25 23:00:27 +08:00
|
|
|
});
|
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-25 23:00:27 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onerror" should not be triggered for any query and "skipped"', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
2016-05-25 23:00:27 +08:00
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 2'
|
2016-05-25 23:00:27 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 4'
|
2016-05-25 23:00:27 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'skipped'
|
2016-05-26 23:37:37 +08:00
|
|
|
}, {
|
2016-11-24 02:22:24 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 4',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'skipped'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-26 23:37:37 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-26 23:37:37 +08:00
|
|
|
});
|
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-26 23:37:37 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" should be "skipped"', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
2016-05-26 23:37:37 +08:00
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1, /* should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2'
|
2016-05-26 23:37:37 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1, /* should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'skipped',
|
|
|
|
failed_reason: 'syntax error at end of input'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-26 23:37:37 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-26 23:37:37 +08:00
|
|
|
});
|
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-26 23:37:37 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" should not be triggered and "skipped"', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
2016-05-26 23:37:37 +08:00
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1, /* should fail */'
|
2016-05-26 23:37:37 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1, /* should fail */',
|
|
|
|
status: 'failed',
|
|
|
|
failed_reason: 'syntax error at end of input'
|
|
|
|
}],
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2'
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" for first query should fail', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onsuccess: 'SELECT * FROM nonexistent_table /* should fail */'
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 3'
|
2016-05-18 00:51:02 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onsuccess: 'SELECT * FROM nonexistent_table /* should fail */',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'failed',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-11-24 02:22:24 +08:00
|
|
|
}]
|
|
|
|
};
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" for second query should fail', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2'
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onsuccess: 'SELECT * FROM nonexistent_table /* should fail */'
|
2016-05-18 00:51:02 +08:00
|
|
|
}]
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onsuccess: 'SELECT * FROM nonexistent_table /* should fail */',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'failed',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-11-24 02:22:24 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" for job & "onsuccess" for each query should be triggered', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2'
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 4'
|
2016-05-18 00:51:02 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 5'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 4',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 5'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" for job & "onsuccess" for each query should be triggered ' +
|
|
|
|
'(even second "onsuccess" fails job should be done)', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2'
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onsuccess: 'SELECT * FROM nonexistent_table /* should fail */'
|
2016-05-18 00:51:02 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 5'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'done'
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onsuccess: 'SELECT * FROM nonexistent_table /* should fail */',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'failed',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 5'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('should fail first "onerror" and job "onerror" and skip the other ones', function (done) {
|
|
|
|
var payload = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM atm_madrid limit 1, should fail',
|
|
|
|
onerror: 'SELECT * FROM atm_madrid limit 2'
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM atm_madrid limit 3',
|
|
|
|
onerror: 'SELECT * FROM atm_madrid limit 4'
|
2016-05-18 19:25:08 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onerror: 'SELECT * FROM atm_madrid limit 5'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM atm_madrid limit 1, should fail',
|
|
|
|
onerror: 'SELECT * FROM atm_madrid limit 2',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'failed',
|
|
|
|
failed_reason: 'relation "atm_madrid" does not exist'
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
2016-11-24 02:22:24 +08:00
|
|
|
query: 'SELECT * FROM atm_madrid limit 3',
|
|
|
|
onerror: 'SELECT * FROM atm_madrid limit 4',
|
|
|
|
status: 'skipped',
|
|
|
|
fallback_status: 'skipped'
|
|
|
|
}],
|
|
|
|
onerror: 'SELECT * FROM atm_madrid limit 5'
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.FAILED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('should run first "onerror" and job "onerror" and skip the other ones', function (done) {
|
|
|
|
var payload = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1, should fail',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 2'
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 4'
|
2016-05-18 19:25:08 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 5'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [
|
|
|
|
{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1, should fail',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'done',
|
|
|
|
failed_reason: 'LIMIT #,# syntax is not supported'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 4',
|
|
|
|
status: 'skipped',
|
|
|
|
fallback_status: 'skipped'
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
],
|
2019-12-24 01:19:08 +08:00
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 5'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-05-20 20:42:53 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.DONE);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-20 20:42:53 +08:00
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
});
|
|
|
|
});
|
2016-05-26 23:37:37 +08:00
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('"onsuccess" for job & "onsuccess" for each query should not be triggered ' +
|
|
|
|
' because it has been cancelled', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT pg_sleep(3)',
|
|
|
|
onsuccess: 'SELECT pg_sleep(0)'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT pg_sleep(0)'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT pg_sleep(3)',
|
|
|
|
onsuccess: 'SELECT pg_sleep(0)',
|
|
|
|
status: 'cancelled',
|
|
|
|
fallback_status: 'skipped'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT pg_sleep(0)'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(JobStatus.RUNNING, function (err, job) {
|
2016-05-26 23:37:37 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.RUNNING);
|
|
|
|
|
|
|
|
jobResult.cancel(function (err, job) {
|
2016-05-26 23:37:37 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
|
|
|
|
assert.equal(job.status, JobStatus.CANCELLED);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.SKIPPED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-26 23:37:37 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-26 23:37:37 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
it('first "onsuccess" should be triggered and it will be cancelled', function (done) {
|
|
|
|
var payload = {
|
|
|
|
query: {
|
|
|
|
query: [{
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'SELECT pg_sleep(0)',
|
|
|
|
onsuccess: 'SELECT pg_sleep(3)'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT pg_sleep(0)'
|
2016-11-24 02:22:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var expectedQuery = {
|
2019-12-24 01:19:08 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT pg_sleep(0)',
|
|
|
|
onsuccess: 'SELECT pg_sleep(3)',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'cancelled'
|
2016-11-24 02:22:24 +08:00
|
|
|
}],
|
2019-12-24 01:19:08 +08:00
|
|
|
onsuccess: 'SELECT pg_sleep(0)'
|
2016-11-24 02:22:24 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
this.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-24 02:22:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobResult.getStatus(JobStatus.RUNNING, function (err, job) {
|
2016-05-26 23:37:37 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-11-24 02:22:24 +08:00
|
|
|
assert.equal(job.status, JobStatus.RUNNING);
|
|
|
|
|
|
|
|
jobResult.cancel(function (err, job) {
|
2016-05-26 23:37:37 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 02:22:24 +08:00
|
|
|
|
|
|
|
assert.equal(job.status, JobStatus.CANCELLED);
|
|
|
|
assert.equal(job.fallback_status, JobStatus.SKIPPED);
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 02:22:24 +08:00
|
|
|
return done();
|
2016-05-26 23:37:37 +08:00
|
|
|
});
|
2016-11-24 02:22:24 +08:00
|
|
|
});
|
2016-05-26 23:37:37 +08:00
|
|
|
});
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|