mirror of
https://github.com/tendermint/tendermint.git
synced 2026-10-01 12:15:45 +00:00
BroadcastTx results
This commit is contained in:
+6
-6
@@ -8,12 +8,12 @@ type AppConn interface {
|
||||
SetResponseCallback(tmspcli.Callback)
|
||||
Error() error
|
||||
|
||||
EchoAsync(msg string)
|
||||
FlushAsync()
|
||||
AppendTxAsync(tx []byte)
|
||||
CheckTxAsync(tx []byte)
|
||||
GetHashAsync()
|
||||
SetOptionAsync(key string, value string)
|
||||
EchoAsync(msg string) *tmspcli.ReqRes
|
||||
FlushAsync() *tmspcli.ReqRes
|
||||
AppendTxAsync(tx []byte) *tmspcli.ReqRes
|
||||
CheckTxAsync(tx []byte) *tmspcli.ReqRes
|
||||
GetHashAsync() *tmspcli.ReqRes
|
||||
SetOptionAsync(key string, value string) *tmspcli.ReqRes
|
||||
|
||||
InfoSync() (info string, err error)
|
||||
FlushSync() error
|
||||
|
||||
+12
-6
@@ -30,18 +30,20 @@ func (app *localAppConn) Error() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (app *localAppConn) EchoAsync(msg string) {
|
||||
func (app *localAppConn) EchoAsync(msg string) *tmspcli.ReqRes {
|
||||
app.Callback(
|
||||
tmsp.RequestEcho(msg),
|
||||
tmsp.ResponseEcho(msg),
|
||||
)
|
||||
return nil // TODO maybe create a ReqRes
|
||||
}
|
||||
|
||||
func (app *localAppConn) FlushAsync() {
|
||||
func (app *localAppConn) FlushAsync() *tmspcli.ReqRes {
|
||||
// Do nothing
|
||||
return nil // TODO maybe create a ReqRes
|
||||
}
|
||||
|
||||
func (app *localAppConn) SetOptionAsync(key string, value string) {
|
||||
func (app *localAppConn) SetOptionAsync(key string, value string) *tmspcli.ReqRes {
|
||||
app.mtx.Lock()
|
||||
log := app.Application.SetOption(key, value)
|
||||
app.mtx.Unlock()
|
||||
@@ -49,9 +51,10 @@ func (app *localAppConn) SetOptionAsync(key string, value string) {
|
||||
tmsp.RequestSetOption(key, value),
|
||||
tmsp.ResponseSetOption(log),
|
||||
)
|
||||
return nil // TODO maybe create a ReqRes
|
||||
}
|
||||
|
||||
func (app *localAppConn) AppendTxAsync(tx []byte) {
|
||||
func (app *localAppConn) AppendTxAsync(tx []byte) *tmspcli.ReqRes {
|
||||
app.mtx.Lock()
|
||||
code, result, log := app.Application.AppendTx(tx)
|
||||
app.mtx.Unlock()
|
||||
@@ -59,9 +62,10 @@ func (app *localAppConn) AppendTxAsync(tx []byte) {
|
||||
tmsp.RequestAppendTx(tx),
|
||||
tmsp.ResponseAppendTx(code, result, log),
|
||||
)
|
||||
return nil // TODO maybe create a ReqRes
|
||||
}
|
||||
|
||||
func (app *localAppConn) CheckTxAsync(tx []byte) {
|
||||
func (app *localAppConn) CheckTxAsync(tx []byte) *tmspcli.ReqRes {
|
||||
app.mtx.Lock()
|
||||
code, result, log := app.Application.CheckTx(tx)
|
||||
app.mtx.Unlock()
|
||||
@@ -69,9 +73,10 @@ func (app *localAppConn) CheckTxAsync(tx []byte) {
|
||||
tmsp.RequestCheckTx(tx),
|
||||
tmsp.ResponseCheckTx(code, result, log),
|
||||
)
|
||||
return nil // TODO maybe create a ReqRes
|
||||
}
|
||||
|
||||
func (app *localAppConn) GetHashAsync() {
|
||||
func (app *localAppConn) GetHashAsync() *tmspcli.ReqRes {
|
||||
app.mtx.Lock()
|
||||
hash, log := app.Application.GetHash()
|
||||
app.mtx.Unlock()
|
||||
@@ -79,6 +84,7 @@ func (app *localAppConn) GetHashAsync() {
|
||||
tmsp.RequestGetHash(),
|
||||
tmsp.ResponseGetHash(hash, log),
|
||||
)
|
||||
return nil // TODO maybe create a ReqRes
|
||||
}
|
||||
|
||||
func (app *localAppConn) InfoSync() (info string, err error) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
tmspcli "github.com/tendermint/tmsp/client"
|
||||
)
|
||||
|
||||
@@ -13,9 +11,13 @@ type remoteAppConn struct {
|
||||
*tmspcli.TMSPClient
|
||||
}
|
||||
|
||||
func NewRemoteAppConn(conn net.Conn, bufferSize int) *remoteAppConn {
|
||||
app := &remoteAppConn{
|
||||
TMSPClient: tmspcli.NewTMSPClient(conn, bufferSize),
|
||||
func NewRemoteAppConn(addr string) (*remoteAppConn, error) {
|
||||
client, err := tmspcli.NewTMSPClient(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return app
|
||||
appConn := &remoteAppConn{
|
||||
TMSPClient: client,
|
||||
}
|
||||
return appConn, nil
|
||||
}
|
||||
|
||||
@@ -1,63 +1,51 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
. "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-logio"
|
||||
"github.com/tendermint/tmsp/example/golang"
|
||||
"github.com/tendermint/tmsp/server"
|
||||
)
|
||||
|
||||
func TestEcho(t *testing.T) {
|
||||
sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
|
||||
|
||||
// Start server
|
||||
_, err := server.StartListener(sockPath, example.NewDummyApplication())
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
}
|
||||
conn, err := Connect(sockPath)
|
||||
// Start client
|
||||
proxy, err := NewRemoteAppConn(sockPath)
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
} else {
|
||||
t.Log("Connected")
|
||||
}
|
||||
|
||||
logBuffer := bytes.NewBuffer(nil)
|
||||
logConn := logio.NewLoggedConn(conn, logBuffer)
|
||||
proxy := NewRemoteAppConn(logConn, 10)
|
||||
proxy.SetResponseCallback(nil)
|
||||
proxy.Start()
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
proxy.EchoAsync(Fmt("echo-%v", i))
|
||||
}
|
||||
proxy.FlushSync()
|
||||
|
||||
/*
|
||||
if t.Failed() {
|
||||
logio.PrintReader(logBuffer)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func BenchmarkEcho(b *testing.B) {
|
||||
b.StopTimer() // Initialize
|
||||
sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
|
||||
// Start server
|
||||
_, err := server.StartListener(sockPath, example.NewDummyApplication())
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
}
|
||||
conn, err := Connect(sockPath)
|
||||
// Start client
|
||||
proxy, err := NewRemoteAppConn(sockPath)
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
} else {
|
||||
b.Log("Connected")
|
||||
}
|
||||
|
||||
proxy := NewRemoteAppConn(conn, 10)
|
||||
proxy.Start()
|
||||
echoString := strings.Repeat(" ", 200)
|
||||
b.StartTimer() // Start benchmarking tests
|
||||
|
||||
@@ -73,20 +61,18 @@ func BenchmarkEcho(b *testing.B) {
|
||||
|
||||
func TestInfo(t *testing.T) {
|
||||
sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
|
||||
// Start server
|
||||
_, err := server.StartListener(sockPath, example.NewDummyApplication())
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
}
|
||||
conn, err := Connect(sockPath)
|
||||
// Start client
|
||||
proxy, err := NewRemoteAppConn(sockPath)
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
} else {
|
||||
t.Log("Connected")
|
||||
}
|
||||
|
||||
logBuffer := bytes.NewBuffer(nil)
|
||||
logConn := logio.NewLoggedConn(conn, logBuffer)
|
||||
proxy := NewRemoteAppConn(logConn, 10)
|
||||
proxy.Start()
|
||||
data, err := proxy.InfoSync()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user