func BenchmarkEcho(b *testing.B) {
	b.StopTimer() // Initialize
	sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
	// Start server
	s, err := server.NewServer(sockPath, dummy.NewDummyApplication())
	if err != nil {
		Exit(err.Error())
	}
	defer s.Stop()
	// Start client
	proxy, err := NewRemoteAppConn(sockPath)
	if err != nil {
		Exit(err.Error())
	} else {
		b.Log("Connected")
	}
	echoString := strings.Repeat(" ", 200)
	b.StartTimer() // Start benchmarking tests

	for i := 0; i < b.N; i++ {
		proxy.EchoAsync(echoString)
	}
	proxy.FlushSync()

	b.StopTimer()
	// info := proxy.InfoSync()
	//b.Log("N: ", b.N, info)
}
Example #2
0
// Get a connection to the proxyAppConn addr.
// Check the current hash, and panic if it doesn't match.
func GetProxyApp(addr string, hash []byte) (proxyAppConn proxy.AppConn) {
	// use local app (for testing)
	switch addr {
	case "nilapp":
		app := nilapp.NewNilApplication()
		mtx := new(sync.Mutex)
		proxyAppConn = tmspcli.NewLocalClient(mtx, app)
	case "dummy":
		app := dummy.NewDummyApplication()
		mtx := new(sync.Mutex)
		proxyAppConn = tmspcli.NewLocalClient(mtx, app)
	default:
		// Run forever in a loop
		remoteApp, err := proxy.NewRemoteAppConn(addr)
		if err != nil {
			Exit(Fmt("Failed to connect to proxy for mempool: %v", err))
		}
		proxyAppConn = remoteApp
	}

	// Check the hash
	res := proxyAppConn.CommitSync()
	if res.IsErr() {
		PanicCrisis(Fmt("Error in getting proxyAppConn hash: %v", res))
	}
	if !bytes.Equal(hash, res.Data) {
		log.Warn(Fmt("ProxyApp hash does not match.  Expected %X, got %X", hash, res.Data))
	}

	return proxyAppConn
}
Example #3
0
File: main.go Project: marleyg/tmsp
func main() {

	addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address")
	flag.Parse()

	// Start the listener
	_, err := server.StartListener(*addrPtr, dummy.NewDummyApplication())
	if err != nil {
		Exit(err.Error())
	}

	// Wait forever
	TrapSignal(func() {
		// Cleanup
	})

}
func TestEcho(t *testing.T) {
	sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))

	// Start server
	s, err := server.NewServer(sockPath, dummy.NewDummyApplication())
	if err != nil {
		Exit(err.Error())
	}
	defer s.Stop()
	// Start client
	proxy, err := NewRemoteAppConn(sockPath)
	if err != nil {
		Exit(err.Error())
	} else {
		t.Log("Connected")
	}

	for i := 0; i < 1000; i++ {
		proxy.EchoAsync(Fmt("echo-%v", i))
	}
	proxy.FlushSync()
}
func TestInfo(t *testing.T) {
	sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
	// Start server
	s, err := server.NewServer(sockPath, dummy.NewDummyApplication())
	if err != nil {
		Exit(err.Error())
	}
	defer s.Stop()
	// Start client
	proxy, err := NewRemoteAppConn(sockPath)
	if err != nil {
		Exit(err.Error())
	} else {
		t.Log("Connected")
	}
	res := proxy.InfoSync()
	if res.IsErr() {
		t.Errorf("Unexpected error: %v", err)
	}
	if string(res.Data) != "size:0" {
		t.Error("Expected ResponseInfo with one element 'size:0' but got something else")
	}
}
Example #6
0
func TestDummy(t *testing.T) {
	fmt.Println("### Testing Dummy")
	testStream(t, dummy.NewDummyApplication())
}