Ejemplo n.º 1
0
func (this *protobufOutput) constructOutput(contents ...interface{}) [][]byte {
	contentList := make([][]byte, len(contents))
	for i, content := range contents {
		encoded, err := proto.Marshal(content.(proto.Message))
		if err != nil {
			panic(err)
		}
		contentList[i] = encoded
	}
	return contentList
}
Ejemplo n.º 2
0
func TestReadBoltMsg(t *testing.T) {
	buffer := new(bytes.Buffer)
	output := NewProtobufOutput(buffer)
	input := NewProtobufInput(buffer)

	for i := 0; i < 100; i++ {
		num := rand.Int63()
		numStr := fmt.Sprintf("%d", num)
		outMsg := newTestObj(numStr, num, []byte(numStr))

		outTuple := &messages.BoltMsg{
			BoltMsgProto: &messages.BoltMsgProto{
				BoltMsgMeta: &messages.BoltMsgMeta{
					Id:     numStr,
					Comp:   numStr,
					Stream: numStr,
					Task:   num,
				},
			},
		}
		outProto, err := proto.Marshal(outMsg)
		checkErr(err, t)
		outTuple.Contents = append(outTuple.Contents, outProto)
		output.SendMsg(outTuple)
		output.Flush()

		inMsg := &messages.Test{}
		inMeta := &messages.BoltMsgMeta{}
		err = input.ReadBoltMsg(inMeta, inMsg)
		checkErr(err, t)

		if !inMeta.Equal(outTuple.BoltMsgProto.BoltMsgMeta) {
			t.Fatalf("Tuple metadata (%+v) does not equal read Tuple metadata (%+v)", outTuple.BoltMsgProto.BoltMsgMeta, inMeta)
		}
		if !inMsg.Equal(outMsg) {
			t.Fatalf("Tuple data (%+v) does not equal read tuple data (%+v)", outMsg, inMsg)
		}
	}
}