@ -4,6 +4,7 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
"github.com/seaweedfs/seaweedfs/weed/util"
"testing"
"testing"
"github.com/seaweedfs/seaweedfs/weed/sequence"
"github.com/seaweedfs/seaweedfs/weed/sequence"
@ -419,11 +420,13 @@ func TestPickForWrite(t *testing.T) {
Rack : "" ,
Rack : "" ,
DataNode : "" ,
DataNode : "" ,
}
}
v := util . GetViper ( )
v . Set ( "master.volume_growth.threshold" , 0.9 )
for _ , rpStr := range [ ] string { "001" , "010" , "100" } {
for _ , rpStr := range [ ] string { "001" , "010" , "100" } {
rp , _ := super_block . NewReplicaPlacementFromString ( rpStr )
rp , _ := super_block . NewReplicaPlacementFromString ( rpStr )
vl := topo . GetVolumeLayout ( "test" , rp , needle . EMPTY_TTL , types . HardDriveType )
vl := topo . GetVolumeLayout ( "test" , rp , needle . EMPTY_TTL , types . HardDriveType )
volumeGrowOption . ReplicaPlacement = rp
volumeGrowOption . ReplicaPlacement = rp
for _ , dc := range [ ] string { "" , "dc1" , "dc2" , "dc3" } {
for _ , dc := range [ ] string { "" , "dc1" , "dc2" , "dc3" , "dc0" } {
volumeGrowOption . DataCenter = dc
volumeGrowOption . DataCenter = dc
for _ , r := range [ ] string { "" } {
for _ , r := range [ ] string { "" } {
volumeGrowOption . Rack = r
volumeGrowOption . Rack = r
@ -432,8 +435,13 @@ func TestPickForWrite(t *testing.T) {
continue
continue
}
}
volumeGrowOption . DataNode = dn
volumeGrowOption . DataNode = dn
fileId , count , _ , _ , err := topo . PickForWrite ( 1 , volumeGrowOption , vl )
if err != nil {
fileId , count , _ , shouldGrow , err := topo . PickForWrite ( 1 , volumeGrowOption , vl )
if dc == "dc0" {
if err == nil || count != 0 || ! shouldGrow {
fmt . Println ( dc , r , dn , "pick for write should be with error" )
t . Fail ( )
}
} else if err != nil {
fmt . Println ( dc , r , dn , "pick for write error :" , err )
fmt . Println ( dc , r , dn , "pick for write error :" , err )
t . Fail ( )
t . Fail ( )
} else if count == 0 {
} else if count == 0 {
@ -442,6 +450,9 @@ func TestPickForWrite(t *testing.T) {
} else if len ( fileId ) == 0 {
} else if len ( fileId ) == 0 {
fmt . Println ( dc , r , dn , "pick for write file id is empty" )
fmt . Println ( dc , r , dn , "pick for write file id is empty" )
t . Fail ( )
t . Fail ( )
} else if shouldGrow {
fmt . Println ( dc , r , dn , "pick for write error : not should grow" )
t . Fail ( )
}
}
}
}
}
}