From 2cfcf497e110aa8e660015cbd3ae1bd86c551f59 Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Fri, 21 Jul 2017 00:16:37 -0500 Subject: [PATCH] add tests for none cache --- cache.go | 6 +++--- fragment.go | 4 ++++ fragment_test.go | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cache.go b/cache.go index e5f1163a0..d6d4174cd 100644 --- a/cache.go +++ b/cache.go @@ -501,11 +501,11 @@ func NewNopCache() *NopCache { func (c *NopCache) Add(id uint64, n uint64) {} func (c *NopCache) BulkAdd(id uint64, n uint64) {} -func (c *NopCache) Get(id uint64) uint64 { return 0 } -func (c *NopCache) IDs() []uint64 { return make([]uint64, 0, 0) } +func (c *NopCache) Get(id uint64) uint64 { return 0 } +func (c *NopCache) IDs() []uint64 { return make([]uint64, 0, 0) } func (c *NopCache) Invalidate() {} -func (c *NopCache) Len() int { return 0 } +func (c *NopCache) Len() int { return 0 } func (c *NopCache) Recalculate() { } func (c *NopCache) SetStats(s StatsClient) { diff --git a/fragment.go b/fragment.go index fdfcddd86..16ec5869f 100644 --- a/fragment.go +++ b/fragment.go @@ -704,6 +704,10 @@ func (f *Fragment) Top(opt TopOptions) ([]Pair, error) { } func (f *Fragment) topBitmapPairs(rowIDs []uint64) []BitmapPair { + // Don't retrieve from storage if CacheTypeNone + if f.CacheType == CacheTypeNone { + return f.cache.Top() + } // If no specific rows are requested, retrieve top rows. if len(rowIDs) == 0 { f.mu.Lock() diff --git a/fragment_test.go b/fragment_test.go index 01f4a46bc..5a58acd60 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -415,6 +415,24 @@ func TestFragment_TopN_IDs(t *testing.T) { } } +// Ensure a fragment can return top rows when specified by ID. +func TestFragment_TopN_NopCache(t *testing.T) { + f := test.MustOpenFragment("i", "f", pilosa.ViewStandard, 0, pilosa.CacheTypeNone) + defer f.Close() + + // Set bits on various rows. + f.MustSetBits(100, 1, 2, 3) + f.MustSetBits(101, 4, 5, 6, 7) + f.MustSetBits(102, 8, 9, 10, 11, 12) + + // Retrieve top rows. + if pairs, err := f.Top(pilosa.TopOptions{RowIDs: []uint64{100, 101, 200}}); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(pairs, []pilosa.Pair{}) { + t.Fatalf("unexpected pairs: %s", spew.Sdump(pairs)) + } +} + // Ensure the fragment cache limit works func TestFragment_TopN_CacheSize(t *testing.T) { slice := uint64(0)