@@ -17,46 +17,15 @@ limitations under the License.
17
17
package kafka
18
18
19
19
import (
20
- "bytes"
21
20
"strconv"
21
+ "sync"
22
22
"testing"
23
23
"time"
24
24
25
25
"github.com/golang/protobuf/proto"
26
26
cb "github.com/hyperledger/fabric/protos/common"
27
27
)
28
28
29
- func TestBroadcastInit (t * testing.T ) {
30
- disk := make (chan []byte )
31
-
32
- mb := mockNewBroadcaster (t , testConf , oldestOffset , disk )
33
- defer testClose (t , mb )
34
-
35
- mbs := newMockBroadcastStream (t )
36
- go func () {
37
- if err := mb .Broadcast (mbs ); err != nil {
38
- t .Fatal ("Broadcast error:" , err )
39
- }
40
- }()
41
-
42
- for {
43
- select {
44
- case in := <- disk :
45
- block := new (cb.Block )
46
- err := proto .Unmarshal (in , block )
47
- if err != nil {
48
- t .Fatal ("Expected a block on the broker's disk" )
49
- }
50
- if ! (bytes .Equal (block .Data .Data [0 ], []byte ("checkpoint" ))) {
51
- t .Fatal ("Expected first block to be a checkpoint" )
52
- }
53
- return
54
- case <- time .After (500 * time .Millisecond ):
55
- t .Fatal ("Should have received the initialization block by now" )
56
- }
57
- }
58
- }
59
-
60
29
func TestBroadcastResponse (t * testing.T ) {
61
30
disk := make (chan []byte )
62
31
@@ -70,8 +39,6 @@ func TestBroadcastResponse(t *testing.T) {
70
39
}
71
40
}()
72
41
73
- <- disk // We tested the checkpoint block in a previous test, so we can ignore it now
74
-
75
42
// Send a message to the orderer
76
43
go func () {
77
44
mbs .incoming <- & cb.Envelope {Payload : []byte ("single message" )}
@@ -103,8 +70,6 @@ func TestBroadcastBatch(t *testing.T) {
103
70
}
104
71
}()
105
72
106
- <- disk // We tested the checkpoint block in a previous test, so we can ignore it now
107
-
108
73
// Pump a batch's worth of messages into the system
109
74
go func () {
110
75
for i := 0 ; i < int (testConf .General .BatchSize ); i ++ {
@@ -158,8 +123,6 @@ func TestBroadcastBatch(t *testing.T) {
158
123
}
159
124
}()
160
125
161
- <-disk // We tested the checkpoint block in a previous test, so we can ignore it now
162
-
163
126
// Force the response queue to overflow by blocking the broadcast stream's Send() method
164
127
mbs.closed = true
165
128
defer func() { mbs.closed = false }()
@@ -201,8 +164,6 @@ func TestBroadcastIncompleteBatch(t *testing.T) {
201
164
}
202
165
}()
203
166
204
- <- disk // We tested the checkpoint block in a previous test, so we can ignore it now
205
-
206
167
// Pump less than batchSize messages into the system
207
168
go func () {
208
169
for i := 0 ; i < messageCount ; i ++ {
@@ -239,6 +200,8 @@ func TestBroadcastConsecutiveIncompleteBatches(t *testing.T) {
239
200
t .Skip ("Skipping test as it requires a batchsize > 1" )
240
201
}
241
202
203
+ var once sync.Once
204
+
242
205
messageCount := int (testConf .General .BatchSize ) - 1
243
206
244
207
disk := make (chan []byte )
@@ -254,8 +217,6 @@ func TestBroadcastConsecutiveIncompleteBatches(t *testing.T) {
254
217
}()
255
218
256
219
for i := 0 ; i < 2 ; i ++ {
257
- <- disk // Checkpoint block in first pass, first incomplete block in second pass -- both tested elsewhere
258
-
259
220
// Pump less than batchSize messages into the system
260
221
go func () {
261
222
for i := 0 ; i < messageCount ; i ++ {
@@ -268,6 +229,10 @@ func TestBroadcastConsecutiveIncompleteBatches(t *testing.T) {
268
229
for i := 0 ; i < messageCount ; i ++ {
269
230
<- mbs .outgoing
270
231
}
232
+
233
+ once .Do (func () {
234
+ <- disk // First incomplete block, tested elsewhere
235
+ })
271
236
}
272
237
273
238
for {
@@ -301,8 +266,6 @@ func TestBroadcastBatchAndQuitEarly(t *testing.T) {
301
266
}
302
267
}()
303
268
304
- <- disk // We tested the checkpoint block in a previous test, so we can ignore it now
305
-
306
269
// Pump a batch's worth of messages into the system
307
270
go func () {
308
271
for i := 0 ; i < int (testConf .General .BatchSize ); i ++ {
0 commit comments