storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kabh...@apache.org
Subject [4/7] storm git commit: STORM-1237: port backtype.storm.security.auth.ThriftClient-test to java
Date Thu, 07 Jul 2016 14:26:36 GMT
STORM-1237: port backtype.storm.security.auth.ThriftClient-test to java


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/487c05ea
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/487c05ea
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/487c05ea

Branch: refs/heads/master
Commit: 487c05eac0ead1c84ecde7bd08cca119fa372480
Parents: 7d43b39
Author: Abhishek Agarwal <abhishek.agarwal@inmobi.com>
Authored: Thu Mar 10 15:09:43 2016 +0530
Committer: Abhishek Agarwal <abhishek.agarwal@inmobi.com>
Committed: Sun Mar 13 18:46:18 2016 +0530

----------------------------------------------------------------------
 storm-core/pom.xml                              | 13 ++--
 .../storm/security/auth/ThriftClient_test.clj   | 61 ------------------
 .../storm/security/auth/ThriftClientTest.java   | 68 ++++++++++++++++++++
 .../utils/ThrowableNestedCauseMatcher.java      | 44 +++++++++++++
 4 files changed, 120 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/487c05ea/storm-core/pom.xml
----------------------------------------------------------------------
diff --git a/storm-core/pom.xml b/storm-core/pom.xml
index 624e340..b3aad6a 100644
--- a/storm-core/pom.xml
+++ b/storm-core/pom.xml
@@ -146,7 +146,7 @@
           <artifactId>java.jmx</artifactId>
           <version>${java_jmx.version}</version>
         </dependency>
-        
+
         <!--java-->
         <dependency>
             <groupId>commons-cli</groupId>
@@ -286,14 +286,17 @@
             <groupId>metrics-clojure</groupId>
             <artifactId>metrics-clojure</artifactId>
         </dependency>
+        <!-- hamcrest-core dependency is shaded inside the mockito-all and junit depends
on newer version of hamcrest-core.
+        To give higher precedence to classes from newer version of hamcrest-core, Junit has
been placed above mockito.
+         -->
         <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-all</artifactId>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/storm/blob/487c05ea/storm-core/test/clj/org/apache/storm/security/auth/ThriftClient_test.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/clj/org/apache/storm/security/auth/ThriftClient_test.clj b/storm-core/test/clj/org/apache/storm/security/auth/ThriftClient_test.clj
deleted file mode 100644
index 48e8421..0000000
--- a/storm-core/test/clj/org/apache/storm/security/auth/ThriftClient_test.clj
+++ /dev/null
@@ -1,61 +0,0 @@
-;; Licensed to the Apache Software Foundation (ASF) under one
-;; or more contributor license agreements.  See the NOTICE file
-;; distributed with this work for additional information
-;; regarding copyright ownership.  The ASF licenses this file
-;; to you under the Apache License, Version 2.0 (the
-;; "License"); you may not use this file except in compliance
-;; with the License.  You may obtain a copy of the License at
-;;
-;; http://www.apache.org/licenses/LICENSE-2.0
-;;
-;; Unless required by applicable law or agreed to in writing, software
-;; distributed under the License is distributed on an "AS IS" BASIS,
-;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-;; See the License for the specific language governing permissions and
-;; limitations under the License.
-(ns org.apache.storm.security.auth.ThriftClient-test
-  (:use [org.apache.storm config util])
-  (:use [clojure test])
-  (:require [org.apache.storm.security.auth [auth-test :refer [nimbus-timeout]]])
-  (:import [org.apache.storm.security.auth ThriftClient ThriftConnectionType])
-  (:import [org.apache.thrift.transport TTransportException])
-  (:import [org.apache.storm.utils Utils])
-)
-
-(deftest test-ctor-throws-if-port-invalid
-  (let [conf (merge
-               (clojurify-structure (Utils/readDefaultConfig))
-              {STORM-NIMBUS-RETRY-TIMES 0})]
-    (is (thrown-cause? java.lang.IllegalArgumentException
-      (ThriftClient. conf
-                     ThriftConnectionType/DRPC
-                     "bogushost"
-                     (int -1)
-                     nimbus-timeout)))
-    (is (thrown-cause? java.lang.IllegalArgumentException
-        (ThriftClient. conf
-                       ThriftConnectionType/DRPC
-                       "bogushost"
-                       (int 0)
-                       nimbus-timeout)))
-  )
-)
-
-(deftest test-ctor-throws-if-host-not-set
-  (let [conf (merge
-               (clojurify-structure (Utils/readDefaultConfig))
-              {STORM-NIMBUS-RETRY-TIMES 0})]
-    (is (thrown-cause? TTransportException
-         (ThriftClient. conf
-                        ThriftConnectionType/DRPC
-                        ""
-                        (int 4242)
-                        nimbus-timeout)))
-    (is (thrown-cause? IllegalArgumentException
-        (ThriftClient. conf
-                       ThriftConnectionType/DRPC
-                       nil
-                       (int 4242)
-                       nimbus-timeout)))
-  )
-)

