mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-25 11:39:12 +08:00
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"math/rand"
|
|
|
|
"github.com/joeslay/seaweedfs/weed/security"
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/joeslay/seaweedfs/weed/operation"
|
|
"github.com/joeslay/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()
|
|
|
|
util.LoadConfiguration("security", false)
|
|
grpcDialOption := security.LoadClientTLS(viper.Sub("grpc"), "client")
|
|
|
|
for i := 0; i < *repeat; i++ {
|
|
assignResult, err := operation.Assign(*master, grpcDialOption, &operation.VolumeAssignRequest{Count: 1})
|
|
if err != nil {
|
|
log.Fatalf("assign: %v", err)
|
|
}
|
|
|
|
data := make([]byte, 1024)
|
|
rand.Read(data)
|
|
reader := bytes.NewReader(data)
|
|
|
|
targetUrl := fmt.Sprintf("http://%s/%s", assignResult.Url, assignResult.Fid)
|
|
|
|
_, err = operation.Upload(targetUrl, fmt.Sprintf("test%d", i), reader, false, "", nil, assignResult.Auth)
|
|
if err != nil {
|
|
log.Fatalf("upload: %v", err)
|
|
}
|
|
|
|
util.Delete(targetUrl, string(assignResult.Auth))
|
|
|
|
util.Get(fmt.Sprintf("http://%s/vol/vacuum", *master))
|
|
|
|
}
|
|
|
|
}
|