Exemplo n.º 1
0
func (q *CGQueue) initialize() error {
	var err error
	q.Queue, err = queue.Open(q.Name, q.dataDir, &queue.Options{})
	if err != nil {
		return err
	}

	q.CGManager, err = NewCGManager(q.dataDir+"/_.metadata", q.Queue)
	return err
}
Exemplo n.º 2
0
// Get existing queue from repository or create a new one
func (self *QueueRepository) GetQueue(key string) (*queue.Queue, error) {
	if !self.storage.Has(key) {
		q, err := queue.Open(key, self.DataPath)
		if err != nil {
			return nil, err
		}
		self.storage.Set(key, q)
	}
	return self.get(key)
}
Exemplo n.º 3
0
func setupCGManager(t *testing.T, numItems int) (*CGManager, error) {
	source, err := queue.Open(sourceQueueName, dir, &options)
	assert.NoError(t, err)

	for i := 0; i < numItems+1; i++ {
		source.Enqueue([]byte(strconv.Itoa(i)))
	}

	// dequeue first element so head is not 0
	source.GetNext()
	return NewCGManager(storagePath, source)
}
Exemplo n.º 4
0
// GetQueue returns existing queue from repository,
// creates a new one if it doesn't exist
func (repo *QueueRepository) GetQueue(key string) (*queue.Queue, error) {
	q, ok := repo.get(key)
	if !ok {
		repo.Lock()
		if q, ok = repo.get(key); !ok {
			q, err = queue.Open(key, repo.DataPath)
			if err != nil {
				return nil, err
			}
			repo.storage.Set(key, q)
		}
		repo.Unlock()
	}
	return q, nil
}
Exemplo n.º 5
0
func setupConsumerGroup(t *testing.T, name string,
	numItems int) (*ConsumerGroup, error) {

	storage, err := leveldb.OpenFile(storageDBPath, &opt.Options{})
	assert.NoError(t, err)
	source, err := queue.Open(sourceQueueName, dir, &options)
	assert.NoError(t, err)

	for i := 0; i < numItems+1; i++ {
		source.Enqueue([]byte(strconv.Itoa(i)))
	}

	source.GetNext()
	return NewConsumerGroup(name, source, storage)
}