test automation for nosql databases

Post on 10-May-2015

2.757 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

NoSQL Unit & Travis CI - Test automation for NoSQL databases

TRANSCRIPT

codecentric AG 1

NoSQL Unit & Travis CI Test Automation for NoSQL Databases

Tobias.Trelle@codecentric.de @tobiastrelle

codecentric AG 2

Tobias Trelle

Senior IT Consultant @ codecentric AG

Organizer of MongoDB User Group Düsseldorf

Author of „MongoDB – Ein praktischer Einstieg“

(dpunkt-Verlag)

codecentric AG 3

Agenda

Unit Testing NoSQL Unit Travis CI

codecentric AG 4

Unit Testing Your Persistence Layer

UI Layer

Database

Business Layer

Persistence Layer

DAO / Repository

Production

codecentric AG 5

Unit Testing Your Persistence Layer

UI Layer

Database

Business Layer

Persistence Layer

DAO / Repository

Production

UI Layer

EmbeddedDatabase

Business Layer

Persistence Layer

DAO / Repository

Unit Test

Unit Test

In Process

codecentric AG 6

Unit Testing Your Persistence Layer

Unit tests should …

be fast run in isolation load test data compare data

codecentric AG 7

NoSQL Unit

Github - https://github.com/lordofthejars/nosql-unit

codecentric AG 8

NoSQL Unit > Overview

Benefits

Database Lifecycle Management

Connection Management Load Test Data Compare Data

codecentric AG 9

NoSQL Unit > Overview

How does it work?

JUnit Extension JUnit Rules Annotations

codecentric AG 10

NoSQL Unit > Database Management Options

DatabaseNoSQL Unit

Embedded

JVM

Local Machine

Database

Database

Remote Machine

Managed Remote

codecentric AG 11

NoSQL Unit > Supported Databases

Database Type ImplLanguage

Embedded Managed / Remote

Cassandra Column Java ü üCouchDB Documen

tErlang --- ü

Elasticsearch

Document

Java ü üHBase Column Java ü üInfinispan In

MemoryJava ü ü

MongoDB Document

C++ fongo Mock üNeo4j Graph Java ü üRedis Key/Value C/C++ NoSQL Unit

Mockü

codecentric AG 12

NoSQL Unit > Lifecycle

NoSQL Unit Database Test Case

Loop overtests

Launch (optional)

Connect to

Load Test Data (optional)

Compare Data Sets (optional)

Shutdown (optional)

Run Test

Interact with

codecentric AG 13

NoSQL Unit > Redis Examplepublic class EmbeddedRedisTest {

@ClassRulepublic static EmbeddedRedis embeddedRedis = newEmbeddedRedisRule().build();

@Rulepublic RedisRule redisRule = newRedisRule().defaultEmbeddedRedis();

/** Unit under test. */private KeyValueRepository repository;

@Test @UsingDataSet( loadStrategy = LoadStrategyEnum.DELETE_ALL ) @ShouldMatchDataSet( location="keyvalue.json" ) public void should_insert_string() { // given KeyValueRepository repo = new KeyValueRepository( getJedisInstance() );

// when repo.setValue("hello", "redis");

// then: should match data }}

Create embedded instance once for all tests

Get connection once per test

Prepare data

Compare given and expected data after test

codecentric AG 14

NoSQL Unit > Redis Example > keyvalue.json

{ "data": [ {"simple": [ { "key":"hello", "value":"redis"} ]

} ]}

codecentric AG 15

NoSQL Unit > MongoDB Examplepublic class RemoteMongoDBTest {

@Rule // use already running "remote" instancepublic MongoDbRule mongoRule = new MongoDbRule( mongoDb().databaseName("test").host("localhost").port(27017) .build());

/** Unit under test. */private OrderRepository repository;

@Test @UsingDataSet(locations = "orders.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT) public void should_find_all_orders() { // given repository = createOrderRepository();

// when List<DBObject> orders = repository.findAll();

// then assertThat(orders, notNullValue()); assertThat(orders.size(), is(2)); }

Load test data from JSON file

codecentric AG 16

NoSQL Unit > MongoDB Example > orders.json

{ "orders": [ { "type": 4711, "desc": "1st order" }, { "type": 42, "desc": "2nd order" } ]}

codecentric AG 17

NoSQL Unit > MongoDB > Advanced Features

NoSQL Unit MongoDB supports

Replica Sets Sharded Environments Sharded Env. + Replica Sets

…in managed mode.

codecentric AG 18

Travis CIhttp://www.travis-ci.org

codecentric AG 19

Travis CI > Overview

Free Continuous Integration Platform:

Lanuguages: C/C++ Closure Erlang Go Groovy Java JavaScript / Node.js Objective-C Ruby Scala …

Services: MySQL PostgreSQL MongoDB CouchDB Redis Riak RabbitMQ Memcached Cassandra Neo4j …

codecentric AG 20

Travis CI > Lifecycle

Travis CI Database GitHubTests

start services

shutdown services

clone / checkout

build & run use

.travis.yml:

language: javaservices: - mongodb - redis

codecentric AG 21

Travis CI > Demo

codecentric AG 22

Travis CI > Demo

codecentric AG 23

Travis CI > Demo

codecentric AG 24

Online Resources

NoSQL Unithttps://github.com/lordofthejars/nosql-unit

Travis CIhttps://travis-ci.org/

NoSQL Unit Exampleshttps://github.com/ttrelle/nosqlunit-examples

codecentric AG 25

MongoDB User Group Düsseldorf

https://www.xing.com/net/mongodb-dus/http://www.meetup.com/Dusseldorf-MongoDB-User-Group/@MongoDUS

Meetup #10:

MongoDB at LUMsearch.com (by Christian Douven)

03.07.2014, 19:00

codecentric AG 26

QUESTIONS?

Tobias Trelle

codecentric AGMerscheider Str. 142699 Solingen

tel +49 (0) 212.233628.47fax +49 (0) 212.233628.79mail Tobias.Trelle@codecentric.de

twitter @tobiastrelle

www.codecentric.de

blog.codecentric.de/en/author/tobias-trelle

www.xing.com/net/mongodb-dus

top related