http://git-wip-us.apache.org/repos/asf/storm/blob/487c05ea/storm-core/test/jvm/org/apache/storm/security/auth/ThriftClientTest.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/org/apache/storm/security/auth/ThriftClientTest.java b/storm-core/test/jvm/org/apache/storm/security/auth/ThriftClientTest.java
new file mode 100644
index 0000000..0e568dd
--- /dev/null
+++ b/storm-core/test/jvm/org/apache/storm/security/auth/ThriftClientTest.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.storm.security.auth;
+
+import org.apache.storm.Config;
+import org.apache.storm.utils.ThrowableNestedCauseMatcher;
+import org.apache.storm.utils.Utils;
+import org.apache.thrift.transport.TTransportException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.util.Map;
+
+public class ThriftClientTest {
+
+    private int NIMBUS_TIMEOUT = 3 * 1000;
+    private Map conf;
+
+    @Before
+    public void setup() {
+        conf = Utils.readDefaultConfig();
+        conf.put(Config.STORM_NIMBUS_RETRY_TIMES, 0);
+    }
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Test
+    public void testConstructorThrowsIfPortNegative() {
+        expectedException.expect(ThrowableNestedCauseMatcher.isCausedBy(IllegalArgumentException.class));
+        new ThriftClient(conf, ThriftConnectionType.DRPC, "bogushost", -1, NIMBUS_TIMEOUT);
+    }
+
+    @Test
+    public void testConstructorThrowsIfPortZero() {
+        expectedException.expect(ThrowableNestedCauseMatcher.isCausedBy(IllegalArgumentException.class));
+        new ThriftClient(conf, ThriftConnectionType.DRPC, "bogushost", 0, NIMBUS_TIMEOUT);
+    }
+
+    @Test
+    public void testConstructorThrowsIfHostNull() {
+        expectedException.expect(ThrowableNestedCauseMatcher.isCausedBy(IllegalArgumentException.class));
+        new ThriftClient(conf, ThriftConnectionType.DRPC, null, 4242, NIMBUS_TIMEOUT);
+    }
+
+    @Test
+    public void testConstructorThrowsIfHostEmpty() {
+        expectedException.expectCause(ThrowableNestedCauseMatcher.isCausedBy(TTransportException.class));
+        new ThriftClient(conf, ThriftConnectionType.DRPC, "", 4242, NIMBUS_TIMEOUT);
+    }
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/487c05ea/storm-core/test/jvm/org/apache/storm/utils/ThrowableNestedCauseMatcher.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/org/apache/storm/utils/ThrowableNestedCauseMatcher.java b/storm-core/test/jvm/org/apache/storm/utils/ThrowableNestedCauseMatcher.java
new file mode 100644
index 0000000..ad6094e
--- /dev/null
+++ b/storm-core/test/jvm/org/apache/storm/utils/ThrowableNestedCauseMatcher.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.storm.utils;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+
+public class ThrowableNestedCauseMatcher extends BaseMatcher<Throwable> {
+
+    private Class<? extends Throwable> exceptionCause;
+
+    public ThrowableNestedCauseMatcher(Class<? extends Throwable> exceptionCause) {
+        this.exceptionCause = exceptionCause;
+    }
+
+    @Override
+    public boolean matches(Object throwable) {
+        return Utils.exceptionCauseIsInstanceOf(exceptionCause, (Throwable) throwable);
+    }
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText(exceptionCause.getName());
+    }
+
+    public static ThrowableNestedCauseMatcher isCausedBy(Class<? extends Throwable>
exceptionCause) {
+        return new ThrowableNestedCauseMatcher(exceptionCause);
+    }
+}


Mime
View raw message