Skip to content

Commit

Permalink
module: register disco info default entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
ortuman committed May 20, 2018
1 parent de4dc99 commit 55f2b62
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions storage/badgerdb/badgerdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ type Config struct {
DataDir string `yaml:"data_dir"`
}

// Storage represents a BadgerDB storage sub system.
type Storage struct {
db *badger.DB
pool *pool.BufferPool
doneCh chan chan bool
}

// New returns a new BadgerDB storage instance.
func New(cfg *Config) *Storage {
b := &Storage{
pool: pool.NewBufferPool(),
Expand All @@ -57,6 +59,7 @@ func New(cfg *Config) *Storage {
return b
}

// Shutdown shuts down BadgerDB storage sub system.
func (b *Storage) Shutdown() {
ch := make(chan bool)
b.doneCh <- ch
Expand Down
6 changes: 3 additions & 3 deletions storage/badgerdb/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
"github.com/ortuman/jackal/xml"
)

// FetchPrivateXML retrieves from storage a private element.
// InsertOrUpdatePrivateXML inserts a new private element into storage,
// or updates it in case it's been previously inserted.
func (b *Storage) InsertOrUpdatePrivateXML(privateXML []xml.XElement, namespace string, username string) error {
r := xml.NewElementName("r")
r.AppendElements(privateXML)
Expand All @@ -19,8 +20,7 @@ func (b *Storage) InsertOrUpdatePrivateXML(privateXML []xml.XElement, namespace
})
}

// InsertOrUpdatePrivateXML inserts a new private element into storage,
// or updates it in case it's been previously inserted.
// FetchPrivateXML retrieves from storage a private element.
func (b *Storage) FetchPrivateXML(namespace string, username string) ([]xml.XElement, error) {
var r xml.Element
err := b.fetch(&r, b.privateStorageKey(username, namespace))
Expand Down
5 changes: 5 additions & 0 deletions storage/memstorage/memstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// when mocked error is activated.
var ErrMockedError = errors.New("storage mocked error")

// Storage represents an in memory storage sub system.
type Storage struct {
mockErr uint32
mu sync.RWMutex
Expand All @@ -31,6 +32,7 @@ type Storage struct {
blockListItems map[string][]model.BlockListItem
}

// New returns a new in memory storage instance.
func New() *Storage {
return &Storage{
users: make(map[string]*model.User),
Expand All @@ -44,13 +46,16 @@ func New() *Storage {
}
}

// Shutdown shuts down in memory storage sub system.
func (m *Storage) Shutdown() {
}

// ActivateMockedError activates in memory mocked error.
func (m *Storage) ActivateMockedError() {
atomic.StoreUint32(&m.mockErr, 1)
}

// DeactivateMockedError deactivates in memory mocked error.
func (m *Storage) DeactivateMockedError() {
atomic.StoreUint32(&m.mockErr, 0)
}
Expand Down
6 changes: 3 additions & 3 deletions storage/memstorage/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ package memstorage

import "github.com/ortuman/jackal/xml"

// FetchPrivateXML retrieves from storage a private element.
// InsertOrUpdatePrivateXML inserts a new private element into storage,
// or updates it in case it's been previously inserted.
func (m *Storage) InsertOrUpdatePrivateXML(privateXML []xml.XElement, namespace string, username string) error {
return m.inWriteLock(func() error {
var elems []xml.XElement
Expand All @@ -19,8 +20,7 @@ func (m *Storage) InsertOrUpdatePrivateXML(privateXML []xml.XElement, namespace
})
}

// InsertOrUpdatePrivateXML inserts a new private element into storage,
// or updates it in case it's been previously inserted.
// FetchPrivateXML retrieves from storage a private element.
func (m *Storage) FetchPrivateXML(namespace string, username string) ([]xml.XElement, error) {
var ret []xml.XElement
err := m.inReadLock(func() error {
Expand Down
6 changes: 5 additions & 1 deletion storage/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type rowsScanner interface {
Next() bool
}

// Config represents MySQL storage configuration.
// Config represents SQL storage configuration.
type Config struct {
Host string `yaml:"host"`
User string `yaml:"user"`
Expand All @@ -39,12 +39,14 @@ type Config struct {
PoolSize int `yaml:"pool_size"`
}

// Storage represents a SQL storage sub system.
type Storage struct {
db *sql.DB
pool *pool.BufferPool
doneCh chan chan bool
}

// New returns a SQL storage instance.
func New(cfg *Config) *Storage {
var err error
s := &Storage{
Expand Down Expand Up @@ -72,6 +74,7 @@ func New(cfg *Config) *Storage {
return s
}

// NewMock returns a mocked SQL storage instance.
func NewMock() (*Storage, sqlmock.Sqlmock) {
var err error
var sqlMock sqlmock.Sqlmock
Expand All @@ -85,6 +88,7 @@ func NewMock() (*Storage, sqlmock.Sqlmock) {
return s, sqlMock
}

// Shutdown shuts down SQL storage sub system.
func (s *Storage) Shutdown() {
ch := make(chan bool)
s.doneCh <- ch
Expand Down

0 comments on commit 55f2b62

Please sign in to comment.