當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Container.Run方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry-incubator/garden/warden.Container.Run方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.Run方法的具體用法?Golang Container.Run怎麽用?Golang Container.Run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry-incubator/garden/warden.Container的用法示例。


在下文中一共展示了Container.Run方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

		container, err = client.Create(warden.ContainerSpec{})
		Expect(err).ToNot(HaveOccurred())
	})

	AfterEach(func() {
		err := runner.Stop()
		Expect(err).ToNot(HaveOccurred())

		err = runner.Start()
		Expect(err).ToNot(HaveOccurred())
	})

	Context("when a request takes longer than the grace time", func() {
		It("is not destroyed after the request is over", func() {
			_, _, err := container.Run(warden.ProcessSpec{Script: "sleep 6"})
			Expect(err).ToNot(HaveOccurred())

			_, err = container.Info()
			Expect(err).ToNot(HaveOccurred())
		})
	})

	Context("when no requests are made for longer than the grace time", func() {
		It("is destroyed", func() {
			time.Sleep(6 * time.Second)

			_, err := container.Info()
			Expect(err).To(HaveOccurred())
		})
	})
開發者ID:vito,項目名稱:warden-linux,代碼行數:30,代碼來源:grace_time_test.go

示例2:

				var started time.Time
				var receivedBytes uint64

				numToSpawn := streams

				BeforeEach(func() {
					atomic.StoreUint64(&receivedBytes, 0)
					started = time.Now()

					spawned := make(chan bool)

					for j := 0; j < numToSpawn; j++ {
						go func() {
							defer GinkgoRecover()
							_, results, err := container.Run(warden.ProcessSpec{
								Script: "cat /dev/zero",
							})
							Expect(err).ToNot(HaveOccurred())

							go func(results <-chan warden.ProcessStream) {
								for {
									res, ok := <-results
									if !ok {
										break
									}

									atomic.AddUint64(&receivedBytes, uint64(len(res.Data)))
								}
							}(results)

							spawned <- true
開發者ID:vito,項目名稱:warden-linux,代碼行數:31,代碼來源:stream_measure_test.go

示例3:

				exitStatus := uint32(123)
				stream <- warden.ProcessStream{
					ExitStatus: &exitStatus,
				}

				close(stream)

				return 42, stream, nil
			}

			spec := warden.ProcessSpec{
				Script: "some-script",
			}

			pid, stream, err := container.Run(spec)
			Ω(err).ShouldNot(HaveOccurred())
			Ω(pid).Should(Equal(uint32(42)))

			Ω(fakeConnection.SpawnedProcesses("some-handle")).Should(ContainElement(spec))

			Ω(<-stream).Should(Equal(warden.ProcessStream{
				Source: warden.ProcessStreamSourceStdout,
				Data:   []byte("stdout data"),
			}))

			Ω(<-stream).Should(Equal(warden.ProcessStream{
				Source: warden.ProcessStreamSourceStderr,
				Data:   []byte("stderr data"),
			}))
開發者ID:vito,項目名稱:warden-linux,代碼行數:29,代碼來源:container_test.go

示例4:

	BeforeEach(func() {
		var err error

		container, err = client.Create(warden.ContainerSpec{})
		Expect(err).ToNot(HaveOccurred())
	})

	AfterEach(func() {
		err := client.Destroy(container.Handle())
		Expect(err).ToNot(HaveOccurred())
	})

	It("sources /etc/seed", func() {
		_, stream, err := container.Run(warden.ProcessSpec{
			Script: "test -e /tmp/ran-seed",
		})
		Expect(err).ToNot(HaveOccurred())

		for chunk := range stream {
			if chunk.ExitStatus != nil {
				Expect(*chunk.ExitStatus).To(Equal(uint32(0)))
			}
		}
	})

	It("should provide 64k of /dev/shm within the container", func() {
		command1 := "df|grep /dev/shm|grep 342678243768342867432"
		command2 := "mount|grep /dev/shm|grep tmpfs"
		_, _, err := container.Run(warden.ProcessSpec{
			Script: fmt.Sprintf("%s && %s", command1, command2),
開發者ID:vito,項目名稱:warden-linux,代碼行數:30,代碼來源:lifecycle_test.go

示例5:

		err = runner.Start()
		Expect(err).ToNot(HaveOccurred())
	}

	It("retains the container list", func() {
		restartServer()

		handles := getContainerHandles()
		Expect(handles).To(ContainElement(container.Handle()))
	})

	Describe("a started job", func() {
		It("continues to stream", func() {
			processID, runStream, err := container.Run(warden.ProcessSpec{
				Script: "while true; do echo hi; sleep 0.5; done",
			})

			Expect(err).ToNot(HaveOccurred())

			restartServer()

			Eventually(runStream).Should(BeClosed())

			stream, err := container.Attach(processID)
			Expect(err).ToNot(HaveOccurred())

			var chunk warden.ProcessStream
			Eventually(stream).Should(Receive(&chunk))
			Expect(chunk.Data).To(ContainSubstring("hi\n"))
		})
開發者ID:vito,項目名稱:warden-linux,代碼行數:30,代碼來源:drain_test.go


注:本文中的github.com/cloudfoundry-incubator/garden/warden.Container.Run方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。