SlideShare a Scribd company logo
Making Cassandra fail for effective testing 1
@chbatey
Who am I?
• Based in London
• Technical Evangelist for Apache Cassandra
•Work on Stubbed Cassandra
•Help out Apache Cassandra users
• Previous: Cassandra backed apps at BSkyB
@chbatey
Agenda
• Realistic production environment
• How does Cassandra fail
- What should you do
• How to test your application
@chbatey
Motivation
• Continuous integration
• Continuous deployment
Commit code CI - tests
Deploy to
Test/UAT
Deploy to
realistic
preprod
Production
•Slower tests
•Exploratory tests
@chbatey
Production?
Application
@chbatey
Production?
ApplicationApplicationApplicationApplicationApplication
replication factor: 3
consistency: ONE
@chbatey
Production?
ApplicationApplicationApplicationApplicationApplication
ApplicationApplicationApplicationApplicationApplication
DC1
DC2
@chbatey
Read timeout
Application C
R1
R2
R3
C=QUROUM
Replication factor: 3
timeout
timeout
Read timeout
@chbatey
Read timeout
• Received acknowledgements
• Required acknowledgements
• Consistency level
• Data received
@chbatey
Write timeout
Application C
R1
R2
R3
C=QUROUM
Replication factor: 3
timeout
timeout
Write timeout
@chbatey
Retrying writes
• Cassandra does not roll back!
@chbatey
Write timeout
• Received acknowledgements
• Required acknowledgements
• Consistency level
• Batches are more complicated:
- WriteType: SIMPLE, BATCH, UNLOGGED_BATCH,
BATCH_LOG
@chbatey
Batches
• BATCH_LOG
- Timed out waiting for batch log replicas
- Retry if you like
• BATCH
- Written to batch log but timed out waiting for actual replica
- Will eventually be committed
@chbatey
Idempotent writes
• All writes are idempotent with the following exceptions:
- Counters
- lists
@chbatey
Unavailable
Application C
R1
R2
R3
C=QUROUM
Replication factor: 3
Unavailable
@chbatey
Unavailable
• Alive Replicas
• Required Replicas
• Consistency
@chbatey
Coordinator issue
Application C
R1
R2
R3
C=QUROUM
Replication factor: 3
???
Application level timeout
@chbatey
Unit & Integration testing
• Requirements: Quick to run, deterministic, not brittle!!
• Integration tests against an embedded Cassandra?
• cassandra-unit
• Integration tests against an external Cassandra running on developer / CI
machines
• CCM
• Regular install
• Docker
• Vagrant
@chbatey
Acceptance testing
Application
Acceptance
test
prepare data
verification
@chbatey
How do this if it was a HTTP service?
• Wiremock - mocking HTTP
services
• Saboteur - adding network
latency
If you want to build a fault tolerant application
you better test faults!
@chbatey
The options
• Disrupt traffic between driver and the cluster
• Disrupt traffic between Cassandra nodes
• Make Cassandra fail deterministically?
- Modify C* code
- Build a protocol level test double
@chbatey
The QueryHandler
@chbatey
KillrCassandra
@chbatey
Stubbed Cassandra
Application
Acceptance
test
prime on admin port (REST)
verification on admin port
Admin endpoints
Native protocol
@chbatey
Native protocol
@chbatey
Features
• Prime to respond to:
- Queries
- Prepared statements
- Batches
• Simulate all failures
• Disconnect clients
@chbatey
Activity Client
• Query
‣ Query text
‣ Consistency
• PrepreparedStatementExecution
‣ Prepared statement text
‣ Bound variables


public List<Query> retrieveQueries();
public List<PreparedStatementExecution> retrievePreparedStatementExecutions()


public List<Connection> retrieveConnections();
public void clearAllRecordedActivity()


@chbatey
Priming Client
• PrimingRequest
‣ Either a Query or PreparedStatement
‣ Query text or QueryPattern (regex)
‣ Consistency (default all)
‣ Result (success, read timeout, unavailable etc)
‣ Rows for successful response
‣ Column types for rows
‣ Variable types for prepared statements
public void prime(PrimingRequest prime)


public List<PrimingRequest> retrievePreparedPrimes()

public List<PrimingRequest> retrieveQueryPrimes()

