コード例 #1
0
ファイル: stream_test.go プロジェクト: mistifyio/acomm
func (s *TrackerTestSuite) TestStreamUnix() {
	if !s.NoError(s.Tracker.Start(), "failed to start Tracker") {
		return
	}
	data := []byte("foobar")
	src := ioutil.NopCloser(bytes.NewReader(data))
	addr, err := s.Tracker.NewStreamUnix("", src)
	if !s.NoError(err) {
		return
	}

	// Unix
	var dest bytes.Buffer
	s.Error(acomm.Stream(nil, addr), "should fail without dest")
	s.Equal(0, dest.Len(), "should not have streamed any data")

	s.Error(acomm.Stream(&dest, nil), "should fail without addr")
	s.Equal(0, dest.Len(), "should not have streamed any data")

	s.NoError(acomm.Stream(&dest, addr), "unix stream should not fail")
	s.Equal(data, dest.Bytes(), "unix stream should have streamed data")
	dest.Reset()

	s.Error(acomm.Stream(&dest, addr), "stream should only be available once")
	s.Equal(0, dest.Len(), "should not have streamed any data")
}
コード例 #2
0
ファイル: stream_test.go プロジェクト: mistifyio/acomm
func (s *TrackerTestSuite) TestStreamHTTP() {
	if !s.NoError(s.Tracker.Start(), "failed to start Tracker") {
		return
	}
	data := []byte("foobar")
	src := ioutil.NopCloser(bytes.NewReader(data))
	addr, err := s.Tracker.NewStreamUnix("", src)
	if !s.NoError(err) {
		return
	}
	var dest bytes.Buffer

	// HTTP
	httpAddr, err := s.Tracker.ProxyStreamHTTPURL(nil)
	s.Nil(httpAddr, "shouldn't be able to create HTTP url without stream addr")
	s.Error(err, "shouldn't be able to create HTTP url without stream addr")

	httpAddr, err = s.Tracker.ProxyStreamHTTPURL(addr)
	s.NotNil(httpAddr, "should be able to create HTTP url with stream addr")
	s.NoError(err, "should be able to create HTTP url with stream addr")

	s.NoError(acomm.Stream(&dest, httpAddr), "http stream should not fail")
	s.Equal(data, dest.Bytes(), "http stream should have streamed data")
	dest.Reset()
}
コード例 #3
0
ファイル: main.go プロジェクト: mistifyio/coordinator
func main() {
	log.SetLevel(log.FatalLevel)

	var coordinator, responseAddr, taskName string
	var taskArgs []string
	flags.StringVarP(&coordinator, "coordinator_url", "c", "", "url of the coordinator")
	flags.StringVarP(&taskName, "task", "t", "", "task to run")
	flags.StringSliceVarP(&taskArgs, "request_arg", "a", []string{}, fmt.Sprintf("task specific argument the form 'key%svalue'. can be set multiple times", argSep))
	flags.StringVarP(&responseAddr, "response_addr", "r", ":4080", "address for response http handler to listen on")
	flags.Parse()

	args, err := parseTaskArgs(taskArgs)
	dieOnError(err)

	result, stream, respErr, err := startResponseServer(responseAddr)
	dieOnError(err)

	dieOnError(makeRequest(coordinator, taskName, responseAddr, args))

	select {
	case err := <-respErr:
		dieOnError(err)
	case result := <-result:
		j, _ := json.Marshal(result)
		fmt.Println(string(j))
	case stream := <-stream:
		dieOnError(acomm.Stream(os.Stdout, stream))
	}
}