Skip to content

Commit 705eab2

Browse files
author
Aries Yuwono
committed
add
1 parent ecc2969 commit 705eab2

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright 2014-2015 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
var should = require('should');
17+
18+
var testconfig = require('../etc/test-config-qa.js');
19+
20+
var marklogic = require('../');
21+
var q = marklogic.queryBuilder;
22+
var db = marklogic.createDatabaseClient(testconfig.restWriterConnection);
23+
24+
describe('Transaction remove multiple documents test', function() {
25+
26+
var tid = 0;
27+
var tid2 = 0;
28+
29+
it('should do transaction remove multiple', function(done) {
30+
db.transactions.open({transactionName: 'removeTransaction', timeLimit: 30})
31+
.result(function(response) {
32+
//console.log(JSON.stringify(response, null, 2));
33+
tid = response.txid;
34+
return db.documents.write({
35+
txid: tid,
36+
uri: '/test/remove/transaction/doc1.json',
37+
contentType: 'application/json',
38+
content: {firstname: 'John', lastname: 'Doe', txKey: tid}
39+
}, {
40+
txid: tid,
41+
uri: '/test/remove/transaction/doc2.json',
42+
contentType: 'application/json',
43+
content: {firstname: 'Harry', lastname: 'Kane', txKey: tid}
44+
}).result();
45+
})
46+
.then(function(response) {
47+
//console.log(JSON.stringify(response, null, 2));
48+
return db.documents.read({
49+
txid: tid,
50+
uris: [
51+
'/test/remove/transaction/doc1.json',
52+
'/test/remove/transaction/doc2.json'
53+
]
54+
}).result();
55+
})
56+
.then(function(response) {
57+
//console.log(JSON.stringify(response, null, 2));
58+
response[0].uri.should.equal('/test/remove/transaction/doc1.json');
59+
response[1].uri.should.equal('/test/remove/transaction/doc2.json');
60+
return db.transactions.read(tid).result();
61+
})
62+
.then(function(response) {
63+
//console.log(JSON.stringify(response, null, 2));
64+
response['transaction-status']['transaction-id'].should.equal(tid);
65+
response['transaction-status']['time-limit'].should.equal('30');
66+
return db.documents.read({uris: '/test/remove/transaction/doc1.json'}).result();
67+
})
68+
.then(function(response) {
69+
//console.log(JSON.stringify(response, null, 2));
70+
response[0].uri.should.equal('/test/remove/transaction/doc1.json');
71+
return db.transactions.commit(tid).result();
72+
})
73+
.then(function(response) {
74+
//console.log(JSON.stringify(response, null, 2));
75+
return db.documents.read({uris: '/test/remove/transaction/doc1.json'}).result();
76+
})
77+
.then(function(response) {
78+
//console.log(JSON.stringify(response, null, 2));
79+
response[0].uri.should.equal('/test/remove/transaction/doc1.json');
80+
return db.documents.read({uris: '/test/remove/transaction/doc2.json'}).result();
81+
})
82+
.then(function(response) {
83+
//console.log(JSON.stringify(response, null, 2));
84+
response[0].uri.should.equal('/test/remove/transaction/doc2.json');
85+
return db.transactions.open({transactionName: 'removeTransaction2', timeLimit: 60}).result();
86+
})
87+
.then(function(response) {
88+
//console.log(JSON.stringify(response, null, 2));
89+
tid2 = response.txid;
90+
return db.documents.remove({
91+
txid: tid2,
92+
uris: [
93+
'/test/remove/transaction/doc1.json',
94+
'/test/remove/transaction/doc2.json'
95+
]
96+
}).result();
97+
})
98+
.then(function(response) {
99+
//console.log(JSON.stringify(response, null, 2));
100+
response.removed.should.equal(true);
101+
return db.transactions.commit(tid2).result();
102+
})
103+
.then(function(response) {
104+
//console.log(JSON.stringify(response, null, 2));
105+
return db.documents.read({
106+
uris: [
107+
'/test/remove/transaction/doc1.json',
108+
'/test/remove/transaction/doc2.json'
109+
]
110+
}).result();
111+
})
112+
.then(function(response) {
113+
//console.log(JSON.stringify(response, null, 2));
114+
response.length.should.equal(0);
115+
done();
116+
}, done);
117+
/*.catch(function(error) {
118+
console.log(error);
119+
done();
120+
}, done);*/
121+
});
122+
});
123+

0 commit comments

Comments
 (0)