Skip to content
Browse files

langohr.core cleanup

  • Loading branch information...
1 parent a07cfbf commit 311a3a18d7f1efb415e8c1584ddff40c7a125aeb Michael Klishin committed Feb 27, 2013
Showing with 50 additions and 50 deletions.
  1. +11 −11 src/clojure/langohr/core.clj
  2. +39 −39 test/langohr/test/channel_test.clj
View
22 src/clojure/langohr/core.clj
@@ -14,18 +14,18 @@
[clojure.walk :as walk]))
;;
-;; Defaults
+;; Implementation
;;
(def ^{:dynamic true :doc "Default connection settings."} *default-config*
{:username "guest"
:password "guest"
:vhost "/"
:host "localhost"
- :port 5672})
+ :port ConnectionFactory/DEFAULT_AMQP_PORT})
;;
-;; Protocols
+;; API
;;
(defprotocol Closeable
@@ -40,22 +40,21 @@
(defprotocol Openable
- (open? [this] "Checks whether given entity is still open"))
+ (open? [this] "Checks whether given entity is open")
+ (closed? [this] "Checks whether given entity is closed"))
(extend-protocol Openable
com.rabbitmq.client.Connection
- (open? [this] (.isOpen this))
+ (open? [conn] (.isOpen conn))
+ (closed? [conn] (not (.isOpen conn)))
com.rabbitmq.client.Channel
- (open? [this] (.isOpen this)))
-
+ (open? [ch] (.isOpen ch))
+ (closed? [ch] (not (.isOpen ch))))
-;;
-;; API
-;;
(def ^{:const true}
- version "1.0.0-beta10-SNAPSHOT")
+ version "1.0.0-beta12-SNAPSHOT")
(declare create-connection-factory)
(defn ^Connection connect
@@ -96,6 +95,7 @@
*default-config*))
(defn capabilities-of
+ "Returns capabilities of the broker on the other side of the connection"
[^Connection conn]
(walk/keywordize-keys (into {} (-> conn .getServerProperties (get "capabilities")))))
View
78 test/langohr/test/channel_test.clj
@@ -1,56 +1,56 @@
(ns langohr.test.channel-test
- (:import [com.rabbitmq.client Connection Channel])
+ (:require [langohr.core :as lc]
+ [langohr.channel :as lch])
(:use clojure.test)
- (:require [langohr.core :as lhcore]
- [langohr.channel :as lhch]))
+ (:import [com.rabbitmq.client Connection Channel]))
-(deftest t-open-a-channel
- (let [conn (lhcore/connect)
- ch (lhch/open conn)]
+(deftest test-open-a-channel
+ (let [conn (lc/connect)
+ ch (lch/open conn)]
(is (instance? com.rabbitmq.client.Channel ch))
- (is (lhcore/open? ch))))
+ (is (lc/open? ch))))
-(deftest t-open-a-channel-with-explicitly-given-id
- (let [conn (lhcore/connect)
- ch (.createChannel conn 987)]
+(deftest test-open-a-channel-with-explicitly-given-id
+ (let [conn (lc/connect)
+ ch (lc/create-channel conn 987)]
(is (instance? com.rabbitmq.client.Channel ch))
- (is (lhcore/open? ch))
+ (is (lc/open? ch))
(is (= (.getChannelNumber ch) 987))
- (lhcore/close ch)))
+ (lc/close ch)))
-(deftest t-close-a-channel-using-langohr-core-close
- (let [conn (lhcore/connect)
- ch (lhch/open conn)]
- (is (lhcore/open? ch))
- (lhcore/close ch)
- (is (not (lhcore/open? ch)))))
+(deftest test-close-a-channel-using-langohr-core-close
+ (let [conn (lc/connect)
+ ch (lch/open conn)]
+ (is (lc/open? ch))
+ (lc/close ch)
+ (is (lc/closed? ch))))
-(deftest t-close-a-channel-using-langohr-channel-close
- (let [conn (lhcore/connect)
- ch (lhch/open conn)]
- (is (lhcore/open? ch))
- (lhch/close ch)
- (is (not (lhcore/open? ch)))))
+(deftest test-close-a-channel-using-langohr-channel-close
+ (let [conn (lc/connect)
+ ch (lch/open conn)]
+ (is (lc/open? ch))
+ (lch/close ch)
+ (is (lc/closed? ch))))
-(deftest t-close-a-channel-using-langohr-channel-close-with-provided-message
- (let [conn (lhcore/connect)
- ch (lhch/open conn)]
- (is (lhcore/open? ch))
- (lhch/close ch 200 "Bye-bye")
- (is (not (lhcore/open? ch)))))
+(deftest test-close-a-channel-using-langohr-channel-close-with-provided-message
+ (let [conn (lc/connect)
+ ch (lch/open conn)]
+ (is (lc/open? ch))
+ (lch/close ch 200 "Bye-bye")
+ (is (lc/closed? ch))))
-(deftest t-toggle-flow-control
- (let [conn (lhcore/connect)
- ch (lhch/open conn)]
- (is (lhch/flow? ch))
- (lhch/flow ch false)
- (lhch/flow ch true)
- (is (lhch/flow? ch))
- (lhch/close ch)
- (is (not (lhch/open? ch)))))
+(deftest test-toggle-flow-control
+ (let [conn (lc/connect)
+ ch (lch/open conn)]
+ (is (lch/flow? ch))
+ (lch/flow ch false)
+ (lch/flow ch true)
+ (is (lch/flow? ch))
+ (lch/close ch)
+ (is (not (lch/open? ch)))))

0 comments on commit 311a3a1

Please sign in to comment.
Something went wrong with that request. Please try again.