Exemplo n.º 1
0
func (pool *connectionPool) Release(conn connection.Connection) {
	select {
	case pool.connections <- conn:
	default:
		conn.Close()
	}
}
Exemplo n.º 2
0
func streamStreamOut(conn connection.Connection) {
	for {
		payload := &warden.StreamChunk{}

		err := conn.ReadResponse(payload)
		if err != nil {
			fmt.Println("stream failed:", err)
			os.Exit(1)
		}

		os.Stdout.Write(payload.GetContent())

		if payload.EOF != nil {
			break
		}
	}
}
Exemplo n.º 3
0
func streamProcessPayloads(conn connection.Connection, encoder *json.Encoder) {
	for {
		payload := &warden.ProcessPayload{}

		err := conn.ReadResponse(payload)
		if err != nil {
			fmt.Println("stream failed:", err)
			os.Exit(1)
		}

		encoder.Encode(payload)

		if payload.ExitStatus != nil {
			break
		}
	}
}
Exemplo n.º 4
0
func streamStreamIn(conn connection.Connection) {
	for {
		buf := make([]byte, 64*1024)

		n, err := os.Stdin.Read(buf)

		if n > 0 {
			err := conn.SendMessage(&warden.StreamChunk{
				Content: buf[:n],
			})
			if err != nil {
				fmt.Println("writing content failed:", err)
				os.Exit(1)
			}
		}

		if err == io.EOF {
			err := conn.SendMessage(&warden.StreamChunk{
				EOF: proto.Bool(true),
			})
			if err != nil {
				fmt.Println("writing EOF failed:", err)
				os.Exit(1)
			}
			break
		}

		if err != nil {
			fmt.Println("stream interrupted:", err)
			os.Exit(1)
		}
	}

	resp := &warden.StreamInResponse{}

	err := conn.ReadResponse(resp)
	if err != nil {
		fmt.Println("stream failed:", err)
		os.Exit(1)
	}
}
Exemplo n.º 5
0
	gconn "github.com/cloudfoundry-incubator/garden/client/connection"
	fconn "github.com/cloudfoundry-incubator/garden/client/connection/fakes"
	gfakes "github.com/cloudfoundry-incubator/garden/fakes"
	"github.com/concourse/atc/worker"
	"github.com/concourse/atc/worker/fakes"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("Retryable", func() {
	var (
		innerConnection *fconn.FakeConnection
		retryPolicy     *fakes.FakeRetryPolicy
		sleeper         *fakes.FakeSleeper

		conn gconn.Connection
	)

	BeforeEach(func() {
		innerConnection = new(fconn.FakeConnection)
		retryPolicy = new(fakes.FakeRetryPolicy)
		sleeper = new(fakes.FakeSleeper)

		conn = worker.RetryableConnection{
			Connection:  innerConnection,
			Logger:      lagertest.NewTestLogger("retryable-connection"),
			Sleeper:     sleeper,
			RetryPolicy: retryPolicy,
		}