Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use thrown? or thrown-cause? in test

  • Loading branch information...
commit 4b669806530007fc92721fe1a2baa8646f479b5d 1 parent 6a6dab8
afeng authored
View
12 src/clj/backtype/storm/util.clj
@@ -127,6 +127,13 @@
(some (partial instance? klass))
boolean))
+(defmacro thrown-cause? [klass & body]
+ `(try
+ ~@body
+ false
+ (catch Throwable t#
+ (exception-cause? ~klass t#))))
+
(defmacro forcat [[args aseq] & body]
`(mapcat (fn [~args]
~@body)
@@ -368,7 +375,8 @@
:kill-fn (fn [error] (halt-process! 1 "Async loop died!"))
:priority Thread/NORM_PRIORITY
:factory? false
- :start true]
+ :start true
+ :thread-name nil]
(let [thread (Thread.
(fn []
(try-cause
@@ -389,6 +397,8 @@
))]
(.setDaemon thread daemon)
(.setPriority thread priority)
+ (when thread-name
+ (.setName thread (str (.getName thread) "-" thread-name)))
(when start
(.start thread))
;; should return object that supports stop, interrupt, join, and waiting?
View
2  src/jvm/backtype/storm/security/auth/digest/DigestSaslTransportPlugin.java
@@ -29,7 +29,7 @@ protected TTransportFactory getServerTransportFactory() throws IOException {
TSaslServerTransport.Factory factory = new TSaslServerTransport.Factory();
factory.addServerDefinition(DIGEST, AuthUtils.SERVICE, "localhost", null, serer_callback_handler);
- LOG.info("SASL DIGEST-MD5 transport factory will be used:"+login_conf);
+ LOG.info("SASL DIGEST-MD5 transport factory will be used");
return factory;
}
View
40 test/clj/backtype/storm/security/auth/auth_test.clj
@@ -129,10 +129,8 @@
{STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
"java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest.conf"})]
(testing "(Negative authentication) Server: Simple vs. Client: Digest"
- (is (= "java.net.SocketTimeoutException: Read timed out"
- (try (NimbusClient. storm-conf "localhost" 6627 nimbus-timeout)
- nil
- (catch TTransportException ex (.getMessage ex))))))))
+ (is (thrown-cause? java.net.SocketTimeoutException
+ (NimbusClient. storm-conf "localhost" 6627 nimbus-timeout))))))
(deftest positive-authorization-test
(launch-server 6628 nil
@@ -167,13 +165,13 @@
"test/clj/backtype/storm/security/auth/jaas_digest.conf"
nil
"backtype.storm.security.auth.digest.DigestSaslTransportPlugin")
- ;(log-message "(Positive authentication) valid digest authentication")
(let [storm-conf (merge (read-storm-config)
{STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
"java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest.conf"})
client (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)
nimbus_client (.getClient client)]
- (.activate nimbus_client "security_auth_test_topology")
+ (testing "(Positive authentication) valid digest authentication"
+ (.activate nimbus_client "security_auth_test_topology"))
(.close client))
(let [storm-conf (merge (read-storm-config)
@@ -181,41 +179,37 @@
client (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)
nimbus_client (.getClient client)]
(testing "(Negative authentication) Server: Digest vs. Client: Simple"
- (is (thrown? TTransportException
- (.activate nimbus_client "security_auth_test_topology"))))
+ (is (thrown-cause? java.net.SocketTimeoutException
+ (.activate nimbus_client "security_auth_test_topology"))))
(.close client))
(let [storm-conf (merge (read-storm-config)
- {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
- "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_bad_password.conf"})]
+ {STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
+ "java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_bad_password.conf"})]
(testing "(Negative authentication) Invalid password"
- (is (= "Peer indicated failure: DIGEST-MD5: digest response format violation. Mismatched response."
- (try (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)
- nil
- (catch TTransportException ex (.getMessage ex)))))))
+ (is (thrown? TTransportException
+ (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
(let [storm-conf (merge (read-storm-config)
{STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
"java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_unknown_user.conf"})]
(testing "(Negative authentication) Unknown user"
- (is (= "Peer indicated failure: DIGEST-MD5: cannot acquire password for unknown_user in realm : localhost"
- (try (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)
- nil
- (catch TTransportException ex (.getMessage ex)))))))
+ (is (thrown? TTransportException
+ (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
(let [storm-conf (merge (read-storm-config)
{STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
"java.security.auth.login.config" "test/clj/backtype/storm/security/auth/nonexistent.conf"})]
- (testing "(Negative authentication) nonexistent configuration file"
- (is (thrown? RuntimeException
- (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
+ (testing "(Negative authentication) nonexistent configuration file"
+ (is (thrown? RuntimeException
+ (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout)))))
(let [storm-conf (merge (read-storm-config)
{STORM-THRIFT-TRANSPORT-PLUGIN "backtype.storm.security.auth.digest.DigestSaslTransportPlugin"
"java.security.auth.login.config" "test/clj/backtype/storm/security/auth/jaas_digest_missing_client.conf"})]
(testing "(Negative authentication) Missing client"
- (is (thrown? RuntimeException
- (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout))))))
+ (is (thrown-cause? java.io.IOException
+ (NimbusClient. storm-conf "localhost" 6630 nimbus-timeout))))))
(deftest test-GetTransportPlugin-throws-RuntimeException
Please sign in to comment.
Something went wrong with that request. Please try again.