Skip to content

Commit

Permalink
Change Message method name: Bytes -> Encode
Browse files Browse the repository at this point in the history
  • Loading branch information
bogh committed Mar 17, 2017
1 parent 0653489 commit 4a3cd88
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestReceiveAMessage(t *testing.T) {
// than we receive the expected message
select {
case m := <-c.Messages():
a.Equal(aNormalMessage, string(m.Bytes()))
a.Equal(aNormalMessage, string(m.Encode()))
case <-time.After(time.Millisecond * 10):
a.Fail("timeout while waiting for message")
}
Expand Down
2 changes: 1 addition & 1 deletion guble-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func readLoop(client client.Client) {
select {
case incomingMessage := <-client.Messages():
if *verbose {
fmt.Println(string(incomingMessage.Bytes()))
fmt.Println(string(incomingMessage.Encode()))
} else {
fmt.Printf("%v: %v\n", incomingMessage.UserID, string(incomingMessage.Body))
}
Expand Down
4 changes: 2 additions & 2 deletions protocol/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (m *Message) String() string {
return fmt.Sprintf("%d: %s", m.ID, string(m.Body))
}

// Bytes serializes the message into a byte slice
func (m *Message) Bytes() []byte {
// Encode serializes the message into a byte slice
func (m *Message) Encode() []byte {
buff := &bytes.Buffer{}

m.writeMetadata(buff)
Expand Down
8 changes: 4 additions & 4 deletions protocol/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestSerializeANormalMessage(t *testing.T) {
}

// then: the serialisation is as expected
assert.Equal(t, aNormalMessageNoExpires, string(msg.Bytes()))
assert.Equal(t, aNormalMessageNoExpires, string(msg.Encode()))
assert.Equal(t, "42: Hello World", msg.String())

// and: the first line is as expected
Expand All @@ -87,7 +87,7 @@ func TestSerializeANormalMessageWithExpires(t *testing.T) {
msg.Expires = &expire

// then: the serialisation is as expected
assert.Equal(t, aNormalMessage, string(msg.Bytes()))
assert.Equal(t, aNormalMessage, string(msg.Encode()))
assert.Equal(t, "42: Hello World", msg.String())

// and: the first line is as expected
Expand All @@ -101,7 +101,7 @@ func TestSerializeAMinimalMessage(t *testing.T) {
Time: unixTime.Unix(),
}

assert.Equal(t, aMinimalMessage, string(msg.Bytes()))
assert.Equal(t, aMinimalMessage, string(msg.Encode()))
}

func TestSerializeAMinimalMessageWithBody(t *testing.T) {
Expand All @@ -112,7 +112,7 @@ func TestSerializeAMinimalMessageWithBody(t *testing.T) {
Body: []byte("Hello World"),
}

assert.Equal(t, aMinimalMessage+"\n\nHello World", string(msg.Bytes()))
assert.Equal(t, aMinimalMessage+"\n\nHello World", string(msg.Encode()))
}

func TestParsingAMinimalMessage(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (cluster *Cluster) BroadcastMessage(pMessage *protocol.Message) error {
cMessage := &message{
NodeID: cluster.Config.ID,
Type: mtGubleMessage,
Body: pMessage.Bytes(),
Body: pMessage.Encode(),
}
return cluster.broadcastClusterMessage(cMessage)
}
Expand Down
2 changes: 1 addition & 1 deletion server/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (router *router) HandleMessage(message *protocol.Message) error {
nodeID = router.cluster.Config.ID
}

mTotalMessagesIncomingBytes.Add(int64(len(message.Bytes())))
mTotalMessagesIncomingBytes.Add(int64(len(message.Encode())))
size, err := router.messageStore.StoreMessage(message, nodeID)
if err != nil {
logger.WithField("error", err.Error()).Error("Error storing message")
Expand Down
4 changes: 2 additions & 2 deletions server/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestRouter_HandleMessageNotAllowed(t *testing.T) {
m.ID = id
m.Time = ts
m.NodeID = nodeID
return len(m.Bytes()), nil
return len(m.Encode()), nil
})

// sending message
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestRouter_SimpleMessageSending(t *testing.T) {
m.ID = id
m.Time = ts
m.NodeID = nodeID
return len(m.Bytes()), nil
return len(m.Encode()), nil
})

// when i send a message to the route
Expand Down
2 changes: 1 addition & 1 deletion server/store/dummystore/dummy_message_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (dms *DummyMessageStore) StoreMessage(message *protocol.Message, nodeID uin
message.ID = nextID
message.Time = ts
message.NodeID = nodeID
data := message.Bytes()
data := message.Encode()
if err := dms.Store(partitionName, nextID, data); err != nil {
return 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions server/store/filestore/message_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func (fms *FileMessageStore) StoreMessage(message *protocol.Message, nodeID uint
}).Debug("Locally generated ID for message")
}

data := message.Bytes()
data := message.Encode()

if err := fms.Store(partitionName, message.ID, message.Bytes()); err != nil {
if err := fms.Store(partitionName, message.ID, message.Encode()); err != nil {
logger.
WithError(err).WithField("partition", partitionName).
Error("Error storing locally generated messagein partition")
Expand Down
2 changes: 1 addition & 1 deletion server/websocket/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (rec *Receiver) receiveFromSubscription() {

if m.ID > rec.lastSentID {
rec.lastSentID = m.ID
rec.sendC <- m.Bytes()
rec.sendC <- m.Encode()
} else {
logger.WithFields(log.Fields{
"msgId": m.ID,
Expand Down
10 changes: 5 additions & 5 deletions server/websocket/websocket_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func Test_AnIncomingMessageIsDelivered(t *testing.T) {

wsconn, routerMock, messageStore := createDefaultMocks([]string{})

wsconn.EXPECT().Send(aTestMessage.Bytes())
wsconn.EXPECT().Send(aTestMessage.Encode())

handler := runNewWebSocket(wsconn, routerMock, messageStore, nil)

handler.sendChannel <- aTestMessage.Bytes()
handler.sendChannel <- aTestMessage.Encode()
time.Sleep(time.Millisecond * 2)
}

Expand All @@ -106,18 +106,18 @@ func Test_AnIncomingMessageIsNotAllowed(t *testing.T) {
}()
time.Sleep(time.Millisecond * 2)

handler.sendChannel <- aTestMessage.Bytes()
handler.sendChannel <- aTestMessage.Encode()
time.Sleep(time.Millisecond * 2)
//nothing shall have been sent

//now allow
tam.EXPECT().IsAllowed(auth.READ, "testuser", protocol.Path("/foo")).Return(true)

wsconn.EXPECT().Send(aTestMessage.Bytes())
wsconn.EXPECT().Send(aTestMessage.Encode())

time.Sleep(time.Millisecond * 2)

handler.sendChannel <- aTestMessage.Bytes()
handler.sendChannel <- aTestMessage.Encode()
time.Sleep(time.Millisecond * 2)
}

Expand Down

0 comments on commit 4a3cd88

Please sign in to comment.