testing polyglot persistence done right
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
Frequently omitted rules
in Persistence tests
FAST
Fast
FAST
Network access
Long bootstrap
Humongous amount of data
FAST
HSQLDB
MongoDB (fongo)
Neo4J
Cassandra
Infinispan
HBase
Isolation
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(??); }
}
ISOLATION
DBUnit
Unitils
NoSQLUnit
Arquillian Persistence Extension
Plain Old SQL World
Text
TITLE
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
Demo Time
Arquillian
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); }
}
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
Demo Time
●Standalone mode
●Scriptable data sets
●Full NoSQLUnit integration
●Schema validation
FUTURE