-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change introduces the CachingConnector. This component provides the ability to cache GRPC connections. It provides a GRPC compatible Context Dialer interface via the "DialContext" method. Change-Id: Idd2f61e52a3e078cf81042853808c59c9a37b47b Signed-off-by: Troy Ronda <troy@troyronda.com>
- Loading branch information
Showing
15 changed files
with
717 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package comm | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
eventmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/mocks" | ||
"github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks" | ||
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" | ||
"github.com/pkg/errors" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
const ( | ||
peerAddress = "localhost:9999" | ||
endorserAddress = "127.0.0.1:0" | ||
peerURL = "grpc://" + peerAddress | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
var opts []grpc.ServerOption | ||
grpcServer := grpc.NewServer(opts...) | ||
|
||
lis, err := net.Listen("tcp", peerAddress) | ||
if err != nil { | ||
panic(fmt.Sprintf("Error starting events listener %s", err)) | ||
} | ||
|
||
testServer = eventmocks.NewMockEventhubServer() | ||
|
||
pb.RegisterEventsServer(grpcServer, testServer) | ||
|
||
go grpcServer.Serve(lis) | ||
|
||
srvs, addrs, err := startEndorsers(2, endorserAddress) | ||
if err != nil { | ||
panic(fmt.Sprintf("Error starting endorser %s", err)) | ||
} | ||
for _, srv := range srvs { | ||
defer srv.Stop() | ||
} | ||
endorserAddr = addrs | ||
|
||
time.Sleep(2 * time.Second) | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func startEndorsers(count int, address string) ([]*grpc.Server, []string, error) { | ||
srvs := make([]*grpc.Server, 0, count) | ||
addrs := make([]string, 0, count) | ||
|
||
for i := 0; i < count; i++ { | ||
srv := grpc.NewServer() | ||
_, addr, ok := startEndorserServer(srv, address) | ||
if !ok { | ||
return nil, nil, errors.New("unable to start GRPC server") | ||
} | ||
srvs = append(srvs, srv) | ||
addrs = append(addrs, addr) | ||
} | ||
return srvs, addrs, nil | ||
} | ||
|
||
func startEndorserServer(grpcServer *grpc.Server, address string) (*mocks.MockEndorserServer, string, bool) { | ||
lis, err := net.Listen("tcp", address) | ||
if err != nil { | ||
fmt.Printf("Error starting test server %s", err) | ||
return nil, "", false | ||
} | ||
addr := lis.Addr().String() | ||
|
||
endorserServer := &mocks.MockEndorserServer{} | ||
pb.RegisterEndorserServer(grpcServer, endorserServer) | ||
fmt.Printf("Starting test server on %s", addr) | ||
go grpcServer.Serve(lis) | ||
return endorserServer, addr, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.