func (s *StandaloneSuite) TestUploadToStubKeepServerBufferReader(c *C) { log.Printf("TestUploadToStubKeepServerBufferReader") st := StubPutHandler{ c, "acbd18db4cc2f85cedef654fccc4a4d8", "abc123", "foo", make(chan string)} UploadToStubHelper(c, st, func(kc KeepClient, url string, reader io.ReadCloser, writer io.WriteCloser, upload_status chan uploadStatus) { tr := streamer.AsyncStreamFromReader(512, reader) defer tr.Close() br1 := tr.MakeStreamReader() go kc.uploadToKeepServer(url, st.expectPath, br1, upload_status, 3) writer.Write([]byte("foo")) writer.Close() <-st.handled status := <-upload_status c.Check(status, DeepEquals, uploadStatus{nil, fmt.Sprintf("%s/%s", url, st.expectPath), 200, 1, ""}) }) log.Printf("TestUploadToStubKeepServerBufferReader done") }
// Put a block given the block hash, a reader with the block data, and the // expected length of that data. The desired number of replicas is given in // KeepClient.Want_replicas. Returns the number of replicas that were written // and if there was an error. Note this will return InsufficientReplias // whenever 0 <= replicas < this.Wants_replicas. func (this KeepClient) PutHR(hash string, r io.Reader, expectedLength int64) (locator string, replicas int, err error) { // Buffer for reads from 'r' var bufsize int if expectedLength > 0 { if expectedLength > BLOCKSIZE { return "", 0, OversizeBlockError } bufsize = int(expectedLength) } else { bufsize = BLOCKSIZE } t := streamer.AsyncStreamFromReader(bufsize, HashCheckingReader{r, md5.New(), hash}) defer t.Close() return this.putReplicas(hash, t, expectedLength) }