You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

6 years ago
  1. package main
  2. import (
  3. "bytes"
  4. "flag"
  5. "fmt"
  6. "log"
  7. "math/rand"
  8. "github.com/chrislusf/seaweedfs/weed/operation"
  9. "github.com/chrislusf/seaweedfs/weed/security"
  10. "github.com/chrislusf/seaweedfs/weed/util"
  11. )
  12. var (
  13. master = flag.String("master", "127.0.0.1:9333", "the master server")
  14. repeat = flag.Int("n", 5, "repeat how many times")
  15. )
  16. func main() {
  17. flag.Parse()
  18. util.LoadConfiguration("security", false)
  19. grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
  20. for i := 0; i < *repeat; i++ {
  21. assignResult, err := operation.Assign(*master, grpcDialOption, &operation.VolumeAssignRequest{Count: 1})
  22. if err != nil {
  23. log.Fatalf("assign: %v", err)
  24. }
  25. data := make([]byte, 1024)
  26. rand.Read(data)
  27. reader := bytes.NewReader(data)
  28. targetUrl := fmt.Sprintf("http://%s/%s", assignResult.Url, assignResult.Fid)
  29. _, err = operation.Upload(targetUrl, fmt.Sprintf("test%d", i), reader, false, "", nil, assignResult.Auth)
  30. if err != nil {
  31. log.Fatalf("upload: %v", err)
  32. }
  33. util.Delete(targetUrl, string(assignResult.Auth))
  34. util.Get(fmt.Sprintf("http://%s/vol/vacuum", *master))
  35. }
  36. }