public void clearAllPrimes()

public void clearQueryPrimes()

public void clearPreparedPrimes()





@chbatey
Example time
public interface PersonDao {

void connect();



void disconnect();



List<Person> retrievePeople();



List<Person> retrievePeopleByName(String firstName);



void storePerson(Person person);

}

@chbatey
Testing the connect method


//given

activityClient.clearConnections();

@chbatey
Testing the connect method


//given

activityClient.clearConnections();

//when

underTest.connect();

@chbatey
Testing the connect method


//given

activityClient.clearConnections();

//when

underTest.connect();

//then

assertTrue("Expected at least one connection",

activityClient.retrieveConnections().size() > 0);

@chbatey
Testing retrieve
public List<Person> retrieveNames() {

ResultSet result;

try {

Statement statement = new SimpleStatement("select * from person");

statement.setConsistencyLevel(ConsistencyLevel.QUORUM);

result = session.execute(statement);

} catch (ReadTimeoutException e) {

throw new UnableToRetrievePeopleException();

}



List<Person> people = new ArrayList<>();

for (Row row : result) {

people.add(new Person(row.getString("first_name"), row.getInt("age")));

}

return people;

}
@chbatey
Test the query + consistency


//given

Query expectedQuery = Query.builder()

.withQuery("select * from person")

.withConsistency("QUORUM").build();

@chbatey
Test the query + consistency


//given

Query expectedQuery = Query.builder()

.withQuery("select * from person")

.withConsistency("QUORUM").build();



//when

underTest.retrievePeople();



@chbatey
Test the query + consistency


//given

Query expectedQuery = Query.builder()

.withQuery("select * from person")

.withConsistency("QUORUM").build();



//when

underTest.retrievePeople();



//then

assertThat(activityClient.retrieveQueries(), containsQuery(expectedQuery));
Hamcrest matcher
@chbatey
Testing behaviour


Map<String, ?> row = ImmutableMap.of(

"first_name", "Chris",

"last_name", "Batey",

"age", 29);

primingClient.prime(PrimingRequest.queryBuilder()

.withQuery("select * from person")

.withColumnTypes(column("age", PrimitiveType.INT))

.withRows(row)

.build());



Each Cassandra Row == Java map
Tell Scassandra about your schema
@chbatey
Testing behaviour


Map<String, ?> row = ImmutableMap.of(

"first_name", "Chris",

"last_name", "Batey",

"age", 29);

primingClient.prime(PrimingRequest.queryBuilder()

.withQuery("select * from person")

.withColumnTypes(column("age", PrimitiveType.INT))

.withRows(row)

.build());



//when

List<Person> names = underTest.retrievePeople();



Each Cassandra Row == Java map
Tell Scassandra about your schema
@chbatey
Testing behaviour


Map<String, ?> row = ImmutableMap.of(

"first_name", "Chris",

"last_name", "Batey",

"age", 29);

primingClient.prime(PrimingRequest.queryBuilder()

.withQuery("select * from person")

.withColumnTypes(column("age", PrimitiveType.INT))

.withRows(row)

.build());



//when

List<Person> names = underTest.retrievePeople();



//then

assertEquals(1, names.size());

assertEquals(“Chris Batey", names.get(0).getName());

Each Cassandra Row == Java map
Tell Scassandra about your schema
@chbatey
Testing errors
// given

PrimingRequest primeReadRequestTimeout = PrimingRequest.queryBuilder()

.withQuery("select * from person")

.withResult(Result.read_request_timeout)

.build();

primingClient.prime(primeReadRequestTimeout);



@chbatey
Testing errors
@Test(expected = UnableToRetrievePeopleException.class)

public void testHandlingOfReadRequestTimeout() throws Exception {

// given

PrimingRequest primeReadRequestTimeout = PrimingRequest.queryBuilder()

.withQuery("select * from person")

.withResult(Result.read_request_timeout)

.build();

primingClient.prime(primeReadRequestTimeout);



//when

underTest.retrievePeople();



//then

} Expecting custom exception
@chbatey
Testing retries
@Override

public RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses,
int receivedResponses, boolean dataRetrieved, int nbRetry) {

if (nbRetry < configuredRetries) {

return RetryDecision.retry(cl);

} else {

return RetryDecision.rethrow();

}

}
@chbatey
Testing retries


