I'm writing unit tests for an application which sends events to Riemann. Riemann starts up very slowly, so I decided to launch it once and reuse the instance for all tests. Therefore I need to clean the index from events produced by previous tests in the beginning of each new test.
What I'm trying to do is to configure Riemann in such a way that on receiving a special event it will clear its index. There is an API call that seems to be suitable for the task: http://riemann.io/api/riemann.index.html#var-clear. But I am not very familiar with Clojure and I cannot figure out how to use it. Here is a part of my config:
(streams
index
(where (state "clear-all")
(riemann.index/clear (:index @core))))
But Riemann fails to start with this error: No implementation of method: :clear of protocol: #'riemann.index/Index found for class: nil
This looks like (:index @core)
is evaluated to nil
.
This does not work too:
(streams
index
(where (state "clear-all")
(riemann.index/clear index)))
The error is: No implementation of method: :clear of protocol: #'riemann.index/Index found for class: riemann.streams$default$stream__9829
Instead trying to evaluate (riemann.index/clear (:index @core))
immediately I need a function which will be called when an event arrives:
(streams
(where (state "clear-all")
(fn [_]
(riemann.index/clear (:index @core)))
(else index)))
Now everything works.