XL: Add mis-aligned GetObject() test. (#1960)

master
Harshavardhana 9 years ago committed by GitHub
parent 5725f3c809
commit 41c089a7e0
  1. 64
      server_xl_test.go

@ -25,6 +25,7 @@ import (
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"strings"
"sync"
@ -1033,6 +1034,69 @@ func (s *MyAPIXLSuite) TestGetObjectLarge11MiB(c *C) {
c.Assert(hex.EncodeToString(putMD5), Equals, hex.EncodeToString(getMD5))
}
// TestGetPartialObjectMisAligned - tests get object partially mis-aligned.
func (s *MyAPIXLSuite) TestGetPartialObjectMisAligned(c *C) {
// Make bucket for this test.
request, err := newTestRequest("PUT", s.testServer.Server.URL+"/test-bucket-align",
0, nil, s.testServer.AccessKey, s.testServer.SecretKey)
c.Assert(err, IsNil)
client := http.Client{}
response, err := client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
var buffer bytes.Buffer
line := "1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,123"
rand.Seed(time.Now().UTC().UnixNano())
// Create a misalgined data.
for i := 0; i < 13*rand.Intn(1<<16); i++ {
buffer.WriteString(fmt.Sprintf("[%05d] %s\n", i, line[:rand.Intn(1<<8)]))
}
putContent := buffer.String()
// Put object
buf := bytes.NewReader([]byte(putContent))
request, err = newTestRequest("PUT", s.testServer.Server.URL+"/test-bucket-align/big-file-13",
int64(buf.Len()), buf, s.testServer.AccessKey, s.testServer.SecretKey)
c.Assert(err, IsNil)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
// Prepare request
var testCases = []struct {
byteRange string
expectedString string
}{
{"10-11", putContent[10:12]},
{"1-", putContent[1:]},
{"6-", putContent[6:]},
{"-2", putContent[len(putContent)-2:]},
{"-7", putContent[len(putContent)-7:]},
}
for _, t := range testCases {
// Get object
request, err = newTestRequest("GET", s.testServer.Server.URL+"/test-bucket-align/big-file-13",
0, nil, s.testServer.AccessKey, s.testServer.SecretKey)
c.Assert(err, IsNil)
// Get a different byte range.
request.Header.Add("Range", "bytes="+t.byteRange)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusPartialContent)
getContent, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
// Compare putContent and getContent
c.Assert(string(getContent), Equals, t.expectedString)
}
}
func (s *MyAPIXLSuite) TestGetPartialObjectLarge11MiB(c *C) {
// Make bucket for this test.
request, err := newTestRequest("PUT", s.testServer.Server.URL+"/test-bucket-11p",

Loading…
Cancel
Save