Testing Polyglot Persistence Done Right

Post on 25-May-2015

3,477 views 1 download

Tags:

description

Data storage is one of the most crucial parts of any applications, and we use many different tools and tricks to keep it in a good shape. We frequently use both old school relational systems with new approaches commonly known as NoSQL. We write sophisticated queries and use optimization techniques to give our end users the greatest possible experience. So why is persistence very often skipped in the testing efforts? Is it really that complex and painful to setup? During this talk we will have a closer look at Arquillian Persistence Extension together with NoSQLUnit. These tools remove that burden and boilerplate to make you a happy and productive programmer again! Join this session and see for yourself that writing tests for your data storage logic is as easy as writing normal unit tests!

transcript

Testing Polyglot Persistence Done Right

Alex Soto @alexsotob

Bartosz Majsak@majson

●Open source advocate● lordofthejars.com curator●Father

[alex@geecon ~]$ whoami

@alexsotob lordofthejars

●Java Developer by day●Open source junkie by night●Conference speaker by passion

[bartek@geecon ~]$ whoami

@majson bartoszmajsak

FIRST things first

Fast Run more oftenIsolated Can be executed in any orderRepeatable Always return the same resultSelf-Validating Know exactly their purposeTimely Run before code

Bartosz Majsak
I'm not sure if these titles are of any help
Bartosz Majsak
From where do we have explanation for this points? What would like to say here?
Bartosz Majsak
The look&feel is not final, however you can change it as you want
Alex Soto
I will start saying that before starting on persistence test 2 minutes of theory, and all tests in general and unit tests in particular should follow the FIRST rule

Frequently omitted rules

in Persistence tests

FAST

Fast

FAST

Network access

Long bootstrap

Humongous amount of data

Bartosz Majsak
Final transitions at the end of the process :)

FAST

HSQLDB

MongoDB (fongo)

Neo4J

Cassandra

Infinispan

HBase

Isolation

Bartosz Majsak
You can talk about isolation as you know better nosql areaI can mentioned about per-dev schemas and cleanup strategies as a remark

ISOLATION

public class BeerRepositoryTest {

BeerRepository beerRepository;

@Test public void should_persist_beer() { beerRepository.save(new Beer(“Mocny Full”)); }

@Test public void should_count_beers() { int beers = beerRepository.count(); assertThat(beers).isEqualTo(??); }

}

Bartosz Majsak
as with the previous one - coloring as final touch
Bartosz Majsak
it will based on the Arquillian example, but I will take care of it tomorrow
Alex Soto
I think it is enough

ISOLATION

DBUnit

Unitils

NoSQLUnit

Arquillian Persistence Extension

Bartosz Majsak
I thought maybe we break it down to problem-solution
Alex Soto
I think that this slide should go after isolation because the isolation are acquired by these tools, fast is acquired by using embedded db
Bartosz Majsak
correct! my fault
Bartosz Majsak
But then you talk about FAST and I talk about isolation
Alex Soto
Om perfect I will start talking about FIRST and Fast, then you talk about Isolation and the beer and dbunit

Plain Old SQL World

Text

TITLE

Alex Soto
Let show the application

Text

TITLE

FIRST ATTEMPT

FIRST ATTEMPT

FIRST ATTEMPT

FIRST ATTEMPT

<dataset> <brewery id="1" name="Brew Dog" country="Scotland" /> <beer id="1" name="End of History" price="756" alcohol="55.0" brewery_id="1" /></dataset>

We can do better

And even better

Hipster’s world of NoSQL

Trending Topic

Why NoSQL?

Why NoSQL?

Clustering from scratch

“Schemaless”

Polyglot

More Natural for Developer

Manage Lifecycle

Maintain Database State

Polyglot Persistence

Spring Data Support

Text

Not a single point of access

Supported Engines

MongoDB

CouchDB

Elasticsearch

Neo4j

Redis

Infinispan

HBase

Cassandra

Text

Starting/Stopping Databases

Manging MongoDB Lifecycle

Text

Seeding Database with the Known Data

Seeding Database with Known Data

Bartosz Majsak
Me no like test() as a name for the method ;)

Demo Time

Arquillian

Bartosz Majsak
Intro to Arquillian [not that much]
Alex Soto
If you want I can explain the intro to arquillian only few words and then you explain APE

TITLE Integration

TITLE

Containers

Text

TITLE

Deployments

TITLE

TITLE

TITLE

TITLE

TITLE

TITLE

TITLE

@RunWith(Arquillian.class)public class FluidOunceConverterTestCase {

@Deployment public static JavaArchive createDeployment() { return ShrinkWrap.create(JavaArchive.class, "test.jar") .addClasses(FluidOunceConverter.class,

FluidOunceConverterBean.class); }

@Inject FluidOunceConverter converter;

@Test public void should_convert_fluid_ounces_to_millilitres() { // given double ouncesToConvert = 8d; double expectedMillilitres = 236.588237d;

// when double ouncesInMl = converter.convertToMillilitres(ouncesToConvert);

// then assertThat(ouncesInMl).isEqualTo(expectedMillilitres); }

}

Bartosz Majsak
Here I will go with APE demo
Alex Soto
I think that after this slide we should put an example of APE or something to explain what is APE

Demo Time

●You can write your test fixtures in XML, Excel, YAML or JSON

●@UsingDataSet / @ShouldMatchDataSet

●@Cleanup / @CleanupUsingScript

●@ApplyScriptBefore / After

●@CreateSchema

●JPA 2nd level cache eviction

Bartosz Majsak
And here we will talk about NoSQLUnit + APE story and then live demo

Demo Time

Alex Soto
title talk is polyglot so maybe we can how to actually use both engines together through APE

●Standalone mode

●Scriptable data sets

●Full NoSQLUnit integration

●Schema validation

FUTURE