本文整理匯總了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())
})
})
示例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
示例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"),
}))
示例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),
示例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"))
})