Ejemplo n.º 1
0
// CloseAllQueues closes all queues
func (repo *QueueRepository) CloseAllQueues() error {
	var err error
	var q *cgroup.CGQueue
	for pair := range repo.storage.IterBuffered() {
		q, err = repo.GetQueue(pair.Key)
		if err != nil {
			return err
		}
		q.Close()
	}
	return nil
}
Ejemplo n.º 2
0
// FlushAllQueues removes all items from all the queues
func (repo *QueueRepository) FlushAllQueues() error {
	var (
		err error
		q   *cgroup.CGQueue
	)

	for pair := range repo.storage.IterBuffered() {
		q, err = repo.GetQueue(pair.Key)
		if err != nil {
			return err
		}

		err = q.Flush()
		if err != nil {
			return err
		}
	}
	return nil
}
Ejemplo n.º 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 *cgroup.CGQueue
	var cg *cgroup.ConsumerGroup
	for pair := range repo.storage.IterBuffered() {
		q = pair.Val.(*cgroup.CGQueue)
		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().OpenReads)})
		for pair := range q.ConsumerGroupIterator() {
			cg = pair.Val.(*cgroup.ConsumerGroup)
			stats = append(stats, StatItem{"queue_" + q.Name + "." + cg.Name + "_items", fmt.Sprintf("%d", cg.Length())})
			stats = append(stats, StatItem{"queue_" + q.Name + "." + cg.Name + "_open_transactions", fmt.Sprintf("%d", cg.Stats().OpenReads)})
		}
	}
	return stats
}
Ejemplo n.º 4
0
func Test_NewRepository(t *testing.T) {
	repo, err := NewRepository(dir)
	assert.Nil(t, err)

	// Create 3 queues and push some data
	queueNames := []string{"test1", "test2", "test3"}
	var q *cgroup.CGQueue
	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.GetNext()
	}

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

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

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

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