GithubHelp home page GithubHelp logo

bhanditz / cassandra-spy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ajermakovics/cassandra-spy

0.0 2.0 0.0 75 KB

Helper library to test error cases with Cassandra

License: Other

Kotlin 68.59% Java 31.41%

cassandra-spy's Introduction

Cassandra Spy Tests

Test error cases in code that uses Cassandra.

Features

CassandraSpy is a library that helps you:

  • Start embedded Cassandra
  • Throw exceptions for certain queries so you can test how your application handles them
  • Query embedded Cassandra

Exceptions are triggered in Cassandra server so your application code does not need to be changed and does not need to use mocks.

Cassandra-Spy is implemented as a JUnit rule but can also be used in other contexts like Cucumber scenarios.

Usage

public class IntegrationTest {
    
    @ClassRule
    public static CassandraSpy cassandra = new CassandraSpy();
    
    @Before
    public void initApp() {
        String host = cassandra.getHost();
        int port = cassandra.getPort(); // started on random port
        // init app with host and port
    }
    
    @Test
    public void testInsertFails() throws Exception {
        cassandra.when(inserts("users")).willThrow(writeTimeout());
        
        app.addUser(1, "user"); // does an insert
        
        // assert app does the right thing
    }
    
    @Test
    public void testSelectFails() throws Exception {
        cassandra.when(selects("users")).willThrow(readTimeout());
        
        app.getUser(1); // does a select
        
        // assert app does the right thing
    }
    
    @Test
    public void testInsertWithValuesFails() throws Exception {
        cassandra.when(inserts("users", 2, "user2")).willThrow(writeTimeout());
        
        app.addUser(1, "user"); // will not fail
        app.addUser(2, "user2"); // will fail
        // ...
    }
}

Also see the tests for an example with more details.

Download

https://jitpack.io/#org.andrejs/cassandra-spy

    repositories {
        maven { url 'https://jitpack.io' }
    }
    
    dependencies {
        compile 'org.andrejs:cassandra-spy:{version}'
    }

About

The project is inspired by:

It is written in Kotlin so is usable from other JVM languages.

License

Apache 2.0

cassandra-spy's People

Contributors

ajermakovics avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.