@@ -28,9 +28,9 @@ import (
28
28
)
29
29
30
30
func TestBlockfileMgrBlockReadWrite (t * testing.T ) {
31
- env := newTestEnv (t )
31
+ env := newTestEnv (t , NewConf ( "/tmp/fabric/ledgertests" , 0 ) )
32
32
defer env .Cleanup ()
33
- blkfileMgrWrapper := newTestBlockfileWrapper (t , env )
33
+ blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
34
34
defer blkfileMgrWrapper .close ()
35
35
blocks := testutil .ConstructTestBlocks (t , 10 )
36
36
blkfileMgrWrapper .addBlocks (blocks )
@@ -47,9 +47,10 @@ func TestBlockfileMgrCrashDuringWriting(t *testing.T) {
47
47
48
48
func testBlockfileMgrCrashDuringWriting (t * testing.T , numBlocksBeforeCheckpoint int ,
49
49
numBlocksAfterCheckpoint int , numLastBlockBytes int , numPartialBytesToWrite int ) {
50
- env := newTestEnv (t )
50
+ env := newTestEnv (t , NewConf ( "/tmp/fabric/ledgertests" , 0 ) )
51
51
defer env .Cleanup ()
52
- blkfileMgrWrapper := newTestBlockfileWrapper (t , env )
52
+ ledgerid := "testLedger"
53
+ blkfileMgrWrapper := newTestBlockfileWrapper (env , ledgerid )
53
54
bg := testutil .NewBlockGenerator (t )
54
55
blocksBeforeCP := bg .NextTestBlocks (numBlocksBeforeCheckpoint )
55
56
blkfileMgrWrapper .addBlocks (blocksBeforeCP )
@@ -75,7 +76,7 @@ func testBlockfileMgrCrashDuringWriting(t *testing.T, numBlocksBeforeCheckpoint
75
76
blkfileMgrWrapper .close ()
76
77
77
78
// simulate a start after a crash
78
- blkfileMgrWrapper = newTestBlockfileWrapper (t , env )
79
+ blkfileMgrWrapper = newTestBlockfileWrapper (env , ledgerid )
79
80
defer blkfileMgrWrapper .close ()
80
81
cpInfo3 := blkfileMgrWrapper .blockfileMgr .cpInfo
81
82
testutil .AssertEquals (t , cpInfo3 , cpInfo2 )
@@ -91,9 +92,9 @@ func testBlockfileMgrCrashDuringWriting(t *testing.T, numBlocksBeforeCheckpoint
91
92
}
92
93
93
94
func TestBlockfileMgrBlockIterator (t * testing.T ) {
94
- env := newTestEnv (t )
95
+ env := newTestEnv (t , NewConf ( "/tmp/fabric/ledgertests" , 0 ) )
95
96
defer env .Cleanup ()
96
- blkfileMgrWrapper := newTestBlockfileWrapper (t , env )
97
+ blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
97
98
defer blkfileMgrWrapper .close ()
98
99
blocks := testutil .ConstructTestBlocks (t , 10 )
99
100
blkfileMgrWrapper .addBlocks (blocks )
@@ -109,7 +110,7 @@ func testBlockfileMgrBlockIterator(t *testing.T, blockfileMgr *blockfileMgr,
109
110
for {
110
111
block , err := itr .Next ()
111
112
testutil .AssertNoError (t , err , fmt .Sprintf ("Error while getting block number [%d] from iterator" , numBlocksItrated ))
112
- testutil .AssertEquals (t , block .(* BlockHolder ).GetBlock (), expectedBlocks [numBlocksItrated ])
113
+ testutil .AssertEquals (t , block .(* blockHolder ).GetBlock (), expectedBlocks [numBlocksItrated ])
113
114
numBlocksItrated ++
114
115
if numBlocksItrated == lastBlockNum - firstBlockNum + 1 {
115
116
break
@@ -119,9 +120,9 @@ func testBlockfileMgrBlockIterator(t *testing.T, blockfileMgr *blockfileMgr,
119
120
}
120
121
121
122
func TestBlockfileMgrBlockchainInfo (t * testing.T ) {
122
- env := newTestEnv (t )
123
+ env := newTestEnv (t , NewConf ( "/tmp/fabric/ledgertests" , 0 ) )
123
124
defer env .Cleanup ()
124
- blkfileMgrWrapper := newTestBlockfileWrapper (t , env )
125
+ blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
125
126
defer blkfileMgrWrapper .close ()
126
127
127
128
bcInfo := blkfileMgrWrapper .blockfileMgr .getBlockchainInfo ()
@@ -134,9 +135,9 @@ func TestBlockfileMgrBlockchainInfo(t *testing.T) {
134
135
}
135
136
136
137
func TestBlockfileMgrGetTxById (t * testing.T ) {
137
- env := newTestEnv (t )
138
+ env := newTestEnv (t , NewConf ( "/tmp/fabric/ledgertests" , 0 ) )
138
139
defer env .Cleanup ()
139
- blkfileMgrWrapper := newTestBlockfileWrapper (t , env )
140
+ blkfileMgrWrapper := newTestBlockfileWrapper (env , "testLedger" )
140
141
defer blkfileMgrWrapper .close ()
141
142
blocks := testutil .ConstructTestBlocks (t , 10 )
142
143
blkfileMgrWrapper .addBlocks (blocks )
@@ -155,21 +156,21 @@ func TestBlockfileMgrGetTxById(t *testing.T) {
155
156
}
156
157
157
158
func TestBlockfileMgrRestart (t * testing.T ) {
158
- env := newTestEnv (t )
159
+ env := newTestEnv (t , NewConf ( "/tmp/fabric/ledgertests" , 0 ) )
159
160
defer env .Cleanup ()
160
- blkfileMgrWrapper := newTestBlockfileWrapper (t , env )
161
+ ledgerid := "testLedger"
162
+ blkfileMgrWrapper := newTestBlockfileWrapper (env , ledgerid )
161
163
blocks := testutil .ConstructTestBlocks (t , 10 )
162
164
blkfileMgrWrapper .addBlocks (blocks )
163
165
blkfileMgrWrapper .close ()
164
166
165
- blkfileMgrWrapper = newTestBlockfileWrapper (t , env )
167
+ blkfileMgrWrapper = newTestBlockfileWrapper (env , ledgerid )
166
168
defer blkfileMgrWrapper .close ()
167
169
testutil .AssertEquals (t , int (blkfileMgrWrapper .blockfileMgr .cpInfo .lastBlockNumber ), 10 )
168
170
blkfileMgrWrapper .testGetBlockByHash (blocks )
169
171
}
170
172
171
173
func TestBlockfileMgrFileRolling (t * testing.T ) {
172
- env := newTestEnv (t )
173
174
blocks := testutil .ConstructTestBlocks (t , 100 )
174
175
size := 0
175
176
for _ , block := range blocks {
@@ -180,18 +181,17 @@ func TestBlockfileMgrFileRolling(t *testing.T) {
180
181
size += blockBytesSize + len (encodedLen )
181
182
}
182
183
183
- env .conf .maxBlockfileSize = int (0.75 * float64 (size ))
184
- blkfileMgrWrapper := newTestBlockfileWrapper (t , env )
184
+ maxFileSie := int (0.75 * float64 (size ))
185
+ env := newTestEnv (t , NewConf ("/tmp/fabric/ledgertests" , maxFileSie ))
186
+ defer env .Cleanup ()
187
+ ledgerid := "testLedger"
188
+ blkfileMgrWrapper := newTestBlockfileWrapper (env , ledgerid )
185
189
blkfileMgrWrapper .addBlocks (blocks )
186
190
testutil .AssertEquals (t , blkfileMgrWrapper .blockfileMgr .cpInfo .latestFileChunkSuffixNum , 1 )
187
191
blkfileMgrWrapper .testGetBlockByHash (blocks )
188
192
blkfileMgrWrapper .close ()
189
- env .Cleanup ()
190
193
191
- env = newTestEnv (t )
192
- defer env .Cleanup ()
193
- env .conf .maxBlockfileSize = int (0.40 * float64 (size ))
194
- blkfileMgrWrapper = newTestBlockfileWrapper (t , env )
194
+ blkfileMgrWrapper = newTestBlockfileWrapper (env , ledgerid )
195
195
defer blkfileMgrWrapper .close ()
196
196
blkfileMgrWrapper .addBlocks (blocks )
197
197
testutil .AssertEquals (t , blkfileMgrWrapper .blockfileMgr .cpInfo .latestFileChunkSuffixNum , 2 )
0 commit comments