Last active
April 5, 2017 13:28
-
-
Save beltran/f4a56ee8efa81cd93edd9a89db521cc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cassandra.io.eventletreactor import EventletConnection | |
from cassandra.io.geventreactor import GeventConnection | |
from cassandra.io.libevreactor import LibevConnection | |
from cassandra.io.asyncorereactor import AsyncoreConnection | |
connection_class = AsyncoreConnection | |
if connection_class == EventletConnection: | |
from eventlet import monkey_patch | |
monkey_patch() | |
elif connection_class == GeventConnection: | |
import gevent.monkey | |
gevent.monkey.patch_all() | |
from cassandra.cluster import Cluster | |
import logging | |
import time | |
log = logging.getLogger() | |
log.setLevel('DEBUG') | |
handler = logging.StreamHandler() | |
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s")) | |
log.addHandler(handler) | |
KEYSPACE = "testkeyspace" | |
max_in_flight = 2 | |
GeventConnection.max_in_flight = max_in_flight | |
LibevConnection.max_in_flight = max_in_flight | |
EventletConnection.max_in_flight = max_in_flight | |
AsyncoreConnection.max_in_flight = max_in_flight | |
#Only one cassandra node should be running if we want to reproduce this | |
cluster = Cluster(['127.0.0.1'], connection_class=connection_class) | |
session = cluster.connect() | |
while 1: | |
try: | |
session.execute(""" | |
CREATE KEYSPACE IF NOT EXISTS %s | |
WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '2' } | |
""" % KEYSPACE) | |
session.set_keyspace(KEYSPACE) | |
session.execute(""" | |
CREATE TABLE IF NOT EXISTS mytable ( | |
thekey text, | |
col1 text, | |
col2 text, | |
PRIMARY KEY (thekey, col1) | |
) | |
""") | |
session.execute("DROP KEYSPACE " + KEYSPACE) | |
except Exception as e: | |
logging.error(e, exc_info=True) | |
continue | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment