本文整理汇总了Golang中camlistore/org/pkg/blobserver/stats.Receiver类的典型用法代码示例。如果您正苦于以下问题:Golang Receiver类的具体用法?Golang Receiver怎么用?Golang Receiver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Receiver类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DumpStats
// DumpStats creates the destFile and writes a line per received blob,
// with its blob size.
func DumpStats(sr *statspkg.Receiver, destFile string) {
sr.Lock()
defer sr.Unlock()
f, err := os.Create(destFile)
if err != nil {
log.Fatal(err)
}
var sum int64
for _, size := range sr.Have {
fmt.Fprintf(f, "%d\n", size)
}
fmt.Printf("In-memory blob stats: %d blobs, %d bytes\n", len(sr.Have), sum)
err = f.Close()
if err != nil {
log.Fatal(err)
}
}
示例2: TestWriteFileMap
func TestWriteFileMap(t *testing.T) {
m := NewFileMap("test-file")
r := &randReader{seed: 123, length: 5 << 20}
sr := new(stats.Receiver)
var buf bytes.Buffer
br, err := WriteFileMap(sr, m, io.TeeReader(r, &buf))
if err != nil {
t.Fatal(err)
}
t.Logf("Got root file %v; %d blobs, %d bytes", br, sr.NumBlobs(), sr.SumBlobSize())
sizes := sr.Sizes()
t.Logf("Sizes are %v", sizes)
// TODO(bradfitz): these are fragile tests and mostly just a placeholder.
// Real tests to add:
// -- no "bytes" schema with a single "blobref"
// -- more seeds (including some that tickle the above)
// -- file reader reading back the root gets the same sha1 content back
// (will require keeping the full data in our stats receiver, not
// just the size)
// -- well-balanced tree
// -- nothing too big, nothing too small.
if g, w := br.String(), "sha1-95a5d2686b239e36dff3aeb5a45ed18153121835"; g != w {
t.Errorf("root blobref = %v; want %v", g, w)
}
if g, w := sr.NumBlobs(), 88; g != w {
t.Errorf("num blobs = %v; want %v", g, w)
}
if g, w := sr.SumBlobSize(), int64(5252655); g != w {
t.Errorf("sum blob size = %v; want %v", g, w)
}
if g, w := sizes[len(sizes)-1], 262144; g != w {
t.Errorf("biggest blob is %d; want %d", g, w)
}
}