mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-21 07:24:36 +00:00
update for a new ABCI API
This commit is contained in:
+36
-12
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/tendermint/abci/server"
|
||||
"github.com/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
//----------------------------------------
|
||||
@@ -48,16 +49,23 @@ func TestEcho(t *testing.T) {
|
||||
clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
|
||||
|
||||
// Start server
|
||||
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
||||
if err != nil {
|
||||
cmn.Exit(err.Error())
|
||||
s := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
||||
s.SetLogger(log.TestingLogger().With("module", "abci-server"))
|
||||
if _, err := s.Start(); err != nil {
|
||||
t.Fatalf("Error starting socket server: %v", err.Error())
|
||||
}
|
||||
defer s.Stop()
|
||||
|
||||
// Start client
|
||||
cli, err := clientCreator.NewABCIClient()
|
||||
if err != nil {
|
||||
cmn.Exit(err.Error())
|
||||
t.Fatalf("Error creating ABCI client: %v", err.Error())
|
||||
}
|
||||
cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
|
||||
if _, err := cli.Start(); err != nil {
|
||||
t.Fatalf("Error starting ABCI client: %v", err.Error())
|
||||
}
|
||||
|
||||
proxy := NewAppConnTest(cli)
|
||||
t.Log("Connected")
|
||||
|
||||
@@ -71,17 +79,25 @@ func BenchmarkEcho(b *testing.B) {
|
||||
b.StopTimer() // Initialize
|
||||
sockPath := cmn.Fmt("unix:///tmp/echo_%v.sock", cmn.RandStr(6))
|
||||
clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
|
||||
|
||||
// Start server
|
||||
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
||||
if err != nil {
|
||||
cmn.Exit(err.Error())
|
||||
s := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
||||
s.SetLogger(log.TestingLogger().With("module", "abci-server"))
|
||||
if _, err := s.Start(); err != nil {
|
||||
b.Fatalf("Error starting socket server: %v", err.Error())
|
||||
}
|
||||
defer s.Stop()
|
||||
|
||||
// Start client
|
||||
cli, err := clientCreator.NewABCIClient()
|
||||
if err != nil {
|
||||
cmn.Exit(err.Error())
|
||||
b.Fatalf("Error creating ABCI client: %v", err.Error())
|
||||
}
|
||||
cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
|
||||
if _, err := cli.Start(); err != nil {
|
||||
b.Fatalf("Error starting ABCI client: %v", err.Error())
|
||||
}
|
||||
|
||||
proxy := NewAppConnTest(cli)
|
||||
b.Log("Connected")
|
||||
echoString := strings.Repeat(" ", 200)
|
||||
@@ -100,17 +116,25 @@ func BenchmarkEcho(b *testing.B) {
|
||||
func TestInfo(t *testing.T) {
|
||||
sockPath := cmn.Fmt("unix:///tmp/echo_%v.sock", cmn.RandStr(6))
|
||||
clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
|
||||
|
||||
// Start server
|
||||
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
||||
if err != nil {
|
||||
cmn.Exit(err.Error())
|
||||
s := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
||||
s.SetLogger(log.TestingLogger().With("module", "abci-server"))
|
||||
if _, err := s.Start(); err != nil {
|
||||
t.Fatalf("Error starting socket server: %v", err.Error())
|
||||
}
|
||||
defer s.Stop()
|
||||
|
||||
// Start client
|
||||
cli, err := clientCreator.NewABCIClient()
|
||||
if err != nil {
|
||||
cmn.Exit(err.Error())
|
||||
t.Fatalf("Error creating ABCI client: %v", err.Error())
|
||||
}
|
||||
cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
|
||||
if _, err := cli.Start(); err != nil {
|
||||
t.Fatalf("Error starting ABCI client: %v", err.Error())
|
||||
}
|
||||
|
||||
proxy := NewAppConnTest(cli)
|
||||
t.Log("Connected")
|
||||
|
||||
|
||||
+3
-3
@@ -1,9 +1,10 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
abcicli "github.com/tendermint/abci/client"
|
||||
"github.com/tendermint/abci/example/dummy"
|
||||
"github.com/tendermint/abci/types"
|
||||
@@ -51,10 +52,9 @@ func NewRemoteClientCreator(addr, transport string, mustConnect bool) ClientCrea
|
||||
}
|
||||
|
||||
func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
|
||||
// Run forever in a loop
|
||||
remoteApp, err := abcicli.NewClient(r.addr, r.transport, r.mustConnect)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to connect to proxy: %v", err)
|
||||
return nil, errors.Wrap(err, "Failed to connect to proxy")
|
||||
}
|
||||
return remoteApp, nil
|
||||
}
|
||||
|
||||
+18
-6
@@ -1,6 +1,8 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
)
|
||||
|
||||
@@ -70,25 +72,34 @@ func (app *multiAppConn) Query() AppConnQuery {
|
||||
func (app *multiAppConn) OnStart() error {
|
||||
// query connection
|
||||
querycli, err := app.clientCreator.NewABCIClient()
|
||||
querycli.SetLogger(app.Logger.With("module", "abci-client", "connection", "query"))
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "Error creating ABCI client (query connection)")
|
||||
}
|
||||
querycli.SetLogger(app.Logger.With("module", "abci-client", "connection", "query"))
|
||||
if _, err := querycli.Start(); err != nil {
|
||||
return errors.Wrap(err, "Error starting ABCI client (query connection)")
|
||||
}
|
||||
app.queryConn = NewAppConnQuery(querycli)
|
||||
|
||||
// mempool connection
|
||||
memcli, err := app.clientCreator.NewABCIClient()
|
||||
memcli.SetLogger(app.Logger.With("module", "abci-client", "connection", "mempool"))
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "Error creating ABCI client (mempool connection)")
|
||||
}
|
||||
memcli.SetLogger(app.Logger.With("module", "abci-client", "connection", "mempool"))
|
||||
if _, err := memcli.Start(); err != nil {
|
||||
return errors.Wrap(err, "Error starting ABCI client (mempool connection)")
|
||||
}
|
||||
app.mempoolConn = NewAppConnMempool(memcli)
|
||||
|
||||
// consensus connection
|
||||
concli, err := app.clientCreator.NewABCIClient()
|
||||
concli.SetLogger(app.Logger.With("module", "abci-client", "connection", "consensus"))
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "Error creating ABCI client (consensus connection)")
|
||||
}
|
||||
concli.SetLogger(app.Logger.With("module", "abci-client", "connection", "consensus"))
|
||||
if _, err := concli.Start(); err != nil {
|
||||
return errors.Wrap(err, "Error starting ABCI client (consensus connection)")
|
||||
}
|
||||
app.consensusConn = NewAppConnConsensus(concli)
|
||||
|
||||
@@ -96,5 +107,6 @@ func (app *multiAppConn) OnStart() error {
|
||||
if app.handshaker != nil {
|
||||
return app.handshaker.Handshake(app)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user