Files
dolt/chunks/test_utils.go
Chris Masone d8a2d285e9 Pull DataStore API over the wire and kill chunks.HTTPStore
This patch is unfortunately large, but it seemed necessary to make all
these changes at once to transition away from having an HTTP
ChunkStore that could allow for invalid state in the DB. Now, we have
a RemoteDataStoreClient that allows for reading and writing of Values,
and performs validation on the server side before persisting chunks.
The semantics of DataStore are that written values can be read back
out immediately, but are not guaranteed to be persistent until after
Commit() The semantics are now that Put() blocks until the Chunk is
persisted, and the new PutMany() can be used to write a number of
Chunks all at once.

From a command-line tool point of view, -h and -h-auth still work as
expected.
2016-04-12 14:08:58 -07:00

77 lines
1.5 KiB
Go

package chunks
import (
"sync"
"github.com/attic-labs/noms/ref"
"github.com/stretchr/testify/assert"
)
func assertInputInStore(input string, ref ref.Ref, s ChunkStore, assert *assert.Assertions) {
chunk := s.Get(ref)
assert.False(chunk.IsEmpty(), "Shouldn't get empty chunk for %s", ref.String())
assert.Equal(input, string(chunk.Data()))
}
func assertInputNotInStore(input string, ref ref.Ref, s ChunkStore, assert *assert.Assertions) {
data := s.Get(ref)
assert.Nil(data, "Shouldn't have gotten data for %s", ref.String())
}
type TestStore struct {
MemoryStore
Reads int
Hases int
Writes int
}
func NewTestStore() *TestStore {
return &TestStore{
MemoryStore: MemoryStore{
mu: &sync.Mutex{},
},
}
}
func (s *TestStore) Get(ref ref.Ref) Chunk {
s.Reads++
return s.MemoryStore.Get(ref)
}
func (s *TestStore) Has(ref ref.Ref) bool {
s.Hases++
return s.MemoryStore.Has(ref)
}
func (s *TestStore) Put(c Chunk) {
s.Writes++
s.MemoryStore.Put(c)
}
func (s *TestStore) PutMany(chunks []Chunk) (e BackpressureError) {
for _, c := range chunks {
s.Put(c)
}
return
}
type testStoreFactory struct {
stores map[string]*TestStore
}
func NewTestStoreFactory() *testStoreFactory {
return &testStoreFactory{map[string]*TestStore{}}
}
func (f *testStoreFactory) CreateStore(ns string) ChunkStore {
if cs, present := f.stores[ns]; present {
return cs
}
f.stores[ns] = NewTestStore()
return f.stores[ns]
}
func (f *testStoreFactory) Shutter() {
f.stores = map[string]*TestStore{}
}