Beispiel #1
0
func TestPeek(t *testing.T) {
	pagesize := os.Getpagesize()

	peeks := []int{3, pagesize * 2 / 3, 3, pagesize - 1, 3, pagesize * 13 / 5, 3, 0, 3}
	counts := []int{1, 0, 0, 0, 0, 1, 0, 0, 1}
	sizes := []int{0, 1, 0, pagesize * 2 / 3, 0, pagesize * 11 / 7, 0, pagesize * 13 / 5, 0}
	lastAttempt := 511
	incomplete := 255
	lastCount := 0

	total := incomplete
	for _, size := range sizes {
		total += size
	}

	rndr := newrndreader(23, 0, total, io.EOF, nil)
	r := bufio.NewReader(rndr)

	offset := 0
	for i, size := range sizes {
		verifypeek(t, r, peeks[i], []error{nil}, rndr, 23, offset, peeks[i], counts[i])
		offset = verifyread(t, r, size, []error{nil}, rndr, 23, offset, size)
	}

	verifypeek(t, r, lastAttempt, []error{io.EOF}, rndr, 23, offset, incomplete, lastCount)
}
Beispiel #2
0
func TestReadFlatSnapshot(t *testing.T) {
	pagesize := os.Getpagesize()

	rndr := newrndreader(23, 0, -1, io.EOF, nil)
	r := bufio.NewReader(rndr)
	offset := 0

	readers := make([]bufio.SnapshotReader, 30)
	offsets := make([]int, 30)

	rnd := newrnd(42)
	for i := 0; i < len(readers); i++ {
		rnd.step()
		d := rnd.intn(256) + 128
		rnd.step()
		n := rnd.intn(256) + d + 1

		offset = verifyread(t, r, pagesize*n/d, []error{nil}, rndr, 23, offset, pagesize*n/d)

		for j := 0; j < i; j++ {
			rnd.step()
			d := rnd.intn(256) + 128
			rnd.step()
			n := rnd.intn(256) + d + 1

			offsets[j] = verifyread(t, readers[j], pagesize*n/d, []error{nil}, rndr, 23, offsets[j], pagesize*n/d)
		}

		readers[i] = r.Snapshot()
		offsets[i] = offset
	}

	for i := 0; i < len(readers); i++ {
		rnd.step()
		d := rnd.intn(256) + 128
		rnd.step()
		n := rnd.intn(256) + d + 1

		offset = verifyread(t, r, pagesize*n/d, []error{nil}, rndr, 23, offset, pagesize*n/d)

		for j := i; j < len(readers); j++ {
			rnd.step()
			d := rnd.intn(256) + 128
			rnd.step()
			n := rnd.intn(256) + d + 1

			offsets[j] = verifyread(t, readers[j], pagesize*n/d, []error{nil}, rndr, 23, offsets[j], pagesize*n/d)
		}

		readers[i].Close()
		readers[i] = nil
		offsets[i] = -1
	}
}
Beispiel #3
0
func TestReadDeepSnapshot(t *testing.T) {
	pagesize := os.Getpagesize()

	readers := make([]bufio.SnapshotReader, 31)
	offsets := make([]int, 31)

	rndr := newrndreader(23, 0, -1, io.EOF, nil)
	readers[0] = bufio.NewReader(rndr)
	offsets[0] = 0

	rndk := newrnd(42)
	rndj := newrnd(80)
	for i := 1; i < len(readers); i++ {
		for j := 0; j < i; j++ {
			rndk.step()
			d := rndk.intn(256) + 128
			rndk.step()
			n := rndk.intn(256) + d + 1

			offsets[j] = verifyread(t, readers[j], pagesize*n/d, []error{nil}, rndr, 23, offsets[j], pagesize*n/d)
		}

		rndj.step()
		j := rndj.intn(i)
		readers[i] = readers[j].Snapshot()
		offsets[i] = offsets[j]
	}
	/*
		rndi := newrnd(66)
		for len(readers) > 1 {
			for j := 0; j < len(readers); j++ {
				rndk.step()
				d := rndk.intn(256) + 128
				rndk.step()
				n := rndk.intn(256) + d + 1

				offsets[j] = verifyread(t, readers[j], pagesize*n/d, []error{nil}, rndr, 23, offsets[j], pagesize*n/d)
			}

			m := len(readers) - 1
			rndi.step()
			i := rndi.intn(m) + 1
			readers[i].Close()
			readers[i], readers[m], readers = readers[m], nil, readers[:m]
			offsets[i], offsets = offsets[m], offsets[:m]
		}
	*/
}
Beispiel #4
0
func TestReadSmallSplit(t *testing.T) {
	pagesize := os.Getpagesize()
	split := pagesize/2 + 1

	mutate := func(length int, r *testreader) (n int, err error) {
		n = (int(r.offset)/split+1)*split - int(r.offset)
		if length < n {
			n = length
		}
		return
	}

	rndr := newrndreader(23, 0, split*3+1, io.EOF, mutate)
	r := bufio.NewReader(rndr)

	offset := 0
	offset = verifyread(t, r, split-1, []error{nil}, rndr, 23, offset, split-1)
	offset = verifyread(t, r, pagesize+3, []error{nil}, rndr, 23, offset, split+1)
	offset = verifyread(t, r, pagesize+3, []error{nil}, rndr, 23, offset, split)
	offset = verifyread(t, r, 2, []error{io.EOF}, rndr, 23, offset, 1)
}
Beispiel #5
0
func TestRead(t *testing.T) {
	pagesize := os.Getpagesize()

	sizes := []int{0, 1, 0, pagesize * 2 / 3, 0, pagesize * 11 / 7, 0, pagesize * 13 / 5, 0}
	incomplete := 255
	attempt := 511

	total := incomplete
	for _, size := range sizes {
		total += size
	}

	rndr := newrndreader(23, 0, total, io.EOF, nil)
	r := bufio.NewReader(rndr)

	offset := 0
	for _, size := range sizes {
		offset = verifyread(t, r, size, []error{nil}, rndr, 23, offset, size)
	}

	offset = verifyread(t, r, attempt, []error{io.EOF}, rndr, 23, offset, incomplete)
}