 
 (use-fixtures :each
   (fn [f]
-    (.clear cache)
+    (.clear tx-cache)
+    (.clear non-tx-cache)
     (try
       (sql/db-do-commands spec
         (sql/drop-table-ddl :things)

            [clojure.java.jdbc :as sql]))

(set-log-level! (or (System/getenv "LOG_LEVEL") :OFF))
(def cache (csh/cache "tx-test" :transactional? true))
(def queue (msg/queue "/queue/test" :durable? false))
(def local-remote-queue (msg/queue "remote" :durable? false))
(def conn (msg/context (cond-> {:host "localhost" :xa? true}

  (with-open [_ (msg/listen trigger listener)]
    (msg/publish trigger {:tx? true :throw? true})
    (verify-failure)
    (is (= 10 (:deliveries tx-cache)))))

(deftest transactional-writes-in-listener-should-fail-on-rollback
  (with-open [_ (msg/listen trigger listener)]
    (msg/publish trigger {:tx? true :rollback? true})
    (verify-failure)
    (is (= 1 (:deliveries tx-cache)))))

(deftest non-transactional-writes-in-listener-with-exception
  (with-open [_ (msg/listen trigger listener :mode :auto-ack)]
    (msg/publish trigger {:throw? true :non-tx-cache? true})
    (is (= 10 (loop [i 0]
                (Thread/sleep 100)
                (if (or (= 50 i) (= 10 (:deliveries non-tx-cache)))
                  (:deliveries non-tx-cache)
                  (recur (inc i))))))
    (is (= 1 (:a non-tx-cache)))
    (is (= (repeat 10 "kiwi")      (repeatedly 10 #(msg/receive queue))))
    (is (= (repeat 10 "starfruit") (repeatedly 10 #(msg/receive local-remote-queue))))))
