Skip to content

Commit

Permalink
[FAB-8863]: Rename WithProposalProcessor to WithTargets
Browse files Browse the repository at this point in the history
Change-Id: I784bf7f41a0c48d17eb28d1b7dad64d2a54eb890
Signed-off-by: Sandra Vrtikapa <[email protected]>
  • Loading branch information
sandrask committed Mar 5, 2018
1 parent cad7007 commit 1491559
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 33 deletions.
12 changes: 6 additions & 6 deletions pkg/client/channel/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type Registration interface {

// opts allows the user to specify more advanced options
type opts struct {
ProposalProcessors []fab.ProposalProcessor // targets
Timeout time.Duration
Retry retry.Opts
Targets []fab.Peer // targets
Timeout time.Duration
Retry retry.Opts
}

//Option func for each Opts argument
Expand Down Expand Up @@ -62,10 +62,10 @@ func WithTimeout(timeout time.Duration) Option {
}
}

//WithProposalProcessor encapsulates ProposalProcessors to Option
func WithProposalProcessor(proposalProcessors ...fab.ProposalProcessor) Option {
//WithTargets encapsulates ProposalProcessors to Option
func WithTargets(targets []fab.Peer) Option {
return func(o *opts) error {
o.ProposalProcessors = proposalProcessors
o.Targets = targets
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/channel/chclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (cc *Client) resolveRetry(ctx *invoke.RequestContext, o opts) bool {
cc.greylist.Greylist(e)

// Reset context parameters
ctx.Opts.ProposalProcessors = o.ProposalProcessors
ctx.Opts.Targets = o.Targets
ctx.Error = nil
ctx.Response = invoke.Response{}

Expand Down
6 changes: 2 additions & 4 deletions pkg/client/channel/chclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,8 @@ func TestQueryWithOptTarget(t *testing.T) {

peers := []fab.Peer{testPeer}

targets := peer.PeersToTxnProcessors(peers)

response, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke",
Args: [][]byte{[]byte("query"), []byte("b")}}, WithProposalProcessor(targets...))
Args: [][]byte{[]byte("query"), []byte("b")}}, WithTargets(peers))
if err != nil {
t.Fatalf("Failed to invoke test cc: %s", err)
}
Expand Down Expand Up @@ -251,7 +249,7 @@ type customEndorsementHandler struct {
}

func (h *customEndorsementHandler) Handle(requestContext *invoke.RequestContext, clientContext *invoke.ClientContext) {
transactionProposalResponses, txnID, err := createAndSendTestTransactionProposal(h.transactor, &requestContext.Request, requestContext.Opts.ProposalProcessors)
transactionProposalResponses, txnID, err := createAndSendTestTransactionProposal(h.transactor, &requestContext.Request, peer.PeersToTxnProcessors(requestContext.Opts.Targets))

requestContext.Response.TransactionID = txnID

Expand Down
6 changes: 3 additions & 3 deletions pkg/client/channel/invoke/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (

// Opts allows the user to specify more advanced options
type Opts struct {
ProposalProcessors []fab.ProposalProcessor // targets
Timeout time.Duration
Retry retry.Opts
Targets []fab.Peer // targets
Timeout time.Duration
Retry retry.Opts
}

// Request contains the parameters to execute transaction
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/channel/invoke/txnhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ type EndorsementHandler struct {
//Handle for endorsing transactions
func (e *EndorsementHandler) Handle(requestContext *RequestContext, clientContext *ClientContext) {

if len(requestContext.Opts.ProposalProcessors) == 0 {
if len(requestContext.Opts.Targets) == 0 {
requestContext.Error = status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "targets were not provided", nil)
return
}

// Endorse Tx
transactionProposalResponses, proposal, err := createAndSendTransactionProposal(clientContext.Transactor, &requestContext.Request, requestContext.Opts.ProposalProcessors)
transactionProposalResponses, proposal, err := createAndSendTransactionProposal(clientContext.Transactor, &requestContext.Request, peer.PeersToTxnProcessors(requestContext.Opts.Targets))

requestContext.Response.Proposal = proposal
requestContext.Response.TransactionID = proposal.TxnID // TODO: still needed?
Expand Down Expand Up @@ -66,7 +66,7 @@ type ProposalProcessorHandler struct {
func (h *ProposalProcessorHandler) Handle(requestContext *RequestContext, clientContext *ClientContext) {
//Get proposal processor, if not supplied then use discovery service to get available peers as endorser
//If selection service available then get endorser peers for this chaincode
if len(requestContext.Opts.ProposalProcessors) == 0 {
if len(requestContext.Opts.Targets) == 0 {
// Use discovery service to figure out proposal processors
peers, err := clientContext.Discovery.GetPeers()
if err != nil {
Expand All @@ -81,7 +81,7 @@ func (h *ProposalProcessorHandler) Handle(requestContext *RequestContext, client
return
}
}
requestContext.Opts.ProposalProcessors = peer.PeersToTxnProcessors(endorsers)
requestContext.Opts.Targets = endorsers
}

//Delegate to next step if any
Expand Down
16 changes: 8 additions & 8 deletions pkg/client/channel/invoke/txnhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestExecuteTxHandlerErrors(t *testing.T) {
func TestEndorsementHandler(t *testing.T) {
request := Request{ChaincodeID: "test", Fcn: "invoke", Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}}

requestContext := prepareRequestContext(request, Opts{ProposalProcessors: []fab.ProposalProcessor{fcmocks.NewMockPeer("p2", "")}}, t)
requestContext := prepareRequestContext(request, Opts{Targets: []fab.Peer{fcmocks.NewMockPeer("p2", "")}}, t)
clientContext := setupChannelClientContext(nil, nil, nil, t)

handler := NewEndorsementHandler()
Expand Down Expand Up @@ -183,23 +183,23 @@ func TestProposalProcessorHandler(t *testing.T) {
if requestContext.Error != nil {
t.Fatalf("Got error: %s", requestContext.Error)
}
if len(requestContext.Opts.ProposalProcessors) != len(discoveryPeers) {
t.Fatalf("Expecting %d proposal processors but got %d", len(discoveryPeers), len(requestContext.Opts.ProposalProcessors))
if len(requestContext.Opts.Targets) != len(discoveryPeers) {
t.Fatalf("Expecting %d proposal processors but got %d", len(discoveryPeers), len(requestContext.Opts.Targets))
}
if requestContext.Opts.ProposalProcessors[0] != peer1 || requestContext.Opts.ProposalProcessors[1] != peer2 {
if requestContext.Opts.Targets[0] != peer1 || requestContext.Opts.Targets[1] != peer2 {
t.Fatalf("Didn't get expected peers")
}

// Directly pass in the proposal processors. In this case it should use those directly
requestContext = prepareRequestContext(request, Opts{ProposalProcessors: []fab.ProposalProcessor{peer2}}, t)
requestContext = prepareRequestContext(request, Opts{Targets: []fab.Peer{peer2}}, t)
handler.Handle(requestContext, setupChannelClientContext(nil, nil, discoveryPeers, t))
if requestContext.Error != nil {
t.Fatalf("Got error: %s", requestContext.Error)
}
if len(requestContext.Opts.ProposalProcessors) != 1 {
t.Fatalf("Expecting 1 proposal processor but got %d", len(requestContext.Opts.ProposalProcessors))
if len(requestContext.Opts.Targets) != 1 {
t.Fatalf("Expecting 1 proposal processor but got %d", len(requestContext.Opts.Targets))
}
if requestContext.Opts.ProposalProcessors[0] != peer2 {
if requestContext.Opts.Targets[0] != peer2 {
t.Fatalf("Didn't get expected peers")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (dp *ccPolicyProvider) queryChaincode(ccID string, ccFcn string, ccArgs [][
Args: ccArgs,
}

resp, err := client.Query(request, channel.WithProposalProcessor(peer))
resp, err := client.Query(request, channel.WithTargets([]fab.Peer{peer}))
if err != nil {
queryErrors = append(queryErrors, err.Error())
continue
Expand Down
12 changes: 6 additions & 6 deletions test/integration/orgs/multiple_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
t.Fatalf("Failed to create new ledger client: %s", err)
}

channelCfg, err := ledgerClient.QueryConfig(ledger.WithTargets(orgTestPeer0.(fab.Peer), orgTestPeer1.(fab.Peer)), ledger.WithMinTargets(2))
channelCfg, err := ledgerClient.QueryConfig(ledger.WithTargets(orgTestPeer0, orgTestPeer1), ledger.WithMinTargets(2))
if err != nil {
t.Fatalf("QueryConfig return error: %v", err)
}
Expand All @@ -188,7 +188,7 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
t.Fatalf("Expecting %s, got %s", expectedOrderer, channelCfg.Orderers()[0])
}

ledgerInfoBefore, err := ledgerClient.QueryInfo(ledger.WithTargets(orgTestPeer0.(fab.Peer), orgTestPeer1.(fab.Peer)), ledger.WithMinTargets(2), ledger.WithMaxTargets(3))
ledgerInfoBefore, err := ledgerClient.QueryInfo(ledger.WithTargets(orgTestPeer0, orgTestPeer1), ledger.WithMinTargets(2), ledger.WithMaxTargets(3))
if err != nil {
t.Fatalf("QueryInfo return error: %v", err)
}
Expand All @@ -203,7 +203,7 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
}

// Org2 user moves funds on org2 peer
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithProposalProcessor(orgTestPeer1))
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets([]fab.Peer{orgTestPeer1}))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down Expand Up @@ -267,13 +267,13 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
}

// Org2 user moves funds on org2 peer (cc policy fails since both Org1 and Org2 peers should participate)
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithProposalProcessor(orgTestPeer1))
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets([]fab.Peer{orgTestPeer1}))
if err == nil {
t.Fatalf("Should have failed to move funds due to cc policy")
}

// Org2 user moves funds (cc policy ok since we have provided peers for both Orgs)
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithProposalProcessor(orgTestPeer0, orgTestPeer1))
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets([]fab.Peer{orgTestPeer0, orgTestPeer1}))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
Expand Down Expand Up @@ -331,7 +331,7 @@ func verifyValue(t *testing.T, chClient *channel.Client, expected int) {
var valueInt int
for i := 0; i < pollRetries; i++ {
// Query final value on org1 peer
response, err := chClient.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()}, channel.WithProposalProcessor(orgTestPeer0))
response, err := chClient.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCQueryArgs()}, channel.WithTargets([]fab.Peer{orgTestPeer0}))
if err != nil {
t.Fatalf("Failed to query funds after transaction: %s", err)
}
Expand Down

0 comments on commit 1491559

Please sign in to comment.