MCPcopy Index your code
hub / github.com/apache/cassandra-python-driver / setup

Function setup

benchmarks/base.py:91–126  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

89
90
91def setup(options):
92 log.info("Using 'cassandra' package from %s", cassandra.__path__)
93
94 cluster = Cluster(options.hosts, schema_metadata_enabled=False, token_metadata_enabled=False)
95 try:
96 session = cluster.connect()
97
98 log.debug("Creating keyspace...")
99 try:
100 session.execute("""
101 CREATE KEYSPACE %s
102 WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '2' }
103 """ % options.keyspace)
104
105 log.debug("Setting keyspace...")
106 except cassandra.AlreadyExists:
107 log.debug("Keyspace already exists")
108
109 session.set_keyspace(options.keyspace)
110
111 log.debug("Creating table...")
112 create_table_query = """
113 CREATE TABLE {0} (
114 thekey text,
115 """
116 for i in range(options.num_columns):
117 create_table_query += "col{0} {1},\n".format(i, options.column_type)
118 create_table_query += "PRIMARY KEY (thekey))"
119
120 try:
121 session.execute(create_table_query.format(TABLE))
122 except cassandra.AlreadyExists:
123 log.debug("Table already exists.")
124
125 finally:
126 cluster.shutdown()
127
128
129def teardown(options):

Callers 2

benchmarkFunction · 0.70
setup.pyFile · 0.50

Calls 5

connectMethod · 0.95
shutdownMethod · 0.95
ClusterClass · 0.90
set_keyspaceMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected