@@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package history
17
+ package couchdbhistmgr
18
18
19
19
import (
20
20
"fmt"
21
21
"testing"
22
22
23
+ helper "github.com/hyperledger/fabric/core/ledger/kvledger/history/histmgr"
23
24
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
24
25
"github.com/hyperledger/fabric/core/ledger/testutil"
25
26
)
@@ -34,48 +35,48 @@ otherwise HistoryDB may not be installed and all the tests would fail
34
35
func TestHistoryDatabaseAutoCreate (t * testing.T ) {
35
36
36
37
//call a helper method to load the core.yaml
37
- testutil .SetupCoreYAMLConfig ("./../../../peer" )
38
+ testutil .SetupCoreYAMLConfig ("./../../../../../../ peer" )
38
39
logger .Debugf ("===HISTORYDB=== TestHistoryDatabaseAutoCreate IsCouchDBEnabled()value: %v , IsHistoryDBEnabled()value: %v\n " ,
39
40
ledgerconfig .IsCouchDBEnabled (), ledgerconfig .IsHistoryDBEnabled ())
40
41
41
42
if ledgerconfig .IsHistoryDBEnabled () == true {
42
43
43
- env := newTestEnvHistoryCouchDB (t , "history-test" )
44
- env .cleanup () //cleanup at the beginning to ensure the database doesn't exist already
45
- defer env .cleanup () //and cleanup at the end
44
+ env := newTestEnvCouchDB (t , "history-test" )
45
+ env .cleanupCouchDB () //cleanup at the beginning to ensure the database doesn't exist already
46
+ defer env .cleanupCouchDB () //and cleanup at the end
46
47
47
- logger .Debugf ("===HISTORYDB=== env.couchDBAddress : %v , env.couchDatabaseName : %v env.couchUsername : %v env.couchPassword : %v\n " ,
48
- env .couchDBAddress , env .couchDatabaseName , env .couchUsername , env .couchPassword )
48
+ logger .Debugf ("===HISTORYDB=== env.CouchDBAddress : %v , env.CouchDatabaseName : %v env.CouchUsername : %v env.CouchPassword : %v\n " ,
49
+ env .CouchDBAddress , env .CouchDatabaseName , env .CouchUsername , env .CouchPassword )
49
50
50
51
histMgr := NewCouchDBHistMgr (
51
- env .couchDBAddress , //couchDB Address
52
- env .couchDatabaseName , //couchDB db name
53
- env .couchUsername , //enter couchDB id
54
- env .couchPassword ) //enter couchDB pw
52
+ env .CouchDBAddress , //couchDB Address
53
+ env .CouchDatabaseName , //couchDB db name
54
+ env .CouchUsername , //enter couchDB id
55
+ env .CouchPassword ) //enter couchDB pw
55
56
56
57
//NewCouchDBhistMgr should have automatically created the database, let's make sure it has been created
57
58
//Retrieve the info for the new database and make sure the name matches
58
59
dbResp , _ , errdb := histMgr .couchDB .GetDatabaseInfo ()
59
60
testutil .AssertNoError (t , errdb , fmt .Sprintf ("Error when trying to retrieve database information" ))
60
- testutil .AssertEquals (t , dbResp .DbName , env .couchDatabaseName )
61
+ testutil .AssertEquals (t , dbResp .DbName , env .CouchDatabaseName )
61
62
62
63
//Call NewCouchDBhistMgr again, this time the database will already exist from last time
63
64
histMgr2 := NewCouchDBHistMgr (
64
- env .couchDBAddress , //couchDB Address
65
- env .couchDatabaseName , //couchDB db name
66
- env .couchUsername , //enter couchDB id
67
- env .couchPassword ) //enter couchDB pw
65
+ env .CouchDBAddress , //couchDB Address
66
+ env .CouchDatabaseName , //couchDB db name
67
+ env .CouchUsername , //enter couchDB id
68
+ env .CouchPassword ) //enter couchDB pw
68
69
69
70
//Retrieve the info for the database again, and make sure the name still matches
70
71
dbResp2 , _ , errdb2 := histMgr2 .couchDB .GetDatabaseInfo ()
71
72
testutil .AssertNoError (t , errdb2 , fmt .Sprintf ("Error when trying to retrieve database information" ))
72
- testutil .AssertEquals (t , dbResp2 .DbName , env .couchDatabaseName )
73
+ testutil .AssertEquals (t , dbResp2 .DbName , env .CouchDatabaseName )
73
74
74
75
}
75
76
}
76
77
77
78
func TestConstructCompositeKey (t * testing.T ) {
78
- compositeKey := constructCompositeKey ("ns1" , "key1" , 1 , 1 )
79
+ compositeKey := helper . ConstructCompositeKey ("ns1" , "key1" , 1 , 1 )
79
80
80
81
var compositeKeySep = []byte {0x00 }
81
82
var strKeySep = string (compositeKeySep )
@@ -86,24 +87,29 @@ func TestConstructCompositeKey(t *testing.T) {
86
87
//TestSavepoint tests the recordSavepoint and GetBlockNumfromSavepoint methods for recording and reading a savepoint document
87
88
func TestSavepoint (t * testing.T ) {
88
89
90
+ //call a helper method to load the core.yaml
91
+ testutil .SetupCoreYAMLConfig ("./../../../../../../peer" )
92
+ logger .Debugf ("===HISTORYDB=== TestHistoryDatabaseAutoCreate IsCouchDBEnabled()value: %v , IsHistoryDBEnabled()value: %v\n " ,
93
+ ledgerconfig .IsCouchDBEnabled (), ledgerconfig .IsHistoryDBEnabled ())
94
+
89
95
if ledgerconfig .IsHistoryDBEnabled () == true {
90
96
91
- env := newTestEnvHistoryCouchDB (t , "history-test" )
92
- env .cleanup () //cleanup at the beginning to ensure the database doesn't exist already
93
- defer env .cleanup () //and cleanup at the end
97
+ env := newTestEnvCouchDB (t , "history-test" )
98
+ env .cleanupCouchDB () //cleanup at the beginning to ensure the database doesn't exist already
99
+ defer env .cleanupCouchDB () //and cleanup at the end
94
100
95
101
logger .Debugf ("===HISTORYDB=== env.couchDBAddress: %v , env.couchDatabaseName: %v env.couchUsername: %v env.couchPassword: %v\n " ,
96
- env .couchDBAddress , env .couchDatabaseName , env .couchUsername , env .couchPassword )
102
+ env .CouchDBAddress , env .CouchDatabaseName , env .CouchUsername , env .CouchPassword )
97
103
98
104
histMgr := NewCouchDBHistMgr (
99
- env .couchDBAddress , //couchDB Address
100
- env .couchDatabaseName , //couchDB db name
101
- env .couchUsername , //enter couchDB id
102
- env .couchPassword ) //enter couchDB pw
105
+ env .CouchDBAddress , //couchDB Address
106
+ env .CouchDatabaseName , //couchDB db name
107
+ env .CouchUsername , //enter couchDB id
108
+ env .CouchPassword ) //enter couchDB pw
103
109
104
110
// read the savepoint
105
111
blockNum , err := histMgr .GetBlockNumFromSavepoint ()
106
- testutil .AssertEquals (t , blockNum , 0 )
112
+ testutil .AssertEquals (t , blockNum , uint64 ( 0 ) )
107
113
108
114
// record savepoint
109
115
blockNo := uint64 (5 )
@@ -117,16 +123,18 @@ func TestSavepoint(t *testing.T) {
117
123
}
118
124
}
119
125
126
+ /*
120
127
//History Database commit and read is being tested with kv_ledger_test.go.
121
128
//This test will push some of the testing down into history itself
122
129
func TestHistoryDatabaseCommit(t *testing.T) {
123
- //call a helper method to load the core.yaml
124
- testutil .SetupCoreYAMLConfig ("./../../../peer" )
125
- logger .Debugf ("===HISTORYDB=== TestHistoryDatabaseCommit IsCouchDBEnabled()value: %v , IsHistoryDBEnabled()value: %v\n " ,
130
+
131
+ testutil.SetupCoreYAMLConfig("./../../../../../../ peer")
132
+ logger.Debugf("===HISTORYDB=== TestHistoryDatabaseAutoCreate IsCouchDBEnabled()value: %v , IsHistoryDBEnabled()value: %v\n",
126
133
ledgerconfig.IsCouchDBEnabled(), ledgerconfig.IsHistoryDBEnabled())
127
134
128
135
if ledgerconfig.IsHistoryDBEnabled() == true {
129
- //TODO Build the necessary infrastructure so that history can be tested iwthout ledger
136
+ //TODO Build the necessary infrastructure so that history can be tested without ledger
130
137
131
138
}
132
139
}
140
+ */
0 commit comments