Ejemplo n.º 1
0
func TestMain(m *testing.M) {
	rawlevel := flag.String("loglevel", "debug", "Log level.")
	flag.Parse()
	level, err := log.ParseLevel(*rawlevel)
	if err != nil {
		level = log.DebugPrio
	}
	log.SetLevel("all", level)
	os.Exit(m.Run())
}
Ejemplo n.º 2
0
func TestProtoSortIncoming(t *testing.T) {
	const size = 1e6 + 100
	const num = 100

	log.SetLevel("all", log.ProtoPrio)
	defer log.SetLevel("all", log.DebugPrio)

	buf := bytes.NewBuffer([]byte{})
	reader := bufio.NewReader(buf)
	buffers := newBuffers(10)

	ins := make([][]byte, num+1)

	for i := 2; i <= num; i++ {
		err := buffers.New(uint32(i))
		if err != nil {
			t.Fatal(e.Trace(e.Forward(err)))
		}

		b := make([]byte, 14)
		err = header(b, uint32(i), size)
		if err != nil {
			t.Fatal(e.Trace(e.Forward(err)))
		}

		ins[i], err = rand.Bytes(size, "go")
		if err != nil {
			t.Fatal(e.Trace(e.Forward(err)))
		}

		n, err := buf.Write(b)
		if err != nil {
			t.Fatal(e.Trace(e.Forward(err)))
		}
		if n != 14 {
			t.Fatal("write fail")
		}

		n, err = buf.Write(ins[i])
		if err != nil {
			t.Fatal(e.Trace(e.Forward(err)))
		}
		if n != size {
			t.Fatal("write fail")
		}
	}

	err := sortIncoming(reader, buffers, "test")
	if err != nil {
		t.Fatal(e.Trace(e.Forward(err)))
	}

	out := make([]byte, size)

	for i := 2; i <= num; i++ {
		n, err := buffers.Read(uint32(i), out)
		if err != nil {
			t.Fatal(e.Trace(e.Forward(err)))
		}
		if n != size {
			t.Fatal("read fail", i)
		}

		//t.Log(i, ins[i][:30])
		//t.Log(i, out[:30])

		if !bytes.Equal(ins[i], out) {
			// t.Log(ins[i][:30])
			t.Fatal("not equal", i)
		}
	}

}