mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-27 15:39:39 +00:00
Replace deprecated NewDeltaFIFO with NewDeltaFIFOWithOptions
Kubernetes-commit: 8dc45c8e0ecdefa37df8c118f38fa0767c5c52b0
This commit is contained in:
parent
af56ae8bf9
commit
aa707b1f81
5
tools/cache/controller_test.go
vendored
5
tools/cache/controller_test.go
vendored
@ -44,7 +44,10 @@ func Example() {
|
|||||||
// This will hold incoming changes. Note how we pass downstream in as a
|
// This will hold incoming changes. Note how we pass downstream in as a
|
||||||
// KeyLister, that way resync operations will result in the correct set
|
// KeyLister, that way resync operations will result in the correct set
|
||||||
// of update/delete deltas.
|
// of update/delete deltas.
|
||||||
fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, downstream)
|
fifo := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
|
KeyFunction: MetaNamespaceKeyFunc,
|
||||||
|
KnownObjects: downstream,
|
||||||
|
})
|
||||||
|
|
||||||
// Let's do threadsafe output to get predictable test results.
|
// Let's do threadsafe output to get predictable test results.
|
||||||
deletionCounter := make(chan string, 1000)
|
deletionCounter := make(chan string, 1000)
|
||||||
|
94
tools/cache/delta_fifo_test.go
vendored
94
tools/cache/delta_fifo_test.go
vendored
@ -56,7 +56,7 @@ func (kl literalListerGetter) GetByKey(key string) (interface{}, bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_basic(t *testing.T) {
|
func TestDeltaFIFO_basic(t *testing.T) {
|
||||||
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
||||||
const amount = 500
|
const amount = 500
|
||||||
go func() {
|
go func() {
|
||||||
for i := 0; i < amount; i++ {
|
for i := 0; i < amount; i++ {
|
||||||
@ -100,9 +100,12 @@ func TestDeltaFIFO_replaceWithDeleteDeltaIn(t *testing.T) {
|
|||||||
oldObj := mkFifoObj("foo", 1)
|
oldObj := mkFifoObj("foo", 1)
|
||||||
newObj := mkFifoObj("foo", 2)
|
newObj := mkFifoObj("foo", 2)
|
||||||
|
|
||||||
f := NewDeltaFIFO(testFifoObjectKeyFunc, literalListerGetter(func() []testFifoObject {
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
return []testFifoObject{oldObj}
|
KeyFunction: testFifoObjectKeyFunc,
|
||||||
}))
|
KnownObjects: literalListerGetter(func() []testFifoObject {
|
||||||
|
return []testFifoObject{oldObj}
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
f.Delete(oldObj)
|
f.Delete(oldObj)
|
||||||
f.Replace([]interface{}{newObj}, "")
|
f.Replace([]interface{}{newObj}, "")
|
||||||
@ -118,7 +121,7 @@ func TestDeltaFIFO_replaceWithDeleteDeltaIn(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_requeueOnPop(t *testing.T) {
|
func TestDeltaFIFO_requeueOnPop(t *testing.T) {
|
||||||
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
||||||
|
|
||||||
f.Add(mkFifoObj("foo", 10))
|
f.Add(mkFifoObj("foo", 10))
|
||||||
_, err := f.Pop(func(obj interface{}) error {
|
_, err := f.Pop(func(obj interface{}) error {
|
||||||
@ -162,7 +165,7 @@ func TestDeltaFIFO_requeueOnPop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_addUpdate(t *testing.T) {
|
func TestDeltaFIFO_addUpdate(t *testing.T) {
|
||||||
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
||||||
f.Add(mkFifoObj("foo", 10))
|
f.Add(mkFifoObj("foo", 10))
|
||||||
f.Update(mkFifoObj("foo", 12))
|
f.Update(mkFifoObj("foo", 12))
|
||||||
f.Delete(mkFifoObj("foo", 15))
|
f.Delete(mkFifoObj("foo", 15))
|
||||||
@ -200,7 +203,7 @@ func TestDeltaFIFO_addUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_enqueueingNoLister(t *testing.T) {
|
func TestDeltaFIFO_enqueueingNoLister(t *testing.T) {
|
||||||
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
||||||
f.Add(mkFifoObj("foo", 10))
|
f.Add(mkFifoObj("foo", 10))
|
||||||
f.Update(mkFifoObj("bar", 15))
|
f.Update(mkFifoObj("bar", 15))
|
||||||
f.Add(mkFifoObj("qux", 17))
|
f.Add(mkFifoObj("qux", 17))
|
||||||
@ -221,12 +224,12 @@ func TestDeltaFIFO_enqueueingNoLister(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_enqueueingWithLister(t *testing.T) {
|
func TestDeltaFIFO_enqueueingWithLister(t *testing.T) {
|
||||||
f := NewDeltaFIFO(
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
testFifoObjectKeyFunc,
|
KeyFunction: testFifoObjectKeyFunc,
|
||||||
literalListerGetter(func() []testFifoObject {
|
KnownObjects: literalListerGetter(func() []testFifoObject {
|
||||||
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
|
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
|
||||||
}),
|
}),
|
||||||
)
|
})
|
||||||
f.Add(mkFifoObj("foo", 10))
|
f.Add(mkFifoObj("foo", 10))
|
||||||
f.Update(mkFifoObj("bar", 15))
|
f.Update(mkFifoObj("bar", 15))
|
||||||
|
|
||||||
@ -245,7 +248,7 @@ func TestDeltaFIFO_enqueueingWithLister(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_addReplace(t *testing.T) {
|
func TestDeltaFIFO_addReplace(t *testing.T) {
|
||||||
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
||||||
f.Add(mkFifoObj("foo", 10))
|
f.Add(mkFifoObj("foo", 10))
|
||||||
f.Replace([]interface{}{mkFifoObj("foo", 15)}, "0")
|
f.Replace([]interface{}{mkFifoObj("foo", 15)}, "0")
|
||||||
got := make(chan testFifoObject, 2)
|
got := make(chan testFifoObject, 2)
|
||||||
@ -271,12 +274,12 @@ func TestDeltaFIFO_addReplace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_ResyncNonExisting(t *testing.T) {
|
func TestDeltaFIFO_ResyncNonExisting(t *testing.T) {
|
||||||
f := NewDeltaFIFO(
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
testFifoObjectKeyFunc,
|
KeyFunction: testFifoObjectKeyFunc,
|
||||||
literalListerGetter(func() []testFifoObject {
|
KnownObjects: literalListerGetter(func() []testFifoObject {
|
||||||
return []testFifoObject{mkFifoObj("foo", 5)}
|
return []testFifoObject{mkFifoObj("foo", 5)}
|
||||||
}),
|
}),
|
||||||
)
|
})
|
||||||
f.Delete(mkFifoObj("foo", 10))
|
f.Delete(mkFifoObj("foo", 10))
|
||||||
f.Resync()
|
f.Resync()
|
||||||
|
|
||||||
@ -290,12 +293,12 @@ func TestDeltaFIFO_ResyncNonExisting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_Resync(t *testing.T) {
|
func TestDeltaFIFO_Resync(t *testing.T) {
|
||||||
f := NewDeltaFIFO(
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
testFifoObjectKeyFunc,
|
KeyFunction: testFifoObjectKeyFunc,
|
||||||
literalListerGetter(func() []testFifoObject {
|
KnownObjects: literalListerGetter(func() []testFifoObject {
|
||||||
return []testFifoObject{mkFifoObj("foo", 5)}
|
return []testFifoObject{mkFifoObj("foo", 5)}
|
||||||
}),
|
}),
|
||||||
)
|
})
|
||||||
f.Resync()
|
f.Resync()
|
||||||
|
|
||||||
deltas := f.items["foo"]
|
deltas := f.items["foo"]
|
||||||
@ -308,12 +311,12 @@ func TestDeltaFIFO_Resync(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_DeleteExistingNonPropagated(t *testing.T) {
|
func TestDeltaFIFO_DeleteExistingNonPropagated(t *testing.T) {
|
||||||
f := NewDeltaFIFO(
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
testFifoObjectKeyFunc,
|
KeyFunction: testFifoObjectKeyFunc,
|
||||||
literalListerGetter(func() []testFifoObject {
|
KnownObjects: literalListerGetter(func() []testFifoObject {
|
||||||
return []testFifoObject{}
|
return []testFifoObject{}
|
||||||
}),
|
}),
|
||||||
)
|
})
|
||||||
f.Add(mkFifoObj("foo", 5))
|
f.Add(mkFifoObj("foo", 5))
|
||||||
f.Delete(mkFifoObj("foo", 6))
|
f.Delete(mkFifoObj("foo", 6))
|
||||||
|
|
||||||
@ -331,12 +334,12 @@ func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) {
|
|||||||
// promise about how their deletes are ordered.
|
// promise about how their deletes are ordered.
|
||||||
|
|
||||||
// Try it with a pre-existing Delete
|
// Try it with a pre-existing Delete
|
||||||
f := NewDeltaFIFO(
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
testFifoObjectKeyFunc,
|
KeyFunction: testFifoObjectKeyFunc,
|
||||||
literalListerGetter(func() []testFifoObject {
|
KnownObjects: literalListerGetter(func() []testFifoObject {
|
||||||
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
|
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
|
||||||
}),
|
}),
|
||||||
)
|
})
|
||||||
f.Delete(mkFifoObj("baz", 10))
|
f.Delete(mkFifoObj("baz", 10))
|
||||||
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")
|
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")
|
||||||
|
|
||||||
@ -356,12 +359,12 @@ func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now try starting with an Add instead of a Delete
|
// Now try starting with an Add instead of a Delete
|
||||||
f = NewDeltaFIFO(
|
f = NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
testFifoObjectKeyFunc,
|
KeyFunction: testFifoObjectKeyFunc,
|
||||||
literalListerGetter(func() []testFifoObject {
|
KnownObjects: literalListerGetter(func() []testFifoObject {
|
||||||
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
|
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
|
||||||
}),
|
}),
|
||||||
)
|
})
|
||||||
f.Add(mkFifoObj("baz", 10))
|
f.Add(mkFifoObj("baz", 10))
|
||||||
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")
|
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")
|
||||||
|
|
||||||
@ -382,10 +385,7 @@ func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now try starting without an explicit KeyListerGetter
|
// Now try starting without an explicit KeyListerGetter
|
||||||
f = NewDeltaFIFO(
|
f = NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
||||||
testFifoObjectKeyFunc,
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
f.Add(mkFifoObj("baz", 10))
|
f.Add(mkFifoObj("baz", 10))
|
||||||
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")
|
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")
|
||||||
|
|
||||||
@ -458,12 +458,12 @@ func TestDeltaFIFO_ReplaceDeltaType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_UpdateResyncRace(t *testing.T) {
|
func TestDeltaFIFO_UpdateResyncRace(t *testing.T) {
|
||||||
f := NewDeltaFIFO(
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
testFifoObjectKeyFunc,
|
KeyFunction: testFifoObjectKeyFunc,
|
||||||
literalListerGetter(func() []testFifoObject {
|
KnownObjects: literalListerGetter(func() []testFifoObject {
|
||||||
return []testFifoObject{mkFifoObj("foo", 5)}
|
return []testFifoObject{mkFifoObj("foo", 5)}
|
||||||
}),
|
}),
|
||||||
)
|
})
|
||||||
f.Update(mkFifoObj("foo", 6))
|
f.Update(mkFifoObj("foo", 6))
|
||||||
f.Resync()
|
f.Resync()
|
||||||
|
|
||||||
@ -480,12 +480,12 @@ func TestDeltaFIFO_UpdateResyncRace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_HasSyncedCorrectOnDeletion(t *testing.T) {
|
func TestDeltaFIFO_HasSyncedCorrectOnDeletion(t *testing.T) {
|
||||||
f := NewDeltaFIFO(
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
testFifoObjectKeyFunc,
|
KeyFunction: testFifoObjectKeyFunc,
|
||||||
literalListerGetter(func() []testFifoObject {
|
KnownObjects: literalListerGetter(func() []testFifoObject {
|
||||||
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
|
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
|
||||||
}),
|
}),
|
||||||
)
|
})
|
||||||
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")
|
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")
|
||||||
|
|
||||||
expectedList := []Deltas{
|
expectedList := []Deltas{
|
||||||
@ -511,7 +511,7 @@ func TestDeltaFIFO_HasSyncedCorrectOnDeletion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_detectLineJumpers(t *testing.T) {
|
func TestDeltaFIFO_detectLineJumpers(t *testing.T) {
|
||||||
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
||||||
|
|
||||||
f.Add(mkFifoObj("foo", 10))
|
f.Add(mkFifoObj("foo", 10))
|
||||||
f.Add(mkFifoObj("bar", 1))
|
f.Add(mkFifoObj("bar", 1))
|
||||||
@ -539,7 +539,7 @@ func TestDeltaFIFO_detectLineJumpers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeltaFIFO_addIfNotPresent(t *testing.T) {
|
func TestDeltaFIFO_addIfNotPresent(t *testing.T) {
|
||||||
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
||||||
|
|
||||||
f.Add(mkFifoObj("b", 3))
|
f.Add(mkFifoObj("b", 3))
|
||||||
b3 := Pop(f)
|
b3 := Pop(f)
|
||||||
@ -645,7 +645,7 @@ func TestDeltaFIFO_HasSynced(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
|
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
||||||
|
|
||||||
for _, action := range test.actions {
|
for _, action := range test.actions {
|
||||||
action(f)
|
action(f)
|
||||||
|
Loading…
Reference in New Issue
Block a user