// should not allow two buffered queues with the same name func (suite *TestSuite) TestUniqueBufferedQueue(c *C) { q := redismq.NewBufferedQueue(redisURL, redisPassword, redisDb, "buffered_test1", 100) err := q.Start() c.Check(err, Equals, nil) q2 := redismq.NewBufferedQueue(redisURL, redisPassword, redisDb, "buffered_test1", 100) err = q2.Start() c.Check(err.Error(), Equals, "buffered queue with this name is already started") }
// should flush buffered queue upon call func (suite *TestSuite) TestBufferedFlush(c *C) { q := redismq.NewBufferedQueue(redisURL, redisPassword, redisDb, "buffered_test4", 1000) err := q.Start() c.Assert(err, Equals, nil) time.Sleep(100 * time.Millisecond) for i := 0; i < 999; i++ { c.Check(q.Put("testpayload"), Equals, nil) } c.Check(len(q.Buffer), Not(Equals), 0) q.FlushBuffer() c.Check(len(q.Buffer), Equals, 0) }
// This example demonstrates maximum performance func main() { runtime.GOMAXPROCS(5) server := redismq.NewServer("localhost:6379", "", 9, "9999") server.Start() testQueue := redismq.NewBufferedQueue("localhost:6379", "", 9, "example", 100) err := testQueue.Start() if err != nil { panic(err) } go write(testQueue) go read(testQueue, "1") go read(testQueue, "2") go read(testQueue, "3") go read(testQueue, "4") select {} }
// should not wait longer than 1 second to read from buffered queue func (suite *TestSuite) TestBufferedQueueNoWait(c *C) { q := redismq.NewBufferedQueue(redisURL, redisPassword, redisDb, "buffered_test3", 100) err := q.Start() c.Assert(err, Equals, nil) c.Check(q.Put("testpayload"), Equals, nil) time.Sleep(1 * time.Second) consumer, err := q.AddConsumer("testconsumer") c.Assert(err, Equals, nil) p, err := consumer.Get() c.Check(err, Equals, nil) c.Check(p.Ack(), Equals, nil) c.Check(q.GetInputLength(), Equals, int64(0)) c.Check(consumer.GetUnackedLength(), Equals, int64(0)) }
// should be able to put and get from buffered queue func (suite *TestSuite) TestBufferedQueue(c *C) { q := redismq.NewBufferedQueue(redisURL, redisPassword, redisDb, "buffered_test2", 100) err := q.Start() c.Assert(err, Equals, nil) for i := 0; i < 100; i++ { c.Check(q.Put("testpayload"), Equals, nil) } consumer, err := q.AddConsumer("testconsumer") c.Assert(err, Equals, nil) for i := 0; i < 100; i++ { p, err := consumer.Get() c.Check(err, Equals, nil) c.Check(p.Ack(), Equals, nil) } c.Check(q.GetInputLength(), Equals, int64(0)) c.Check(consumer.GetUnackedLength(), Equals, int64(0)) }