Exemplo n.º 1
0
func TestChannelQueueTimeout(t *testing.T) {
	q := queue.NewChannelQueue(50)
	q.Put("abc")
	q.Put("def")
	vals := q.Poll(time.Second * time.Duration(5))
	if vals[0].(string) != "abc" || vals[1].(string) != "def" {
		t.Error("got wrong values")
	}

	var wg sync.WaitGroup
	wg.Add(1)

	wait := func() {
		vals := q.Poll(time.Second * time.Duration(1))
		if vals != nil {
			t.Error("poll on empty returned values!")
		}
		wg.Done()
	}

	go wait()
	wg.Wait()

	q.Put("abc")
	q.Put("def")
	vals = q.Poll(time.Millisecond * time.Duration(1))
	if vals[0].(string) != "abc" || vals[1].(string) != "def" {
		t.Error("got wrong values")
	}
}
Exemplo n.º 2
0
func TestChannelQueue(t *testing.T) {
	queue := queue.NewChannelQueue(maxNum)
	testQueue(queue, t)
}
Exemplo n.º 3
0
func NewConsumer() *Consumer {
	consumer := new(Consumer)
	consumer.MessageQueue = queue.NewChannelQueue(ConsumerQueueSize)
	consumer.InWait = false
	return consumer
}