コード例 #1
0
ファイル: files.go プロジェクト: camlistore/camlistore
// 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
0
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)
	}
}