예제 #1
0
func TestServerErrorGroup(t *testing.T) {
	srv := newTestServer(
		&imageserver.StaticServer{
			Error: fmt.Errorf("error"),
		},
		imageserver_cache.StringKeyGenerator("test"),
	)
	_, err := srv.Get(imageserver.Params{})
	if err == nil {
		t.Fatal("no error")
	}
}
예제 #2
0
func TestServerErrorGroup(t *testing.T) {
	srv := newTestServer(
		imageserver.ServerFunc(func(params imageserver.Params) (*imageserver.Image, error) {
			return nil, fmt.Errorf("error")
		}),
		imageserver_cache.StringKeyGenerator("test"),
	)
	_, err := srv.Get(imageserver.Params{})
	if err == nil {
		t.Fatal("no error")
	}
}
예제 #3
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 {
				dest.SetBytes(nil)
				return nil
			}),
		),
		KeyGenerator: imageserver_cache.StringKeyGenerator("test"),
	}
	_, err := srv.Get(imageserver.Params{})
	if err == nil {
		t.Fatal("no error")
	}
}
예제 #4
0
func TestServer(t *testing.T) {
	srv := newTestServer(
		&imageserver.StaticServer{
			Image: testdata.Medium,
		},
		imageserver_cache.StringKeyGenerator("test"),
	)
	im, err := srv.Get(imageserver.Params{
		imageserver.SourceParam: testdata.MediumFileName,
	})
	if err != nil {
		t.Fatal(err)
	}
	if !imageserver.ImageEqual(im, testdata.Medium) {
		t.Fatal("not equal")
	}
}
예제 #5
0
func TestServer(t *testing.T) {
	srv := newTestServer(
		imageserver.ServerFunc(func(params imageserver.Params) (*imageserver.Image, error) {
			return testdata.Medium, nil
		}),
		imageserver_cache.StringKeyGenerator("test"),
	)
	im, err := srv.Get(imageserver.Params{
		imageserver.SourceParam: 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) {
	srv := newTestServer(
		&imageserver.StaticServer{
			Image: im,
		},
		imageserver_cache.StringKeyGenerator("test"),
	)
	params := imageserver.Params{}
	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)))
}
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.StringKeyGenerator("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)))
}