"encoding/xml"
"flag"
"fmt"
- "io"
"io/ioutil"
"math/rand"
"net"
rw.WriteHeader(http.StatusCreated)
case r.Method == "PUT" && r.Form.Get("comp") == "metadata":
// "Set Metadata Headers" API. We don't bother
- // stubbing "Get Metadata Headers": AzureBlobVolume
+ // stubbing "Get Metadata Headers": azureBlobVolume
// sets metadata headers only as a way to bump Etag
// and Last-Modified.
if !blobExists {
}
type testableAzureBlobVolume struct {
- *AzureBlobVolume
+ *azureBlobVolume
azHandler *azStubHandler
azStub *httptest.Server
t TB
azClient.Sender = &singleSender{}
bs := azClient.GetBlobService()
- v := &AzureBlobVolume{
+ v := &azureBlobVolume{
ContainerName: container,
WriteRaceInterval: arvados.Duration(time.Millisecond),
WriteRacePollTime: arvados.Duration(time.Nanosecond),
}
return &testableAzureBlobVolume{
- AzureBlobVolume: v,
+ azureBlobVolume: v,
azHandler: azHandler,
azStub: azStub,
t: t,
if err != nil {
c.Error(err)
}
- gotData := bytes.NewBuffer(nil)
- gotLen, err := v.BlockRead(context.Background(), hash, gotData)
+ gotData := &brbuffer{}
+ err = v.BlockRead(context.Background(), hash, gotData)
if err != nil {
c.Error(err)
}
gotHash := fmt.Sprintf("%x", md5.Sum(gotData.Bytes()))
- if gotLen != size {
- c.Errorf("length mismatch: got %d != %d", gotLen, size)
- }
+ c.Check(gotData.Len(), check.Equals, size)
if gotHash != hash {
c.Errorf("hash mismatch: got %s != %s", gotHash, hash)
}
wg.Add(1)
go func() {
defer wg.Done()
- _, err := v.BlockRead(context.Background(), TestHash, io.Discard)
+ err := v.BlockRead(context.Background(), TestHash, brdiscard)
if err != nil {
c.Error(err)
}
MetricsVecs: newVolumeMetricsVecs(prometheus.NewRegistry()),
BufferPool: newBufferPool(ctxlog.TestLogger(c), 8, prometheus.NewRegistry()),
})
- v.AzureBlobVolume.WriteRaceInterval.Set("2s")
- v.AzureBlobVolume.WriteRacePollTime.Set("5ms")
+ v.azureBlobVolume.WriteRaceInterval.Set("2s")
+ v.azureBlobVolume.WriteRacePollTime.Set("5ms")
defer v.Teardown()
v.BlockWriteRaw(TestHash, nil)
allDone := make(chan struct{})
go func() {
defer close(allDone)
- buf := bytes.NewBuffer(nil)
- n, err := v.BlockRead(context.Background(), TestHash, buf)
+ buf := &brbuffer{}
+ err := v.BlockRead(context.Background(), TestHash, buf)
if err != nil {
c.Error(err)
return
}
- if n != 0 {
- c.Errorf("Got %+q (n=%d), expected empty buf", buf.Bytes(), n)
- }
+ c.Check(buf.String(), check.Equals, "")
}()
select {
case <-allDone:
func (s *stubbedAzureBlobSuite) TestAzureBlobVolumeContextCancelBlockRead(c *check.C) {
s.testAzureBlobVolumeContextCancel(c, func(ctx context.Context, v *testableAzureBlobVolume) error {
v.BlockWriteRaw(TestHash, TestBlock)
- _, err := v.BlockRead(ctx, TestHash, io.Discard)
- return err
+ return v.BlockRead(ctx, TestHash, brdiscard)
})
}
c.Check(stats(), check.Matches, `.*"Errors":0,.*`)
loc := "acbd18db4cc2f85cedef654fccc4a4d8"
- _, err := volume.BlockRead(context.Background(), loc, io.Discard)
+ err := volume.BlockRead(context.Background(), loc, brdiscard)
c.Check(err, check.NotNil)
c.Check(stats(), check.Matches, `.*"Ops":[^0],.*`)
c.Check(stats(), check.Matches, `.*"Errors":[^0],.*`)
c.Check(stats(), check.Matches, `.*"OutBytes":3,.*`)
c.Check(stats(), check.Matches, `.*"CreateOps":1,.*`)
- _, err = volume.BlockRead(context.Background(), loc, io.Discard)
+ err = volume.BlockRead(context.Background(), loc, brdiscard)
c.Check(err, check.IsNil)
- _, err = volume.BlockRead(context.Background(), loc, io.Discard)
+ err = volume.BlockRead(context.Background(), loc, brdiscard)
c.Check(err, check.IsNil)
c.Check(stats(), check.Matches, `.*"InBytes":6,.*`)
}