Skip to content

Commit

Permalink
[FABG-800] fallback to global orderers section
Browse files Browse the repository at this point in the history
Change-Id: I28643db31292ce0f8d2b4d4b346412a9524163b3
Signed-off-by: 乔伦 徐 <[email protected]>
  • Loading branch information
gotoxu committed Dec 5, 2018
1 parent 1bd8071 commit 05ffa0a
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 13 deletions.
11 changes: 5 additions & 6 deletions pkg/client/resmgmt/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,13 +1216,12 @@ func (rc *Client) requestOrderer(opts *requestOptions, channelID string) (fab.Or

func (rc *Client) ordererConfig(channelID string) (*fab.OrdererConfig, error) {
orderers := rc.ctx.EndpointConfig().ChannelOrderers(channelID)
if len(orderers) > 0 {
randomNumber := rand.Intn(len(orderers))
return &orderers[randomNumber], nil
}

// TODO: Not sure that we should fallback to global orderers section.
// For now - not doing so.
//if err != nil || len(orderers) == 0 {
// orderers, err = rc.ctx.Config().OrderersConfig()
//}

orderers = rc.ctx.EndpointConfig().OrderersConfig()
if len(orderers) == 0 {
return nil, errors.New("no orderers found")
}
Expand Down
27 changes: 20 additions & 7 deletions pkg/client/resmgmt/resmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ var (
)

const (
networkCfg = "../../../test/fixtures/config/config_test.yaml"
configPath = "../../core/config/testdata/config_test.yaml"
testAddress = "127.0.0.1:0"
networkCfg = "../../../test/fixtures/config/config_test.yaml"
networkCfgWithoutOrderer = "../../../test/fixtures/config/config_test_without_orderer.yaml"
configPath = "../../core/config/testdata/config_test.yaml"
testAddress = "127.0.0.1:0"
)

func withLocalContextProvider(provider context.LocalProvider) ClientOption {
Expand Down Expand Up @@ -1039,6 +1040,20 @@ func getNetworkConfig(t *testing.T) fab.EndpointConfig {
return config
}

func getNetworkConfigWithoutOrderer(t *testing.T) fab.EndpointConfig {
configBackend, err := configImpl.FromFile(networkCfgWithoutOrderer)()
if err != nil {
t.Fatal(err)
}

config, err := fabImpl.ConfigFromBackend(configBackend...)
if err != nil {
t.Fatal(err)
}

return config
}

func TestSaveChannelSuccess(t *testing.T) {

mb := fcmocks.MockBroadcastServer{}
Expand Down Expand Up @@ -1121,11 +1136,9 @@ func TestSaveChannelSuccess(t *testing.T) {
func TestSaveChannelFailure(t *testing.T) {

// Set up context with error in create channel
user := mspmocks.NewMockSigningIdentity("test", "test")
errCtx := fcmocks.NewMockContext(user)
network := getNetworkConfig(t)
errCtx.SetEndpointConfig(network)
network := getNetworkConfigWithoutOrderer(t)
fabCtx := setupTestContext("user", "Org1Msp1")
fabCtx.SetEndpointConfig(network)

cc, err := New(createClientContext(fabCtx))
if err != nil {
Expand Down
Loading

0 comments on commit 05ffa0a

Please sign in to comment.