Example #1
0
func (c *CommandHelper) writeResponses() error {
	defer c.outw.Close()
	for response := range c.Responses {
		udf.WriteMessage(response, c.outw)
	}
	return nil
}
Example #2
0
func (p *UDFProcess) writeRequest(req *udf.Request) error {
	err := udf.WriteMessage(req, p.stdin)
	if err != nil {
		err = fmt.Errorf("write error: %s", err)
	}
	return err
}
Example #3
0
func TestMessage_ReadWriteMultiple(t *testing.T) {
	req := &udf.Request{}
	req.Message = &udf.Request_Keepalive{
		Keepalive: &udf.KeepaliveRequest{
			Time: 42,
		},
	}

	var buf bytes.Buffer

	var count int = 1e4
	for i := 0; i < count; i++ {
		err := udf.WriteMessage(req, &buf)
		if err != nil {
			t.Fatal(err)
		}
	}

	nreq := &udf.Request{}
	var b []byte

	for i := 0; i < count; i++ {
		err := udf.ReadMessage(&b, &buf, nreq)
		if err != nil {
			t.Fatal(err)
		}

		if !reflect.DeepEqual(req, nreq) {
			t.Fatalf("unexpected request: i:%d \ngot %v\nexp %v", i, nreq, req)
		}
	}
}
Example #4
0
func TestMessage_ReadWrite(t *testing.T) {
	req := &udf.Request{}
	req.Message = &udf.Request_Keepalive{
		Keepalive: &udf.KeepaliveRequest{
			Time: 42,
		},
	}

	var buf bytes.Buffer

	err := udf.WriteMessage(req, &buf)
	if err != nil {
		t.Fatal(err)
	}

	nreq := &udf.Request{}
	var b []byte
	err = udf.ReadMessage(&b, &buf, nreq)
	if err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(req, nreq) {
		t.Errorf("unexpected request: \ngot %v\nexp %v", nreq, req)
	}
}
Example #5
0
func (o *IO) writeResponses() error {
	defer o.outw.Close()
	for response := range o.Responses {
		udf.WriteMessage(response, o.outw)
	}
	return nil
}
Example #6
0
func (a *Agent) writeLoop() error {
	defer a.out.Close()
	for response := range a.outResponses {
		err := udf.WriteMessage(response, a.out)
		if err != nil {
			return err
		}
	}
	return nil
}