Created
April 5, 2017 19:32
-
-
Save beltran/5467dad85766ec9915d3d8d76c921637 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 = LibevConnection | |
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" | |
cluster = Cluster(['127.0.0.1'], connection_class=connection_class) | |
session = cluster.connect() | |
session.execute(""" | |
CREATE KEYSPACE IF NOT EXISTS %s | |
WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '2' } | |
""" % KEYSPACE) | |
session.set_keyspace(KEYSPACE) | |
session.execute("DROP KEYSPACE " + KEYSPACE) | |
while 1: | |
try: | |
# If C* rebooted somewhere in this loop the driver doesn't come back | |
# The error is : | |
# ConnectionException: Problem while setting keyspace: InvalidRequest('Error from server: code=2200 [Invalid query] message="Keyspace \'testkeyspace\' does not exist"',) | |
log.info("Executing select in main") | |
future = session.execute_async("SELECT * FROM system.hints") | |
time.sleep(3) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment