From 3917822d11db814ad465f473003da8cef859cfc1 Mon Sep 17 00:00:00 2001 From: Michael Wu Date: Mon, 11 Apr 2011 23:08:03 -0400 Subject: [PATCH 1/2] changed PriorityBlockingQueue to LinkedBlockingQueue so that multiple messages with timestamp 0 get sent out in FIFO order --- src/osc.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/osc.clj b/src/osc.clj index 5d756dd..2f8bcd8 100644 --- a/src/osc.clj +++ b/src/osc.clj @@ -1,6 +1,6 @@ (ns osc (:import - (java.util.concurrent TimeUnit TimeoutException PriorityBlockingQueue) + (java.util.concurrent TimeUnit TimeoutException LinkedBlockingQueue) (java.net InetSocketAddress DatagramSocket DatagramPacket) (java.nio.channels DatagramChannel AsynchronousCloseException ClosedChannelException) (java.nio ByteBuffer ByteOrder)) @@ -152,7 +152,7 @@ (let [chan (DatagramChannel/open) rcv-buf (ByteBuffer/allocate BUFFER-SIZE) send-buf (ByteBuffer/allocate BUFFER-SIZE) - send-q (PriorityBlockingQueue. OSC-SEND-Q-SIZE (comparator (fn [a b] (< (:timestamp (second a)) (:timestamp (second b)))))) + send-q (LinkedBlockingQueue.) running? (ref true) handlers (ref {}) listeners (ref #{(msg-handler-dispatcher handlers)}) From b311f2a93d0ce7a5b9f432afc7b29df854334ae6 Mon Sep 17 00:00:00 2001 From: Michael Wu Date: Fri, 12 Aug 2011 20:47:00 -0400 Subject: [PATCH 2/2] osc-slowpoke-server-test --- test/osc_test.clj | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/osc_test.clj b/test/osc_test.clj index d875201..9236bd3 100644 --- a/test/osc_test.clj +++ b/test/osc_test.clj @@ -61,6 +61,25 @@ (osc-close server true) (osc-close client true))))) +(deftest osc-slowpoke-server-test [] + (let [server (osc-server PORT) + client (osc-client HOST PORT) + coll (atom []) + end 50 + end-millis (+ (System/currentTimeMillis) (* end 1000 1/5))] + (try + (osc-handle server "/test" (fn [msg] (swap! coll (fn [s] + (Thread/sleep 100) + (conj s (first (:args msg))))))) + (dotimes [i end] (osc-send client "/test" i)) + (while (or (not= (count @coll) end) (< (System/currentTimeMillis) end-millis)) + (Thread/sleep 250)) + (dorun (map-indexed #(is (= %1 %2)) @coll)) + (finally + (osc-close server true) + (osc-close client true))))) + + (defn osc-tests [] (binding [*test-out* *out*] (run-tests 'osc-test))) @@ -68,4 +87,5 @@ (defn test-ns-hook [] (osc-msg-test) (thread-lifetime-test) - (osc-basic-test)) + (osc-basic-test) + (osc-slowpoke-server-test))