Skip to content

Commit

Permalink
test: add run cases
Browse files Browse the repository at this point in the history
  • Loading branch information
xibao-nr committed Jan 16, 2023
1 parent 7e1a1ed commit d48ce76
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 6 deletions.
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ go build -ldflags "\
-X 'main.BuildTime=${BuildTime}'" \
-o storage_provider cmd/storage_provider/*.go

go build -o test-storage-provider test/e2e/services/case_driver.go

if [ ! -d build ];then
mkdir build
mkdir -p build/data
fi
mv storage_provider ./build
mv test-storage-provider ./build
cp config/config.toml ./build
3 changes: 2 additions & 1 deletion service/downloader/downloader_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func (downloader *Downloader) DownloaderObject(req *service.DownloaderServiceDow
resp.ErrMessage = merrors.MakeErrMsgResponse(err)
err = stream.Send(resp)
}
log.CtxInfow(ctx, "download object completed", "error", err, "objectSize", objectInfo.Size, "sendSize", size)
// log.CtxInfow(ctx, "download object completed", "error", err, "objectSize", objectInfo.Size, "sendSize", size)
log.CtxInfow(ctx, "download object completed", "error", err, "sendSize", size)
}()

objectInfo, err = downloader.mockChain.QueryObjectByName(req.BucketName + "/" + req.ObjectName)
Expand Down
5 changes: 0 additions & 5 deletions test/e2e/piecestore/disk_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import (
"os"
"testing"

<<<<<<< HEAD
"github.com/bnb-chain/greenfield-storage-provider/util/log"

=======
>>>>>>> develop
"github.com/stretchr/testify/assert"

"github.com/bnb-chain/greenfield-storage-provider/util/log"
Expand Down
308 changes: 308 additions & 0 deletions test/e2e/services/case_driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
package main

import (
"bytes"
"flag"
"io/ioutil"
"math/rand"
"net/http"
"strings"
"time"

"github.com/bnb-chain/greenfield-storage-provider/config"
"github.com/bnb-chain/greenfield-storage-provider/model"
"github.com/bnb-chain/greenfield-storage-provider/util/log"
)

var (
configFile = flag.String("config", "./config.toml", "config file path")
letters = []byte("0123456789")
gatewayAddress string
)

func generateRandString(n int) string {
rand.Seed(time.Now().Unix())
b := make([]byte, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}

// case1 128bytes, Inline type, do not need to be segmented(< segment size, 16MB).
func runCase1() {
log.Info("start run case1(128byte, Inline type)")
// get auth
{
log.Infow("start get auth")
url := "http://" + gatewayAddress + "/greenfield/admin/v1/get-approval?action=createObject"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(""))
if err != nil {
log.Errorw("get auth failed, due to new request", "error", err)
return
}
req.Header.Add(model.BFSResourceHeader, "test_bucket/case1")
res, err := client.Do(req)
if err != nil {
log.Errorw("get auth failed, due to send request", "error", err)
return
}
defer res.Body.Close()
_, err = ioutil.ReadAll(res.Body)
if err != nil {
log.Errorw("get auth failed, due to read response body", "error", err)
return
}
log.Infow("finish get auth",
"preSign", res.Header.Get("X-Bfs-Pre-Signature"),
"statusCode", res.StatusCode)
}
// put object
{
log.Infow("start prepare data for put object")
buf := generateRandString(64)
log.Infow("finish prepare data for put object")

log.Infow("start put object")
url := "http://" + gatewayAddress + "/case1?putobjectv2"
method := "PUT"
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(buf))
if err != nil {
log.Errorw("put object failed, due to new request", "error", err)
return
}
req.Host = "test_bucket.bfs.nodereal.com"
req.Header.Add(model.BFSTransactionHashHeader, generateRandString(64))
req.Header.Add(model.ContentLengthHeader, "1")
res, err := client.Do(req)
if err != nil {
log.Errorw("put object failed, due to send request", "error", err)
return
}
defer res.Body.Close()
_, err = ioutil.ReadAll(res.Body)
if err != nil {
log.Errorw("put object failed, due to read response body", "error", err)
return
}
log.Infow("finish put object",
"etag", res.Header.Get(model.ETagHeader),
"statusCode", res.StatusCode)
}
// get object
{
log.Infow("start get object")
url := "http://" + gatewayAddress + "/case1"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(""))
if err != nil {
log.Errorw("get object failed, due to new request", "error", err)
return
}
req.Host = "test_bucket.bfs.nodereal.com"
res, err := client.Do(req)
if err != nil {
log.Errorw("get object failed, due to send request", "error", err)
return
}
buf := new(bytes.Buffer)
buf.ReadFrom(res.Body)
log.Infow("finish get object payload", "statusCode", res.StatusCode, "body len", len(buf.String()))
}
log.Info("end run case1")
}

// case2 64MB, Replica type, should be segmented.
func runCase2() {
log.Info("start run case2(64MB, Replica type)")
// get auth
{
log.Infow("start get auth")
url := "http://" + gatewayAddress + "/greenfield/admin/v1/get-approval?action=createObject"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(""))
if err != nil {
log.Errorw("get auth failed, due to new request", "error", err)
return
}
req.Header.Add(model.BFSResourceHeader, "test_bucket/case2")
res, err := client.Do(req)
if err != nil {
log.Errorw("get auth failed, due to send request", "error", err)
return
}
defer res.Body.Close()
_, err = ioutil.ReadAll(res.Body)
if err != nil {
log.Errorw("get auth failed, due to read response body", "error", err)
return
}
log.Infow("finish get auth",
"preSign", res.Header.Get("X-Bfs-Pre-Signature"),
"statusCode", res.StatusCode)
}
// put object
{
log.Infow("start prepare data for put object")
buf := generateRandString(64 * 1024 * 1024)
log.Infow("finish prepare data for put object")

log.Infow("start put object")
url := "http://" + gatewayAddress + "/case2?putobjectv2"
method := "PUT"
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(buf))
if err != nil {
log.Errorw("put object failed, due to new request", "error", err)
return
}
req.Host = "test_bucket.bfs.nodereal.com"
req.Header.Add(model.BFSTransactionHashHeader, generateRandString(64))
req.Header.Add(model.ContentLengthHeader, "67108864")
req.Header.Add(model.BFSRedundancyTypeHeader, model.ReplicaRedundancyTypeHeaderValue)
res, err := client.Do(req)
if err != nil {
log.Errorw("put object failed, due to send request", "error", err)
return
}
defer res.Body.Close()
_, err = ioutil.ReadAll(res.Body)
if err != nil {
log.Errorw("put object failed, due to read response body", "error", err)
return
}
log.Infow("finish put object",
"etag", res.Header.Get(model.ETagHeader),
"statusCode", res.StatusCode)
}
// get object
{
log.Infow("start get object")
url := "http://" + gatewayAddress + "/case2"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(""))
if err != nil {
log.Errorw("get object failed, due to new request", "error", err)
return
}
req.Host = "test_bucket.bfs.nodereal.com"
res, err := client.Do(req)
if err != nil {
log.Errorw("get object failed, due to send request", "error", err)
return
}
buf := new(bytes.Buffer)
buf.ReadFrom(res.Body)
log.Infow("finish get object payload", "statusCode", res.StatusCode, "body len", len(buf.String()))

}
log.Info("end run case2")
}

// case3 200MB, EC type, should be segmented.
func runCase3() {
log.Info("start run case3(200MB, EC type)")
// get auth
{
log.Infow("start get auth")
url := "http://" + gatewayAddress + "/greenfield/admin/v1/get-approval?action=createObject"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(""))
if err != nil {
log.Errorw("get auth failed, due to new request", "error", err)
return
}
req.Header.Add(model.BFSResourceHeader, "test_bucket/case3")
res, err := client.Do(req)
if err != nil {
log.Errorw("get auth failed, due to send request", "error", err)
return
}
defer res.Body.Close()
_, err = ioutil.ReadAll(res.Body)
if err != nil {
log.Errorw("get auth failed, due to read response body", "error", err)
return
}
log.Infow("finish get auth",
"preSign", res.Header.Get("X-Bfs-Pre-Signature"),
"statusCode", res.StatusCode)
}
// put object
{
log.Infow("start prepare data for put object")
buf := generateRandString(200 * 1024 * 1024)
log.Infow("finish prepare data for put object")

log.Infow("start put object")
url := "http://" + gatewayAddress + "/case3?putobjectv2"
method := "PUT"
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(buf))
if err != nil {
log.Errorw("put object failed, due to new request", "error", err)
return
}
req.Host = "test_bucket.bfs.nodereal.com"
req.Header.Add(model.BFSTransactionHashHeader, generateRandString(64))
req.Header.Add(model.ContentLengthHeader, "209715200")
res, err := client.Do(req)
if err != nil {
log.Errorw("put object failed, due to send request", "error", err)
return
}
defer res.Body.Close()
_, err = ioutil.ReadAll(res.Body)
if err != nil {
log.Errorw("put object failed, due to read response body", "error", err)
return
}
log.Infow("finish put object",
"etag", res.Header.Get(model.ETagHeader),
"statusCode", res.StatusCode)
}
// get object
{
log.Infow("start get object")
url := "http://" + gatewayAddress + "/case3"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(""))
if err != nil {
log.Errorw("get object failed, due to new request", "error", err)
return
}
req.Host = "test_bucket.bfs.nodereal.com"
res, err := client.Do(req)
if err != nil {
log.Errorw("get object failed, due to send request", "error", err)
return
}
buf := new(bytes.Buffer)
buf.ReadFrom(res.Body)
log.Infow("finish get object payload", "statusCode", res.StatusCode, "body len", len(buf.String()))

}
log.Info("end run case3")
}

func main() {
log.Info("start run cases")

rand.Seed(time.Now().Unix())
cfg := config.LoadConfig(*configFile)
gatewayAddress = cfg.GatewayCfg.Address

runCase1()
runCase2()
runCase3()

log.Info("end run cases")
}

0 comments on commit d48ce76

Please sign in to comment.