Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Re-enable throwing of exceptions that happen remotely.

  • Loading branch information...
commit 09b27d437c02ce6bddece388c5b136af2f57243f 1 parent 3b50704
@technomancy authored
Showing with 25 additions and 18 deletions.
  1. +1 −0  .gitignore
  2. +11 −9 src/die/roboter.clj
  3. +13 −9 test/die/test/roboter.clj
View
1  .gitignore
@@ -4,3 +4,4 @@ pom.xml
/classes/
.lein-failures
.lein-deps-sum
+/checkouts
View
20 src/die/roboter.clj
@@ -81,8 +81,14 @@
(String. (.encode (Base64.) (.toByteArray baos)))))
(defn throw-form [e]
- `(-> (.decode (Base64.) ~(serialize-64 e))
- ByteArrayInputStream. ObjectInputStream. .readObject))
+ `(do ::eval (-> (.decode (Base64.) ~(serialize-64 e))
+ ByteArrayInputStream. ObjectInputStream. .readObject throw)))
+
+(defn read-or-eval [{:keys [body props]}]
+ (let [value (-> body String. read-string)]
+ (if (and (coll? value) (= (second value) ::eval))
+ (eval value)
+ value)))
(defn send-back
([form] (send-back form {}))
@@ -96,11 +102,7 @@
(catch Exception e#
(throw-form e#)))))))
(wabbit/with-queue reply-queue
- (-> (wabbit/consuming-seq true) first :body
- ;; TODO: detect exception forms and eval them; side-channel needed
- ;; 3-arg version of publish lets you set properties?
- String. read-string ;; eval
- )))))))
+ (-> (wabbit/consuming-seq true) first read-or-eval)))))))
(defn- success? [f timeout]
(try (.get f timeout TimeUnit/MILLISECONDS) true
@@ -181,7 +183,7 @@
others)))
(defn -main [& {:as opts}]
- (let [opts (into {:workers (Integer. (or (System/getenv "WORKER_COUNT") 4))}
+ (let [opts (into {:workers (or (System/getenv "WORKER_COUNT") 4)}
(walk/keywordize-keys opts))]
(println "Starting" (:workers opts) "workers.")
- (dotimes [n (:workers opts)] (add-worker opts))))
+ (dotimes [n (Integer. (:workers opts))] (add-worker opts))))
View
22 test/die/test/roboter.clj
@@ -68,6 +68,7 @@
(is (= 1 (.get (send-back 1) 100 TimeUnit/MILLISECONDS)))
(is (= 2 (.get (send-back `(+ 1 1)) 100 TimeUnit/MILLISECONDS)))))
+;; TODO: still too much nondeterminism here.
(deftest test-simple-broadcast
(let [worker (future
(binding [bound 1]
@@ -118,12 +119,15 @@
(finally (future-cancel worker)))
(is (:ran @state))))
-;; (deftest test-exception-over-future
-;; (let [worker (future
-;; (binding [*exception-handler* ack-handler]
-;; (work {:timeout 100})))]
-;; (try
-;; (is (instance? IOException (try @(send-back '(throw (java.io.IOException.)))
-;; (catch ExecutionException e
-;; (-> e .getCause .getCause)))))
-;; (finally (future-cancel worker)))))
+(deftest test-exception-over-future
+ (let [worker (future
+ (binding [*exception-handler* ack-handler]
+ (work {:timeout 100})))]
+ (try
+ (is (instance? IOException (try @(send-back '(throw (java.io.IOException.)))
+ (catch ExecutionException e
+ (-> e .getCause .getCause)))))
+ #_(prn (try @(send-back '(throw (java.io.IOException.)))
+ (catch ExecutionException e
+ e)))
+ (finally (future-cancel worker)))))
Please sign in to comment.
Something went wrong with that request. Please try again.