github.com/thanos-io/thanos@v0.32.5/internal/cortex/chunk/cache/tiered_test.go (about)

     1  // Copyright (c) The Cortex Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package cache_test
     5  
     6  import (
     7  	"context"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/require"
    11  
    12  	"github.com/thanos-io/thanos/internal/cortex/chunk/cache"
    13  )
    14  
    15  func TestTieredSimple(t *testing.T) {
    16  	for i := 1; i < 10; i++ {
    17  		caches := []cache.Cache{}
    18  		for j := 0; j <= i; j++ {
    19  			caches = append(caches, cache.NewMockCache())
    20  		}
    21  		cache := cache.NewTiered(caches)
    22  		testCache(t, cache)
    23  	}
    24  }
    25  
    26  func TestTiered(t *testing.T) {
    27  	level1, level2 := cache.NewMockCache(), cache.NewMockCache()
    28  	cache := cache.NewTiered([]cache.Cache{level1, level2})
    29  
    30  	level1.Store(context.Background(), []string{"key1"}, [][]byte{[]byte("hello")})
    31  	level2.Store(context.Background(), []string{"key2"}, [][]byte{[]byte("world")})
    32  
    33  	keys, bufs, missing := cache.Fetch(context.Background(), []string{"key1", "key2", "key3"})
    34  	require.Equal(t, []string{"key1", "key2"}, keys)
    35  	require.Equal(t, [][]byte{[]byte("hello"), []byte("world")}, bufs)
    36  	require.Equal(t, []string{"key3"}, missing)
    37  }