Exemple #1
0
// CloseAllQueues closes all queues
func (repo *QueueRepository) CloseAllQueues() error {
	var err error
	var q *queue.Queue
	for pair := range repo.storage.IterBuffered() {
		q, err = repo.GetQueue(pair.Key)
		if err != nil {
			return err
		}
		q.Close()
	}
	return nil
}
Exemple #2
0
func (self *QueueRepository) CloseAllQueues() error {
	var err error
	var q *queue.Queue
	for pair := range self.storage.Iter() {
		q, err = self.GetQueue(pair.Key)
		if err != nil {
			return err
		}
		q.Close()
	}
	return nil
}
Exemple #3
0
// FullStats gets repository stats
func (repo *QueueRepository) FullStats() []StatItem {
	stats := []StatItem{}
	currentTime := time.Now().Unix()
	stats = append(stats, StatItem{"uptime", fmt.Sprintf("%d", currentTime-repo.Stats.StartTime)})
	stats = append(stats, StatItem{"time", fmt.Sprintf("%d", currentTime)})
	stats = append(stats, StatItem{"version", fmt.Sprintf("%s", repo.Stats.Version)})
	stats = append(stats, StatItem{"curr_connections", fmt.Sprintf("%d", repo.Stats.CurrentConnections)})
	stats = append(stats, StatItem{"total_connections", fmt.Sprintf("%d", repo.Stats.TotalConnections)})
	stats = append(stats, StatItem{"cmd_get", fmt.Sprintf("%d", repo.Stats.CmdGet)})
	stats = append(stats, StatItem{"cmd_set", fmt.Sprintf("%d", repo.Stats.CmdSet)})
	var q *queue.Queue
	for pair := range repo.storage.IterBuffered() {
		q = pair.Val.(*queue.Queue)
		stats = append(stats, StatItem{"queue_" + q.Name + "_items", fmt.Sprintf("%d", q.Length())})
		stats = append(stats, StatItem{"queue_" + q.Name + "_open_transactions", fmt.Sprintf("%d", q.Stats.OpenTransactions)})
	}
	return stats
}
func Test_Initialize(t *testing.T) {
	repo, err := Initialize(dir)
	assert.Nil(t, err)

	// Create 3 queues and push some data
	queueNames := []string{"test1", "test2", "test3"}
	var q *queue.Queue
	totalItems := 3
	for i := 0; i < len(queueNames); i++ {
		q, _ = repo.GetQueue(queueNames[i])
		for j := 0; j < totalItems; j++ {
			q.Enqueue([]byte("value"))
		}
		// Get one element out
		_, _ = q.Dequeue()
	}

	// Close all queues and destroy repo
	repo.CloseAllQueues()
	repo = nil

	// Initialize repo again and check loaded queues
	repo, err = Initialize(dir)
	assert.Nil(t, err)

	assert.Equal(t, repo.Count(), 3, "Invalid repo count after initialization")

	for i := 0; i < len(queueNames); i++ {
		q, _ = repo.GetQueue(queueNames[i])
		assert.Equal(t, q.Head(), uint64(1), "Invalid queue initialization")
		assert.Equal(t, q.Tail(), uint64(totalItems), "Invalid queue initialization")
		assert.Equal(t, q.Length(), uint64(totalItems-1), "Invalid queue initialization")
	}
	repo.DeleteAllQueues()
}