Skip to content

Commit

Permalink
Add tests for Solr7 cache responses
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhav committed Jun 12, 2018
1 parent 12a96e1 commit 82c9fec
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
26 changes: 26 additions & 0 deletions plugins/inputs/solr/solr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ func TestGatherStats(t *testing.T) {
map[string]string{"core": "main", "handler": "filterCache"})
}

func TestSolr7MbeansStats(t *testing.T) {
ts := createMockSolr7Server()
solr := NewSolr()
solr.Servers = []string{ts.URL}
var acc testutil.Accumulator
require.NoError(t, solr.Gather(&acc))
acc.AssertContainsTaggedFields(t, "solr_cache",
solr7CacheExpected,
map[string]string{"core": "main", "handler": "documentCache"})
}

func TestSolr3GatherStats(t *testing.T) {
ts := createMockSolr3Server()
solr := NewSolr()
Expand Down Expand Up @@ -150,3 +161,18 @@ func createMockSolr3Server() *httptest.Server {
}
}))
}

func createMockSolr7Server() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.URL.Path, "/solr/admin/cores") {
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, statusResponse)
} else if strings.Contains(r.URL.Path, "solr/main/admin") {
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, mBeansSolr7Response)
} else {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintln(w, "nope")
}
}))
}
61 changes: 61 additions & 0 deletions plugins/inputs/solr/testdata7_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package solr

const mBeansSolr7Response = `
{
"responseHeader":{
"status":0,
"QTime":2
},
"solr-mbeans":[
"CORE",
{
},
"QUERYHANDLER",
{
},
"UPDATEHANDLER",
{
},
"CACHE",
{
"documentCache":{
"class":"org.apache.solr.search.LRUCache",
"description":"LRU Cache(maxSize=16384, initialSize=4096)",
"stats":{
"CACHE.searcher.documentCache.evictions": 141485,
"CACHE.searcher.documentCache.cumulative_lookups": 265132,
"CACHE.searcher.documentCache.hitratio": 0.44,
"CACHE.searcher.documentCache.size": 8192,
"CACHE.searcher.documentCache.cumulative_hitratio": 0.42,
"CACHE.searcher.documentCache.lookups": 1234,
"CACHE.searcher.documentCache.warmupTime": 1,
"CACHE.searcher.documentCache.inserts": 987,
"CACHE.searcher.documentCache.hits": 1111,
"CACHE.searcher.documentCache.cumulative_hits": 115364,
"CACHE.searcher.documentCache.cumulative_inserts": 149768,
"CACHE.searcher.documentCache.cumulative_evictions": 141486
}
}
}
]
}
`


var solr7CacheExpected = map[string]interface{}{
"evictions": int64(141485),
"cumulative_evictions": int64(141486),
"cumulative_hitratio": float64(0.42),
"cumulative_hits": int64(115364),
"cumulative_inserts": int64(149768),
"cumulative_lookups": int64(265132),
"hitratio": float64(0.44),
"hits": int64(1111),
"inserts": int64(987),
"lookups": int64(1234),
"size": int64(8192),
"warmup_time": int64(1),
}

0 comments on commit 82c9fec

Please sign in to comment.