Skip to content

Commit d80ff15

Browse files
committed
add specs and start test file
1 parent d922995 commit d80ff15

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
;; Copyright (c) Rich Hickey and contributors. All rights reserved.
2+
;; The use and distribution terms for this software are covered by the
3+
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
;; which can be found in the file epl-v10.html at the root of this distribution.
5+
;; By using this software in any fashion, you are agreeing to be bound by
6+
;; the terms of this license.
7+
;; You must not remove this notice, or any other, from this software.
8+
9+
;;;; flow config
10+
11+
(ns clojure.core.async.flow.specs
12+
(:require
13+
[clojure.spec.alpha :as s]))
14+
15+
;; process identifier
16+
(s/def ::pid keyword?)
17+
18+
;; proc in/out identifier
19+
(s/def ::ioid keyword?)
20+
21+
;; channel end defined by tuple of pid and ioid
22+
(s/def ::port (s/tuple ::pid ::ioid))
23+
24+
;; proc function - symbol resolving to a fn or a fn
25+
(s/def ::proc (s/or symbol? ifn?))
26+
27+
;; proc arg map - arbitrary, keys defined by proc fn
28+
(s/def ::args map?)
29+
30+
;; chan config - buffer symbol or fixed buffer size
31+
(s/def ::buf-or-n (s/or symbol? int?))
32+
33+
;; chan definition - chan config + xform
34+
(s/def ::chan-def
35+
(s/keys :opt-un [::buf-or-n ::xform]))
36+
37+
;; channel opts for a proc, map of ioid to channel definition
38+
(s/def ::chan-opts
39+
(s/map-of ::ioid ::chan-def))
40+
41+
;; process definition
42+
(s/def ::proc-def
43+
(s/keys :opt-un [::proc ::args ::chan-opts]))
44+
45+
;; map of pid to proc def in flow
46+
(s/def ::procs
47+
(s/map-of ::pid ::proc-def))
48+
49+
;; connection is a tuple of from-port and to-port
50+
(s/def ::conn
51+
(s/tuple ::port ::port))
52+
53+
;; connections
54+
(s/def ::conns
55+
(s/coll-of ::conn))
56+
57+
;; flow config consists of procs and conns
58+
;; the exec options take something that resolves to an ExecutorService
59+
(s/def ::flow-config
60+
(s/keys :opt-un [::procs ::conns
61+
::mixed-exec ::io-exec ::compute-exec]))
62+
63+
;;;; process description
64+
65+
;; defines the parameters a proc takes, kw->docstring
66+
(s/def ::params
67+
(s/map-of keyword? string?))
68+
69+
;; defines the in channels a proc takes, kw->docstring
70+
(s/def ::ins
71+
(s/map-of keyword? string?))
72+
73+
;; defines the out channels a proc takes, kw->docstring
74+
(s/def ::outs
75+
(s/map-of keyword? string?))
76+
77+
;; proc workload type
78+
(s/def ::workload #{:mixed :io :compute})
79+
80+
;; returned by the proc :describe function
81+
(s/def ::proc-description
82+
(s/keys
83+
:opt-un [::params ::ins ::outs ::workload]))
84+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
;; Copyright (c) Rich Hickey and contributors. All rights reserved.
2+
;; The use and distribution terms for this software are covered by the
3+
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
;; which can be found in the file epl-v10.html at the root of this distribution.
5+
;; By using this software in any fashion, you are agreeing to be bound by
6+
;; the terms of this license.
7+
;; You must not remove this notice, or any other, from this software.
8+
9+
(ns clojure.core.async.flow-test
10+
(:require [clojure.test :refer :all]
11+
[clojure.core.async :as a]
12+
[clojure.core.async.flow :as flow]
13+
[clojure.core.async.flow.spi :as fspi]))
14+
15+
(deftest test-step1)
16+
17+
;; Test that a proc's describe returns the proc fn's description
18+
(deftest test-proc-description-from-lift
19+
(let [step-fn (flow/lift1->step identity)
20+
proc (flow/process step-fn)]
21+
(is (some? (step-fn)))
22+
(is (= (step-fn) (fspi/describe proc)))))
23+
24+
(deftest test-proc-description-from-lift
25+
(let [step-fn (flow/lift1->step identity)
26+
proc (flow/process step-fn)]
27+
(is (some? (step-fn)))
28+
(is (= (step-fn) (fspi/describe proc)))))
29+
30+
31+
32+
(comment
33+
(def f (flow/lift1->step identity))
34+
(f)
35+
(fspi/describe (flow/process f))
36+
37+
(test-proc-description)
38+
)

0 commit comments

Comments
 (0)