1
0
mirror of https://github.com/docker/docs.git synced 2026-11-05 00:14:17 +03:00

inmem: a message is simply 1 opcode + an array of binary strings.

Remove redundant `Data` field. Every argument can be arbitrary data.

Signed-off-by: Solomon Hykes <solomon@docker.com>
This commit is contained in:
Solomon Hykes
2014-05-11 18:47:54 +00:00
parent 5b89b2fd83
commit 048bed0cd1
4 changed files with 13 additions and 17 deletions

View File

@@ -18,7 +18,6 @@ type Receiver interface {
type Message struct {
Name string
Args []string
Data []byte
}
const (

View File

@@ -27,18 +27,15 @@ func TestSimpleSend(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if string(msg.Data) != "hello world" {
t.Fatalf("%#v", *msg)
}
if msg.Name != "print" {
t.Fatalf("%#v", *msg)
}
if len(msg.Args) != 0 {
if msg.Args[0] != "hello world" {
t.Fatalf("%#v", *msg)
}
assertMode(t, in, out, 0)
}()
in, out, err := w.Send(&Message{Name: "print", Data: []byte("hello world")}, 0)
in, out, err := w.Send(&Message{Name: "print", Args: []string{"hello world"}}, 0)
if err != nil {
t.Fatal(err)
}
@@ -94,7 +91,7 @@ func TestSendReply(t *testing.T) {
// Send
go func() {
// Send a message with mode=R
in, out, err := w.Send(&Message{Data: []byte("this is the request")}, R)
in, out, err := w.Send(&Message{Args: []string{"this is the request"}}, R)
if err != nil {
t.Fatal(err)
}
@@ -104,7 +101,7 @@ func TestSendReply(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if string(resp.Data) != "this is the reply" {
if resp.Args[0] != "this is the reply" {
t.Fatalf("%#v", resp)
}
}()
@@ -113,12 +110,12 @@ func TestSendReply(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if string(msg.Data) != "this is the request" {
if msg.Args[0] != "this is the request" {
t.Fatalf("%#v", msg)
}
assertMode(t, in, out, W)
// Send a reply
_, _, err = out.Send(&Message{Data: []byte("this is the reply")}, 0)
_, _, err = out.Send(&Message{Args: []string{"this is the reply"}}, 0)
if err != nil {
t.Fatal(err)
}
@@ -133,13 +130,13 @@ func TestSendNested(t *testing.T) {
// Send
go func() {
// Send a message with mode=W
in, out, err := w.Send(&Message{Data: []byte("this is the request")}, W)
in, out, err := w.Send(&Message{Args: []string{"this is the request"}}, W)
if err != nil {
t.Fatal(err)
}
assertMode(t, in, out, W)
// Send a nested message
_, _, err = out.Send(&Message{Data: []byte("this is the nested message")}, 0)
_, _, err = out.Send(&Message{Args: []string{"this is the nested message"}}, 0)
if err != nil {
t.Fatal(err)
}
@@ -149,7 +146,7 @@ func TestSendNested(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if string(msg.Data) != "this is the request" {
if msg.Args[0] != "this is the request" {
t.Fatalf("%#v", msg)
}
assertMode(t, in, out, R)
@@ -158,7 +155,7 @@ func TestSendNested(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if string(nested.Data) != "this is the nested message" {
if nested.Args[0] != "this is the nested message" {
t.Fatalf("%#v", nested)
}
})

View File

@@ -8,7 +8,7 @@ import (
// StackSender forwards beam messages to a dynamic list of backend receivers.
// New backends are stacked on top. When a message is sent, each backend is
// tried until one succeeds. Any failing backends encountered along the way
// tried until one succeeds. Any failing backends encountered along the way
// are removed from the queue.
type StackSender struct {
stack *list.List
@@ -92,7 +92,7 @@ func (s *StackSender) Len() int {
return s.stack.Len()
}
var len int
for e := s.front; e != nil ; e = e.Next() {
for e := s.front; e != nil; e = e.Next() {
len++
}
return len

View File

@@ -25,7 +25,7 @@ func TestSendStack(t *testing.T) {
t.Fatalf("%#v", msg)
}
}()
_, _, err := s.Send(&Message{"hello", []string{"wonderful", "world"}, nil}, 0)
_, _, err := s.Send(&Message{"hello", []string{"wonderful", "world"}}, 0)
if err != nil {
t.Fatal(err)
}