PrimingRequest readTimeoutPrime = PrimingRequest.queryBuilder()

.withQuery("select * from person")

.withResult(Result.read_request_timeout)

.build();

primingClient.prime(readTimeoutPrime);
@chbatey
Testing retries


PrimingRequest readTimeoutPrime = PrimingRequest.queryBuilder()

.withQuery("select * from person")

.withResult(Result.read_request_timeout)

.build();

primingClient.prime(readTimeoutPrime);



try {

underTest.retrievePeople();

} catch (UnableToRetrievePeopleException e) {

}
@chbatey
Testing retries


PrimingRequest readTimeoutPrime = PrimingRequest.queryBuilder()

.withQuery("select * from person")

.withResult(Result.read_request_timeout)

.build();

primingClient.prime(readTimeoutPrime);



try {

underTest.retrievePeople();

} catch (UnableToRetrievePeopleException e) {

}



assertEquals(CONFIGURED_RETRIES + 1, activityClient.retrieveQueries().size());

@chbatey
Coordinator issue
Application C
R1
R2
R3
C=QUROUM
Replication factor: 3
???
@chbatey
Testing slow connection


// given

PrimingRequest preparedStatementPrime = PrimingRequest.preparedStatementBuilder()

.withQueryPattern("insert into person.*")

.withVariableTypes(VARCHAR, INT, list(TIMESTAMP))

.withFixedDelay(1000)

.build();

primingClient.prime(preparedStatementPrime);

Delays the response by 1000ms
@chbatey
Testing slow connection
@Test(timeout = 500, expected = UnableToSavePersonException.class)

public void testThatSlowQueriesTimeout() throws Exception {

// given

PrimingRequest preparedStatementPrime = PrimingRequest.preparedStatementBuilder()

.withQueryPattern("insert into person.*")

.withVariableTypes(VARCHAR, INT, list(TIMESTAMP))

.withFixedDelay(1000)

.build();

primingClient.prime(preparedStatementPrime);

underTest.connect();



underTest.storePerson(new Person("Christopher", 29, Collections.emptyList()));

}
Delays the response by 1000ms
Expect a custom exception
@chbatey
Separate process
Application
Acceptance
test
prime on admin port (REST)
verification on admin port
Admin endpoints
Native protocol
@chbatey
How do I get it?
•It is on maven central
•Or go to www.scassandra.org
•Executable jar + REST API
• https://github.com/scassandra/scassandra-server
<dependency>

<groupId>org.scassandra</groupId>

<artifactId>java-client</artifactId>

<version>0.9.1</version>

<scope>test</scope>

</dependency>
@chbatey
Summary
• Testing is good - I want more tools to help me
• Existing tools for Cassandra are great at happy path
scenarios
• Stubbed Cassandra allows testing of edge cases
@chbatey
The end - Questions?
www.scassandra.org
http://christopher-batey.blogspot.co.uk/
Ping me on twitter @chbatey

More Related Content

PDF
Prometheus
PPTX
Estimation
PPTX
Introduction and HDInsight best practices
KEY
Concurrent Programming Using the Disruptor
PPT
Devops at Netflix (re:Invent)
PDF
What's New in Apache Hive
PPTX
Github in Action
PDF
The Four Keys - Measuring DevOps Success
Prometheus
Estimation
Introduction and HDInsight best practices
Concurrent Programming Using the Disruptor
Devops at Netflix (re:Invent)
What's New in Apache Hive
Github in Action
The Four Keys - Measuring DevOps Success

What's hot (20)

