diff options
| author | Lisandro Pin <lisandro.pin@proton.ch> | 2024-12-02 17:44:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-02 08:44:07 -0800 |
| commit | b2ba7d7408500bb450884a288327a1fb53e67fae (patch) | |
| tree | b16eac42446ecd69bf5c2a8b3a57afb49b0d644b /weed/shell/command_ec_common_test.go | |
| parent | 9a741a61b195ccdf9815ab64dc9f0725f620f836 (diff) | |
| download | seaweedfs-b2ba7d7408500bb450884a288327a1fb53e67fae.tar.xz seaweedfs-b2ba7d7408500bb450884a288327a1fb53e67fae.zip | |
Resolve replica placement for EC volumes from master server defaults. (#6303)
Diffstat (limited to 'weed/shell/command_ec_common_test.go')
| -rw-r--r-- | weed/shell/command_ec_common_test.go | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/weed/shell/command_ec_common_test.go b/weed/shell/command_ec_common_test.go index 08e4a41c7..76609c89d 100644 --- a/weed/shell/command_ec_common_test.go +++ b/weed/shell/command_ec_common_test.go @@ -32,6 +32,40 @@ func errorCheck(got error, want string) error { } return nil } +func TestParseReplicaPlacementArg(t *testing.T) { + getDefaultReplicaPlacementOrig := getDefaultReplicaPlacement + getDefaultReplicaPlacement = func(commandEnv *CommandEnv) (*super_block.ReplicaPlacement, error) { + return super_block.NewReplicaPlacementFromString("123") + } + defer func() { + getDefaultReplicaPlacement = getDefaultReplicaPlacementOrig + }() + + testCases := []struct { + argument string + want string + wantErr string + }{ + {"lalala", "lal", "unexpected replication type"}, + {"", "123", ""}, + {"021", "021", ""}, + } + + for _, tc := range testCases { + commandEnv := &CommandEnv{} + got, gotErr := parseReplicaPlacementArg(commandEnv, tc.argument) + + if err := errorCheck(gotErr, tc.wantErr); err != nil { + t.Errorf("argument %q: %s", tc.argument, err.Error()) + continue + } + + want, _ := super_block.NewReplicaPlacementFromString(tc.want) + if !got.Equals(want) { + t.Errorf("got replica placement %q, want %q", got.String(), want.String()) + } + } +} func TestEcDistribution(t *testing.T) { @@ -55,26 +89,35 @@ func TestEcDistribution(t *testing.T) { } func TestVolumeIdToReplicaPlacement(t *testing.T) { + ecReplicaPlacement, _ := super_block.NewReplicaPlacementFromString("123") + testCases := []struct { topology *master_pb.TopologyInfo vid string want string wantErr string }{ - {topology1, "", "", "failed to resolve replica placement for volume ID 0"}, - {topology1, "0", "", "failed to resolve replica placement for volume ID 0"}, + {topology1, "", "", "failed to resolve replica placement"}, + {topology1, "0", "", "failed to resolve replica placement"}, {topology1, "1", "100", ""}, {topology1, "296", "100", ""}, - {topology2, "", "", "failed to resolve replica placement for volume ID 0"}, - {topology2, "19012", "", "failed to resolve replica placement for volume ID 19012"}, + {topology2, "", "", "failed to resolve replica placement"}, + {topology2, "19012", "", "failed to resolve replica placement"}, {topology2, "6271", "002", ""}, {topology2, "17932", "002", ""}, + {topologyEc, "", "", "failed to resolve replica placement"}, + {topologyEc, "0", "", "failed to resolve replica placement"}, + {topologyEc, "6225", "002", ""}, + {topologyEc, "6241", "002", ""}, + {topologyEc, "9577", "123", ""}, // EC volume + {topologyEc, "12737", "123", ""}, // EC volume } for _, tc := range testCases { + commandEnv := &CommandEnv{} vid, _ := needle.NewVolumeId(tc.vid) ecNodes, _ := collectEcVolumeServersByDc(tc.topology, "") - got, gotErr := volumeIdToReplicaPlacement(vid, ecNodes) + got, gotErr := volumeIdToReplicaPlacement(commandEnv, vid, ecNodes, ecReplicaPlacement) if err := errorCheck(gotErr, tc.wantErr); err != nil { t.Errorf("volume %q: %s", tc.vid, err.Error()) |
