Ejemplo n.º 1
0
func Test_Queuefka(t *testing.T) {
	wt, err := queuefka.NewWriter(topic, segmentSizeHint)
	if err != nil {
		panic(err)
	}
	defer wt.Close()

	rd, err := queuefka.NewReader(topic, 0x0000)
	if err != nil && err != queuefka.ErrEndOfLog {
		panic(err)
	}
	defer rd.Close()

	wt.Write(value)
	wt.Flush()

	raw, err := rd.Read()
	if err != nil && err != queuefka.ErrEndOfLog {
		panic(err)
	}

	msg := string(raw)
	if msg != string(value) {
		println(msg)
		panic("queuefka: Read does not match write:")
	}

	wt.Status()
}
Ejemplo n.º 2
0
func main() {
	wt, _ := queuefka.NewWriter("./mytopic", 1024*1024)

	defer wt.Close()
	wt.Write([]byte(string("こんにちは世界!"))) // Hello World in Japanese (i hope)
	wt.Flush()

	rd, _ := queuefka.NewReader("./mytopic", 0x0000)
	defer rd.Close()
	msg, _ := rd.Read()
	println(string(msg))
}
Ejemplo n.º 3
0
func Benchmark_Queuefka_Read(b *testing.B) {
	rd, _ := queuefka.NewReader(topic, 0x0000)
	for i := 0; i < b.N; i++ {
		_, err := rd.Read()
		if err != nil {
			if err == queuefka.ErrEndOfLog {
				println("Not enough data in queuefka log to test fully benchmark Read()")
				break
			}
			panic(err)
		}
	}
	rd.Close()
}
Ejemplo n.º 4
0
func Test_Queuefka_Sequential(t *testing.T) {
	wt, err := queuefka.NewWriter(topic, segmentSizeHint)
	if err != nil {
		panic(err)
	}
	defer wt.Close()

	rd, err := queuefka.NewReader(topic, 0x0000)
	if err != nil && err != queuefka.ErrEndOfLog {
		panic(err)
	}
	defer rd.Close()

	for i := 0; i < 50000; i++ {
		wt.Write(value)
		wt.Flush()

		raw, err := rd.Read()
		if err != nil {
			if err == queuefka.ErrEndOfLog {
				break
			}
			panic(err)
		}

		msg := string(raw)
		if msg != string(value) {
			println(msg)
			panic("queuefka: Read does not match write:")
		}

		// this extra read should return ErrEndOfLog
		raw, err = rd.Read()
		if err != nil {
			if err != queuefka.ErrEndOfLog {
				panic(err)
			}
			continue
		}

	}

	wt.Status()
}