我正在为一个将事件发送到Riemann的应用程序编写单元测试。Riemann启动非常慢,所以我决定启动它一次,并在所有测试中重用该实例。因此,在每次新测试开始时,我需要从以前的测试中生成的事件中清除索引。
我要做的是配置Riemann,这样在接收到一个特殊事件时,它就会清除它的索引。有一个API调用似乎适合这个任务:http://riemann.io/api/riemann.index.html#var-clear。但我对Clojure并不十分熟悉,我也不知道如何使用它。下面是我配置的一部分:
(streams
index
(where (state "clear-all")
(riemann.index/clear (:index @core))))但是Riemann没有从这个错误开始:No implementation of method: :clear of protocol: #'riemann.index/Index found for class: nil
这看起来像(:index @core)被计算为nil。
这一点也不起作用:
(streams
index
(where (state "clear-all")
(riemann.index/clear index)))错误是:No implementation of method: :clear of protocol: #'riemann.index/Index found for class: riemann.streams$default$stream__9829
发布于 2015-10-07 00:02:04
相反,尝试立即计算(riemann.index/clear (:index @core)),我需要一个在事件到达时将被调用的函数:
(streams
(where (state "clear-all")
(fn [_]
(riemann.index/clear (:index @core)))
(else index)))现在一切都正常了。
发布于 2015-10-06 05:52:47
里曼的专家,只能猜测。第一个片段似乎是正确的,但是当您调用该代码时,索引还没有关联到内核中呢?在本例中,您只需为nil值实现nil协议,因此当:index值为nil时,它将什么也不做。类似的东西(未经测试):
(extend-protocol riemann.index/Index
nil
(clear [_])
(delete [_ _])
(delete-exactly [_ _])
(expire [_])
(search [_ _])
(update [_ _])
(lookup [_ _ _]))希望这会有帮助。
https://stackoverflow.com/questions/32958360
复制相似问题