Page MenuHomePhabricator
Authored By
Eevans
Sep 18 2015, 8:40 PM
Size
1 KB
Referenced Files
None
Subscribers
None
#!/usr/bin/env python
from cassandra import ConsistencyLevel
from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import Cluster
from cassandra.policies import DCAwareRoundRobinPolicy
from cassandra.query import SimpleStatement
from uuid import UUID
import logging
import sys
logging.basicConfig(level=logging.INFO)
def data():
for ln in sys.stdin.readlines():
yield tuple(ln.strip().split())
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description="write/read test data")
parser.add_argument("hostname", type=str, help="Cassandra node hostname")
parser.add_argument("--local-dc", type=str, default="eqiad", help="Local datacenter")
args = parser.parse_args()
auth_provider = PlainTextAuthProvider(username='cassandra', password='cassandra')
policy = DCAwareRoundRobinPolicy(local_dc=args.local_dc)
cluster = Cluster([args.hostname], load_balancing_policy=policy, auth_provider=auth_provider)
session = cluster.connect("keyspace1")
if sys.argv[0].endswith('write'):
logging.info("writing...")
insert = session.prepare("INSERT INTO keyspace1.standard1 (id,val) VALUES (?, ?)")
insert.consistency_level = ConsistencyLevel.LOCAL_QUORUM
for (id, val) in data():
session.execute(insert, (UUID(id), int(val)))
logging.info("writing complete.")
else:
logging.info("verifying...")
select = session.prepare("SELECT val FROM keyspace1.standard1 WHERE id = ?")
select.consistency_level = ConsistencyLevel.LOCAL_QUORUM
for (id, val) in data():
row = session.execute(select, (UUID(id),))[0]
assert row.val == int(val)
logging.info("verification complete.")

File Metadata

Mime Type
text/x-python
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2630745
Default Alt Text
read (1 KB)

Event Timeline