-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathsoda2.js
354 lines (293 loc) · 10.6 KB
/
soda2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/* Copyright (c) 2018, 2025, Oracle and/or its affiliates. */
/******************************************************************************
*
* This software is dual-licensed to you under the Universal Permissive License
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
* either license.
*
* If you elect to accept the software under the Apache License, Version 2.0,
* the following applies:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 165. soda2.js
*
* DESCRIPTION
* Some more tests of sodaDatabase object and createCollection() method.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const sodaUtil = require('./sodaUtil.js');
const testsUtil = require('./testsUtil.js');
describe('165. soda2.js', () => {
before(async function() {
const runnable = await testsUtil.isSodaRunnable();
if (!runnable) {
this.skip();
}
await sodaUtil.cleanup();
});
it('165.1 create two sodaDatabase objects which point to the same instance', async () => {
const conn = await oracledb.getConnection(dbConfig);
const sd1 = conn.getSodaDatabase();
const sd2 = conn.getSodaDatabase();
// sd1 creates the collection
const collName = "soda_test_165_1";
const coll_create = await sd1.createCollection(collName);
// sd2 opens the collection
const coll_open = await sd2.openCollection(collName);
assert(coll_open);
await coll_create.drop();
await conn.close();
}); // 165.1
it('165.2 create two sodaDatabase objects from two connections', async () => {
const conn1 = await oracledb.getConnection(dbConfig);
const sd1 = await conn1.getSodaDatabase();
const conn2 = await oracledb.getConnection(dbConfig);
const sd2 = await conn1.getSodaDatabase();
const t_collname = "soda_test_165_2";
const coll = await sd1.createCollection(t_collname);
const cNames = await sd2.getCollectionNames();
assert.deepStrictEqual(cNames, [ t_collname ]);
await coll.drop();
await conn1.close();
await conn2.close();
}); // 165.2
it('165.3 will open this collection when creating a collection with the existing name', async () => {
const conn = await oracledb.getConnection(dbConfig);
const sd = conn.getSodaDatabase();
const t_collname = "soda_test_165_3";
await sd.createCollection(t_collname);
const coll = await sd.createCollection(t_collname);
const cNames = await sd.getCollectionNames();
assert.deepStrictEqual(cNames, [ t_collname ]);
await coll.drop();
await conn.close();
}); // 165.3
it('165.4 Negative - createCollection() when collection name is empty string', async () => {
const conn = await oracledb.getConnection(dbConfig);
const sd = conn.getSodaDatabase();
const collName = "";
await assert.rejects(
async () => await sd.createCollection(collName),
/ORA-40658:/
);
// ORA-40658: Collection name cannot be null for this operation.
await conn.close();
}); // 165.4
// This is a variation of 173.1
it('165.5 connections from a pool concurrently insert documents into the same collection', async () => {
const collectionName = "soda_test_165.5";
await prepareCollection(collectionName);
const pool = await oracledb.createPool(dbConfig);
const t_contents = sodaUtil.t_contents;
await Promise.all(
t_contents.map(function(content) {
return insertDocument(pool, collectionName, content);
})
);
await pool.close(0);
await dropCollection(collectionName);
async function prepareCollection(collName) {
const conn = await oracledb.getConnection(dbConfig);
const soda = conn.getSodaDatabase();
const collection = await soda.createCollection(collName);
const indexSpec = {
"name": "OFFICE_IDX",
"fields": [
{
"path": "office",
"datatype": "string",
"order": "asc"
}
]
};
await collection.createIndex(indexSpec);
await conn.commit();
await conn.close();
} // prepareCollection()
async function insertDocument(pool, collName, content) {
const conn = await pool.getConnection();
const soda = conn.getSodaDatabase();
const collection = await soda.openCollection(collName);
await collection.insertOne(content);
await conn.commit();
await conn.close();
} // insertDocument()
async function dropCollection(collName) {
const conn = await oracledb.getConnection(dbConfig);
const soda = conn.getSodaDatabase();
const collection = await soda.openCollection(collName);
const result = await collection.drop();
assert.strictEqual(result.dropped, true);
await conn.commit();
await conn.close();
} // dropCollection()
}); // 165.5
it('165.6 test multiple collections with same connection', async () => {
const conn = await oracledb.getConnection(dbConfig);
const sd = conn.getSodaDatabase();
const collections = [
"soda_test_165_6_1",
"soda_test_165_6_2",
"soda_test_165_6_3"
];
// Create multiple collections
const createdCollections = await Promise.all(
collections.map(name => sd.createCollection(name))
);
// Verify all collections exist
const collNames = await sd.getCollectionNames();
assert.strictEqual(collNames.length, collections.length);
collections.forEach(name => {
assert(collNames.includes(name));
});
// Cleanup
await Promise.all(
createdCollections.map(coll => coll.drop())
);
await conn.close();
});
it('165.7 test collection creation with metadata', async () => {
const conn = await oracledb.getConnection(dbConfig);
const sd = conn.getSodaDatabase();
const collName = "soda_test_165_7";
const metadata = {
"schemaName": "SODA_TEST",
"tableName": "SODA_TEST_165_7",
"keyColumn": {
"name": "ID",
"sqlType": "VARCHAR2",
"maxLength": 255,
"assignmentMethod": "UUID"
},
"contentColumn": {
"name": "JSON_DOCUMENT",
"sqlType": "BLOB",
"compress": "NONE",
"cache": true,
"encrypt": "NONE",
"validation": "STANDARD"
},
"versionColumn": {
"name": "VERSION",
"method": "UUID"
},
"lastModifiedColumn": {
"name": "LAST_MODIFIED"
},
"creationTimeColumn": {
"name": "CREATED_ON"
}
};
const collection = await sd.createCollection(collName, { metadata });
// Verify collection exists
const cNames = await sd.getCollectionNames();
assert(cNames.includes(collName));
await collection.drop();
await conn.close();
});
it('165.8 test concurrent operations on different collections', async () => {
const pool = await oracledb.createPool(dbConfig);
const collections = ["soda_test_165_8_1", "soda_test_165_8_2"];
// Create collections
const conn = await pool.getConnection();
const sd = conn.getSodaDatabase();
await Promise.all(
collections.map(name => sd.createCollection(name))
);
await conn.close();
// Perform concurrent operations
const operations = [];
for (let i = 0; i < 10; i++) {
operations.push(
insertIntoCollection(pool, collections[0], { data: `doc1_${i}` }),
insertIntoCollection(pool, collections[1], { data: `doc2_${i}` })
);
}
await Promise.all(operations);
// Verify results
const verifyConn = await pool.getConnection();
const verifySd = verifyConn.getSodaDatabase();
for (const collName of collections) {
const coll = await verifySd.openCollection(collName);
const documents = await coll.find().getDocuments();
assert.strictEqual(documents.length, 10);
await coll.drop();
}
await verifyConn.close();
await pool.close();
async function insertIntoCollection(pool, collName, content) {
const conn = await pool.getConnection();
const soda = conn.getSodaDatabase();
const collection = await soda.openCollection(collName);
await collection.insertOne(content);
await conn.commit();
await conn.close();
}
});
it('165.9 test collection name with special characters', async () => {
const conn = await oracledb.getConnection(dbConfig);
const sd = conn.getSodaDatabase();
const specialNames = [
"SODA_test_165_9$",
"SODA_test_165_9#",
"SODA_test_165_9@"
];
for (const name of specialNames) {
const collection = await sd.createCollection(name);
await collection.drop();
}
await conn.close();
});
it('165.10 test collection creation with custom storage options', async () => {
const conn = await oracledb.getConnection(dbConfig);
const sd = conn.getSodaDatabase();
const collName = "soda_test_165_10";
const metadata = {
"storage": {
"tablespace": "USERS",
"logging": true,
"table": {
"compressFor": "BASIC",
"cacheTable": true
}
}
};
const collection = await sd.createCollection(collName, { metadata });
assert(collection);
await collection.drop();
await conn.close();
});
it('165.11 test collection with maximum name length', async () => {
const conn = await oracledb.getConnection(dbConfig);
const sd = conn.getSodaDatabase();
// Create collection name with maximum allowed length
const maxLengthName = "A".repeat(128);
const collection = await sd.createCollection(maxLengthName);
assert(collection);
// Create collection with name longer than maximum
const tooLongName = "A".repeat(129);
await assert.rejects(
async () => await sd.createCollection(tooLongName),
/ORA-40674:/ // ORA-40674: Length of table or column name metadata value cannot exceed 128 bytes.
);
await collection.drop();
await conn.close();
}); // 165.11
});