 (let [s (th/make-test-session)]
   (deftest test-insert
     (let [r {:name "Alex" :city "Munich" :age (int 19)}]
-      (insert-async s :users r)
+      @(insert-async s :users r)
       (is (= r (first @(select-async s :users))))
       (truncate s :users)))
 
   (deftest test-insert-time-unit
     (let [r {:name "Alex" :city "Munich" :age (int 19)}]
-      (insert-async s :users r)
+      @(insert-async s :users r)
       (is (= r (first (deref (select-async s :users) 1 java.util.concurrent.TimeUnit/SECONDS))))
+      (truncate s :users)))
+
+  (deftest test-insert-callback
+    (let [r     {:name "Alex" :city "Munich" :age (int 19)}
+          latch (CountDownLatch. 1)]
+      @(insert-async s :users r)
+      (let [result-future (select-async s :users)]
+        (client/add-listener result-future
+                             (fn [] (.countDown latch))
+                             (Executors/newFixedThreadPool 1))
+        (is (= r (first @result-future)))
+        (.await latch)
+        (is (= 0 (.getCount latch))))
+
       (truncate s :users)))
 
   (deftest test-insert-batch-with-ttl
     (let [input [[{:name "Alex" :city "Munich" :age (int 19)} (using :ttl (int 350))]
                  [{:name "Alex" :city "Munich" :age (int 19)} (using :ttl (int 350))]]]
-      (insert-batch-async s :users input)
+      @(insert-batch-async s :users input)
 
       @(insert-batch-async s :users input)
       (is (= (first (first input)) (first @(select-async s :users))))


    (testing "One of many update"
      (dotimes [i 3]
        (insert-async s :user_posts {:username "user1"
                                     :post_id (str "post" i)
                                     :body (str "body" i)}))
      (update-async s :user_posts
                    {:body "bodynew"}
                    (where {:username "user1"
                            :post_id "post1"}))
      (is (= "bodynew"
             (get-in @(select-async s :user_posts
                                    (where {:username "user1"

(ns clojurewerkz.cassaforte.async-cql-test
  (:refer-clojure :exclude [update])
  (:import [java.util.concurrent CountDownLatch Executors])
  (:require [clojurewerkz.cassaforte.test-helper :as th]
            [clojurewerkz.cassaforte.client      :as client]
            [clojurewerkz.cassaforte.policies    :as cp]
