本文整理匯總了Golang中github.com/cloudfoundry-incubator/garden/warden.Container.Handle方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.Handle方法的具體用法?Golang Container.Handle怎麽用?Golang Container.Handle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry-incubator/garden/warden.Container
的用法示例。
在下文中一共展示了Container.Handle方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
var container warden.Container
BeforeEach(func() {
var err error
container, err = client.Create(warden.ContainerSpec{
Properties: warden.Properties{
"foo": "bar",
"a": "b",
},
})
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err := client.Destroy(container.Handle())
Expect(err).ToNot(HaveOccurred())
})
Describe("when reporting the container's info", func() {
It("includes the properties", func() {
info, err := container.Info()
Ω(err).ShouldNot(HaveOccurred())
Ω(info.Properties["foo"]).Should(Equal("bar"))
Ω(info.Properties["a"]).Should(Equal("b"))
Ω(info.Properties).Should(HaveLen(2))
})
})
示例2:
atomic.AddUint64(&receivedBytes, uint64(len(res.Data)))
}
}(results)
spawned <- true
}()
}
for j := 0; j < numToSpawn; j++ {
<-spawned
}
})
AfterEach(func() {
err := client.Destroy(container.Handle())
Expect(err).ToNot(HaveOccurred())
})
Measure("it should not adversely affect the rest of the API", func(b Benchmarker) {
var newContainer warden.Container
b.Time("creating another container", func() {
var err error
newContainer, err = client.Create(warden.ContainerSpec{})
Expect(err).ToNot(HaveOccurred())
})
for i := 0; i < 10; i++ {
b.Time("getting container info (10x)", func() {
示例3: reapContainer
func (s *WardenServer) reapContainer(container warden.Container) {
log.Printf("reaping %s (idle for %s)\n", container.Handle(), s.backend.GraceTime(container))
s.backend.Destroy(container.Handle())
}
示例4:
. "github.com/onsi/gomega"
archiver "github.com/pivotal-golang/archiver/extractor/test_helper"
)
var _ = Describe("Creating a container", func() {
var container warden.Container
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)))
}
}
})
示例5:
BeforeEach(func() {
fakeContainerPool = fake_container_pool.New()
fakeSystemInfo := fake_system_info.NewFakeProvider()
linuxBackend = linux_backend.New(fakeContainerPool, fakeSystemInfo, "")
newContainer, err := linuxBackend.Create(warden.ContainerSpec{})
Expect(err).ToNot(HaveOccurred())
container = newContainer
})
It("removes the given container from the pool", func() {
Expect(fakeContainerPool.DestroyedContainers).To(BeEmpty())
err := linuxBackend.Destroy(container.Handle())
Expect(err).ToNot(HaveOccurred())
Expect(fakeContainerPool.DestroyedContainers).To(ContainElement(container))
})
It("unregisters the container", func() {
err := linuxBackend.Destroy(container.Handle())
Expect(err).ToNot(HaveOccurred())
_, err = linuxBackend.Lookup(container.Handle())
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(linux_backend.UnknownHandleError{container.Handle()}))
})
Context("when the container does not exist", func() {
示例6:
JustBeforeEach(func() {
var err error
client := New(connectionProvider)
fakeConnection.WhenCreating = func(warden.ContainerSpec) (string, error) {
return "some-handle", nil
}
container, err = client.Create(warden.ContainerSpec{})
Ω(err).ShouldNot(HaveOccurred())
})
Describe("Handle", func() {
It("returns the container's handle", func() {
Ω(container.Handle()).Should(Equal("some-handle"))
})
})
Describe("Stop", func() {
It("sends a stop request", func() {
err := container.Stop(true)
Ω(err).ShouldNot(HaveOccurred())
Ω(fakeConnection.Stopped("some-handle")).Should(ContainElement(
fake_connection.StopSpec{
Background: false,
Kill: true,
},
))
})
示例7:
runner.Stop()
runner.Start(
"-denyNetworks", strings.Join([]string{
blockedListenerIP + "/32",
allowedListenerIP + "/32",
}, ","),
"-allowNetworks", allowedListenerIP+"/32",
)
// create a container with the new deny network configuration
sender, err = client.Create(warden.ContainerSpec{})
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err := client.Destroy(sender.Handle())
Expect(err).ToNot(HaveOccurred())
err = client.Destroy(blockedListener.Handle())
Expect(err).ToNot(HaveOccurred())
err = client.Destroy(unblockedListener.Handle())
Expect(err).ToNot(HaveOccurred())
err = client.Destroy(allowedListener.Handle())
Expect(err).ToNot(HaveOccurred())
})
expectStreamToExitWith := func(stream <-chan warden.ProcessStream, status int) {
for chunk := range stream {
if chunk.ExitStatus != nil {
示例8:
Expect(err).ToNot(HaveOccurred())
})
restartServer := func() {
err := runner.Stop()
Expect(err).ToNot(HaveOccurred())
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)