github.com/ewagmig/fabric@v2.1.1+incompatible/gossip/service/config_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  package service_test
     7  
     8  import (
     9  	"testing"
    10  	"time"
    11  
    12  	"github.com/hyperledger/fabric/gossip/election"
    13  
    14  	"github.com/hyperledger/fabric/gossip/service"
    15  	"github.com/spf13/viper"
    16  	"github.com/stretchr/testify/assert"
    17  )
    18  
    19  func TestGlobalConfig(t *testing.T) {
    20  	viper.Reset()
    21  	// Capture the configuration from viper
    22  	viper.Set("peer.tls.enabled", true)
    23  	viper.Set("peer.gossip.pvtData.pullRetryThreshold", "10s")
    24  	viper.Set("peer.gossip.endpoint", "gossip_endpoint")
    25  	viper.Set("peer.gossip.pvtData.pushAckTimeout", "20s")
    26  	viper.Set("peer.gossip.nonBlockingCommitMode", true)
    27  	viper.Set("peer.gossip.useLeaderElection", true)
    28  	viper.Set("peer.gossip.orgLeader", true)
    29  	viper.Set("peer.gossip.election.leaderAliveThreshold", "10m")
    30  	viper.Set("peer.gossip.election.leaderElectionDuration", "5s")
    31  	viper.Set("peer.gossip.pvtData.btlPullMargin", 15)
    32  	viper.Set("peer.gossip.pvtData.transientstoreMaxBlockRetention", 1000)
    33  	viper.Set("peer.gossip.pvtData.skipPullingInvalidTransactionsDuringCommit", false)
    34  
    35  	coreConfig := service.GlobalConfig()
    36  
    37  	expectedConfig := &service.ServiceConfig{
    38  		PeerTLSEnabled:                             true,
    39  		PvtDataPullRetryThreshold:                  10 * time.Second,
    40  		Endpoint:                                   "gossip_endpoint",
    41  		PvtDataPushAckTimeout:                      20 * time.Second,
    42  		NonBlockingCommitMode:                      true,
    43  		UseLeaderElection:                          true,
    44  		OrgLeader:                                  true,
    45  		ElectionLeaderAliveThreshold:               10 * time.Minute,
    46  		ElectionLeaderElectionDuration:             5 * time.Second,
    47  		ElectionStartupGracePeriod:                 election.DefStartupGracePeriod,
    48  		ElectionMembershipSampleInterval:           election.DefMembershipSampleInterval,
    49  		BtlPullMargin:                              15,
    50  		TransientstoreMaxBlockRetention:            uint64(1000),
    51  		SkipPullingInvalidTransactionsDuringCommit: false,
    52  	}
    53  
    54  	assert.Equal(t, coreConfig, expectedConfig)
    55  }