Repository navigation
Expand file tree
/
Copy pathtest_database.py
More file actions
396 lines (336 loc) · 11.5 KB
/
Copy pathtest_database.py
File metadata and controls
396 lines (336 loc) · 11.5 KB
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
import logging
import os
import sys
import pytest
import threading
from httpapibase import HttpTest
from common.common_values import *
class TestDataBase(HttpTest):
def test_http_verison(self):
pass
def test_http_database(self):
logging.error("test_http_databasetest_http_databasetest_http_databasetest_http_databasetest_http_databasetest_http_databasetest_http_databasetest_http_databasetest_http_database")
db_name = "test_http_my_database"
self.drop_database(db_name)
self.create_database(db_name)
self.create_database("test_http_my_database@#$", {
"status_code": 500,
"error_code": 3003,
})
self.create_database("test_http_my_databasse-dash", {
"status_code": 500,
"error_code": 3003,
})
self.create_database("123_database_test_http", {
"status_code": 500,
"error_code": 3003,
})
# list database
self.list_database({
"error_code": 0,
"databases": [
db_name,
"default_db",
]
})
# drop my_database
self.drop_database(db_name)
# list database
self.list_database({
"error_code": 0,
"databases": [
"default_db",
]
})
self.clear_http_database()
def test_http_create_database_invalid_name(self):
'''
create databse with invalid name
'''
for db_name in invalid_name_array:
if db_name == '':
continue
else:
self.create_database(db_name, {
"status_code": 500,
"error_code": 3003,
})
self.clear_http_database()
def test_http_create_drop_show_1K_databases(self):
'''
create 1K dbs,show these dbs,drop these dbs
'''
self.clear_http_database()
# create databases
db_count = 100
for i in range(db_count):
# print('create test_http_db_name' + str(i))
self.drop_database('test_http_db_name' + str(i))
for i in range(db_count):
self.create_database('test_http_db_name' + str(i))
dbs = self.get_database()
# list all databases
http_database_count = 0
for db_name in dbs:
# print("db name:" + db_name)
if db_name.startswith("test_http") or db_name == "default_db":
http_database_count += 1
assert http_database_count == (db_count + 1)
# drop databases
for i in range(db_count):
# print('drop test_http_db_name' + str(i))
self.drop_database('test_http_db_name' + str(i))
self.clear_http_database()
@pytest.mark.skipif(condition=os.getenv("RUNSLOWTEST")!="1", reason="Cost too much times")
def test_http_create_drop_show_100K_databases(self):
"""
create 100K dbs, show these dbs, drop these dbs
"""
self.clear_http_database()
# create databases
db_count = 100000
for i in range(db_count):
# print('create test_http_db_name' + str(i))
self.drop_database('test_http_db_name' + str(i))
for i in range(db_count):
self.create_database('test_http_db_name' + str(i))
dbs = self.get_database()
# list all databases
http_database_count = 0
for db_name in dbs:
# print("db name:" + db_name)
if db_name.startswith("test_http") or db_name == "default_db":
http_database_count += 1
assert http_database_count == (db_count + 1)
# drop databases
for i in range(db_count):
# print('drop test_http_db_name' + str(i))
self.drop_database('test_http_db_name' + str(i))
def test_http_repeatedly_create_drop_show_databases(self):
"""
create db, show db and drop db, repeat above ops 100 times
"""
loop_count = 100
self.clear_http_database()
db_name = 'test_http_test_repeatedly_create_drop_show_databases'
for i in range(loop_count):
# create database
self.create_database(db_name)
# show database
dbs = self.get_database()
for now_db_name in dbs:
if now_db_name.startswith("test_http"):
assert now_db_name == db_name
# drop databses
self.drop_database(db_name)
self.clear_http_database()
def test_http_drop_database_with_invalid_name(self):
"""
drop database with invalid name
"""
for db_name in invalid_name_array:
if db_name == '':
continue
self.drop_database(db_name, {
"status_code": 500,
"error_code": 3003,
})
self.clear_http_database()
def test_http_get_db(self):
"""
target: get db
method:
1. show non-existent db
2. show existent db
3. show dropped db
4. show invalid name db
expect: all operations successfully
"""
# show database not exist
self.show_database("test_http_db1", {
"status_code": 500,
"error_code": 3021,
# "error_message": "{database_name} doesn't exist."
})
# create database
db_name = "test_http_my_database"
self.create_database(db_name)
# show database
self.show_database(db_name, {
"error_code": 0,
"database_name": "default_db",
"table_count": 0,
})
# show default database
self.show_database("default_db")
# drop database
self.drop_database(db_name)
# drop database with invalid name
for invalid_db_name in invalid_float_array:
self.drop_database(invalid_db_name, {
"status_code": 500,
"error_code": 3021,
# "error_message": "{database_name} doesn't exist."
})
self.clear_http_database()
def test_http_drop_non_existent_db(self):
'''
drop not exist db
'''
db_name = "test_http_my_database2"
self.drop_database(db_name, {
"status_code": 200,
# "error_message": "{database_name} doesn't exist."
})
self.clear_http_database()
def test_http_get_drop_db_with_two_threads(self):
'''
one thread get db, another thread drop this db
'''
db_name = "test_http_test_get_drop_db_with_two_thread"
self.create_database(db_name)
thread1 = threading.Thread(
self.drop_database(db_name, {
"status_code": 200,
}), args=(1,)
)
thread2 = threading.Thread(
self.show_database(db_name, {
"status_code": 500,
"error_code": 3021,
}), args=(2,)
)
thread1.start()
thread2.start()
thread1.join()
thread2.join()
# drop databases
self.drop_database(db_name)
self.clear_http_database()
def test_http_create_same_db_in_different_threads(self):
'''
create same db in different thread to test conflict and show dbs
'''
db_name = "test_http_test_create_same_db_in_different_threads"
thread1 = threading.Thread(
self.create_database(db_name), args=(1,)
)
thread2 = threading.Thread(
self.create_database(db_name), args=(2,)
)
thread1.start()
thread2.start()
thread1.join()
thread2.join()
# drop databases
self.drop_database(db_name)
self.clear_http_database()
def test_http_show_database(self):
# create database
db_name = "test_http_test_show_database"
self.drop_database(db_name)
self.create_database(db_name)
self.show_database(db_name, {
"error_code": 0,
"database_name": db_name,
"table_count": 0
})
self.drop_database(db_name)
self.clear_http_database()
def test_http_create_option(self):
db_name = "test_http_test_create_option"
# create with option: key ignore
self.create_database(db_name)
#create with option: key error
self.create_database(db_name,{
"status_code":500,
"error_code":3016,
},"kError")
#create with option: key replace
# self.create_database(db_name,{
# "error_code":0
# },"kReplace")
self.clear_http_database()
def test_http_drop_option(self):
db_name = "test_http_test_drop_option"
# drop with option: key ignore
self.drop_database(db_name)
# drop with option: key error
self.drop_database(db_name,{
"status_code":500,
"error_code":3021,
},"kError")
self.clear_http_database()
def test_http_update_database_options(self):
'''
test the update database option
'''
db_name = "test_http_test_update_options"
self.create_database(db_name)
# update database option
new_options = {"new_option_key" : "new_option_value"}
self.update_database_options(db_name, new_options)
self.show_database(db_name, {
"error_code": 0,
"new_option_key": "new_option_value",
})
# delete database
self.drop_database(db_name)
self.clear_http_database()
def test_http_add_table(self):
'''
test adding table in database
'''
db_name = "test_http_test_add_table"
table_name = "test_table"
self.create_database(db_name)
# create table
self.create_table(db_name, table_name)
self.show_table(db_name, table_name, {
"error_code": 0,
"table_name": table_name,
})
# delete database
self.drop_database(db_name)
self.clear_http_database()
def test_http_create_table_concurrently(self):
'''
create tables concurrently, test conflict handling and table display
'''
db_name = "test_http_test_create_table_concurrently"
table_name = "test_table"
self.create_database(db_name)
thread1 = threading.Thread(
target=self.create_table, args=(db_name, table_name)
)
thread2 = threading.Thread(
target=self.create_table, args=(db_name, table_name)
)
thread1.start()
thread2.start()
thread1.join()
thread2.join()
self.show_table(db_name, table_name, {
"error_code" : 0,
"table_name": table_name,
})
# delete database
self.drop_database(db_name)
self.clear_http_database()
def test_http_backup_and_restore_database(self):
'''
backup and recovery of test databases
'''
db_name = "test_http_test_backup_restore"
self.create_database(db_name)
backup_name = "backup_test_http_test_backup_restore"
self.backup_database(db_name, backup_name)
self.drop_database(db_name)
self.restore_database(backup_name, db_name)
self.show_database(db_name, {
"error_code": 0,
"database_name": db_name,
})
# delete database
self.drop_database(db_name)
self.clear_http_database()