예제 #1
0
func TestServerErrorGroup(t *testing.T) {
	srv := newTestServer(
		imageserver.ServerFunc(func(params imageserver.Params) (*imageserver.Image, error) {
			return nil, fmt.Errorf("error")
		}),
		imageserver_cache.KeyGeneratorFunc(func(params imageserver.Params) string {
			return "test"
		}),
	)
	_, err := srv.Get(imageserver.Params{})
	if err == nil {
		t.Fatal("no error")
	}
}
예제 #2
0
func TestServerErrorImageUnmarshal(t *testing.T) {
	srv := &Server{
		Group: groupcache.NewGroup(
			newTestServerName(),
			testSize,
			groupcache.GetterFunc(func(ctx groupcache.Context, key string, dest groupcache.Sink) error {
				return dest.SetBytes(nil)
			}),
		),
		KeyGenerator: imageserver_cache.KeyGeneratorFunc(func(params imageserver.Params) string {
			return "test"
		}),
	}
	_, err := srv.Get(imageserver.Params{})
	if err == nil {
		t.Fatal("no error")
	}
}
예제 #3
0
func TestServer(t *testing.T) {
	srv := newTestServer(
		imageserver.ServerFunc(func(params imageserver.Params) (*imageserver.Image, error) {
			return testdata.Medium, nil
		}),
		imageserver_cache.KeyGeneratorFunc(func(params imageserver.Params) string {
			return "test"
		}),
	)
	im, err := srv.Get(imageserver.Params{
		imageserver_source.Param: testdata.MediumFileName,
	})
	if err != nil {
		t.Fatal(err)
	}
	if !imageserver.ImageEqual(im, testdata.Medium) {
		t.Fatal("not equal")
	}
}
func benchmarkServer(b *testing.B, im *imageserver.Image, parallelism int) {
	srv := newTestServer(
		imageserver.ServerFunc(func(params imageserver.Params) (*imageserver.Image, error) {
			return im, nil
		}),
		imageserver_cache.KeyGeneratorFunc(func(params imageserver.Params) string {
			return "test"
		}),
	)
	params := imageserver.Params{}
	b.SetParallelism(parallelism)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			_, err := srv.Get(params)
			if err != nil {
				b.Fatal(err)
			}
		}
	})
	b.SetBytes(int64(len(im.Data)))
}