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.

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