+ All Categories
Home > Technology > Testing Polyglot Persistence Done Right

Testing Polyglot Persistence Done Right

Date post: 25-May-2015
Category:
Upload: alex-soto
View: 3,477 times
Download: 1 times
Share this document with a friend
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!
Popular Tags:
49
Testing Polyglot Persistence Done Right Alex Soto @alexsotob Bartosz Majsak @majson
Transcript
Page 1: Testing Polyglot Persistence Done Right

Testing Polyglot Persistence Done Right

Alex Soto @alexsotob

Bartosz Majsak@majson

Page 2: Testing Polyglot Persistence Done Right

●Open source advocate● lordofthejars.com curator●Father

[alex@geecon ~]$ whoami

@alexsotob lordofthejars

Page 3: Testing Polyglot Persistence Done Right

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

[bartek@geecon ~]$ whoami

@majson bartoszmajsak

Page 4: Testing Polyglot Persistence Done Right

FIRST things first

Page 5: Testing Polyglot Persistence Done Right

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
Page 6: Testing Polyglot Persistence Done Right

Frequently omitted rules

in Persistence tests

Page 7: Testing Polyglot Persistence Done Right

FAST

Fast

Page 8: Testing Polyglot Persistence Done Right

FAST

Network access

Long bootstrap

Humongous amount of data

Bartosz Majsak
Final transitions at the end of the process :)
Page 9: Testing Polyglot Persistence Done Right

FAST

HSQLDB

MongoDB (fongo)

Neo4J

Cassandra

Infinispan

HBase

Page 10: Testing Polyglot Persistence Done Right

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
Page 11: Testing Polyglot Persistence Done Right

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
Page 12: Testing Polyglot Persistence Done Right

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
Page 13: Testing Polyglot Persistence Done Right

Plain Old SQL World

Page 14: Testing Polyglot Persistence Done Right

Text

TITLE

Alex Soto
Let show the application
Page 15: Testing Polyglot Persistence Done Right

Text

TITLE

Page 16: Testing Polyglot Persistence Done Right

FIRST ATTEMPT

Page 17: Testing Polyglot Persistence Done Right

FIRST ATTEMPT

Page 18: Testing Polyglot Persistence Done Right

FIRST ATTEMPT

Page 19: Testing Polyglot Persistence Done Right

FIRST ATTEMPT

Page 20: Testing Polyglot Persistence Done Right

<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

Page 21: Testing Polyglot Persistence Done Right

And even better

Page 22: Testing Polyglot Persistence Done Right

Hipster’s world of NoSQL

Page 23: Testing Polyglot Persistence Done Right

Trending Topic

Why NoSQL?

Page 24: Testing Polyglot Persistence Done Right

Why NoSQL?

Clustering from scratch

“Schemaless”

Polyglot

More Natural for Developer

Page 25: Testing Polyglot Persistence Done Right
Page 26: Testing Polyglot Persistence Done Right

Manage Lifecycle

Maintain Database State

Polyglot Persistence

Spring Data Support

Page 27: Testing Polyglot Persistence Done Right

Text

Not a single point of access

Page 28: Testing Polyglot Persistence Done Right

Supported Engines

MongoDB

CouchDB

Elasticsearch

Neo4j

Redis

Infinispan

HBase

Cassandra

Page 29: Testing Polyglot Persistence Done Right

Text

Starting/Stopping Databases

Page 30: Testing Polyglot Persistence Done Right

Manging MongoDB Lifecycle

Page 31: Testing Polyglot Persistence Done Right

Text

Seeding Database with the Known Data

Page 32: Testing Polyglot Persistence Done Right

Seeding Database with Known Data

Bartosz Majsak
Me no like test() as a name for the method ;)
Page 33: Testing Polyglot Persistence Done Right

Demo Time

Page 34: Testing Polyglot Persistence Done Right

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
Page 35: Testing Polyglot Persistence Done Right

TITLE Integration

Page 36: Testing Polyglot Persistence Done Right

TITLE

Containers

Page 37: Testing Polyglot Persistence Done Right

Text

TITLE

Deployments

Page 38: Testing Polyglot Persistence Done Right

TITLE

Page 39: Testing Polyglot Persistence Done Right

TITLE

Page 40: Testing Polyglot Persistence Done Right

TITLE

Page 41: Testing Polyglot Persistence Done Right

TITLE

Page 42: Testing Polyglot Persistence Done Right

TITLE

Page 43: Testing Polyglot Persistence Done Right

TITLE

Page 44: Testing Polyglot Persistence Done Right

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
Page 45: Testing Polyglot Persistence Done Right

Demo Time

Page 46: Testing Polyglot Persistence Done Right

●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
Page 47: Testing Polyglot Persistence Done Right

Demo Time

Alex Soto
title talk is polyglot so maybe we can how to actually use both engines together through APE
Page 48: Testing Polyglot Persistence Done Right

●Standalone mode

●Scriptable data sets

●Full NoSQLUnit integration

●Schema validation

FUTURE

Page 49: Testing Polyglot Persistence Done Right

Recommended