Skip to content

Commit

Permalink
Add persistent-zookeeper for persistent-2.1.*
Browse files Browse the repository at this point in the history
Add zookeeper's test in persistent-test
  • Loading branch information
junjihashimoto committed Nov 26, 2014
1 parent aa6698a commit 722929f
Show file tree
Hide file tree
Showing 35 changed files with 1,413 additions and 73 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
language: haskell

install:
- sudo add-apt-repository -y ppa:yandex-sysmon/zookeeper-3.4
- sudo apt-get update
- sudo apt-get install libzookeeper-mt-dev zookeeperd
- cabal update
- cabal install -j hspec cabal-meta cabal-src
- cabal-meta install -j --only-dep --force-reinstalls
Expand All @@ -13,12 +16,20 @@ script:
- "cabal configure -fmysql --enable-tests && cabal test"
- "cabal configure -fpostgresql --enable-tests && cabal test"
- "cabal configure -fmongodb --enable-tests && cabal test"
- "cabal configure -fzookeeper --enable-tests && cabal test"

addons:
postgresql: "9.3"
before_script:
- psql -c 'create database persistent;' -U postgres
- mysql -e 'create database persistent;'
- sudo mkdir -p /var/log/zookeeper
- sudo chmod -R 777 /var/log/zookeeper
- sudo chmod 666 /etc/zookeeper/conf/zoo.cfg
- echo maxClientCnxns=128 >> /etc/zookeeper/conf/zoo.cfg
- sudo service zookeeper restart
- sleep 10
- /usr/share/zookeeper/bin/zkCli.sh create /persistent null

services:
- mysql
Expand Down
1 change: 1 addition & 0 deletions package-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pkgs=( ./pool-conduit
./persistent-postgresql
./persistent-mysql
./persistent-mongoDB
./persistent-zookeeper
)

6 changes: 3 additions & 3 deletions persistent-test/CompositeTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ import qualified Control.Exception.Control as Control
import Init

import Control.Applicative ((<$>),(<*>))
#ifndef WITH_MONGODB
#ifndef WITH_NOSQL
import Data.Maybe (isJust)
import Database.Persist.TH (mkDeleteCascade)
#endif


-- mpsGeneric = False is due to a bug or at least lack of a feature in mkKeyTypeDec TH.hs
#if WITH_MONGODB
#if WITH_NOSQL
mkPersist persistSettings { mpsGeneric = False } [persistUpperCase|
#else
share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "compositeMigrate", mkDeleteCascade persistSettings { mpsGeneric = False }] [persistLowerCase|
Expand Down Expand Up @@ -87,7 +87,7 @@ share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "compositeMig
|]


#ifdef WITH_MONGODB
#ifdef WITH_NOSQL
cleanDB :: (PersistQuery backend, PersistEntityBackend TestChild ~ backend, MonadIO m) => ReaderT backend m ()
cleanDB = do
deleteWhere ([] :: [Filter TestChild])
Expand Down
12 changes: 6 additions & 6 deletions persistent-test/DataTypeTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Init

type Tuple a b = (a, b)

