-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support configuration for consistent hash. (#192)
Signed-off-by: morvencao <lcao@redhat.com>
- Loading branch information
Showing
5 changed files
with
134 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
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,83 @@ | ||
package config | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/spf13/pflag" | ||
) | ||
|
||
func TestPulseServerConfig(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
input map[string]string | ||
want *PulseServerConfig | ||
}{ | ||
{ | ||
name: "default subscription type", | ||
input: map[string]string{}, | ||
want: &PulseServerConfig{ | ||
PulseInterval: 15, | ||
SubscriptionType: "shared", | ||
ConsistentHashConfig: &ConsistentHashConfig{ | ||
PartitionCount: 7, | ||
ReplicationFactor: 20, | ||
Load: 1.25, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "broadcast subscription type", | ||
input: map[string]string{ | ||
"subscription-type": "broadcast", | ||
}, | ||
want: &PulseServerConfig{ | ||
PulseInterval: 15, | ||
SubscriptionType: "broadcast", | ||
ConsistentHashConfig: &ConsistentHashConfig{ | ||
PartitionCount: 7, | ||
ReplicationFactor: 20, | ||
Load: 1.25, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "custom consistent hash config", | ||
input: map[string]string{ | ||
"subscription-type": "broadcast", | ||
"consistent-hash-partition-count": "10", | ||
"consistent-hash-replication-factor": "30", | ||
"consistent-hash-load": "1.5", | ||
}, | ||
want: &PulseServerConfig{ | ||
PulseInterval: 15, | ||
SubscriptionType: "broadcast", | ||
ConsistentHashConfig: &ConsistentHashConfig{ | ||
PartitionCount: 10, | ||
ReplicationFactor: 30, | ||
Load: 1.5, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
config := NewPulseServerConfig() | ||
pflag.NewFlagSet("test", pflag.ContinueOnError) | ||
fs := pflag.CommandLine | ||
config.AddFlags(fs) | ||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
// set flags | ||
for key, value := range tc.input { | ||
fs.Set(key, value) | ||
} | ||
if !reflect.DeepEqual(config, tc.want) { | ||
t.Errorf("NewPulseServerConfig() = %v; want %v", config, tc.want) | ||
} | ||
// clear flags | ||
fs.VisitAll(func(f *pflag.Flag) { | ||
fs.Lookup(f.Name).Changed = false | ||
}) | ||
}) | ||
} | ||
} |
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