本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/jobsupervisor/fakes.FakeJobSupervisor類的典型用法代碼示例。如果您正苦於以下問題:Golang FakeJobSupervisor類的具體用法?Golang FakeJobSupervisor怎麽用?Golang FakeJobSupervisor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeJobSupervisor類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
fakeas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec/fakes"
boshassert "github.com/cloudfoundry/bosh-agent/assert"
fakejobsuper "github.com/cloudfoundry/bosh-agent/jobsupervisor/fakes"
boshntp "github.com/cloudfoundry/bosh-agent/platform/ntp"
fakentp "github.com/cloudfoundry/bosh-agent/platform/ntp/fakes"
boshvitals "github.com/cloudfoundry/bosh-agent/platform/vitals"
fakevitals "github.com/cloudfoundry/bosh-agent/platform/vitals/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
fakesettings "github.com/cloudfoundry/bosh-agent/settings/fakes"
)
var _ = Describe("GetState", func() {
var (
settingsService *fakesettings.FakeSettingsService
specService *fakeas.FakeV1Service
jobSupervisor *fakejobsuper.FakeJobSupervisor
vitalsService *fakevitals.FakeService
action GetStateAction
)
BeforeEach(func() {
settingsService = &fakesettings.FakeSettingsService{}
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
vitalsService = fakevitals.NewFakeService()
ntpService := &fakentp.FakeService{
GetOffsetNTPOffset: boshntp.NTPInfo{
Offset: "0.34958",
Timestamp: "12 Oct 17:37:58",
},
}
示例2:
boshassert "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/assert"
boshjobsuper "github.com/cloudfoundry/bosh-agent/jobsupervisor"
fakejobsuper "github.com/cloudfoundry/bosh-agent/jobsupervisor/fakes"
boshntp "github.com/cloudfoundry/bosh-agent/platform/ntp"
fakentp "github.com/cloudfoundry/bosh-agent/platform/ntp/fakes"
boshvitals "github.com/cloudfoundry/bosh-agent/platform/vitals"
fakevitals "github.com/cloudfoundry/bosh-agent/platform/vitals/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
fakesettings "github.com/cloudfoundry/bosh-agent/settings/fakes"
)
var _ = Describe("GetState", func() {
var (
settingsService *fakesettings.FakeSettingsService
specService *fakeas.FakeV1Service
jobSupervisor *fakejobsuper.FakeJobSupervisor
vitalsService *fakevitals.FakeService
action GetStateAction
)
BeforeEach(func() {
settingsService = &fakesettings.FakeSettingsService{}
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
vitalsService = fakevitals.NewFakeService()
ntpService := &fakentp.FakeService{
GetOffsetNTPOffset: boshntp.Info{
Offset: "0.34958",
Timestamp: "12 Oct 17:37:58",
},
}
示例3:
fakeas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec/fakes"
boshscript "github.com/cloudfoundry/bosh-agent/agent/script"
boshdrain "github.com/cloudfoundry/bosh-agent/agent/script/drain"
fakedrain "github.com/cloudfoundry/bosh-agent/agent/script/drain/fakes"
fakescript "github.com/cloudfoundry/bosh-agent/agent/script/fakes"
fakejobsuper "github.com/cloudfoundry/bosh-agent/jobsupervisor/fakes"
fakenotif "github.com/cloudfoundry/bosh-agent/notification/fakes"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
var _ = Describe("DrainAction", func() {
var (
notifier *fakenotif.FakeNotifier
specService *fakeas.FakeV1Service
jobScriptProvider *fakescript.FakeJobScriptProvider
fakeScripts map[string]*fakedrain.FakeScript
jobSupervisor *fakejobsuper.FakeJobSupervisor
action DrainAction
logger boshlog.Logger
)
BeforeEach(func() {
fakeScripts = make(map[string]*fakedrain.FakeScript)
logger = boshlog.NewLogger(boshlog.LevelNone)
notifier = fakenotif.NewFakeNotifier()
specService = fakeas.NewFakeV1Service()
jobScriptProvider = &fakescript.FakeJobScriptProvider{}
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
action = NewDrain(notifier, specService, jobScriptProvider, jobSupervisor, logger)
})
示例4: init
func init() {
Describe("concreteApplier", func() {
var (
jobApplier *fakejobs.FakeApplier
packageApplier *fakepackages.FakeApplier
logRotateDelegate *FakeLogRotateDelegate
jobSupervisor *fakejobsuper.FakeJobSupervisor
applier Applier
)
BeforeEach(func() {
jobApplier = fakejobs.NewFakeApplier()
packageApplier = fakepackages.NewFakeApplier()
logRotateDelegate = &FakeLogRotateDelegate{}
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
applier = NewConcreteApplier(
jobApplier,
packageApplier,
logRotateDelegate,
jobSupervisor,
boshdirs.NewProvider("/fake-base-dir"),
)
})
Describe("Prepare", func() {
It("prepares each jobs", func() {
job := buildJob()
err := applier.Prepare(
&fakeas.FakeApplySpec{JobResults: []models.Job{job}},
)
Expect(err).ToNot(HaveOccurred())
Expect(jobApplier.PreparedJobs).To(Equal([]models.Job{job}))
})
It("returns error when preparing jobs fails", func() {
job := buildJob()
jobApplier.PrepareError = errors.New("fake-prepare-job-error")
err := applier.Prepare(
&fakeas.FakeApplySpec{JobResults: []models.Job{job}},
)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-prepare-job-error"))
})
It("prepares each packages", func() {
pkg1 := buildPackage()
pkg2 := buildPackage()
err := applier.Prepare(
&fakeas.FakeApplySpec{PackageResults: []models.Package{pkg1, pkg2}},
)
Expect(err).ToNot(HaveOccurred())
Expect(packageApplier.PreparedPackages).To(Equal([]models.Package{pkg1, pkg2}))
})
It("returns error when preparing packages fails", func() {
pkg := buildPackage()
packageApplier.PrepareError = errors.New("fake-prepare-package-error")
err := applier.Prepare(
&fakeas.FakeApplySpec{PackageResults: []models.Package{pkg}},
)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-prepare-package-error"))
})
})
Describe("Configure jobs", func() {
It("reloads job supervisor", func() {
job1 := models.Job{Name: "fake-job-name-1", Version: "fake-version-name-1"}
job2 := models.Job{Name: "fake-job-name-2", Version: "fake-version-name-2"}
jobs := []models.Job{job1, job2}
err := applier.ConfigureJobs(&fakeas.FakeApplySpec{JobResults: jobs})
Expect(err).ToNot(HaveOccurred())
Expect(jobSupervisor.Reloaded).To(BeTrue())
})
It("configures jobs", func() {
job1 := models.Job{Name: "fake-job-name-1", Version: "fake-version-name-1"}
job2 := models.Job{Name: "fake-job-name-2", Version: "fake-version-name-2"}
jobs := []models.Job{job1, job2}
err := applier.ConfigureJobs(&fakeas.FakeApplySpec{JobResults: jobs})
Expect(err).ToNot(HaveOccurred())
Expect(jobApplier.ConfiguredJobs).To(ConsistOf(job1, job2))
})
})
Describe("Apply", func() {
It("removes all jobs from job supervisor", func() {
err := applier.Apply(&fakeas.FakeApplySpec{}, &fakeas.FakeApplySpec{})
Expect(err).ToNot(HaveOccurred())
//.........這裏部分代碼省略.........
示例5: init
func init() {
Describe("Agent", func() {
var (
logger boshlog.Logger
handler *fakembus.FakeHandler
platform *fakeplatform.FakePlatform
actionDispatcher *fakeagent.FakeActionDispatcher
jobSupervisor *fakejobsuper.FakeJobSupervisor
specService *fakeas.FakeV1Service
syslogServer *fakesyslog.FakeServer
settingsService *fakesettings.FakeSettingsService
uuidGenerator *fakeuuid.FakeGenerator
timeService *fakeclock.FakeClock
agent Agent
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
handler = &fakembus.FakeHandler{}
platform = fakeplatform.NewFakePlatform()
actionDispatcher = &fakeagent.FakeActionDispatcher{}
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
syslogServer = &fakesyslog.FakeServer{}
settingsService = &fakesettings.FakeSettingsService{}
uuidGenerator = &fakeuuid.FakeGenerator{}
timeService = fakeclock.NewFakeClock(time.Now())
agent = New(
logger,
handler,
platform,
actionDispatcher,
jobSupervisor,
specService,
syslogServer,
5*time.Millisecond,
settingsService,
uuidGenerator,
timeService,
)
})
Describe("Run", func() {
It("lets dispatcher handle requests arriving via handler", func() {
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
expectedResp := boshhandler.NewValueResponse("pong")
actionDispatcher.DispatchResp = expectedResp
req := boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
resp := handler.RunFunc(req)
Expect(actionDispatcher.DispatchReq).To(Equal(req))
Expect(resp).To(Equal(expectedResp))
})
It("resumes persistent actions *before* dispatching new requests", func() {
resumedBeforeStartingToDispatch := false
handler.RunCallBack = func() {
resumedBeforeStartingToDispatch = actionDispatcher.ResumedPreviouslyDispatchedTasks
}
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(resumedBeforeStartingToDispatch).To(BeTrue())
})
Context("when heartbeats can be sent", func() {
BeforeEach(func() {
handler.KeepOnRunning()
})
BeforeEach(func() {
jobName := "fake-job"
nodeID := "node-id"
jobIndex := 1
specService.Spec = boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{Name: &jobName},
Index: &jobIndex,
NodeID: nodeID,
}
jobSupervisor.StatusStatus = "fake-state"
platform.FakeVitalsService.GetVitals = boshvitals.Vitals{
Load: []string{"a", "b", "c"},
}
})
expectedJobName := "fake-job"
expectedJobIndex := 1
expectedNodeID := "node-id"
expectedHb := Heartbeat{
Job: &expectedJobName,
Index: &expectedJobIndex,
JobState: "fake-state",
NodeID: expectedNodeID,
Vitals: boshvitals.Vitals{Load: []string{"a", "b", "c"}},
}
//.........這裏部分代碼省略.........
示例6: init
func init() {
Describe("DrainAction", func() {
var (
notifier *fakenotif.FakeNotifier
specService *fakeas.FakeV1Service
drainScriptProvider *fakedrain.FakeDrainScriptProvider
jobSupervisor *fakejobsuper.FakeJobSupervisor
action DrainAction
)
BeforeEach(func() {
notifier = fakenotif.NewFakeNotifier()
specService = fakeas.NewFakeV1Service()
drainScriptProvider = fakedrain.NewFakeDrainScriptProvider()
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
action = NewDrain(notifier, specService, drainScriptProvider, jobSupervisor)
})
BeforeEach(func() {
drainScriptProvider.NewDrainScriptDrainScript.ExistsBool = true
})
It("is asynchronous", func() {
Expect(action.IsAsynchronous()).To(BeTrue())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
Context("when drain update is requested", func() {
act := func() (int, error) { return action.Run(DrainTypeUpdate, boshas.V1ApplySpec{}) }
Context("when current agent has a job spec template", func() {
var currentSpec boshas.V1ApplySpec
BeforeEach(func() {
currentSpec = boshas.V1ApplySpec{}
currentSpec.JobSpec.Template = "foo"
specService.Spec = currentSpec
})
It("unmonitors services so that drain scripts can kill processes on their own", func() {
value, err := act()
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal(1))
Expect(jobSupervisor.Unmonitored).To(BeTrue())
})
Context("when unmonitoring services succeeds", func() {
It("does not notify of job shutdown", func() {
value, err := act()
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal(1))
Expect(notifier.NotifiedShutdown).To(BeFalse())
})
Context("when new apply spec is provided", func() {
newSpec := boshas.V1ApplySpec{
PackageSpecs: map[string]boshas.PackageSpec{
"foo": boshas.PackageSpec{
Name: "foo",
Sha1: "foo-sha1-new",
},
},
}
Context("when drain script exists", func() {
It("runs drain script with job_shutdown param", func() {
value, err := action.Run(DrainTypeUpdate, newSpec)
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal(1))
Expect(drainScriptProvider.NewDrainScriptTemplateName).To(Equal("foo"))
Expect(drainScriptProvider.NewDrainScriptDrainScript.DidRun).To(BeTrue())
params := drainScriptProvider.NewDrainScriptDrainScript.RunParams
Expect(params).To(Equal(boshdrain.NewUpdateDrainParams(currentSpec, newSpec)))
})
Context("when drain script runs and errs", func() {
It("returns error", func() {
drainScriptProvider.NewDrainScriptDrainScript.RunError = errors.New("fake-drain-run-error")
value, err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-drain-run-error"))
Expect(value).To(Equal(0))
})
})
})
Context("when drain script does not exist", func() {
It("returns 0", func() {
drainScriptProvider.NewDrainScriptDrainScript.ExistsBool = false
value, err := act()
Expect(err).ToNot(HaveOccurred())
//.........這裏部分代碼省略.........