Skip to content

Chapter NOSQL outline

Aslak Knutsen edited this page Aug 24, 2013 · 6 revisions

Use Case / Requirements

  • Data storage backend

  • Domain model

    • Attachment

As a User I should be able to Add/Change/Delete an Attachment
  • Relation

As a User I should be able to Add/Delete an Attachment to a Conference

As a User I should be able to Add/Delete an Attachment to a Session

As a User I should be able to SPEAK a Conference

As a User I should be able to ATTEND a Conference

Background

Infinispan

  • What is a Key/Value Store

    • Hash key

      • Massive scale DataGrid

      • Map/Reduce

      • Search backed by Lucense Index

  • What is the 'Cache'

    • JSR-xxx and how it relates to Infinispan

  • How to configure a Cache

    • Local/Remote, Sync/Async replication

  • How to use it?

    • What is it good for?

    • Mapping of data

      • Hibernate OGM ?

Neo4J

  • What is a Graph DataBase

    • Good for storing relations

      • Ad-hoc relations

    • Fast to query recursive relations

      • Friends friends etc..

    • Search backed by Lucense Index

Implementation

  • Infinispan

    • AttachmentRepository JTA EJB backed by Infinispan Cache

    • Cache produced via CDI @Produces

  • Neo4J

    • RelationRepository backed by CDI bean

    • GraphDatabaseService produced via CDI @Produces

    • Stores the social graph from Twitter

    • Stores relations between domains

      • A User can attend a Conference

      • A User can speak in a Session

      • An Attachment can be attached to a Conference

Requirement Test Scenarios

Overview

  • Store data

  • Get data

  • Update data

Setup

Domain Attachment

@Inject
private Repository<Attachment> repository;

@Test
public void shouldBeAbleToCreateAttachment() throws Exception { .. }

@Test
public void shouldBeAbleToUpdateAttachmnt() throws Exception { .. }

@Test
public void shouldBeAbleToRemoveAttachmnt() throws Exception { .. }
  • ShrinkWrap Resolver to fetch external dependencies

    • Fetching Infinispan version defined in module pom.

      • Could define version to test against a new/other version of infinispan etc.. source file

public static File[] resolveDependencies() {
    return Maven.resolver().loadPomFromFile("pom.xml")
        .resolve(
            "org.infinispan:infinispan-core")
        .withTransitivity()
        .asFile();
}
  • Uses real Infinispan backend

    • Local embedded

  • TransactionalBehaviorTest

  • BaseTransactionalSpecification

    • Use of base class to define the transactional behavior 'imposed' by the Repository interface

      • Used by All Repository implementations, Interface test

    • Verify connected to JTA

    • Use of transactional wrapped callables

    • Injection of UserTransaction

    @Test
    public void shouldSetUpdatedDate() throws Exception { .. }

    @Test
    public void shouldUpdateObjectOnCommit() throws Exception { .. }

    @Test
    public void shouldRemoveObjectOnCommmit() throws Exception { .. }

    @Test
    public void shouldNotStoreObjectOnRollback() throws Exception { .. }

    @Test
    public void shouldNotUpdateObjectOnRollback() throws Exception { .. }

    @Test
    public void shouldNotRemoveObjectOnRollback() throws Exception { .. }

    @Test
    public void shouldSetCreatedDate() throws Exception { .. }

    @Test
    public void shouldSetUpdatedDate() throws Exception { .. }
  • UNIT: Verify Attachment Domain Object

    • Checks created/updated object date rules

    • Checks null field values

    • Rely on base Specification test case TimestampableSpecification

    @Test(expected = IllegalArgumentException.class)
    public void shouldNotAllowNullConstructorTitle() throws Exception {
        new Attachment(null, "", new URL("http://geekseek.org"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldNotAllowNullConstructorMimeType() throws Exception {
        new Attachment("", null, new URL("http://geekseek.org"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldNotAllowNullConstructorUrl() throws Exception {
        new Attachment("", "", null);
    }

Store

Update

Delete

Domain Relation

  • org.cedj.geekseek.domain.relation.test.integration

  • ShrinkWrap Resolver to fetch external dependencies

  • Rely on the core building blocks of Repository and Identifiable

    • Test Doubles for Identifiables and Repositories

      • SourceObject, Sourcerepository

      • Avoids direct dependencies on the other modules, but rely on them runtime

  • Uses real neo4j backend

  • RelationRepositoryTestCase

    @Test @InSequence(0)
    public void shouldBeAbleToCreateRelation() { .. }

    @Test @InSequence(1)
    public void shouldBeAbleToFindTargetedRelations(Repository<TargetObject> targetRepo, Repository<SourceObject> sourceRepo) { .. }

    @Test @InSequence(2)
    public void shouldBeAbleToDeleteRelations() { .. }

    @Test @InSequence(3)
    public void shouldOnlyFindGivenRelation() { .. }

Store

Delete

Graph