Advertisement
NLinker

DebugMain from NS

May 2nd, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# OPTIONS_GHC -fno-warn-unused-imports #-}
  2. {-# OPTIONS_GHC -fno-warn-unused-binds #-}
  3. {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
  4. {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
  5. {-# LANGUAGE OverloadedStrings #-}
  6.  
  7. module DebugMain where
  8.  
  9. import Rapid
  10. import Debug.Trace
  11.  
  12. import           System.FilePath
  13. import           Control.Monad (replicateM_, forM_)
  14. import           Control.Monad.IO.Class (MonadIO, liftIO)
  15. import           Control.Lens ((&), (?~), (^.), (.~))
  16. import           Data.Text (Text)
  17. import           Data.Monoid ((<>))
  18.  
  19. import qualified Data.Aeson  as A
  20.  
  21. import qualified Vertigo.Types.Notification.Ids      as N
  22. import qualified Vertigo.Types.Notification          as N
  23. import qualified Vertigo.Types.Notification.UserCore as N
  24. import qualified Vertigo.Types.Settings.UserSettings as US
  25. import qualified Vertigo.Dsl.Db                      as DB
  26.  
  27. import Vertigo.Ext
  28. import Vertigo.Dsl.Functors (NotifyFree)
  29. import Vertigo.Dsl.Operations
  30. import Vertigo.Dsl.RunProd
  31. import Vertigo.Dsl.Db
  32. import Vertigo.Types.DeviceInfo
  33. import Vertigo.AppM
  34. import Vertigo.Web.Admin
  35. import System.IO.Unsafe -- haha =)
  36.  
  37. import Vertigo.Types.VUUID
  38. import Vertigo.Types.Settings.UserSettings (UserSettings)
  39. import Vertigo.Types.Settings.GlobalSettings (GlobalSettings, Origin(..))
  40. import Vertigo.Types.Settings.GlobalSettingsDelta
  41. import Vertigo.Logic.Settings
  42.  
  43. update :: IO ()
  44. update =
  45.   rapid 0 $ \_r ->
  46.     -- We'll list our components here shortly.
  47. --    ext <- createRef r ("ext" :: String) buildEnvironmentExt
  48. --    let cp = ext ^. pool
  49. --    runAppIO ext $ runProd $ dbInsertSettings uid settings
  50. --    mbUs <- runAppIO ext $ runProd $ dbReadSettings uid
  51. --    putStrLn $ "mbUs = " <> show mbUs
  52.     pure()
  53.  
  54. {-# NOINLINE ext #-}
  55. ext = unsafePerformIO buildEnvironmentExt
  56.  
  57. rid = N.ReceiverId uid
  58. txt = "Oh, yea!" :: Text
  59. fid = N.FollowerId "6a2cd69e-b7f4-4467-952f-ecb585f9509c"
  60. uname = N.UserName "westcoastjim"
  61. nt  = N.NewFollower N.NewFollowerArg
  62. ntf = N.Notification rid
  63. uid = N.UserId "6a2cd69e-b7f4-4467-952f-ecb585f9509e"
  64. did = DeviceId "0de5aa77-9bc5-41e7-be4f-c6df1b102ef7"
  65. endpointArn = EndpointArn "arn:aws:sns:us-west-2:877422789438:endpoint/APNS_SANDBOX/com-vertigomediagroup-mobile-dev-apns-sandbox/5aadfd17-7cff-3493-b330-4961809f9deb"
  66. msg = "Free monads will blow your mind" :: Text
  67.  
  68. device = DeviceInfo
  69.   { _diOperatingSystem = "ios"
  70.   , _diDeviceModel = "iPhone 6 Plus"
  71.   , _diManufacturer = "Apple"
  72.   , _diOsVersion = "9.2.1"
  73.   , _diDeviceId = did
  74.   , _diNotificationEnabled = True
  75.   , _diNotificationToken = DeviceToken "86f48fc27cc72ef86f0d06f24645d50668422ed28655f29f523e2f701e891279"
  76.   , _diSnsEndpointArn = Nothing
  77.   }
  78.  
  79. gs :: GlobalSettings
  80. gs = makeGlobalSettings $ mempty
  81.   & newLiveSession .~ Just True
  82.   & mentionInPost .~ Just Everyone
  83.   & mentionInComment .~ Nothing
  84.   & newFollower .~ Just True
  85.   & commentOnPost .~ Just Following
  86.   & likeOnPost .~ Nothing
  87.  
  88. gsd :: GlobalSettingsDelta
  89. gsd = mempty & newLiveSession .~ Just False
  90.  
  91. kick1 :: IO GlobalSettings
  92. --kick = runAppIO ext $ runProd $ dbReadSettings uid
  93. kick1 = runAppIO ext $ runProd $ getGlobalSettings uid
  94.  
  95. kick2 :: IO ()
  96. kick2 = runAppIO ext $ runProd $ postGlobalSettings uid gsd
  97.  
  98. kick3 :: IO ()
  99. kick3 = replicateM_ 10 $ runAppIO ext $ runProd $ rollbackTest uid gsd
  100.  
  101. uids =
  102.   [ N.UserId "0a2cd69e-b7f4-4467-952f-ecb585f9509e"
  103.   , N.UserId "1a2cd69e-b7f4-4467-952f-ecb585f9509e"
  104.   , N.UserId "2a2cd69e-b7f4-4467-952f-ecb585f9509e"
  105.   , N.UserId "3a2cd69e-b7f4-4467-952f-ecb585f9509e"
  106.   , N.UserId "4a2cd69e-b7f4-4467-952f-ecb585f9509e"
  107.   , N.UserId "5a2cd69e-b7f4-4467-952f-ecb585f9509e"
  108.   , N.UserId "6a2cd69e-b7f4-4467-952f-ecb585f9509e"
  109.   , N.UserId "7a2cd69e-b7f4-4467-952f-ecb585f9509e"
  110.   , N.UserId "8a2cd69e-b7f4-4467-952f-ecb585f9509e"
  111.   , N.UserId "9a2cd69e-b7f4-4467-952f-ecb585f9509e"
  112.   ]
  113.  
  114. rollbackTest :: N.UserId -> GlobalSettingsDelta -> NotifyFree ()
  115. rollbackTest _uid delta = do
  116.   let us = US.UserSettings US.globalVersion delta []
  117.   r <- dbTransaction $ do
  118.     --  us' <- DB.getUserSettings [uid]
  119.     forM_ uids $ \u -> DB.insertUserSettings u us
  120.     traceM "abort DB.rollback"
  121.     DB.rollback
  122.   let x = N.UserId "00000000-b7f4-4467-952f-ecb585f9509e"
  123.   traceM $ "r = " <> show r
  124.   s <- dbTransaction $
  125.     DB.insertUserSettings x us
  126.   traceM $ "s = " <> show s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement