mirror of https://github.com/apache/cassandra
Fixed cqlshlib.test.remove_test_db
patch by Stefania Alborghetti; reviewed by Philip Thompson for CASSANDRA-12214
This commit is contained in:
parent
f0d1d75ebf
commit
e8186fe390
|
|
@ -1,4 +1,5 @@
|
||||||
2.2.8
|
2.2.8
|
||||||
|
* Fixed cqlshlib.test.remove_test_db (CASSANDRA-12214)
|
||||||
* Synchronize ThriftServer::stop() (CASSANDRA-12105)
|
* Synchronize ThriftServer::stop() (CASSANDRA-12105)
|
||||||
* Use dedicated thread for JMX notifications (CASSANDRA-12146)
|
* Use dedicated thread for JMX notifications (CASSANDRA-12146)
|
||||||
* NPE when trying to remove purgable tombstones from result (CASSANDRA-12143)
|
* NPE when trying to remove purgable tombstones from result (CASSANDRA-12143)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from .cassconnect import create_test_db, remove_test_db
|
from .cassconnect import create_db, remove_db
|
||||||
|
|
||||||
setUp = create_test_db
|
setUp = create_db
|
||||||
tearDown = remove_test_db
|
tearDown = remove_db
|
||||||
|
|
|
||||||
|
|
@ -37,15 +37,15 @@ def get_cassandra_cursor(cql_version=cqlsh.DEFAULT_CQLVER):
|
||||||
|
|
||||||
TEST_KEYSPACES_CREATED = []
|
TEST_KEYSPACES_CREATED = []
|
||||||
|
|
||||||
def get_test_keyspace():
|
def get_keyspace():
|
||||||
return TEST_KEYSPACES_CREATED[-1]
|
return None if len(TEST_KEYSPACES_CREATED) == 0 else TEST_KEYSPACES_CREATED[-1]
|
||||||
|
|
||||||
def make_test_ks_name():
|
def make_ks_name():
|
||||||
# abuse mktemp to get a quick random-ish name
|
# abuse mktemp to get a quick random-ish name
|
||||||
return os.path.basename(tempfile.mktemp(prefix='CqlshTests_'))
|
return os.path.basename(tempfile.mktemp(prefix='CqlshTests_'))
|
||||||
|
|
||||||
def create_test_keyspace(cursor):
|
def create_keyspace(cursor):
|
||||||
ksname = make_test_ks_name()
|
ksname = make_ks_name()
|
||||||
qksname = quote_name(ksname)
|
qksname = quote_name(ksname)
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
CREATE KEYSPACE %s WITH replication =
|
CREATE KEYSPACE %s WITH replication =
|
||||||
|
|
@ -72,13 +72,13 @@ def execute_cql_file(cursor, fname):
|
||||||
with open(fname) as f:
|
with open(fname) as f:
|
||||||
return execute_cql_commands(cursor, f.read())
|
return execute_cql_commands(cursor, f.read())
|
||||||
|
|
||||||
def create_test_db():
|
def create_db():
|
||||||
with cassandra_cursor(ks=None) as c:
|
with cassandra_cursor(ks=None) as c:
|
||||||
k = create_test_keyspace(c)
|
k = create_keyspace(c)
|
||||||
execute_cql_file(c, test_keyspace_init)
|
execute_cql_file(c, test_keyspace_init)
|
||||||
return k
|
return k
|
||||||
|
|
||||||
def remove_test_db():
|
def remove_db():
|
||||||
with cassandra_cursor(ks=None) as c:
|
with cassandra_cursor(ks=None) as c:
|
||||||
c.execute('DROP KEYSPACE %s' % quote_name(TEST_KEYSPACES_CREATED.pop(-1)))
|
c.execute('DROP KEYSPACE %s' % quote_name(TEST_KEYSPACES_CREATED.pop(-1)))
|
||||||
|
|
||||||
|
|
@ -112,7 +112,7 @@ def cassandra_cursor(cql_version=None, ks=''):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if ks == '':
|
if ks == '':
|
||||||
ks = get_test_keyspace()
|
ks = get_keyspace()
|
||||||
conn = get_cassandra_connection(cql_version=cql_version)
|
conn = get_cassandra_connection(cql_version=cql_version)
|
||||||
try:
|
try:
|
||||||
c = conn.connect(ks)
|
c = conn.connect(ks)
|
||||||
|
|
@ -131,10 +131,10 @@ def testrun_cqlsh(keyspace=DEFAULTVAL, **kwargs):
|
||||||
# use a positive default sentinel so that keyspace=None can be used
|
# use a positive default sentinel so that keyspace=None can be used
|
||||||
# to override the default behavior
|
# to override the default behavior
|
||||||
if keyspace is DEFAULTVAL:
|
if keyspace is DEFAULTVAL:
|
||||||
keyspace = get_test_keyspace()
|
keyspace = get_keyspace()
|
||||||
return run_cqlsh(keyspace=keyspace, **kwargs)
|
return run_cqlsh(keyspace=keyspace, **kwargs)
|
||||||
|
|
||||||
def testcall_cqlsh(keyspace=None, **kwargs):
|
def testcall_cqlsh(keyspace=None, **kwargs):
|
||||||
if keyspace is None:
|
if keyspace is None:
|
||||||
keyspace = get_test_keyspace()
|
keyspace = get_keyspace()
|
||||||
return call_cqlsh(keyspace=keyspace, **kwargs)
|
return call_cqlsh(keyspace=keyspace, **kwargs)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import re
|
||||||
from itertools import izip
|
from itertools import izip
|
||||||
from .basecase import (BaseTestCase, cqlshlog, dedent, at_a_time, cqlsh,
|
from .basecase import (BaseTestCase, cqlshlog, dedent, at_a_time, cqlsh,
|
||||||
TEST_HOST, TEST_PORT)
|
TEST_HOST, TEST_PORT)
|
||||||
from .cassconnect import (get_test_keyspace, testrun_cqlsh, testcall_cqlsh,
|
from .cassconnect import (get_keyspace, testrun_cqlsh, testcall_cqlsh,
|
||||||
cassandra_cursor, split_cql_commands, quote_name)
|
cassandra_cursor, split_cql_commands, quote_name)
|
||||||
from .ansi_colors import (ColoredText, lookup_colorcode, lookup_colorname,
|
from .ansi_colors import (ColoredText, lookup_colorcode, lookup_colorname,
|
||||||
lookup_colorletter, ansi_seq)
|
lookup_colorletter, ansi_seq)
|
||||||
|
|
@ -534,10 +534,10 @@ class TestCqlshOutput(BaseTestCase):
|
||||||
output = c.read_to_next_prompt().replace('\r\n', '\n')
|
output = c.read_to_next_prompt().replace('\r\n', '\n')
|
||||||
self.assertTrue(output.endswith('cqlsh> '))
|
self.assertTrue(output.endswith('cqlsh> '))
|
||||||
|
|
||||||
cmd = "USE \"%s\";\n" % get_test_keyspace().replace('"', '""')
|
cmd = "USE \"%s\";\n" % get_keyspace().replace('"', '""')
|
||||||
c.send(cmd)
|
c.send(cmd)
|
||||||
output = c.read_to_next_prompt().replace('\r\n', '\n')
|
output = c.read_to_next_prompt().replace('\r\n', '\n')
|
||||||
self.assertTrue(output.endswith('cqlsh:%s> ' % (get_test_keyspace())))
|
self.assertTrue(output.endswith('cqlsh:%s> ' % (get_keyspace())))
|
||||||
|
|
||||||
c.send('use system;\n')
|
c.send('use system;\n')
|
||||||
output = c.read_to_next_prompt().replace('\r\n', '\n')
|
output = c.read_to_next_prompt().replace('\r\n', '\n')
|
||||||
|
|
@ -561,7 +561,7 @@ class TestCqlshOutput(BaseTestCase):
|
||||||
def test_describe_keyspace_output(self):
|
def test_describe_keyspace_output(self):
|
||||||
fullcqlver = cqlsh.DEFAULT_CQLVER
|
fullcqlver = cqlsh.DEFAULT_CQLVER
|
||||||
with testrun_cqlsh(tty=True, cqlver=fullcqlver) as c:
|
with testrun_cqlsh(tty=True, cqlver=fullcqlver) as c:
|
||||||
ks = get_test_keyspace()
|
ks = get_keyspace()
|
||||||
qks = quote_name(ks)
|
qks = quote_name(ks)
|
||||||
for cmd in ('describe keyspace', 'desc keyspace'):
|
for cmd in ('describe keyspace', 'desc keyspace'):
|
||||||
for givename in ('system', '', qks):
|
for givename in ('system', '', qks):
|
||||||
|
|
@ -632,7 +632,7 @@ class TestCqlshOutput(BaseTestCase):
|
||||||
AND read_repair_chance = 0.0
|
AND read_repair_chance = 0.0
|
||||||
AND speculative_retry = '99.0PERCENTILE';
|
AND speculative_retry = '99.0PERCENTILE';
|
||||||
|
|
||||||
""" % quote_name(get_test_keyspace()))
|
""" % quote_name(get_keyspace()))
|
||||||
|
|
||||||
with testrun_cqlsh(tty=True, cqlver=cqlsh.DEFAULT_CQLVER) as c:
|
with testrun_cqlsh(tty=True, cqlver=cqlsh.DEFAULT_CQLVER) as c:
|
||||||
for cmdword in ('describe table', 'desc columnfamily'):
|
for cmdword in ('describe table', 'desc columnfamily'):
|
||||||
|
|
@ -650,7 +650,7 @@ class TestCqlshOutput(BaseTestCase):
|
||||||
\n
|
\n
|
||||||
'''
|
'''
|
||||||
|
|
||||||
ks = get_test_keyspace()
|
ks = get_keyspace()
|
||||||
|
|
||||||
with testrun_cqlsh(tty=True, keyspace=None, cqlver=cqlsh.DEFAULT_CQLVER) as c:
|
with testrun_cqlsh(tty=True, keyspace=None, cqlver=cqlsh.DEFAULT_CQLVER) as c:
|
||||||
|
|
||||||
|
|
@ -711,7 +711,7 @@ class TestCqlshOutput(BaseTestCase):
|
||||||
self.assertNoHasColors(output)
|
self.assertNoHasColors(output)
|
||||||
self.assertRegexpMatches(output, output_re + '$')
|
self.assertRegexpMatches(output, output_re + '$')
|
||||||
|
|
||||||
c.send('USE %s;\n' % quote_name(get_test_keyspace()))
|
c.send('USE %s;\n' % quote_name(get_keyspace()))
|
||||||
c.read_to_next_prompt()
|
c.read_to_next_prompt()
|
||||||
|
|
||||||
for semicolon in ('', ';'):
|
for semicolon in ('', ';'):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue