@@ -22,6 +22,8 @@ import (
22
22
"testing"
23
23
"time"
24
24
25
+ "github.com/stretchr/testify/assert"
26
+
25
27
cb "github.com/hyperledger/fabric/protos/common"
26
28
ab "github.com/hyperledger/fabric/protos/orderer"
27
29
"github.com/hyperledger/fabric/protos/utils"
@@ -132,51 +134,63 @@ func TestConsensusType(t *testing.T) {
132
134
}
133
135
134
136
func TestBatchSize (t * testing.T ) {
135
- endBatchSize := struct { MaxMessageCount uint32 }{
136
- MaxMessageCount : uint32 (10 ),
137
- }
138
- invalidMessage := & cb.ConfigurationItem {
139
- Type : cb .ConfigurationItem_Orderer ,
140
- Key : BatchSizeKey ,
141
- Value : []byte ("Garbage Data" ),
142
- }
143
- zeroBatchSize := & cb.ConfigurationItem {
144
- Type : cb .ConfigurationItem_Orderer ,
145
- Key : BatchSizeKey ,
146
- Value : utils .MarshalOrPanic (& ab.BatchSize {MaxMessageCount : 0 }),
147
- }
148
- validMessage := & cb.ConfigurationItem {
149
- Type : cb .ConfigurationItem_Orderer ,
150
- Key : BatchSizeKey ,
151
- Value : utils .MarshalOrPanic (& ab.BatchSize {MaxMessageCount : endBatchSize .MaxMessageCount }),
152
- }
153
- m := NewManagerImpl ()
154
- m .BeginConfig ()
155
137
156
- err := m .ProposeConfig (validMessage )
157
- if err != nil {
158
- t .Fatalf ("Error applying valid config: %s" , err )
159
- }
138
+ validMaxMessageCount := uint32 (10 )
139
+ validAbsoluteMaxBytes := uint32 (1000 )
160
140
161
- err = m .ProposeConfig (invalidMessage )
162
- if err == nil {
163
- t .Fatalf ("Should have failed on invalid message" )
164
- }
165
-
166
- err = m .ProposeConfig (zeroBatchSize )
167
- if err == nil {
168
- t .Fatalf ("Should have rejected batch size of 0" )
169
- }
141
+ t .Run ("ValidConfiguration" , func (t * testing.T ) {
142
+ m := NewManagerImpl ()
143
+ m .BeginConfig ()
144
+ err := m .ProposeConfig (& cb.ConfigurationItem {
145
+ Type : cb .ConfigurationItem_Orderer ,
146
+ Key : BatchSizeKey ,
147
+ Value : utils .MarshalOrPanic (& ab.BatchSize {MaxMessageCount : validMaxMessageCount , AbsoluteMaxBytes : validAbsoluteMaxBytes }),
148
+ })
149
+ assert .Nil (t , err , "Error applying valid config: %s" , err )
150
+ m .CommitConfig ()
151
+ if m .BatchSize ().MaxMessageCount != validMaxMessageCount {
152
+ t .Fatalf ("Got batch size max message count of %d. Expected: %d" , m .BatchSize ().MaxMessageCount , validMaxMessageCount )
153
+ }
154
+ if m .BatchSize ().AbsoluteMaxBytes != validAbsoluteMaxBytes {
155
+ t .Fatalf ("Got batch size absolute max bytes of %d. Expected: %d" , m .BatchSize ().AbsoluteMaxBytes , validAbsoluteMaxBytes )
156
+ }
157
+ })
170
158
171
- m .CommitConfig ()
159
+ t .Run ("UnserializableConfiguration" , func (t * testing.T ) {
160
+ m := NewManagerImpl ()
161
+ m .BeginConfig ()
162
+ err := m .ProposeConfig (& cb.ConfigurationItem {
163
+ Type : cb .ConfigurationItem_Orderer ,
164
+ Key : BatchSizeKey ,
165
+ Value : []byte ("Garbage Data" ),
166
+ })
167
+ assert .NotNil (t , err , "Should have failed on invalid message" )
168
+ m .CommitConfig ()
169
+ })
172
170
173
- nowBatchSize := struct { MaxMessageCount uint32 }{
174
- MaxMessageCount : m .BatchSize ().MaxMessageCount ,
175
- }
171
+ t .Run ("ZeroMaxMessageCount" , func (t * testing.T ) {
172
+ m := NewManagerImpl ()
173
+ m .BeginConfig ()
174
+ err := m .ProposeConfig (& cb.ConfigurationItem {
175
+ Type : cb .ConfigurationItem_Orderer ,
176
+ Key : BatchSizeKey ,
177
+ Value : utils .MarshalOrPanic (& ab.BatchSize {MaxMessageCount : 0 , AbsoluteMaxBytes : validAbsoluteMaxBytes }),
178
+ })
179
+ assert .NotNil (t , err , "Should have rejected batch size max message count of 0" )
180
+ m .CommitConfig ()
181
+ })
176
182
177
- if nowBatchSize .MaxMessageCount != endBatchSize .MaxMessageCount {
178
- t .Fatalf ("Got batch size max message count of %d. Expected: %d" , nowBatchSize .MaxMessageCount , endBatchSize .MaxMessageCount )
179
- }
183
+ t .Run ("ZeroAbsoluteMaxBytes" , func (t * testing.T ) {
184
+ m := NewManagerImpl ()
185
+ m .BeginConfig ()
186
+ err := m .ProposeConfig (& cb.ConfigurationItem {
187
+ Type : cb .ConfigurationItem_Orderer ,
188
+ Key : BatchSizeKey ,
189
+ Value : utils .MarshalOrPanic (& ab.BatchSize {MaxMessageCount : validMaxMessageCount , AbsoluteMaxBytes : 0 }),
190
+ })
191
+ assert .NotNil (t , err , "Should have rejected batch size absolute max message bytes of 0" )
192
+ m .CommitConfig ()
193
+ })
180
194
}
181
195
182
196
func TestBatchTimeout (t * testing.T ) {
0 commit comments