Merge pull request #23288 from smarterclayton/refactor_codec

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot
2016-03-26 10:47:58 -07:00
10 changed files with 299 additions and 87 deletions

View File

@@ -59,8 +59,6 @@ func fuzzInternalObject(t *testing.T, forVersion unversioned.GroupVersion, item
}
func roundTrip(t *testing.T, codec runtime.Codec, item runtime.Object) {
//t.Logf("codec: %#v", codec)
printer := spew.ConfigState{DisableMethods: true}
name := reflect.TypeOf(item).Elem().Name()
@@ -118,9 +116,6 @@ func roundTripSame(t *testing.T, group testapi.TestGroup, item runtime.Object, e
// For debugging problems
func TestSpecificKind(t *testing.T) {
// api.Scheme.Log(t)
// defer api.Scheme.Log(nil)
kind := "DaemonSet"
for i := 0; i < *fuzzIters; i++ {
doRoundTripTest(testapi.Groups["extensions"], kind, t)
@@ -131,9 +126,6 @@ func TestSpecificKind(t *testing.T) {
}
func TestList(t *testing.T) {
// api.Scheme.Log(t)
// defer api.Scheme.Log(nil)
kind := "List"
item, err := api.Scheme.New(api.SchemeGroupVersion.WithKind(kind))
if err != nil {
@@ -149,9 +141,6 @@ var nonInternalRoundTrippableTypes = sets.NewString("List", "ListOptions", "Expo
var nonRoundTrippableTypesByVersion = map[string][]string{}
func TestRoundTripTypes(t *testing.T) {
// api.Scheme.Log(t)
// defer api.Scheme.Log(nil)
for groupKey, group := range testapi.Groups {
for kind := range group.InternalTypes() {
t.Logf("working on %v in %v", kind, groupKey)
@@ -286,6 +275,26 @@ func BenchmarkEncodeCodec(b *testing.B) {
b.StopTimer()
}
// BenchmarkEncodeCodecFromInternal measures the cost of performing a codec encode,
// including conversions.
func BenchmarkEncodeCodecFromInternal(b *testing.B) {
items := benchmarkItems()
width := len(items)
encodable := make([]api.Pod, width)
for i := range items {
if err := api.Scheme.Convert(&items[i], &encodable[i]); err != nil {
b.Fatal(err)
}
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := runtime.Encode(testapi.Default.Codec(), &encodable[i%width]); err != nil {
b.Fatal(err)
}
}
b.StopTimer()
}
// BenchmarkEncodeJSONMarshal provides a baseline for regular JSON encode performance
func BenchmarkEncodeJSONMarshal(b *testing.B) {
items := benchmarkItems()