#ifdef WITH_MONGODB
#ifdef WITH_NOSQL
mkPersist persistSettings [persistUpperCase|
#else
-- Test lower case names
Expand All @@ -40,7 +40,7 @@ DataTypeTable no-json
double Double
bool Bool
day Day
#ifndef WITH_MONGODB
#ifndef WITH_NOSQL
pico Pico
time TimeOfDay
#endif
Expand All @@ -53,7 +53,7 @@ cleanDB = deleteWhere ([] :: [Filter DataTypeTable])
specs :: Spec
specs = describe "data type specs" $
it "handles all types" $ asIO $ runConn $ do
#ifndef WITH_MONGODB
#ifndef WITH_NOSQL
_ <- runMigrationSilent dataTypeMigrate
-- Ensure reading the data from the database works...
_ <- runMigrationSilent dataTypeMigrate
Expand All @@ -80,11 +80,11 @@ specs = describe "data type specs" $
check "intList" dataTypeTableIntList
check "bool" dataTypeTableBool
check "day" dataTypeTableDay
#ifndef WITH_MONGODB
#ifndef WITH_NOSQL
check' "pico" dataTypeTablePico
check "time" (roundTime . dataTypeTableTime)
#endif
#if !(defined(WITH_MONGODB)) || (defined(WITH_MONGODB) && defined(HIGH_PRECISION_DATE))
#if !(defined(WITH_NOSQL)) || (defined(WITH_NOSQL) && defined(HIGH_PRECISION_DATE))
check "utc" (roundUTCTime . dataTypeTableUtc)
#endif

Expand Down Expand Up @@ -129,7 +129,7 @@ instance Arbitrary DataTypeTable where
<*> arbitrary -- double
<*> arbitrary -- bool
<*> arbitrary -- day
#ifndef WITH_MONGODB
#ifndef WITH_NOSQL
<*> arbitrary -- pico
<*> (truncateTimeOfDay =<< arbitrary) -- time
#endif
Expand Down
6 changes: 3 additions & 3 deletions persistent-test/EmbedOrderTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{-# LANGUAGE QuasiQuotes, TypeFamilies, GeneralizedNewtypeDeriving, TemplateHaskell,
OverloadedStrings, GADTs, FlexibleContexts, EmptyDataDecls, MultiParamTypeClasses #-}
module EmbedOrderTest (specs,
#ifndef WITH_MONGODB
#ifndef WITH_NOSQL
embedOrderMigrate
#endif
) where
Expand All @@ -15,7 +15,7 @@ import Debug.Trace (trace)
debug :: Show s => s -> s
debug x = trace (show x) x

#if WITH_MONGODB
#if WITH_NOSQL
mkPersist persistSettings [persistUpperCase|
#else
share [mkPersist sqlSettings, mkMigrate "embedOrderMigrate"] [persistUpperCase|
Expand All @@ -30,7 +30,7 @@ Bar
deriving Eq Show
|]

#ifdef WITH_MONGODB
#ifdef WITH_NOSQL
cleanDB :: (PersistQuery backend, PersistEntityBackend Foo ~ backend, MonadIO m) => ReaderT backend m ()
cleanDB = do
deleteWhere ([] :: [Filter Foo])
Expand Down
14 changes: 10 additions & 4 deletions persistent-test/EmbedTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE QuasiQuotes, TemplateHaskell, CPP, GADTs, TypeFamilies, OverloadedStrings, FlexibleContexts, EmptyDataDecls, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses #-}
module EmbedTest (specs,
#ifndef WITH_MONGODB
#ifndef WITH_NOSQL
embedMigrate
#endif
) where
Expand All @@ -14,10 +14,12 @@ import Data.Typeable (Typeable)
import qualified Data.Text as T
import qualified Data.Set as S
import qualified Data.Map as M
#if WITH_MONGODB
#if WITH_NOSQL
#ifdef WITH_MONGODB
import Database.Persist.MongoDB
import Database.MongoDB (genObjectId)
import Database.MongoDB (Value(String))
#endif
import EntityEmbedTest
import System.Process (readProcess)
#endif
Expand All @@ -38,8 +40,9 @@ instance PersistField a => PersistField (NonEmpty a) where
Right (l:ls) -> Right (l:|ls)


#if WITH_MONGODB
#if WITH_NOSQL
mkPersist persistSettings [persistUpperCase|
#ifdef WITH_MONGODB
HasObjectId
oid ObjectId
name Text
Expand All @@ -54,6 +57,7 @@ mkPersist persistSettings [persistUpperCase|
hasEntity (Entity ARecord)
arrayWithEntities [AnEntity]
deriving Show Eq Read Ord
#endif

#else
share [mkPersist sqlSettings, mkMigrate "embedMigrate"] [persistUpperCase|
Expand Down Expand Up @@ -141,7 +145,7 @@ share [mkPersist sqlSettings, mkMigrate "embedMigrate"] [persistUpperCase|
ints [Int]
deriving Show Eq
|]
#ifdef WITH_MONGODB
#ifdef WITH_NOSQL
cleanDB :: (PersistQuery backend, PersistEntityBackend HasMap ~ backend, MonadIO m) => ReaderT backend m ()
cleanDB = do
deleteWhere ([] :: [Filter HasEmbed])
Expand Down Expand Up @@ -266,6 +270,7 @@ specs = describe "embedded entities" $ do
Just res <- selectFirst [EmbedsHasMapName ==. (Just "empty map")] []
res @== Entity contK container

#ifdef WITH_NOSQL
#ifdef WITH_MONGODB
it "List" $ db $ do
k1 <- insert $ HasList []
Expand Down Expand Up @@ -409,3 +414,4 @@ specs = describe "embedded entities" $ do
lists <- selectList [] []
fmap entityVal lists @== [ListEmbed [InList 1 2, InList 1 2] 1 2]
#endif
#endif
8 changes: 4 additions & 4 deletions persistent-test/EmptyEntityTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Control.Monad.Trans.Resource (runResourceT)

import Init

#ifdef WITH_MONGODB
#ifdef WITH_NOSQL
mkPersist persistSettings [persistUpperCase|
#else
-- Test lower case names
Expand All @@ -18,15 +18,15 @@ share [mkPersist sqlSettings, mkMigrate "dataTypeMigrate"] [persistLowerCase|
EmptyEntity
|]

#ifdef WITH_MONGODB
cleanDB :: MonadIO m => ReaderT MongoContext m ()
#ifdef WITH_NOSQL
cleanDB :: MonadIO m => ReaderT Context m ()
cleanDB = deleteWhere ([] :: [Filter EmptyEntity])
#endif

specs :: Spec
specs = describe "empty entity" $
it "inserts" $ (id :: IO () -> IO ()) $ runResourceT $ runConn $ do
#ifndef WITH_MONGODB
#ifndef WITH_NOSQL
_ <- runMigrationSilent dataTypeMigrate
-- Ensure reading the data from the database works...
_ <- runMigrationSilent dataTypeMigrate
Expand Down
2 changes: 1 addition & 1 deletion persistent-test/EntityEmbedTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module EntityEmbedTest where

-- because we are using a type alias we need to declare in a separate module
-- this is used in EmbedTest
#if WITH_MONGODB
#if WITH_NOSQL
import Init

mkPersist persistSettings [persistUpperCase|
Expand Down
2 changes: 1 addition & 1 deletion persistent-test/HtmlTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cleanDB = do
specs :: Spec
specs = describe "html" $ do
it "works" $ asIO $ runResourceT $ runConn $ do
#ifndef WITH_MONGODB
#ifndef WITH_NOSQL
_ <- runMigrationSilent htmlMigrate
-- Ensure reading the data from the database works...
_ <- runMigrationSilent htmlMigrate
Expand Down
Loading

0 comments on commit 722929f

Please sign in to comment.