github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/internal/peer/node/config_test.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package node 8 9 import ( 10 "testing" 11 "time" 12 13 "github.com/osdi23p228/fabric/core/ledger" 14 "github.com/spf13/viper" 15 "github.com/stretchr/testify/assert" 16 ) 17 18 func TestLedgerConfig(t *testing.T) { 19 defer viper.Reset() 20 var tests = []struct { 21 name string 22 config map[string]interface{} 23 expected *ledger.Config 24 }{ 25 { 26 name: "goleveldb", 27 config: map[string]interface{}{ 28 "peer.fileSystemPath": "/peerfs", 29 "ledger.state.stateDatabase": "goleveldb", 30 }, 31 expected: &ledger.Config{ 32 RootFSPath: "/peerfs/ledgersData", 33 StateDBConfig: &ledger.StateDBConfig{ 34 StateDatabase: "goleveldb", 35 CouchDB: &ledger.CouchDBConfig{}, 36 }, 37 PrivateDataConfig: &ledger.PrivateDataConfig{ 38 MaxBatchSize: 5000, 39 BatchesInterval: 1000, 40 PurgeInterval: 100, 41 DeprioritizedDataReconcilerInterval: 60 * time.Minute, 42 }, 43 HistoryDBConfig: &ledger.HistoryDBConfig{ 44 Enabled: false, 45 }, 46 SnapshotsConfig: &ledger.SnapshotsConfig{ 47 RootDir: "/peerfs/ledgersData/snapshots", 48 }, 49 }, 50 }, 51 { 52 name: "CouchDB Defaults", 53 config: map[string]interface{}{ 54 "peer.fileSystemPath": "/peerfs", 55 "ledger.state.stateDatabase": "CouchDB", 56 "ledger.state.couchDBConfig.couchDBAddress": "localhost:5984", 57 "ledger.state.couchDBConfig.username": "username", 58 "ledger.state.couchDBConfig.password": "password", 59 "ledger.state.couchDBConfig.maxRetries": 3, 60 "ledger.state.couchDBConfig.maxRetriesOnStartup": 10, 61 "ledger.state.couchDBConfig.requestTimeout": "30s", 62 "ledger.state.couchDBConfig.createGlobalChangesDB": true, 63 "ledger.state.couchDBConfig.cacheSize": 64, 64 }, 65 expected: &ledger.Config{ 66 RootFSPath: "/peerfs/ledgersData", 67 StateDBConfig: &ledger.StateDBConfig{ 68 StateDatabase: "CouchDB", 69 CouchDB: &ledger.CouchDBConfig{ 70 Address: "localhost:5984", 71 Username: "username", 72 Password: "password", 73 MaxRetries: 3, 74 MaxRetriesOnStartup: 10, 75 RequestTimeout: 30 * time.Second, 76 InternalQueryLimit: 1000, 77 MaxBatchUpdateSize: 500, 78 WarmIndexesAfterNBlocks: 1, 79 CreateGlobalChangesDB: true, 80 RedoLogPath: "/peerfs/ledgersData/couchdbRedoLogs", 81 UserCacheSizeMBs: 64, 82 }, 83 }, 84 PrivateDataConfig: &ledger.PrivateDataConfig{ 85 MaxBatchSize: 5000, 86 BatchesInterval: 1000, 87 PurgeInterval: 100, 88 DeprioritizedDataReconcilerInterval: 60 * time.Minute, 89 }, 90 HistoryDBConfig: &ledger.HistoryDBConfig{ 91 Enabled: false, 92 }, 93 SnapshotsConfig: &ledger.SnapshotsConfig{ 94 RootDir: "/peerfs/ledgersData/snapshots", 95 }, 96 }, 97 }, 98 { 99 name: "CouchDB Explicit", 100 config: map[string]interface{}{ 101 "peer.fileSystemPath": "/peerfs", 102 "ledger.state.stateDatabase": "CouchDB", 103 "ledger.state.couchDBConfig.couchDBAddress": "localhost:5984", 104 "ledger.state.couchDBConfig.username": "username", 105 "ledger.state.couchDBConfig.password": "password", 106 "ledger.state.couchDBConfig.maxRetries": 3, 107 "ledger.state.couchDBConfig.maxRetriesOnStartup": 10, 108 "ledger.state.couchDBConfig.requestTimeout": "30s", 109 "ledger.state.couchDBConfig.internalQueryLimit": 500, 110 "ledger.state.couchDBConfig.maxBatchUpdateSize": 600, 111 "ledger.state.couchDBConfig.warmIndexesAfterNBlocks": 5, 112 "ledger.state.couchDBConfig.createGlobalChangesDB": true, 113 "ledger.state.couchDBConfig.cacheSize": 64, 114 "ledger.pvtdataStore.collElgProcMaxDbBatchSize": 50000, 115 "ledger.pvtdataStore.collElgProcDbBatchesInterval": 10000, 116 "ledger.pvtdataStore.purgeInterval": 1000, 117 "ledger.pvtdataStore.deprioritizedDataReconcilerInterval": "180m", 118 "ledger.history.enableHistoryDatabase": true, 119 "ledger.snapshots.rootDir": "/peerfs/snapshots", 120 }, 121 expected: &ledger.Config{ 122 RootFSPath: "/peerfs/ledgersData", 123 StateDBConfig: &ledger.StateDBConfig{ 124 StateDatabase: "CouchDB", 125 CouchDB: &ledger.CouchDBConfig{ 126 Address: "localhost:5984", 127 Username: "username", 128 Password: "password", 129 MaxRetries: 3, 130 MaxRetriesOnStartup: 10, 131 RequestTimeout: 30 * time.Second, 132 InternalQueryLimit: 500, 133 MaxBatchUpdateSize: 600, 134 WarmIndexesAfterNBlocks: 5, 135 CreateGlobalChangesDB: true, 136 RedoLogPath: "/peerfs/ledgersData/couchdbRedoLogs", 137 UserCacheSizeMBs: 64, 138 }, 139 }, 140 PrivateDataConfig: &ledger.PrivateDataConfig{ 141 MaxBatchSize: 50000, 142 BatchesInterval: 10000, 143 PurgeInterval: 1000, 144 DeprioritizedDataReconcilerInterval: 180 * time.Minute, 145 }, 146 HistoryDBConfig: &ledger.HistoryDBConfig{ 147 Enabled: true, 148 }, 149 SnapshotsConfig: &ledger.SnapshotsConfig{ 150 RootDir: "/peerfs/snapshots", 151 }, 152 }, 153 }, 154 } 155 156 for _, test := range tests { 157 _test := test 158 t.Run(_test.name, func(t *testing.T) { 159 for k, v := range _test.config { 160 viper.Set(k, v) 161 } 162 conf := ledgerConfig() 163 assert.EqualValues(t, _test.expected, conf) 164 }) 165 } 166 }