Created
August 29, 2013 12:31
-
-
Save neotyk/6377465 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(ns riemann-config-test | |
(:use | |
midje.sweet | |
riemann.streams | |
riemann.client | |
riemann.email | |
riemann.sns | |
[riemann.time :only [unix-time linear-time once! every!]]) | |
(:require | |
riemann.streams | |
riemann.config | |
riemann.core | |
riemann.index | |
riemann.query)) | |
(defmacro configure-core [& conf] | |
`(binding [*ns* (find-ns 'riemann.config)] | |
(eval '(do | |
(~'riemann.time/reset-tasks!) | |
(~'clear!) | |
(~'pubsub/sweep! (:pubsub @~'core)) | |
(~'logging/init) | |
(~'instrumentation {:enabled? false}) | |
(~'periodically-expire) | |
(~'streams ~@conf) | |
(when-let [idx# (:index @~'core)] | |
(~'riemann.index/clear idx#)) | |
(~'apply!))))) | |
(defn stream-events [& events] | |
(doseq [ev events] | |
(riemann.core/stream! @riemann.config/core ev))) | |
(defn search-index [query] | |
(riemann.index/search (:index @riemann.config/core) | |
(riemann.query/ast query))) | |
(facts "about simple streams" | |
(with-state-changes [(before :facts (configure-core (update-index (index))))] | |
(fact "Event gets indexed" | |
(stream-events {:host ..h.. | |
:service ..s.. | |
:state "ok" | |
:metric 42}) | |
(search-index "true") => [{:host ..h.. | |
:service ..s.. | |
:state "ok" | |
:metric 42}]) | |
(fact "Only last event for [:host :service] stays in the index" | |
(stream-events {:host ..h.. | |
:service ..s.. | |
:state "ok" | |
:metric 42} | |
{:host ..h.. | |
:service ..s.. | |
:state "ok" | |
:metric 43}) | |
(search-index "true") => [{:host ..h.. | |
:service ..s.. | |
:state "ok" | |
:metric 43}]))) |
Is this still something that should work? I'm really keen to test drive riemann config and quickly reached the limits of what was possible with the natively test stuff (searching indexes and what not).
I'm getting problems with it whinging about not being able to load stuff from a lib called amazonica. Something used by the cloudwatch integration. My clojure foo is weak and I can't work out how to tell it to shut up.
Any help gratefully received.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like Hubert wrote a few helper functions to test a Riemann config.
config-core is a macro that takes a Riemann config (in the form of Clojure expressions) and loads it up. stream-events is to run some events through the current config, and search-index is to see what is inside Riemann at the moment.
The rest is Midje, a BDD framework for Clojure.