Skip to content

Commit

Permalink
fixes #4 (process startup coordination), adds example runner to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Halloway committed Jan 12, 2013
1 parent 99a840c commit cba35f7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion examples/simulant/examples/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

(defn convenient
[]
(in-ns 'user)
(set! *warn-on-reflection* true)
(set! *print-length* 20)
(use 'datomic.math)
Expand Down
30 changes: 25 additions & 5 deletions src/simulant/sim.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cba35f7

Please sign in to comment.