Skip to content

Commit ac5846c

Browse files
author
Chris Elder
committed
[FAB-3238] Move CouchDB config to couchdb
CouchDB configuration should be moved from the ledgerconfig package to couchdb package since the config options are specific to CouchDB. Move corresponding unit tests to couchdb package. Change-Id: I438f1ec2aed167b0b3e96304682ffe29d3641ab5 Signed-off-by: Chris Elder <[email protected]>
1 parent 8ce1073 commit ac5846c

File tree

7 files changed

+67
-45
lines changed

7 files changed

+67
-45
lines changed

core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type VersionedDBProvider struct {
5454
// NewVersionedDBProvider instantiates VersionedDBProvider
5555
func NewVersionedDBProvider() (*VersionedDBProvider, error) {
5656
logger.Debugf("constructing CouchDB VersionedDBProvider")
57-
couchDBDef := ledgerconfig.GetCouchDBDefinition()
57+
couchDBDef := couchdb.GetCouchDBDefinition()
5858
couchInstance, err := couchdb.CreateCouchInstance(couchDBDef.URL, couchDBDef.Username, couchDBDef.Password,
5959
couchDBDef.MaxRetries, couchDBDef.MaxRetriesOnStartup, couchDBDef.RequestTimeout)
6060
if err != nil {

core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test_export.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222

2323
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
24-
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
2524
"github.com/hyperledger/fabric/core/ledger/util/couchdb"
2625
)
2726

@@ -52,7 +51,7 @@ func (env *TestVDBEnv) Cleanup(dbName string) {
5251
}
5352
func cleanupDB(dbName string) {
5453
//create a new connection
55-
couchDBDef := ledgerconfig.GetCouchDBDefinition()
54+
couchDBDef := couchdb.GetCouchDBDefinition()
5655
couchInstance, _ := couchdb.CreateCouchInstance(couchDBDef.URL, couchDBDef.Username, couchDBDef.Password,
5756
couchDBDef.MaxRetries, couchDBDef.MaxRetriesOnStartup, couchDBDef.RequestTimeout)
5857
db := couchdb.CouchDatabase{CouchInstance: *couchInstance, DBName: dbName}

core/ledger/ledgerconfig/ledger_config.go

-24
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,11 @@ package ledgerconfig
1818

1919
import (
2020
"path/filepath"
21-
"time"
2221

2322
"github.com/hyperledger/fabric/core/config"
2423
"github.com/spf13/viper"
2524
)
2625

27-
// CouchDBDef contains parameters
28-
type CouchDBDef struct {
29-
URL string
30-
Username string
31-
Password string
32-
MaxRetries int
33-
MaxRetriesOnStartup int
34-
RequestTimeout time.Duration
35-
}
36-
3726
//IsCouchDBEnabled exposes the useCouchDB variable
3827
func IsCouchDBEnabled() bool {
3928
stateDatabase := viper.GetString("ledger.state.stateDatabase")
@@ -75,19 +64,6 @@ func GetMaxBlockfileSize() int {
7564
return 64 * 1024 * 1024
7665
}
7766

78-
//GetCouchDBDefinition exposes the useCouchDB variable
79-
func GetCouchDBDefinition() *CouchDBDef {
80-
81-
couchDBAddress := viper.GetString("ledger.state.couchDBConfig.couchDBAddress")
82-
username := viper.GetString("ledger.state.couchDBConfig.username")
83-
password := viper.GetString("ledger.state.couchDBConfig.password")
84-
maxRetries := viper.GetInt("ledger.state.couchDBConfig.maxRetries")
85-
maxRetriesOnStartup := viper.GetInt("ledger.state.couchDBConfig.maxRetriesOnStartup")
86-
requestTimeout := viper.GetDuration("ledger.state.couchDBConfig.requestTimeout")
87-
88-
return &CouchDBDef{couchDBAddress, username, password, maxRetries, maxRetriesOnStartup, requestTimeout}
89-
}
90-
9167
//GetQueryLimit exposes the queryLimit variable
9268
func GetQueryLimit() int {
9369
queryLimit := viper.GetInt("ledger.state.queryLimit")

core/ledger/ledgerconfig/ledger_config_test.go

-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package ledgerconfig
1818

1919
import (
2020
"testing"
21-
"time"
2221

2322
"github.com/hyperledger/fabric/common/ledger/testutil"
2423
ledgertestutil "github.com/hyperledger/fabric/core/ledger/testutil"
@@ -47,19 +46,6 @@ func TestIsCouchDBEnabled(t *testing.T) {
4746
testutil.AssertEquals(t, updatedValue, true) //test config returns true
4847
}
4948

50-
func TestGetCouchDBDefinition(t *testing.T) {
51-
setUpCoreYAMLConfig()
52-
defer ledgertestutil.ResetConfigToDefaultValues()
53-
viper.Set("ledger.state.stateDatabase", "CouchDB")
54-
couchDBDef := GetCouchDBDefinition()
55-
testutil.AssertEquals(t, couchDBDef.URL, "127.0.0.1:5984")
56-
testutil.AssertEquals(t, couchDBDef.Username, "")
57-
testutil.AssertEquals(t, couchDBDef.Password, "")
58-
testutil.AssertEquals(t, couchDBDef.MaxRetries, 3)
59-
testutil.AssertEquals(t, couchDBDef.MaxRetriesOnStartup, 10)
60-
testutil.AssertEquals(t, couchDBDef.RequestTimeout, time.Second*35)
61-
}
62-
6349
func TestIsHistoryDBEnabledDefault(t *testing.T) {
6450
setUpCoreYAMLConfig()
6551
defaultValue := IsHistoryDBEnabled()

core/ledger/util/couchdb/config.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package couchdb
18+
19+
import (
20+
"time"
21+
22+
"github.com/spf13/viper"
23+
)
24+
25+
// CouchDBDef contains parameters
26+
type CouchDBDef struct {
27+
URL string
28+
Username string
29+
Password string
30+
MaxRetries int
31+
MaxRetriesOnStartup int
32+
RequestTimeout time.Duration
33+
}
34+
35+
//GetCouchDBDefinition exposes the useCouchDB variable
36+
func GetCouchDBDefinition() *CouchDBDef {
37+
38+
couchDBAddress := viper.GetString("ledger.state.couchDBConfig.couchDBAddress")
39+
username := viper.GetString("ledger.state.couchDBConfig.username")
40+
password := viper.GetString("ledger.state.couchDBConfig.password")
41+
maxRetries := viper.GetInt("ledger.state.couchDBConfig.maxRetries")
42+
maxRetriesOnStartup := viper.GetInt("ledger.state.couchDBConfig.maxRetriesOnStartup")
43+
requestTimeout := viper.GetDuration("ledger.state.couchDBConfig.requestTimeout")
44+
45+
return &CouchDBDef{couchDBAddress, username, password, maxRetries, maxRetriesOnStartup, requestTimeout}
46+
}

core/ledger/kvledger/txmgmt/statedb/statecouchdb/config.go core/ledger/util/couchdb/config_test.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package statecouchdb
17+
package couchdb
1818

19-
//TODO - Move couch config from ledger_config to here
19+
import (
20+
"testing"
21+
"time"
22+
23+
"github.com/hyperledger/fabric/common/ledger/testutil"
24+
)
25+
26+
func TestGetCouchDBDefinition(t *testing.T) {
27+
couchDBDef := GetCouchDBDefinition()
28+
testutil.AssertEquals(t, couchDBDef.URL, "couchdb:5984")
29+
testutil.AssertEquals(t, couchDBDef.Username, "")
30+
testutil.AssertEquals(t, couchDBDef.Password, "")
31+
testutil.AssertEquals(t, couchDBDef.MaxRetries, 3)
32+
testutil.AssertEquals(t, couchDBDef.MaxRetriesOnStartup, 10)
33+
testutil.AssertEquals(t, couchDBDef.RequestTimeout, time.Second*35)
34+
}

core/ledger/util/couchdb/couchdb_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const badConnectURL = "couchdb:5990"
3535
const updateDocumentConflictError = "conflict"
3636
const updateDocumentConflictReason = "Document update conflict."
3737

38-
var couchDBDef *ledgerconfig.CouchDBDef
38+
var couchDBDef *CouchDBDef
3939

4040
func cleanup(database string) error {
4141
//create a new connection
@@ -81,7 +81,7 @@ func TestMain(m *testing.M) {
8181
viper.Set("ledger.state.couchDBConfig.requestTimeout", time.Second*35)
8282

8383
// Create CouchDB definition from config parameters
84-
couchDBDef = ledgerconfig.GetCouchDBDefinition()
84+
couchDBDef = GetCouchDBDefinition()
8585

8686
//run the tests
8787
result := m.Run()

0 commit comments

Comments
 (0)