Skip to content

Commit

Permalink
Merge "[FAB-10768] Fix a bug in couchdb version cache"
Browse files Browse the repository at this point in the history
  • Loading branch information
C0rWin authored and Gerrit Code Review committed Jun 21, 2018
2 parents 9ff9531 + 13cad52 commit fef758e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func newVersionCache() *versionsCache {
}

func (c *versionsCache) getVersion(ns, key string) (*version.Height, bool) {
nsVers, ok := c.vers[ns]
ver, ok := c.vers[ns][key]
if ok {
return nsVers[key], true
return ver, true
}
return nil, false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package statecouchdb

import (
"testing"

"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/stretchr/testify/assert"
)

func TestVersionCache(t *testing.T) {
verCache := newVersionCache()
ver1 := version.NewHeight(1, 1)
ver2 := version.NewHeight(2, 2)
verCache.setVerAndRev("ns1", "key1", version.NewHeight(1, 1), "rev1")
verCache.setVerAndRev("ns2", "key2", version.NewHeight(2, 2), "rev2")

ver, found := verCache.getVersion("ns1", "key1")
assert.True(t, found)
assert.Equal(t, ver1, ver)

ver, found = verCache.getVersion("ns2", "key2")
assert.True(t, found)
assert.Equal(t, ver2, ver)

ver, found = verCache.getVersion("ns1", "key3")
assert.False(t, found)
assert.Nil(t, ver)

ver, found = verCache.getVersion("ns3", "key4")
assert.False(t, found)
assert.Nil(t, ver)
}

0 comments on commit fef758e

Please sign in to comment.