-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If a target with an identifier was previously registered with IPs and is now changing its IPs (IP refresh, different target...), the LB can now handle that case by removing it completly and adding it again. the internal setTargets is now removing old targets before adding new ones. It also checks if IPs for an identifier have changed or not.
- Loading branch information
1 parent
6538230
commit 5b01933
Showing
3 changed files
with
177 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright (c) 2023 Nordix Foundation | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package slice | ||
|
||
// ContainsSameStrings returns if 2 slices are containing the exactly the | ||
// same strings, No matter the order. | ||
func ContainsSameStrings(a []string, b []string) bool { | ||
if len(a) != len(b) { | ||
return false | ||
} | ||
aMap := map[string]int{} | ||
for _, e := range a { | ||
aMap[e]++ | ||
} | ||
for _, e := range b { | ||
_, exists := aMap[e] | ||
if !exists { | ||
return false | ||
} | ||
aMap[e]-- | ||
if aMap[e] == 0 { | ||
delete(aMap, e) | ||
} | ||
} | ||
return len(aMap) == 0 | ||
} |
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,115 @@ | ||
/* | ||
Copyright (c) 2023 Nordix Foundation | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package slice_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nordix/meridio/pkg/slice" | ||
) | ||
|
||
func TestContainsSameStrings(t *testing.T) { | ||
type args struct { | ||
a []string | ||
b []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "empty", | ||
args: args{ | ||
a: []string{}, | ||
b: []string{}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "empty and nil", | ||
args: args{ | ||
a: []string{}, | ||
b: nil, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "a empty", | ||
args: args{ | ||
a: []string{"a"}, | ||
b: []string{}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "b empty", | ||
args: args{ | ||
a: []string{"a"}, | ||
b: []string{}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "equal with 1 element", | ||
args: args{ | ||
a: []string{"a"}, | ||
b: []string{"a"}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "not equal with 1 element", | ||
args: args{ | ||
a: []string{"a"}, | ||
b: []string{"b"}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "equal with 2 element same order", | ||
args: args{ | ||
a: []string{"a", "b"}, | ||
b: []string{"a", "b"}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "equal with 2 element different order", | ||
args: args{ | ||
a: []string{"a", "b"}, | ||
b: []string{"b", "a"}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "duplicates", | ||
args: args{ | ||
a: []string{"hello", "world", "hello"}, | ||
b: []string{"hello", "hello", "world"}, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := slice.ContainsSameStrings(tt.args.a, tt.args.b); got != tt.want { | ||
t.Errorf("ContainsSameStrings() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |