add some more arraybuffer unit tests
This commit is contained in:
parent
19cfc50762
commit
8aa0368494
|
@ -6,13 +6,43 @@
|
||||||
(:import (net.thegeez.browserchannel.server ArrayBuffer)))
|
(:import (net.thegeez.browserchannel.server ArrayBuffer)))
|
||||||
|
|
||||||
(deftest basics-test
|
(deftest basics-test
|
||||||
(let [empty-array (ArrayBuffer. 0 0 (->queue) (->queue))]
|
(let [ab (ArrayBuffer. 0 0 (->queue) (->queue))]
|
||||||
(is (= (to-flush empty-array)
|
(is (= (to-flush ab)
|
||||||
nil))
|
nil))
|
||||||
(is (= (last-acknowledged-id empty-array)
|
(is (= (last-acknowledged-id ab)
|
||||||
0))
|
0))
|
||||||
(is (= (outstanding-bytes empty-array)
|
(is (= (outstanding-bytes ab)
|
||||||
0))))
|
0)))
|
||||||
|
|
||||||
|
(let [ab (ArrayBuffer. 3
|
||||||
|
0
|
||||||
|
(->queue)
|
||||||
|
(->queue
|
||||||
|
[1 "one"]
|
||||||
|
[2 "two"]
|
||||||
|
[3 "three"]))]
|
||||||
|
(is (= (first (to-flush ab))
|
||||||
|
[[1 "one"]
|
||||||
|
[2 "two"]
|
||||||
|
[3 "three"]]))
|
||||||
|
(is (= (last-acknowledged-id ab)
|
||||||
|
0))
|
||||||
|
(is (= (outstanding-bytes ab)
|
||||||
|
11)))
|
||||||
|
|
||||||
|
(let [ab (ArrayBuffer. 3
|
||||||
|
0
|
||||||
|
(->queue
|
||||||
|
[1 "one"]
|
||||||
|
[2 "two"]
|
||||||
|
[3 "three"])
|
||||||
|
(->queue))]
|
||||||
|
(is (= (first (to-flush ab))
|
||||||
|
nil))
|
||||||
|
(is (= (last-acknowledged-id ab)
|
||||||
|
0))
|
||||||
|
(is (= (outstanding-bytes ab)
|
||||||
|
0))))
|
||||||
|
|
||||||
(deftest queue-tests
|
(deftest queue-tests
|
||||||
(let [ab (-> (ArrayBuffer. 0 0 (->queue) (->queue))
|
(let [ab (-> (ArrayBuffer. 0 0 (->queue) (->queue))
|
||||||
|
@ -24,6 +54,16 @@
|
||||||
(is (= (outstanding-bytes ab)
|
(is (= (outstanding-bytes ab)
|
||||||
3)))
|
3)))
|
||||||
|
|
||||||
|
(let [ab (-> (ArrayBuffer. 1 0 (->queue) (->queue [1 "one"]))
|
||||||
|
(queue "two"))]
|
||||||
|
(is (= (first (to-flush ab))
|
||||||
|
[[1 "one"]
|
||||||
|
[2 "two"]]))
|
||||||
|
(is (= (last-acknowledged-id ab)
|
||||||
|
0))
|
||||||
|
(is (= (outstanding-bytes ab)
|
||||||
|
6)))
|
||||||
|
|
||||||
(let [ab (-> (ArrayBuffer. 0 0 (->queue) (->queue))
|
(let [ab (-> (ArrayBuffer. 0 0 (->queue) (->queue))
|
||||||
(queue nil))]
|
(queue nil))]
|
||||||
(is (= (first (to-flush ab))
|
(is (= (first (to-flush ab))
|
||||||
|
@ -58,7 +98,7 @@
|
||||||
(is (= (first (to-flush flushed))
|
(is (= (first (to-flush flushed))
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
(deftest acknowledge-tests
|
(deftest acknowledge-no-existing-data-tests
|
||||||
(let [ab (-> (ArrayBuffer. 0 0 (->queue) (->queue))
|
(let [ab (-> (ArrayBuffer. 0 0 (->queue) (->queue))
|
||||||
(queue "one")
|
(queue "one")
|
||||||
(queue "two")
|
(queue "two")
|
||||||
|
@ -103,3 +143,95 @@
|
||||||
6))
|
6))
|
||||||
(is (= (outstanding-bytes ack-ab)
|
(is (= (outstanding-bytes ack-ab)
|
||||||
0)))))
|
0)))))
|
||||||
|
|
||||||
|
(deftest acknowledge-existing-ack-data-tests
|
||||||
|
(let [ab (-> (ArrayBuffer. 2
|
||||||
|
0
|
||||||
|
(->queue
|
||||||
|
[1 "one"]
|
||||||
|
[2 "two"])
|
||||||
|
(->queue))
|
||||||
|
(queue "three")
|
||||||
|
(queue "four")
|
||||||
|
(queue "five"))]
|
||||||
|
(is (= (first (to-flush ab))
|
||||||
|
[[3 "three"]
|
||||||
|
[4 "four"]
|
||||||
|
[5 "five"]]))
|
||||||
|
(is (= (last-acknowledged-id ab)
|
||||||
|
0))
|
||||||
|
|
||||||
|
(let [ack-ab (acknowledge-id ab 4)]
|
||||||
|
(is (= (first (to-flush ack-ab))
|
||||||
|
[[5 "five"]]))
|
||||||
|
(is (= (last-acknowledged-id ack-ab)
|
||||||
|
4))
|
||||||
|
(is (= (outstanding-bytes ack-ab)
|
||||||
|
4)))
|
||||||
|
|
||||||
|
(let [ack-ab (acknowledge-id ab 2)]
|
||||||
|
(is (= (first (to-flush ack-ab))
|
||||||
|
[[3 "three"]
|
||||||
|
[4 "four"]
|
||||||
|
[5 "five"]]))
|
||||||
|
(is (= (last-acknowledged-id ack-ab)
|
||||||
|
2))
|
||||||
|
(is (= (outstanding-bytes ack-ab)
|
||||||
|
13)))
|
||||||
|
|
||||||
|
(let [ack-ab (acknowledge-id ab 6)]
|
||||||
|
(is (= (first (to-flush ack-ab))
|
||||||
|
nil))
|
||||||
|
(is (= (last-acknowledged-id ack-ab)
|
||||||
|
6))
|
||||||
|
(is (= (outstanding-bytes ack-ab)
|
||||||
|
0)))))
|
||||||
|
|
||||||
|
(deftest acknowledge-existing-to-flush-data-tests
|
||||||
|
(let [ab (-> (ArrayBuffer. 2
|
||||||
|
0
|
||||||
|
(->queue)
|
||||||
|
(->queue
|
||||||
|
[1 "one"]
|
||||||
|
[2 "two"]))
|
||||||
|
(queue "three")
|
||||||
|
(queue "four")
|
||||||
|
(queue "five"))]
|
||||||
|
(is (= (first (to-flush ab))
|
||||||
|
[[1 "one"]
|
||||||
|
[2 "two"]
|
||||||
|
[3 "three"]
|
||||||
|
[4 "four"]
|
||||||
|
[5 "five"]]))
|
||||||
|
(is (= (last-acknowledged-id ab)
|
||||||
|
0))
|
||||||
|
|
||||||
|
(let [ack-ab (acknowledge-id ab 2)]
|
||||||
|
(is (= (first (to-flush ack-ab))
|
||||||
|
[[3 "three"]
|
||||||
|
[4 "four"]
|
||||||
|
[5 "five"]]))
|
||||||
|
(is (= (last-acknowledged-id ack-ab)
|
||||||
|
2))
|
||||||
|
(is (= (outstanding-bytes ack-ab)
|
||||||
|
13)))
|
||||||
|
|
||||||
|
(let [ack-ab (acknowledge-id ab 0)]
|
||||||
|
(is (= (first (to-flush ack-ab))
|
||||||
|
[[1 "one"]
|
||||||
|
[2 "two"]
|
||||||
|
[3 "three"]
|
||||||
|
[4 "four"]
|
||||||
|
[5 "five"]]))
|
||||||
|
(is (= (last-acknowledged-id ack-ab)
|
||||||
|
0))
|
||||||
|
(is (= (outstanding-bytes ack-ab)
|
||||||
|
19)))
|
||||||
|
|
||||||
|
(let [ack-ab (acknowledge-id ab 6)]
|
||||||
|
(is (= (first (to-flush ack-ab))
|
||||||
|
nil))
|
||||||
|
(is (= (last-acknowledged-id ack-ab)
|
||||||
|
6))
|
||||||
|
(is (= (outstanding-bytes ack-ab)
|
||||||
|
0)))))
|
||||||
|
|
Reference in a new issue