testing polyglot persistence done right
Post on 25-May-2015
3.481 Views
Preview:
DESCRIPTION
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
top related