Permalink
Browse files

fixes #4 (process startup coordination), adds example runner to tests

  • Loading branch information...
1 parent 99a840c commit cba35f75225a545425f759e003f946d8881bb1e9 Stuart Halloway committed Jan 12, 2013
Showing with 37 additions and 11 deletions.
  1. +12 −5 README.md
  2. 0 examples/{ → repl}/hello_world.clj
  3. +0 −1 examples/simulant/examples/repl.clj
  4. +25 −5 src/simulant/sim.clj
View
@@ -1,19 +1,26 @@
-## Simulant ##
+## Simulant
Simulant is a library and schema for developing simulation-based
tests.
-## Docs ##
+## Docs
See the [wiki](https://github.com/Datomic/simulant/wiki).
-## Getting Started ##
+## Getting Started
Simulant requires leiningen 2.
-Work through examples/hello_world.clj at a REPL.
+Work through examples/repl/hello_world.clj at a REPL.
-## License ##
+## Running Tests
+
+From a repl:
+
+ (require :reload '[simulant.examples-test :as et])
+ (et/-main)
+
+## License
Copyright (c) Metadata Partners, LLC. All rights reserved. The use
and distribution terms for this software are covered by the
File renamed without changes.
@@ -29,7 +29,6 @@
(defn convenient
[]
- (in-ns 'user)
(set! *warn-on-reflection* true)
(set! *print-length* 20)
(use 'datomic.math)
View
@@ -115,8 +115,7 @@ process."
(fn [_]
(binding [*out* writer]
(pr tx-data))
- nil))
- (await serializer)))
+ nil))))
(defmethod start-service :service.type/actionLog
[conn process service]
@@ -162,6 +161,11 @@ process."
this if you want to allocate processes to a sim asymmetrically."
(fn [conn sim process] (getx sim :sim/type)))
+(defmulti await-processes-ready
+ "Returns a future that will be realized when all of a sim's
+ processes are ready to begin"
+ (fn [conn sim] (getx sim :sim/type)))
+
(defmulti process-agents
"Given a process that has joined a sim, return that process's
agents"
@@ -198,7 +202,6 @@ process."
(start-sim conn sim process @default-executor))
([conn sim process executor]
(reset! process-executor executor)
- (start-clock conn (getx sim :sim/clock))
(join-sim conn sim process)))
(defmethod join-sim :default
@@ -211,6 +214,18 @@ process."
:process/uuid (d/squuid))]])
(tx-ent id))))
+(defn await-processes-ready
+ [sim-conn sim]
+ (logged-future
+ (while
+ (<
+ (ffirst (d/q '[:find (count ?procid)
+ :in $ ?simid
+ :where [?simid :sim/processes ?procid]]
+ (d/db sim-conn) (e sim)))
+ (:sim/processCount sim))
+ (Thread/sleep 1000))))
+
;; The default implementation of process-agents assumes that all
;; processes in the sim should have agents allocated round-robin
;; across them.
@@ -325,8 +340,13 @@ process."
and returns a future you can use to wait for the sim to complete."
[sim-conn process]
(logged-future
- (let [agents (process-agents process)
- actions (action-seq (d/db sim-conn) agents)]
+ (let [sim (-> process :sim/_processes only)]
+ @(await-processes-ready sim-conn sim)
+ (start-clock sim-conn (getx sim :sim/clock)))
+ (let [db (d/db sim-conn)
+ process (d/entity db (e process)) ;; reload with clock!
+ agents (process-agents process)
+ actions (action-seq db agents)]
(try
(with-services sim-conn process
#(do

0 comments on commit cba35f7

Please sign in to comment.