PPTX
Agile Transformation: People, Process and Tools to Make Your Transformation S...
PPTX
Centralized log-management-with-elastic-stack
PDF
Definition of Ready (XP2011)
ODP
Monitoring With Prometheus
PDF
Jenkins-CI
PDF
Story Points Explained
PDF
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
PDF
0-60: Tesla's Streaming Data Platform ( Jesse Yates, Tesla) Kafka Summit SF 2019
PPTX
User story slicing
PPTX
Backup and Disaster Recovery in Hadoop
PDF
Event Driven-Architecture from a Scalability perspective
PPTX
Trunk based development and Canary deployment
PPT
Effective Spring Transaction Management
PPTX
User Story Mapping Workshop
PPSX
Agile, User Stories, Domain Driven Design
PDF
Scaling containers with keda
PDF
Scaling Twitter
PDF
Integration Patterns and Anti-Patterns for Microservices Architectures
PPT
Monitoring using Prometheus and Grafana
PPTX
Achieving Elite and High Performance DevOps Using DORA Metrics
Agile Transformation: People, Process and Tools to Make Your Transformation S...
Centralized log-management-with-elastic-stack
Definition of Ready (XP2011)
Monitoring With Prometheus
Jenkins-CI
Story Points Explained
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
0-60: Tesla's Streaming Data Platform ( Jesse Yates, Tesla) Kafka Summit SF 2019
User story slicing
Backup and Disaster Recovery in Hadoop
Event Driven-Architecture from a Scalability perspective
Trunk based development and Canary deployment
Effective Spring Transaction Management
User Story Mapping Workshop
Agile, User Stories, Domain Driven Design
Scaling containers with keda
Scaling Twitter
Integration Patterns and Anti-Patterns for Microservices Architectures
Monitoring using Prometheus and Grafana
Achieving Elite and High Performance DevOps Using DORA Metrics
Ad

Viewers also liked (20)

PDF
Cassandra is great but how do I test my application?
PDF
cassandra
PDF
Battery Ventures: Simulating and Visualizing Large Scale Cassandra Deployments
PDF
DataStax: Old Dogs, New Tricks. Teaching your Relational DBA to fetch
PDF
DataStax: How to Roll Cassandra into Production Without Losing your Health, M...
PDF
Cassandra 3.0 Awesomeness
PDF
Crash course intro to cassandra
PDF
Cassandra Core Concepts
PDF
DataStax & O'Reilly Media: Large Scale Data Analytics with Spark and Cassandr...
PDF
DataStax: 7 Deadly Sins for Cassandra Ops
PDF
Diagnosing Problems in Production (Nov 2015)
PDF
Instaclustr: Securing Cassandra
PDF
Diagnosing Problems in Production - Cassandra
PDF
Enter the Snake Pit for Fast and Easy Spark
PDF
Spark and cassandra (Hulu Talk)
PDF
DataStax: Enabling Search in your Cassandra Application with DataStax Enterprise
PDF
Azure + DataStax Enterprise Powers Office 365 Per User Store
PDF
Cake Solutions: Cassandra as event sourced journal for big data analytics
PDF
Cassandra meetup slides - Oct 15 Santa Monica Coloft
PDF
Cassandra Core Concepts - Cassandra Day Toronto
Cassandra is great but how do I test my application?
cassandra
Battery Ventures: Simulating and Visualizing Large Scale Cassandra Deployments
DataStax: Old Dogs, New Tricks. Teaching your Relational DBA to fetch
DataStax: How to Roll Cassandra into Production Without Losing your Health, M...
Cassandra 3.0 Awesomeness
Crash course intro to cassandra
Cassandra Core Concepts
DataStax & O'Reilly Media: Large Scale Data Analytics with Spark and Cassandr...
DataStax: 7 Deadly Sins for Cassandra Ops
Diagnosing Problems in Production (Nov 2015)
Instaclustr: Securing Cassandra
Diagnosing Problems in Production - Cassandra
Enter the Snake Pit for Fast and Easy Spark
Spark and cassandra (Hulu Talk)
DataStax: Enabling Search in your Cassandra Application with DataStax Enterprise
Azure + DataStax Enterprise Powers Office 365 Per User Store
Cake Solutions: Cassandra as event sourced journal for big data analytics
Cassandra meetup slides - Oct 15 Santa Monica Coloft
Cassandra Core Concepts - Cassandra Day Toronto
Ad

Similar to DataStax: Making Cassandra Fail (for effective testing) (20)

