Example #1
0
// TestGetMiss is a helper to test Cache.Get() with a "cache miss".
func TestGetMiss(t *testing.T, cache imageserver_cache.Cache) {
	im, err := cache.Get(KeyMiss, imageserver.Params{})
	if err != nil {
		t.Fatal(err)
	}
	if im != nil {
		t.Fatal("image not nil")
	}
}
Example #2
0
// TestGetSet is a helper to test Cache.Get()/Set().
func TestGetSet(t *testing.T, cache imageserver_cache.Cache) {
	err := cache.Set(KeyValid, testdata.Medium, imageserver.Params{})
	if err != nil {
		t.Fatal(err)
	}
	im, err := cache.Get(KeyValid, imageserver.Params{})
	if err != nil {
		t.Fatal(err)
	}
	if im == nil {
		t.Fatal("image nil")
	}
	if !imageserver.ImageEqual(im, testdata.Medium) {
		t.Fatal("image not equals")
	}
}
Example #3
0
// BenchmarkGet is a helper to benchmark Cache.Get().
func BenchmarkGet(b *testing.B, cache imageserver_cache.Cache, parallelism int, im *imageserver.Image) {
	key := "test"
	err := cache.Set(key, im, imageserver.Params{})
	if err != nil {
		b.Fatal(err)
	}
	params := imageserver.Params{}
	b.SetParallelism(parallelism)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			im, err := cache.Get(key, params)
			if err != nil {
				b.Fatal(err)
			}
			if im == nil {
				b.Fatal("image nil")
			}
		}
	})
	b.SetBytes(int64(len(im.Data)))
}