github.com/ewagmig/fabric@v2.1.1+incompatible/common/channelconfig/orderer_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package channelconfig
     8  
     9  import (
    10  	"testing"
    11  
    12  	ab "github.com/hyperledger/fabric-protos-go/orderer"
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestBatchSize(t *testing.T) {
    17  	validMaxMessageCount := uint32(10)
    18  	validAbsoluteMaxBytes := uint32(1000)
    19  	validPreferredMaxBytes := uint32(500)
    20  
    21  	oc := &OrdererConfig{protos: &OrdererProtos{BatchSize: &ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: validAbsoluteMaxBytes, PreferredMaxBytes: validPreferredMaxBytes}}}
    22  	assert.NoError(t, oc.validateBatchSize(), "BatchSize was valid")
    23  
    24  	oc = &OrdererConfig{protos: &OrdererProtos{BatchSize: &ab.BatchSize{MaxMessageCount: 0, AbsoluteMaxBytes: validAbsoluteMaxBytes, PreferredMaxBytes: validPreferredMaxBytes}}}
    25  	assert.Error(t, oc.validateBatchSize(), "MaxMessageCount was zero")
    26  
    27  	oc = &OrdererConfig{protos: &OrdererProtos{BatchSize: &ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: 0, PreferredMaxBytes: validPreferredMaxBytes}}}
    28  	assert.Error(t, oc.validateBatchSize(), "AbsoluteMaxBytes was zero")
    29  
    30  	oc = &OrdererConfig{protos: &OrdererProtos{BatchSize: &ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: validAbsoluteMaxBytes, PreferredMaxBytes: validAbsoluteMaxBytes + 1}}}
    31  	assert.Error(t, oc.validateBatchSize(), "PreferredMaxBytes larger to AbsoluteMaxBytes")
    32  }
    33  
    34  func TestBatchTimeout(t *testing.T) {
    35  	oc := &OrdererConfig{protos: &OrdererProtos{BatchTimeout: &ab.BatchTimeout{Timeout: "1s"}}}
    36  	assert.NoError(t, oc.validateBatchTimeout(), "Valid batch timeout")
    37  
    38  	oc = &OrdererConfig{protos: &OrdererProtos{BatchTimeout: &ab.BatchTimeout{Timeout: "-1s"}}}
    39  	assert.Error(t, oc.validateBatchTimeout(), "Negative batch timeout")
    40  
    41  	oc = &OrdererConfig{protos: &OrdererProtos{BatchTimeout: &ab.BatchTimeout{Timeout: "0s"}}}
    42  	assert.Error(t, oc.validateBatchTimeout(), "Zero batch timeout")
    43  }
    44  
    45  func TestKafkaBrokers(t *testing.T) {
    46  	oc := &OrdererConfig{protos: &OrdererProtos{KafkaBrokers: &ab.KafkaBrokers{Brokers: []string{"127.0.0.1:9092", "foo.bar:9092"}}}}
    47  	assert.NoError(t, oc.validateKafkaBrokers(), "Valid kafka brokers")
    48  
    49  	oc = &OrdererConfig{protos: &OrdererProtos{KafkaBrokers: &ab.KafkaBrokers{Brokers: []string{"127.0.0.1", "foo.bar", "127.0.0.1:-1", "localhost:65536", "foo.bar.:9092", ".127.0.0.1:9092", "-foo.bar:9092"}}}}
    50  	assert.Error(t, oc.validateKafkaBrokers(), "Invalid kafka brokers")
    51  }