diff options
| author | chrislu <chris.lu@gmail.com> | 2024-09-29 20:47:16 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2024-09-29 20:47:16 -0700 |
| commit | 190b2fc27637017cdd075331fd04b8cb0e5879b7 (patch) | |
| tree | 93db54c4ad83af2b09eb7862380b8c634154e203 /weed/shell/command_volume_fix_replication_test.go | |
| parent | 8111ec13bd06e4a9142a87640986de8c41d4b75a (diff) | |
| parent | 20929f2a5753a04385be2378e698c8df762b3256 (diff) | |
| download | seaweedfs-origin/mq2.tar.xz seaweedfs-origin/mq2.zip | |
Merge branch 'master' into mq2origin/mq2
Diffstat (limited to 'weed/shell/command_volume_fix_replication_test.go')
| -rw-r--r-- | weed/shell/command_volume_fix_replication_test.go | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/weed/shell/command_volume_fix_replication_test.go b/weed/shell/command_volume_fix_replication_test.go index 97f270306..5f2318c32 100644 --- a/weed/shell/command_volume_fix_replication_test.go +++ b/weed/shell/command_volume_fix_replication_test.go @@ -438,3 +438,90 @@ func TestPickingMisplacedVolumeToDelete(t *testing.T) { } } + +func TestSatisfyReplicaCurrentLocation(t *testing.T) { + + var tests = []testcase{ + { + name: "test 001", + replication: "001", + replicas: []*VolumeReplica{ + { + location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}}, + }, + { + location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}}, + }, + }, + expected: false, + }, + { + name: "test 010", + replication: "010", + replicas: []*VolumeReplica{ + { + location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}}, + }, + { + location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}}, + }, + }, + expected: true, + }, + { + name: "test 011", + replication: "011", + replicas: []*VolumeReplica{ + { + location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}}, + }, + { + location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}}, + }, + { + location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn3"}}, + }, + }, + expected: true, + }, + { + name: "test 110", + replication: "110", + replicas: []*VolumeReplica{ + { + location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}}, + }, + { + location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}}, + }, + { + location: &location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn3"}}, + }, + }, + expected: true, + }, + { + name: "test 100", + replication: "100", + replicas: []*VolumeReplica{ + { + location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}}, + }, + { + location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}}, + }, + }, + expected: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + replicaPlacement, _ := super_block.NewReplicaPlacementFromString(tt.replication) + if satisfyReplicaCurrentLocation(replicaPlacement, tt.replicas) != tt.expected { + t.Errorf("%s: expect %v %v %+v", + tt.name, tt.expected, tt.replication, tt.replicas) + } + }) + } +} |
