Newer
Older
# --coding:utf-8--
#
# Copyright (c) 2020 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
import time
import re
from tests.common.nebula_test_suite import NebulaTestSuite
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
class TestSpace(NebulaTestSuite):
@classmethod
def prepare(self):
pass
@classmethod
def cleanup(self):
pass
def test_space(self):
# not exist
resp = self.client.execute('USE not_exist_space')
self.check_resp_failed(resp)
# with default options
resp = self.client.execute('CREATE SPACE space_with_default_options')
self.check_resp_succeeded(resp)
# check result
resp = self.client.execute_query('DESC SPACE space_with_default_options')
expect_result = [['space_with_default_options', 100, 1, 8, 'utf8', 'utf8_bin']]
self.check_result(resp, expect_result, {0})
# drop space
resp = self.client.execute('DROP SPACE space_with_default_options')
self.check_resp_succeeded(resp)
# create space succeeded
resp = self.client.execute('CREATE SPACE default_space(partition_num=9, replica_factor=1)')
self.check_resp_succeeded(resp)
# show spaces
resp = self.client.execute_query('SHOW SPACES')
self.check_resp_succeeded(resp)
self.search_result(resp, [['default_space']])
# desc space
resp = self.client.execute_query('DESC SPACE default_space')
self.check_resp_succeeded(resp)
expect_result = [['default_space', 9, 1, 8, 'utf8', 'utf8_bin']]
self.check_result(resp, expect_result, {0})
# show create space
resp = self.client.execute_query('SHOW CREATE SPACE default_space')
self.check_resp_succeeded(resp)
create_space_str = 'CREATE SPACE `default_space` ('\
'partition_num = 9, '\
'replica_factor = 1, '\
'vid_size = 8, '\
'charset = utf8, '\
'collate = utf8_bin)';
expect_result = [['default_space', create_space_str]]
self.check_result(resp, expect_result)
# check result from show create
resp = self.client.execute('DROP SPACE default_space')
self.check_resp_succeeded(resp)
resp = self.client.execute(create_space_str)
self.check_resp_succeeded(resp)
resp = self.client.execute_query('SHOW SPACES')
self.check_resp_succeeded(resp)
# 2.0 when use space, the validator get from cache
time.sleep(self.delay)
resp = self.client.execute("USE default_space")
self.check_resp_succeeded(resp)
def test_charset_collate(self):
resp = self.client.execute('CREATE SPACE space_charset_collate (partition_num=9, '
'replica_factor=1, charset=utf8, collate=utf8_bin)')
self.check_resp_succeeded(resp)
resp = self.client.execute_query('DESC SPACE space_charset_collate')
self.check_resp_succeeded(resp)
expect_result = [['space_charset_collate', 9, 1, 8, 'utf8', 'utf8_bin']]
self.check_result(resp, expect_result, {0})
# drop space
resp = self.client.execute('DROP SPACE space_charset_collate')
self.check_resp_succeeded(resp)
resp = self.client.execute('CREATE SPACE space_charset (partition_num=9, '
'replica_factor=1, charset=utf8)')
self.check_resp_succeeded(resp)
resp = self.client.execute_query('DESC SPACE space_charset')
self.check_resp_succeeded(resp)
expect_result = [['space_charset', 9, 1, 8, 'utf8', 'utf8_bin']]
self.check_result(resp, expect_result, {0})
# drop space
resp = self.client.execute('DROP SPACE space_charset')
self.check_resp_succeeded(resp)
resp = self.client.execute('CREATE SPACE space_collate (partition_num=9, '
'replica_factor=1, collate=utf8_bin)')
self.check_resp_succeeded(resp)
resp = self.client.execute_query('DESC SPACE space_collate')
self.check_resp_succeeded(resp)
expect_result = [['space_collate', 9, 1, 8, 'utf8', 'utf8_bin']]
self.check_result(resp, expect_result, {0})
# drop space
resp = self.client.execute('DROP SPACE space_collate')
self.check_resp_succeeded(resp)
# not supported collate
resp = self.client.execute('CREATE SPACE space_charset_collate_nomatch (partition_num=9, '
'replica_factor=1, charset = utf8, collate=gbk_bin)')
self.check_resp_failed(resp)
# not supported charset
resp = self.client.execute_query('CREATE SPACE space_charset_collate_nomatch (partition_num=9, '
'replica_factor=1, charset = gbk, collate=utf8_bin)')
self.check_resp_failed(resp)
# not supported charset
resp = self.client.execute_query('CREATE SPACE space_illegal_charset (partition_num=9, '
'replica_factor=1, charset = gbk)')
self.check_resp_failed(resp)
# not supported collate
resp = self.client.execute_query('CREATE SPACE space_illegal_collate (partition_num=9, '
'replica_factor=1, collate = gbk_bin)')
self.check_resp_failed(resp)
resp = self.client.execute('CREATE SPACE space_illegal_collate (partition_num=9, '
'replica_factor=1, collate = gbk_bin)')
self.check_resp_failed(resp)
resp = self.client.execute('CREATE SPACE space_capital (partition_num=9, '
'replica_factor=1, charset=UTF8, collate=UTF8_bin)')
self.check_resp_succeeded(resp)
resp = self.client.execute_query('DESC SPACE space_capital')
self.check_resp_succeeded(resp)
expect_result = [['space_capital', 9, 1, 8, 'utf8', 'utf8_bin']]
self.check_result(resp, expect_result, {0})
# drop space
resp = self.client.execute('DROP SPACE space_capital')
self.check_resp_succeeded(resp)
def test_if_not_exists_and_if_exist(self):
# exist then failed
resp = self.client.execute('CREATE SPACE default_space')
self.check_resp_failed(resp)
# exist but success
resp = self.client.execute('CREATE SPACE IF NOT EXISTS default_space')
self.check_resp_succeeded(resp)
# not exist but success
resp = self.client.execute('DROP SPACE IF EXISTS not_exist_space')
self.check_resp_succeeded(resp)
# not exist then failed
resp = self.client.execute('DROP SPACE not_exist_space')
self.check_resp_failed(resp)
resp = self.client.execute('CREATE SPACE exist_space')
self.check_resp_succeeded(resp)
resp = self.client.execute('DROP SPACE IF EXISTS exist_space')
self.check_resp_succeeded(resp)
def test_drop_space(self):
resp = self.client.execute_query('SHOW SPACES')
self.check_resp_succeeded(resp)
expect_result = [['default_space']]
self.search_result(resp, expect_result)
resp = self.client.execute('DROP SPACE default_space')
self.check_resp_succeeded(resp)
resp = self.client.execute_query('SHOW SPACES')
self.check_resp_succeeded(resp)
expect_result = []
self.check_result(resp, expect_result)