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.2 KiB

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