mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
fix test
This commit is contained in:
parent
44b3f2efc8
commit
18b98fdb72
|
@ -8,11 +8,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type testcase struct {
|
type testcase struct {
|
||||||
name string
|
name string
|
||||||
replication string
|
replication string
|
||||||
existingLocations []location
|
replicas []*VolumeReplica
|
||||||
possibleLocation location
|
possibleLocation location
|
||||||
expected bool
|
expected bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||||
|
@ -21,8 +21,10 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 100 negative",
|
name: "test 100 negative",
|
||||||
replication: "100",
|
replication: "100",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
possibleLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
expected: false,
|
expected: false,
|
||||||
|
@ -30,8 +32,10 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 100 positive",
|
name: "test 100 positive",
|
||||||
replication: "100",
|
replication: "100",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
possibleLocation: location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
expected: true,
|
expected: true,
|
||||||
|
@ -39,10 +43,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 022 positive",
|
name: "test 022 positive",
|
||||||
replication: "022",
|
replication: "022",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn4"}},
|
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||||
expected: true,
|
expected: true,
|
||||||
|
@ -50,10 +60,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 022 negative",
|
name: "test 022 negative",
|
||||||
replication: "022",
|
replication: "022",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r4", &master_pb.DataNodeInfo{Id: "dn4"}},
|
possibleLocation: location{"dc1", "r4", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||||
expected: false,
|
expected: false,
|
||||||
|
@ -61,10 +77,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 210 moved from 200 positive",
|
name: "test 210 moved from 200 positive",
|
||||||
replication: "210",
|
replication: "210",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r4", &master_pb.DataNodeInfo{Id: "dn4"}},
|
possibleLocation: location{"dc1", "r4", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||||
expected: true,
|
expected: true,
|
||||||
|
@ -72,10 +94,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 210 moved from 200 negative extra dc",
|
name: "test 210 moved from 200 negative extra dc",
|
||||||
replication: "210",
|
replication: "210",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc4", "r4", &master_pb.DataNodeInfo{Id: "dn4"}},
|
possibleLocation: location{"dc4", "r4", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||||
expected: false,
|
expected: false,
|
||||||
|
@ -83,10 +111,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 210 moved from 200 negative extra data node",
|
name: "test 210 moved from 200 negative extra data node",
|
||||||
replication: "210",
|
replication: "210",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn4"}},
|
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||||
expected: false,
|
expected: false,
|
||||||
|
@ -103,9 +137,13 @@ func TestSatisfyReplicaPlacement01x(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 011 same existing rack",
|
name: "test 011 same existing rack",
|
||||||
replication: "011",
|
replication: "011",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn3"}},
|
possibleLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
expected: true,
|
expected: true,
|
||||||
|
@ -113,9 +151,13 @@ func TestSatisfyReplicaPlacement01x(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 011 negative",
|
name: "test 011 negative",
|
||||||
replication: "011",
|
replication: "011",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
expected: false,
|
expected: false,
|
||||||
|
@ -123,9 +165,13 @@ func TestSatisfyReplicaPlacement01x(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 011 different existing racks",
|
name: "test 011 different existing racks",
|
||||||
replication: "011",
|
replication: "011",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn3"}},
|
possibleLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
expected: true,
|
expected: true,
|
||||||
|
@ -133,9 +179,13 @@ func TestSatisfyReplicaPlacement01x(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 011 different existing racks negative",
|
name: "test 011 different existing racks negative",
|
||||||
replication: "011",
|
replication: "011",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
possibleLocation: location{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
expected: false,
|
expected: false,
|
||||||
|
@ -152,8 +202,10 @@ func TestSatisfyReplicaPlacement00x(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 001",
|
name: "test 001",
|
||||||
replication: "001",
|
replication: "001",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
expected: true,
|
expected: true,
|
||||||
|
@ -161,9 +213,13 @@ func TestSatisfyReplicaPlacement00x(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 002 positive",
|
name: "test 002 positive",
|
||||||
replication: "002",
|
replication: "002",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
expected: true,
|
expected: true,
|
||||||
|
@ -171,9 +227,13 @@ func TestSatisfyReplicaPlacement00x(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 002 negative, repeat the same node",
|
name: "test 002 negative, repeat the same node",
|
||||||
replication: "002",
|
replication: "002",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
expected: false,
|
expected: false,
|
||||||
|
@ -181,10 +241,16 @@ func TestSatisfyReplicaPlacement00x(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test 002 negative, enough node already",
|
name: "test 002 negative, enough node already",
|
||||||
replication: "002",
|
replication: "002",
|
||||||
existingLocations: []location{
|
replicas: []*VolumeReplica{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
{
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn4"}},
|
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||||
expected: false,
|
expected: false,
|
||||||
|
@ -199,9 +265,9 @@ func runTests(tests []testcase, t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
replicaPlacement, _ := super_block.NewReplicaPlacementFromString(tt.replication)
|
replicaPlacement, _ := super_block.NewReplicaPlacementFromString(tt.replication)
|
||||||
println("replication:", tt.replication, "expected", tt.expected, "name:", tt.name)
|
println("replication:", tt.replication, "expected", tt.expected, "name:", tt.name)
|
||||||
if satisfyReplicaPlacement(replicaPlacement, tt.existingLocations, tt.possibleLocation) != tt.expected {
|
if satisfyReplicaPlacement(replicaPlacement, tt.replicas, tt.possibleLocation) != tt.expected {
|
||||||
t.Errorf("%s: expect %v add %v to %s %+v",
|
t.Errorf("%s: expect %v add %v to %s %+v",
|
||||||
tt.name, tt.expected, tt.possibleLocation, tt.replication, tt.existingLocations)
|
tt.name, tt.expected, tt.possibleLocation, tt.replication, tt.replicas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue