本文整理汇总了Golang中github.com/pressly/chainstore.Store.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Store.Get方法的具体用法?Golang Store.Get怎么用?Golang Store.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pressly/chainstore.Store
的用法示例。
在下文中一共展示了Store.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestS3Store
func TestS3Store(t *testing.T) {
var store chainstore.Store
var err error
ctx := context.Background()
assert := assert.New(t)
store = chainstore.New(New(bucketID, accessKey, secretKey))
err = store.Open()
assert.Nil(err)
defer store.Close()
// Put a bunch of objects
e1 := store.Put(ctx, "hi", []byte{1, 2, 3})
e2 := store.Put(ctx, "bye", []byte{4, 5, 6})
assert.Nil(e1)
assert.Nil(e2)
// Get those objects
v1, _ := store.Get(ctx, "hi")
v2, _ := store.Get(ctx, "bye")
assert.Equal(v1, []byte{1, 2, 3})
assert.Equal(v2, []byte{4, 5, 6})
// Delete those objects
e1 = store.Del(ctx, "hi")
e2 = store.Del(ctx, "bye")
assert.Equal(e1, nil)
assert.Equal(e2, nil)
}
示例2: TestFileStore
func TestFileStore(t *testing.T) {
var store chainstore.Store
var err error
Convey("Fsdb Open", t, func() {
store = filestore.New(chainstore.TempDir(), 0755)
err = nil
So(err, ShouldEqual, nil)
Convey("Put/Get/Del basic data", func() {
err = store.Put("test.txt", []byte{1, 2, 3, 4})
So(err, ShouldEqual, nil)
data, err := store.Get("test.txt")
So(err, ShouldEqual, nil)
So(data, ShouldResemble, []byte{1, 2, 3, 4})
})
Convey("Auto-creating directories on put", func() {
err = store.Put("hello/there/everyone.txt", []byte{1, 2, 3, 4})
So(err, ShouldEqual, nil)
})
})
}
示例3: TestFileStore
func TestFileStore(t *testing.T) {
var store chainstore.Store
var err error
ctx := context.Background()
store = chainstore.New(New(tempDir(), 0755))
assert := assert.New(t)
err = store.Open()
assert.Nil(err)
// Put/Get/Del basic data
err = store.Put(ctx, "test.txt", []byte{1, 2, 3, 4})
assert.Nil(err)
data, err := store.Get(ctx, "test.txt")
assert.Nil(err)
assert.Equal(data, []byte{1, 2, 3, 4})
// Auto-creating directories on put
err = store.Put(ctx, "hello/there/everyone.txt", []byte{1, 2, 3, 4})
assert.Nil(err)
}
示例4: TestBasicChain
func TestBasicChain(t *testing.T) {
var ms, fs, chain chainstore.Store
var err error
ctx := context.Background()
logger := log.New(os.Stdout, "", log.LstdFlags)
storeDir := tempDir()
err = nil
ms = memstore.New(100)
fs = filestore.New(storeDir+"/filestore", 0755)
chain = chainstore.New(
logmgr.New(logger, ""),
ms,
fs,
)
assert := assert.New(t)
err = chain.Open()
assert.Nil(err)
v := []byte("value")
err = chain.Put(ctx, "k", v)
assert.Nil(err)
val, err := chain.Get(ctx, "k")
assert.Nil(err)
assert.Equal(val, v)
val, err = ms.Get(ctx, "k")
assert.Nil(err)
assert.Equal(val, v)
val, err = fs.Get(ctx, "k")
assert.Nil(err)
assert.Equal(val, v)
err = chain.Del(ctx, "k")
assert.Nil(err)
val, err = fs.Get(ctx, "k")
assert.Nil(err)
assert.Equal(len(val), 0)
val, err = chain.Get(ctx, "[email protected]#")
assert.NotNil(err)
}
示例5: TestBasicChain
func TestBasicChain(t *testing.T) {
var ms, fs, chain chainstore.Store
var err error
logger := log.New(os.Stdout, "", log.LstdFlags)
Convey("Basic chain", t, func() {
storeDir := chainstore.TempDir()
err = nil
ms = memstore.New(100)
fs = filestore.New(storeDir+"/filestore", 0755)
chain = chainstore.New(
logmgr.New(logger, ""),
ms,
fs,
)
err = chain.Open()
So(err, ShouldEqual, nil)
Convey("Put/Get/Del", func() {
v := []byte("value")
err = chain.Put("k", v)
So(err, ShouldEqual, nil)
val, err := chain.Get("k")
So(err, ShouldEqual, nil)
So(v, ShouldResemble, v)
val, err = ms.Get("k")
So(err, ShouldEqual, nil)
So(val, ShouldResemble, v)
val, err = fs.Get("k")
So(err, ShouldEqual, nil)
So(val, ShouldResemble, v)
err = chain.Del("k")
So(err, ShouldEqual, nil)
val, err = fs.Get("k")
So(err, ShouldEqual, nil)
So(len(val), ShouldEqual, 0)
val, err = chain.Get("[email protected]#")
So(err, ShouldNotBeNil)
})
})
}
示例6: TestAsyncChain
func TestAsyncChain(t *testing.T) {
var ms, fs, bs, chain chainstore.Store
var err error
logger := log.New(os.Stdout, "", log.LstdFlags)
Convey("Async chain", t, func() {
storeDir := chainstore.TempDir()
err = nil
ms = memstore.New(100)
fs = filestore.New(storeDir+"/filestore", 0755)
bs = boltstore.New(storeDir+"/boltstore/bolt.db", "test")
chain = chainstore.New(
logmgr.New(logger, ""),
ms,
chainstore.Async(
logmgr.New(logger, "async"),
metricsmgr.New("chaintest", nil,
fs,
lrumgr.New(100, bs),
),
),
)
err = chain.Open()
So(err, ShouldEqual, nil)
Convey("Put/Get/Del", func() {
v := []byte("value")
err = chain.Put("k", v)
So(err, ShouldEqual, nil)
val, err := chain.Get("k")
So(err, ShouldEqual, nil)
So(v, ShouldResemble, v)
val, err = ms.Get("k")
So(err, ShouldEqual, nil)
So(val, ShouldResemble, v)
time.Sleep(10e6) // wait for async operation..
val, err = fs.Get("k")
So(err, ShouldEqual, nil)
So(val, ShouldResemble, v)
val, err = bs.Get("k")
So(err, ShouldEqual, nil)
So(val, ShouldResemble, v)
})
})
}
示例7: TestMemCacheStore
func TestMemCacheStore(t *testing.T) {
var store chainstore.Store
var err error
var obj []byte
ctx := context.Background()
store = chainstore.New(New(10))
assert := assert.New(t)
err = store.Put(ctx, "hi", []byte{1, 2, 3})
assert.Nil(err)
obj, err = store.Get(ctx, "hi")
assert.Nil(err)
assert.Equal(obj, []byte{1, 2, 3})
err = store.Put(ctx, "bye", []byte{5, 6, 7, 8, 9, 10, 11, 12})
assert.Nil(err)
obj, err = store.Get(ctx, "hi")
assert.Equal(len(obj), 0)
obj, err = store.Get(ctx, "bye")
assert.Equal(len(obj), 8)
}
示例8: TestMockStoreCancelWithDefaultTimeout
// TestMockStoreCancelWithDefaultTimeout tests automatic operation cancellation
// and posterior recover.
func TestMockStoreCancelWithDefaultTimeout(t *testing.T) {
var store chainstore.Store
var err error
ctx := context.Background()
cfg := &Config{
Capacity: 100,
SuccessRate: 1.0, // always succeeds.
Delay: time.Second * 1, // any operation takes 0.5s.
}
store = chainstore.New(New(cfg))
assert := assert.New(t)
// This is going to fail because the timeout is lower than the delay.
cfg.Timeout = time.Millisecond * 500
err = store.Put(ctx, "notnil", []byte("something"))
assert.Equal(chainstore.ErrTimeout, err)
// This is going to succeed because the timeout is greater than the delay.
cfg.Timeout = time.Millisecond * 1500
err = store.Put(ctx, "notnil", []byte("something"))
assert.Nil(err)
// This is going to fail because the timeout is lower than the delay.
cfg.Timeout = time.Millisecond * 500
_, err = store.Get(ctx, "notnil")
assert.Equal(chainstore.ErrTimeout, err)
// This is going to succeed because the timeout is greater than the delay.
cfg.Timeout = time.Millisecond * 1500
_, err = store.Get(ctx, "notnil")
assert.Nil(err)
}
示例9: TestLevelStore
func TestLevelStore(t *testing.T) {
var store chainstore.Store
var err error
store = levelstore.New(chainstore.TempDir())
err = store.Open()
if err != nil {
t.Error(err)
}
defer store.Close()
Convey("Leveldb Open", t, func() {
Convey("Put a bunch of objects", func() {
e1 := store.Put("hi", []byte{1, 2, 3})
e2 := store.Put("bye", []byte{4, 5, 6})
So(e1, ShouldEqual, nil)
So(e2, ShouldEqual, nil)
})
Convey("Get those objects", func() {
v1, _ := store.Get("hi")
v2, _ := store.Get("bye")
So(v1, ShouldResemble, []byte{1, 2, 3})
So(v2, ShouldResemble, []byte{4, 5, 6})
})
Convey("Delete those objects", func() {
e1 := store.Del("hi")
e2 := store.Del("bye")
So(e1, ShouldEqual, nil)
So(e2, ShouldEqual, nil)
})
})
}
示例10: TestMockStoreCancelWithFunc
// TestMockStoreCancelWithFunc creates and test a mockstore that succeeds at
// first but then is cancelled.
func TestMockStoreCancelWithFunc(t *testing.T) {
var store chainstore.Store
var err error
ctx, cancel := context.WithCancel(context.Background())
store = chainstore.New(New(&Config{
Capacity: 100,
SuccessRate: 1.0, // always succeeds.
Delay: time.Second * 1, // any operation takes 1s.
}))
go func() {
time.Sleep(time.Millisecond * 1500)
cancel()
}()
assert := assert.New(t)
// This is going to succeed.
err = store.Put(ctx, "notnil", []byte("something"))
assert.Nil(err)
// This will fail because after 1.5s the context will send a cancellation signal.
err = store.Put(ctx, "hi", []byte{1, 2, 3})
assert.NotNil(err)
_, err = store.Get(ctx, "hi")
assert.NotNil(err)
err = store.Put(ctx, "bye", []byte{5, 6, 7, 8, 9, 10, 11, 12})
assert.NotNil(err)
err = store.Del(ctx, "hi")
assert.NotNil(err)
_, err = store.Get(ctx, "hi")
assert.NotNil(err)
_, err = store.Get(ctx, "bye")
assert.NotNil(err)
_, err = store.Get(ctx, "notnil")
assert.NotNil(err)
}
示例11: TestMockStoreSuccess
// TestMockStoreSuccess creates and test a mockstore that always succeeds.
func TestMockStoreSuccess(t *testing.T) {
var store chainstore.Store
var err error
var obj []byte
ctx := context.Background()
store = chainstore.New(New(&Config{
Capacity: 100,
SuccessRate: 1.0, // always succeeds.
}))
assert := assert.New(t)
err = store.Put(ctx, "notnil", []byte("something"))
assert.Nil(err)
err = store.Put(ctx, "hi", []byte{1, 2, 3})
assert.Nil(err)
obj, err = store.Get(ctx, "hi")
assert.Nil(err)
assert.Equal(obj, []byte{1, 2, 3})
err = store.Put(ctx, "bye", []byte{5, 6, 7, 8, 9, 10, 11, 12})
assert.Nil(err)
err = store.Del(ctx, "hi")
assert.Nil(err)
obj, err = store.Get(ctx, "hi")
assert.NotNil(err)
assert.Equal(len(obj), 0)
obj, err = store.Get(ctx, "bye")
assert.Nil(err)
assert.Equal(len(obj), 8)
obj, err = store.Get(ctx, "notnil")
assert.Nil(err)
assert.Equal(len(obj), 9)
}
示例12: TestMockStoreCancelWithTimeout
// TestMockStoreCancelWithTimeout creates and test a mockstore with that after
// a while gets cancelled.
func TestMockStoreCancelWithTimeout(t *testing.T) {
var store chainstore.Store
var err error
assert := assert.New(t)
store = chainstore.New(New(&Config{
Capacity: 100,
SuccessRate: 1.0, // always succeeds.
Delay: time.Second * 1, // any operation takes 1s.
}))
ctx, _ := context.WithTimeout(context.Background(), time.Millisecond*500)
// After 0.5s this all is going to fail, because the context timed out.
err = store.Put(ctx, "notnil", []byte("something"))
assert.NotNil(err)
err = store.Put(ctx, "hi", []byte{1, 2, 3})
assert.NotNil(err)
_, err = store.Get(ctx, "hi")
assert.NotNil(err)
err = store.Put(ctx, "bye", []byte{5, 6, 7, 8, 9, 10, 11, 12})
assert.NotNil(err)
err = store.Del(ctx, "hi")
assert.NotNil(err)
_, err = store.Get(ctx, "hi")
assert.NotNil(err)
_, err = store.Get(ctx, "bye")
assert.NotNil(err)
_, err = store.Get(ctx, "notnil")
assert.NotNil(err)
}
示例13: TestMemCacheStore
func TestMemCacheStore(t *testing.T) {
var store chainstore.Store
store = memstore.New(10)
Convey("MemCacheStore", t, func() {
e := store.Put("hi", []byte{1, 2, 3})
So(e, ShouldEqual, nil)
obj, e := store.Get("hi")
So(e, ShouldEqual, nil)
So(obj, ShouldResemble, []byte{1, 2, 3})
e = store.Put("bye", []byte{5, 6, 7, 8, 9, 10, 11, 12})
So(e, ShouldEqual, nil)
obj, e = store.Get("hi")
So(len(obj), ShouldEqual, 0)
obj, e = store.Get("bye")
So(len(obj), ShouldEqual, 8)
})
}
示例14: TestBoltStore
func TestBoltStore(t *testing.T) {
var store chainstore.Store
var err error
store = boltstore.New(chainstore.TempDir()+"/test.db", "test")
err = store.Open()
if err != nil {
t.Error(err)
}
defer store.Close() // does this get called?
Convey("Boltdb Open", t, func() {
Convey("Put a bunch of objects", func() {
e1 := store.Put("hi", []byte{1, 2, 3})
e2 := store.Put("bye", []byte{4, 5, 6})
So(e1, ShouldEqual, nil)
So(e2, ShouldEqual, nil)
})
Convey("Get those objects", func() {
v1, _ := store.Get("hi")
v2, _ := store.Get("bye")
So(v1, ShouldResemble, []byte{1, 2, 3})
So(v2, ShouldResemble, []byte{4, 5, 6})
})
Convey("Delete those objects", func() {
e1 := store.Del("hi")
e2 := store.Del("bye")
So(e1, ShouldEqual, nil)
So(e2, ShouldEqual, nil)
v, _ := store.Get("hi")
So(len(v), ShouldEqual, 0)
})
})
}
示例15: TestBoltStore
func TestBoltStore(t *testing.T) {
var store chainstore.Store
var err error
ctx := context.Background()
store = chainstore.New(New(tempDir()+"/test.db", "test"))
assert := assert.New(t)
err = store.Open()
assert.Nil(err)
defer store.Close() // does this get called?
// Put a bunch of objects
e1 := store.Put(ctx, "hi", []byte{1, 2, 3})
e2 := store.Put(ctx, "bye", []byte{4, 5, 6})
assert.Equal(e1, nil)
assert.Equal(e2, nil)
// Get those objects
v1, _ := store.Get(ctx, "hi")
v2, _ := store.Get(ctx, "bye")
assert.Equal(v1, []byte{1, 2, 3})
assert.Equal(v2, []byte{4, 5, 6})
// Delete those objects
e1 = store.Del(ctx, "hi")
e2 = store.Del(ctx, "bye")
assert.Equal(e1, nil)
assert.Equal(e2, nil)
v, _ := store.Get(ctx, "hi")
assert.Equal(len(v), 0)
}