-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ojung/add-tests
Add tests
- Loading branch information
Showing
6 changed files
with
110 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,72 @@ | ||
(ns mbeanz.handler_test | ||
(ns mbeanz.handler-test | ||
(:require [clojure.test :refer :all] | ||
[mbeanz.handler :refer :all] | ||
[ring.mock.request :as mock] | ||
[clojure.data.json :as json])) | ||
|
||
(deftest handler | ||
(use-fixtures :once (fn [do-tests] (reset! object-pattern "java.lang:*") (do-tests))) | ||
|
||
(defn- request [url params cb] | ||
(let [mock-request (mock/query-string (mock/request :get url) params) | ||
response (app mock-request)] | ||
(cb response))) | ||
|
||
(deftest list-route | ||
(testing "list route" | ||
(let [response (app (mock/request :get "/list"))] | ||
(is (= (:status response) 200)) | ||
(is (= (json/read-str (:body response)) | ||
["java.lang:type=Memory gc", | ||
"java.lang:type=MemoryPool,name=Code Cache resetPeakUsage", | ||
"java.lang:type=MemoryPool,name=Compressed Class Space resetPeakUsage", | ||
"java.lang:type=MemoryPool,name=Metaspace resetPeakUsage", | ||
"java.lang:type=MemoryPool,name=PS Eden Space resetPeakUsage", | ||
"java.lang:type=MemoryPool,name=PS Old Gen resetPeakUsage", | ||
"java.lang:type=MemoryPool,name=PS Survivor Space resetPeakUsage", | ||
"java.lang:type=Threading getThreadCpuTime", | ||
"java.lang:type=Threading getThreadCpuTime", | ||
"java.lang:type=Threading getThreadUserTime", | ||
"java.lang:type=Threading getThreadUserTime", | ||
"java.lang:type=Threading getThreadAllocatedBytes", | ||
"java.lang:type=Threading getThreadAllocatedBytes", | ||
"java.lang:type=Threading getThreadInfo", | ||
"java.lang:type=Threading getThreadInfo", | ||
"java.lang:type=Threading getThreadInfo", | ||
"java.lang:type=Threading getThreadInfo", | ||
"java.lang:type=Threading getThreadInfo", | ||
"java.lang:type=Threading findMonitorDeadlockedThreads", | ||
"java.lang:type=Threading resetPeakThreadCount", | ||
"java.lang:type=Threading findDeadlockedThreads", | ||
"java.lang:type=Threading dumpAllThreads"])))) | ||
(testing "describe route" | ||
(let [response (app (mock/request :get "/describe/gc?bean=java.lang:type=Memory"))] | ||
(is (= (:status response) 200))))) | ||
(request "/list" {} | ||
#(is (= (json/read-str (:body %)) | ||
[{"bean" "java.lang:type=Memory", "operation" "gc"} | ||
{"bean" "java.lang:type=MemoryPool,name=Code Cache", "operation" "resetPeakUsage"} | ||
{"bean" "java.lang:type=MemoryPool,name=Compressed Class Space" | ||
"operation" "resetPeakUsage"} | ||
{"bean" "java.lang:type=MemoryPool,name=Metaspace", "operation" "resetPeakUsage"} | ||
{"bean" "java.lang:type=MemoryPool,name=PS Eden Space", "operation" "resetPeakUsage"} | ||
{"bean" "java.lang:type=MemoryPool,name=PS Old Gen", "operation" "resetPeakUsage"} | ||
{"bean" "java.lang:type=MemoryPool,name=PS Survivor Space", "operation" "resetPeakUsage"} | ||
{"bean" "java.lang:type=Threading", "operation" "dumpAllThreads"} | ||
{"bean" "java.lang:type=Threading", "operation" "findDeadlockedThreads"} | ||
{"bean" "java.lang:type=Threading", "operation" "findMonitorDeadlockedThreads"} | ||
{"bean" "java.lang:type=Threading", "operation" "getThreadAllocatedBytes"} | ||
{"bean" "java.lang:type=Threading", "operation" "getThreadCpuTime"} | ||
{"bean" "java.lang:type=Threading", "operation" "getThreadInfo"} | ||
{"bean" "java.lang:type=Threading", "operation" "getThreadUserTime"} | ||
{"bean" "java.lang:type=Threading", "operation" "resetPeakThreadCount"}]))))) | ||
|
||
(deftest describe-route | ||
(testing "operation with single signature" | ||
(request "/describe/gc" {"bean" "java.lang:type=Memory"} | ||
#(is (= (json/read-str (:body %)) | ||
[{"name" "gc", "description" "gc", "signature" []}])))) | ||
|
||
(testing "operation with multiple signatures" | ||
(request "/describe/getThreadCpuTime" {"bean" "java.lang:type=Threading"} | ||
#(is (= (json/read-str (:body %)) | ||
[{"name" "getThreadCpuTime" | ||
"description" "getThreadCpuTime" | ||
"signature" [{"description" "p0", "name" "p0", "type" "[J"}]} | ||
{"name" "getThreadCpuTime" | ||
"description" "getThreadCpuTime" | ||
"signature" [{"description" "p0", "name" "p0", "type" "long"}]}])))) | ||
|
||
(testing "inexistent operation" | ||
;TODO: Make api return error (404): | ||
(request "/describe/inexistent" {"bean" "java.lang:type=Threading"} | ||
#(is (= (json/read-str (:body %)) []))))) | ||
|
||
(deftest invoke-route | ||
(testing "operation without arguments" | ||
(request "/invoke/gc" {"bean" "java.lang:type=Memory"} | ||
#(is (= (json/read-str (:body %)) {"result" nil})))) | ||
|
||
(testing "operation with arguments invoked with wrong signature" | ||
(request "/invoke/getThreadInfo" {"bean" "java.lang:type=Threading"} | ||
#(is (= (json/read-str (:body %)) | ||
{"error" {"class" "class javax.management.ReflectionException" | ||
"message" "Operation getThreadInfo exists but not with this signature: ()"}})))) | ||
|
||
(testing "operation with single argument invoked with correct signature" | ||
;TODO: Setup mock mbeans | ||
(request "/invoke/getThreadCpuTime" | ||
;Hoping this thread id doesn't exist | ||
{"bean" "java.lang:type=Threading", "args" "99999999999", "types" "long"} | ||
#(is (= (json/read-str (:body %)) {"result" -1}))))) |