2018-11-04 13:32:36 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"math/rand"
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/security"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2018-11-04 13:32:36 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/operation"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
master = flag.String("master", "127.0.0.1:9333", "the master server")
|
|
|
|
repeat = flag.Int("n", 5, "repeat how many times")
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
util.LoadConfiguration("security", false)
|
2019-02-19 04:11:52 +08:00
|
|
|
grpcDialOption := security.LoadClientTLS(viper.Sub("grpc"), "client")
|
|
|
|
|
2018-11-04 13:32:36 +08:00
|
|
|
for i := 0; i < *repeat; i++ {
|
2019-02-19 04:11:52 +08:00
|
|
|
assignResult, err := operation.Assign(*master, grpcDialOption, &operation.VolumeAssignRequest{Count: 1})
|
2018-11-04 13:32:36 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("assign: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
data := make([]byte, 1024)
|
|
|
|
rand.Read(data)
|
|
|
|
reader := bytes.NewReader(data)
|
|
|
|
|
2019-01-17 09:17:19 +08:00
|
|
|
targetUrl := fmt.Sprintf("http://%s/%s", assignResult.Url, assignResult.Fid)
|
2018-11-04 13:32:36 +08:00
|
|
|
|
2019-02-15 16:09:19 +08:00
|
|
|
_, err = operation.Upload(targetUrl, fmt.Sprintf("test%d", i), reader, false, "", nil, assignResult.Auth)
|
2018-11-04 13:32:36 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("upload: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-02-17 04:23:35 +08:00
|
|
|
util.Delete(targetUrl, string(assignResult.Auth))
|
2018-11-04 14:14:05 +08:00
|
|
|
|
2018-11-04 13:32:36 +08:00
|
|
|
util.Get(fmt.Sprintf("http://%s/vol/vacuum", *master))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|