Example #1
0
func BenchmarkNewChunker(b *testing.B) {
	p, err := chunker.RandomPolynomial()
	OK(b, err)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		chunker.New(bytes.NewBuffer(nil), p, nil)
	}
}
Example #2
0
func createConfig(s *Repository) (err error) {
	s.Config.ChunkerPolynomial, err = chunker.RandomPolynomial()
	if err != nil {
		return err
	}

	newID := make([]byte, repositoryIDSize)
	_, err = io.ReadFull(rand.Reader, newID)
	if err != nil {
		return err
	}

	s.Config.ID = hex.EncodeToString(newID)
	s.Config.Version = RepoVersion

	debug.Log("Repo.createConfig", "New config: %#v", s.Config)

	_, err = s.SaveJSONUnpacked(backend.Config, s.Config)
	return err
}
Example #3
0
func TestChunkerWithRandomPolynomial(t *testing.T) {
	// setup data source
	buf := getRandom(23, 32*1024*1024)

	// generate a new random polynomial
	start := time.Now()
	p, err := chunker.RandomPolynomial()
	OK(t, err)
	t.Logf("generating random polynomial took %v", time.Since(start))

	start = time.Now()
	ch := chunker.New(bytes.NewReader(buf), p, sha256.New())
	t.Logf("creating chunker took %v", time.Since(start))

	// make sure that first chunk is different
	c, err := ch.Next()

	Assert(t, c.Cut != chunks1[0].CutFP,
		"Cut point is the same")
	Assert(t, c.Length != chunks1[0].Length,
		"Length is the same")
	Assert(t, !bytes.Equal(c.Digest, chunks1[0].Digest),
		"Digest is the same")
}
Example #4
0
func BenchmarkRandomPolynomial(t *testing.B) {
	for i := 0; i < t.N; i++ {
		_, err := chunker.RandomPolynomial()
		OK(t, err)
	}
}
Example #5
0
func TestRandomPolynomial(t *testing.T) {
	_, err := chunker.RandomPolynomial()
	OK(t, err)
}