PDF
LA Cassandra Day 2015 - Testing Cassandra
PDF
Cassandra Summit EU 2014 - Testing Cassandra Applications
PDF
Data Consistency Workshop — Oslo Cassandra Users Oct 8, 2013
PDF
DataStax: Ramping up Cassandra QA
PPT
Apache cassandra
PDF
Cassandra drivers and libraries
PPTX
Cassandra Java APIs Old and New – A Comparison
PDF
How you can contribute to Apache Cassandra
PPTX
Cassandra Overview
PDF
Introduction to Apache Cassandra
PPTX
Performance Testing: Scylla vs. Cassandra vs. Datastax
PDF
Testing Cassandra Guarantees under Diverse Failure Modes with Jepsen
PDF
DataStax: Testing Cassandra Guarantees Under Diverse Failure Modes With Jepsen
PDF
LJC: Fault tolerance with Apache Cassandra
PDF
Cassandra: An Alien Technology That's not so Alien
PDF
NYC Cassandra Day - Java Intro
PDF
Software Development with Apache Cassandra
PDF
Successful Software Development with Apache Cassandra
KEY
Oscon 2012 tdd_cassandra
PPTX
DataStax NYC Java Meetup: Cassandra with Java
LA Cassandra Day 2015 - Testing Cassandra
Cassandra Summit EU 2014 - Testing Cassandra Applications
Data Consistency Workshop — Oslo Cassandra Users Oct 8, 2013
DataStax: Ramping up Cassandra QA
Apache cassandra
Cassandra drivers and libraries
Cassandra Java APIs Old and New – A Comparison
How you can contribute to Apache Cassandra
Cassandra Overview
Introduction to Apache Cassandra
Performance Testing: Scylla vs. Cassandra vs. Datastax
Testing Cassandra Guarantees under Diverse Failure Modes with Jepsen
DataStax: Testing Cassandra Guarantees Under Diverse Failure Modes With Jepsen
LJC: Fault tolerance with Apache Cassandra
Cassandra: An Alien Technology That's not so Alien
NYC Cassandra Day - Java Intro
Software Development with Apache Cassandra
Successful Software Development with Apache Cassandra
Oscon 2012 tdd_cassandra
DataStax NYC Java Meetup: Cassandra with Java

More from DataStax Academy (20)

PDF
Forrester CXNYC 2017 - Delivering great real-time cx is a true craft
PPTX
Introduction to DataStax Enterprise Graph Database
PPTX
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
PPTX
Cassandra on Docker @ Walmart Labs
PDF
Cassandra 3.0 Data Modeling
PPTX
Cassandra Adoption on Cisco UCS & Open stack
PDF
Data Modeling for Apache Cassandra
PDF
Coursera Cassandra Driver
PDF
Production Ready Cassandra
PDF
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
PPTX
Cassandra @ Sony: The good, the bad, and the ugly part 1
PPTX
Cassandra @ Sony: The good, the bad, and the ugly part 2
PDF
Standing Up Your First Cluster
PDF
Real Time Analytics with Dse
PDF
Introduction to Data Modeling with Apache Cassandra
PDF
Cassandra Core Concepts
PPTX
Enabling Search in your Cassandra Application with DataStax Enterprise
PPTX
Bad Habits Die Hard
PDF
Advanced Data Modeling with Apache Cassandra
PDF
Advanced Cassandra
Forrester CXNYC 2017 - Delivering great real-time cx is a true craft
Introduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
Cassandra on Docker @ Walmart Labs
Cassandra 3.0 Data Modeling
Cassandra Adoption on Cisco UCS & Open stack
Data Modeling for Apache Cassandra
Coursera Cassandra Driver
Production Ready Cassandra
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Sony: The good, the bad, and the ugly part 1
Cassandra @ Sony: The good, the bad, and the ugly part 2
Standing Up Your First Cluster
Real Time Analytics with Dse
Introduction to Data Modeling with Apache Cassandra
Cassandra Core Concepts
Enabling Search in your Cassandra Application with DataStax Enterprise
Bad Habits Die Hard
Advanced Data Modeling with Apache Cassandra
Advanced Cassandra

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Cloud computing and distributed systems.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles - August'25 Week I
Reach Out and Touch Someone: Haptics and Empathic Computing
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Cloud computing and distributed systems.
Diabetes mellitus diagnosis method based random forest with bat algorithm
The Rise and Fall of 3GPP – Time for a Sabbatical?
Building Integrated photovoltaic BIPV_UPV.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
Digital-Transformation-Roadmap-for-Companies.pptx
Review of recent advances in non-invasive hemoglobin estimation
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf

DataStax: Making Cassandra Fail (for effective testing)