change stuff
This commit is contained in:
@@ -49,11 +49,8 @@ func (h *GrainHandler) RemoteHandleMessageHandler(data *FrameWithPayload, result
|
|||||||
|
|
||||||
replyData, err := h.pool.Process(cartData.Id, msg)
|
replyData, err := h.pool.Process(cartData.Id, msg)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error handling message:", err)
|
|
||||||
}
|
|
||||||
resultChan <- *replyData
|
resultChan <- *replyData
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *GrainHandler) RemoteGetStateHandler(data *FrameWithPayload, resultChan chan<- FrameWithPayload) error {
|
func (h *GrainHandler) RemoteGetStateHandler(data *FrameWithPayload, resultChan chan<- FrameWithPayload) error {
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ func (p *SyncedPool) GrainOwnerChangeHandler(data *FrameWithPayload, resultChan
|
|||||||
idAndHostParts := strings.Split(string(data.Payload), ";")
|
idAndHostParts := strings.Split(string(data.Payload), ";")
|
||||||
if len(idAndHostParts) != 2 {
|
if len(idAndHostParts) != 2 {
|
||||||
log.Printf("Invalid remote grain change message\n")
|
log.Printf("Invalid remote grain change message\n")
|
||||||
resultChan <- MakeFrameWithPayload(AckError, 400, []byte("invalid"))
|
resultChan <- MakeFrameWithPayload(AckError, 500, []byte("invalid"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
id := ToCartId(idAndHostParts[0])
|
id := ToCartId(idAndHostParts[0])
|
||||||
@@ -360,17 +360,17 @@ func (p *SyncedPool) removeLocalGrain(id CartId) {
|
|||||||
delete(p.local.grains, id)
|
delete(p.local.grains, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SyncedPool) AddRemote(host string) error {
|
func (p *SyncedPool) AddRemote(host string) {
|
||||||
|
|
||||||
_, hasHost := p.remotes[host]
|
_, hasHost := p.remotes[host]
|
||||||
if host == "" || p.IsKnown(host) || hasHost {
|
if host == "" || hasHost {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
client := NewConnection(fmt.Sprintf("%s:1338", host))
|
client := NewConnection(fmt.Sprintf("%s:1338", host))
|
||||||
_, err := client.Call(Ping, nil)
|
_, err := client.Call(Ping, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error connecting to remote %s: %s\n", host, err)
|
log.Printf("Error connecting to remote %s: %s\n", host, err)
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
remote := RemoteHost{
|
remote := RemoteHost{
|
||||||
@@ -403,7 +403,7 @@ func (p *SyncedPool) AddRemote(host string) error {
|
|||||||
log.Printf("Added remote %s\n", remote.Host)
|
log.Printf("Added remote %s\n", remote.Host)
|
||||||
|
|
||||||
go remote.Initialize(p)
|
go remote.Initialize(p)
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SyncedPool) getGrain(id CartId) (Grain, error) {
|
func (p *SyncedPool) getGrain(id CartId) (Grain, error) {
|
||||||
|
|||||||
@@ -83,8 +83,9 @@ func (c *Connection) CallAsync(msg FrameType, payload []byte, ch chan<- FrameWit
|
|||||||
|
|
||||||
err = SendFrame(conn, &toSend)
|
err = SendFrame(conn, &toSend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Close()
|
log.Printf("Error sending frame: %v\n", err)
|
||||||
close(ch)
|
close(ch)
|
||||||
|
conn.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestGenericConnection(t *testing.T) {
|
func TestGenericConnection(t *testing.T) {
|
||||||
conn := NewConnection("localhost:51337")
|
conn := NewConnection("localhost:51337")
|
||||||
@@ -17,6 +20,9 @@ func TestGenericConnection(t *testing.T) {
|
|||||||
resultChan <- MakeFrameWithPayload(2, 200, datta)
|
resultChan <- MakeFrameWithPayload(2, 200, datta)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
listener.AddHandler(3, func(input *FrameWithPayload, resultChan chan<- FrameWithPayload) error {
|
||||||
|
return fmt.Errorf("Error")
|
||||||
|
})
|
||||||
r, err := conn.Call(1, datta)
|
r, err := conn.Call(1, datta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error calling: %v\n", err)
|
t.Errorf("Error calling: %v\n", err)
|
||||||
@@ -28,6 +34,11 @@ func TestGenericConnection(t *testing.T) {
|
|||||||
if err != nil || response.StatusCode != 200 || response.Type != Pong {
|
if err != nil || response.StatusCode != 200 || response.Type != Pong {
|
||||||
t.Errorf("Error connecting to remote %v\n", response)
|
t.Errorf("Error connecting to remote %v\n", response)
|
||||||
}
|
}
|
||||||
|
res, err := conn.Call(3, datta)
|
||||||
|
if res.StatusCode == 200 {
|
||||||
|
t.Errorf("Expected error, got %v\n", res)
|
||||||
|
}
|
||||||
|
|
||||||
i := 100
|
i := 100
|
||||||
results := make(chan FrameWithPayload, i)
|
results := make(chan FrameWithPayload, i)
|
||||||
for i > 0 {
|
for i > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user