TechnologyFebruary 19, 2016

How to Write a Dtest

Philip Thompson
Philip Thompson
How to Write a Dtest

cluster = self.cluster

cluster.populate(3).start(wait_for_binary_proto=True)

cluster = self.cluster

cluster.set_configuration_options(values={'hinted_handoff_enabled': False}) # Set a cassandra.yaml option

cluster.populate([2, 2]).start(wait_for_binary_proto=True) # A four node cluster. Two nodes in each of two datacenters

def cql_connection(self, node)

def exclusive_cql_connection(self, node)

def patient_cql_connection(self, node)

def patient_exclusive_cql_connection(self, node)

cluster = self.cluster

cluster.populate(3).start(wait_for_binary_proto=True)

node1, node2, node3 = cluster.nodelist()

session = self.patient_cql_connection(node1)

session.execute("CREATE KEYSPACE ks WITH replication = { 'class':'SimpleStrategy', 'replication_factor':1} AND DURABLE_WRITES = true")

session.execute("USE ks")

session.execute("CREATE TABLE t (id int PRIMARY KEY, v int)")

session.execute("INSERT INTO t (id, v) VALUES (1, 2)")

rows = session.execute("SELECT * FROM t")

node1, node2, node3 = cluster.nodelist()

node1.stress(['write', 'n=1M', '-rate', 'threads=10'])

node2.decommission()

node3.repair()

from assertions import assert_one

session.execute("CREATE KEYSPACE ks WITH replication = { 'class':'SimpleStrategy', 'replication_factor':1} AND DURABLE_WRITES = true")

session.execute("USE ks")

session.execute("CREATE TABLE t (id int PRIMARY KEY, v int)")

session.execute("INSERT INTO t (id, v) VALUES (1, 2)")

assert_one(session, "SELECT * FROM t", [1, 2])

rows = list(session.execute("SELECT * FROM t"))

self.assertEqual(rows[0], 1)

self.assertEqual(rows[1], 2)

rows = list(session.execute("SELECT * FROM t"))

assert rows[0] == 1 # Do not do this.

assert rows[1] == 2

Discover more
Python
Share

Open-Source,
Scale-Out, Cloud-Native
NoSQL Database

Astra DB is scale-out NoSQL built on Apache Cassandra™. Handle any workload with zero downtime and zero lock-in at global scale.

Company
Resources
Cloud Partners

DataStax, is a registered trademark of DataStax, Inc.. Apache, Apache Cassandra, Cassandra, Apache Pulsar, and Pulsar are either registered trademarks or trademarks of the Apache Software Foundation.

United States