use correct packages
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m51s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m51s
This commit is contained in:
@@ -61,7 +61,7 @@ func (g *RemoteGrain) GetId() CartId {
|
||||
}
|
||||
|
||||
func (g *RemoteGrain) GetCurrentState() ([]byte, error) {
|
||||
return g.Call(RemoteGetState, g.Id, RemoteGetStateReply, nil)
|
||||
return g.Call(RemoteGetState, g.Id, RemoteGetStateReply, []byte{})
|
||||
}
|
||||
|
||||
func NewRemoteGrainPool(addr string) *RemoteGrainPool {
|
||||
|
||||
@@ -263,7 +263,7 @@ func (h *RemoteHost) Negotiate(knownHosts []string) ([]string, error) {
|
||||
}
|
||||
|
||||
func (g *RemoteHost) GetCartMappings() ([]CartId, error) {
|
||||
data, err := g.Call(GetCartIds, CartIdsResponse, nil)
|
||||
data, err := g.Call(GetCartIds, CartIdsResponse, []byte{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -359,7 +359,7 @@ func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error {
|
||||
}
|
||||
|
||||
func (h *RemoteHost) Ping() error {
|
||||
_, err := h.Call(Ping, Pong, nil)
|
||||
_, err := h.Call(Ping, Pong, []byte{})
|
||||
|
||||
if err != nil {
|
||||
h.MissedPings++
|
||||
@@ -379,7 +379,7 @@ func (p *SyncedPool) AddRemote(host string) error {
|
||||
if err != nil {
|
||||
log.Printf("Error connecting to remote %s: %v\n", host, err)
|
||||
}
|
||||
_, err = client.Call(Ping, Pong, nil)
|
||||
_, err = client.Call(Ping, Pong, []byte{})
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Error pinging remote %s: %v\n", host, err)
|
||||
|
||||
@@ -31,7 +31,7 @@ type CartTCPClient struct {
|
||||
Errors chan error
|
||||
ErrorCount int
|
||||
address string
|
||||
*PacketQueue
|
||||
*CartPacketQueue
|
||||
}
|
||||
|
||||
func NewCartTCPClient(address string) (*CartTCPClient, error) {
|
||||
@@ -44,7 +44,7 @@ func NewCartTCPClient(address string) (*CartTCPClient, error) {
|
||||
ErrorCount: 0,
|
||||
Conn: connection,
|
||||
address: address,
|
||||
PacketQueue: NewPacketQueue(connection),
|
||||
CartPacketQueue: NewCartPacketQueue(connection),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func (m *CartTCPClient) Call(messageType uint32, id CartId, responseType uint32,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
packet, err := m.Expect(responseType, time.Second)
|
||||
packet, err := m.Expect(responseType, id, time.Second)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
47
tcp-cart_test.go
Normal file
47
tcp-cart_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCartTcpHelpers(t *testing.T) {
|
||||
|
||||
server, err := CartListen("localhost:51337")
|
||||
if err != nil {
|
||||
t.Errorf("Error listening: %v\n", err)
|
||||
}
|
||||
client, err := CartDial("localhost:51337")
|
||||
if err != nil {
|
||||
t.Errorf("Error dialing: %v\n", err)
|
||||
}
|
||||
var messageData string
|
||||
server.ListenFor(1, func(id CartId, data []byte) error {
|
||||
log.Printf("Received message: %s\n", string(data))
|
||||
messageData = string(data)
|
||||
return nil
|
||||
})
|
||||
server.HandleCall(2, func(id CartId, data []byte) (uint32, []byte, error) {
|
||||
log.Printf("Received call: %s\n", string(data))
|
||||
return 3, []byte("Hello, client!"), nil
|
||||
})
|
||||
server.HandleCall(Ping, func(id CartId, data []byte) (uint32, []byte, error) {
|
||||
return Pong, nil, nil
|
||||
})
|
||||
id := ToCartId("kalle")
|
||||
client.SendPacket(1, id, []byte("Hello, world!"))
|
||||
answer, err := client.Call(2, id, 3, []byte("Hello, server!"))
|
||||
if err != nil {
|
||||
t.Errorf("Error calling: %v\n", err)
|
||||
}
|
||||
_, err = client.Call(Ping, id, Pong, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Error calling: %v\n", err)
|
||||
}
|
||||
if string(answer) != "Hello, client!" {
|
||||
t.Errorf("Expected answer 'Hello, client!', got %s\n", string(answer))
|
||||
}
|
||||
if messageData != "Hello, world!" {
|
||||
t.Errorf("Expected message 'Hello, world!', got %s\n", messageData)
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,19 @@ func TestTcpHelpers(t *testing.T) {
|
||||
log.Printf("Received call: %s\n", string(data))
|
||||
return 3, []byte("Hello, client!"), nil
|
||||
})
|
||||
server.HandleCall(Ping, func(data []byte) (uint32, []byte, error) {
|
||||
return Pong, nil, nil
|
||||
})
|
||||
|
||||
client.SendPacket(1, []byte("Hello, world!"))
|
||||
answer, err := client.Call(2, 3, []byte("Hello, server!"))
|
||||
if err != nil {
|
||||
t.Errorf("Error calling: %v\n", err)
|
||||
}
|
||||
_, err = client.Call(Ping, Pong, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Error calling: %v\n", err)
|
||||
}
|
||||
if string(answer) != "Hello, client!" {
|
||||
t.Errorf("Expected answer 'Hello, client!', got %s\n", string(answer))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user