-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alec Holmes <[email protected]>
- Loading branch information
1 parent
ee35819
commit 776db2e
Showing
6 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cache | ||
|
||
// Key is an internal sorting data structure we can use to | ||
// order responses by Type and their associated watch IDs. | ||
type key struct { | ||
ID int64 | ||
TypeURL string | ||
} | ||
|
||
// Keys implements Go's sorting.Sort interface | ||
type keys []key | ||
|
||
func (k keys) Len() int { | ||
return len(k) | ||
} | ||
|
||
// Less compares the typeURL and determines what order things should be sent. | ||
func (k keys) Less(i, j int) bool { | ||
return GetResponseType(k[i].TypeURL) > GetResponseType(k[j].TypeURL) | ||
} | ||
|
||
func (k keys) Swap(i, j int) { | ||
k[i], k[j] = k[j], k[i] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cache | ||
|
||
import ( | ||
"errors" | ||
"sort" | ||
"testing" | ||
|
||
"github.com/envoyproxy/go-control-plane/pkg/resource/v3" | ||
) | ||
|
||
func TestOrderKeys(t *testing.T) { | ||
unorderedKeys := keys{ | ||
{ | ||
ID: 1, | ||
TypeURL: resource.EndpointType, | ||
}, | ||
{ | ||
ID: 2, | ||
TypeURL: resource.ClusterType, | ||
}, | ||
{ | ||
ID: 4, | ||
TypeURL: resource.ListenerType, | ||
}, | ||
{ | ||
ID: 3, | ||
TypeURL: resource.RouteType, | ||
}, | ||
{ | ||
ID: 5, | ||
TypeURL: resource.ScopedRouteType, | ||
}, | ||
} | ||
|
||
orderedKeys := unorderedKeys | ||
sort.Sort(orderedKeys) | ||
|
||
if !sort.IsSorted(orderedKeys) { | ||
t.Fatal(errors.New("failed to sort keys")) | ||
} | ||
|
||
// Ordering: | ||
// === RUN TestOrderKeys | ||
// order_test.go:43: {ID:4 TypeURL:type.googleapis.com/envoy.config.listener.v3.Listener} | ||
// order_test.go:43: {ID:3 TypeURL:type.googleapis.com/envoy.config.route.v3.RouteConfiguration} | ||
// order_test.go:43: {ID:5 TypeURL:type.googleapis.com/envoy.config.route.v3.ScopedRouteConfiguration} | ||
// order_test.go:43: {ID:2 TypeURL:type.googleapis.com/envoy.config.cluster.v3.Cluster} | ||
// order_test.go:43: {ID:1 TypeURL:type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters