fakeClock *fakeclock.FakeClock eventHub *efakes.FakeHub allocationStore depot.AllocationStore gardenStore *fakes.FakeGardenStore resources executor.ExecutorResources lockManager *fakelockmanager.FakeLockManager ) BeforeEach(func() { logger = lagertest.NewTestLogger("test") fakeClock = fakeclock.NewFakeClock(time.Now()) eventHub = new(efakes.FakeHub) allocationStore = allocationstore.NewAllocationStore(fakeClock, eventHub) gardenStore = new(fakes.FakeGardenStore) resources = executor.ExecutorResources{ MemoryMB: 1024, DiskMB: 1024, Containers: 3, } lockManager = &fakelockmanager.FakeLockManager{} workPoolSettings := executor.WorkPoolSettings{ CreateWorkPoolSize: 5, DeleteWorkPoolSize: 5, ReadWorkPoolSize: 5, MetricsWorkPoolSize: 5,
func Initialize(logger lager.Logger, config Configuration, clock clock.Clock) (executor.Client, grouper.Members, error) { gardenClient := GardenClient.New(GardenConnection.New(config.GardenNetwork, config.GardenAddr)) err := waitForGarden(logger, gardenClient, clock) if err != nil { return nil, nil, err } containersFetcher := &executorContainers{ gardenClient: gardenClient, owner: config.ContainerOwnerName, } destroyContainers(gardenClient, containersFetcher, logger) workDir := setupWorkDir(logger, config.TempDir) transformer := initializeTransformer( logger, config.CachePath, workDir, config.MaxCacheSizeInBytes, uint(config.MaxConcurrentDownloads), maxConcurrentUploads, config.SkipCertVerify, config.ExportNetworkEnvVars, clock, ) hub := event.NewHub() gardenStore, err := gardenstore.NewGardenStore( gardenClient, config.ContainerOwnerName, config.ContainerMaxCpuShares, config.ContainerInodeLimit, config.HealthyMonitoringInterval, config.UnhealthyMonitoringInterval, transformer, clock, hub, config.HealthCheckWorkPoolSize, ) if err != nil { return nil, grouper.Members{}, err } allocationStore := allocationstore.NewAllocationStore(clock, hub) workPoolSettings := executor.WorkPoolSettings{ CreateWorkPoolSize: config.CreateWorkPoolSize, DeleteWorkPoolSize: config.DeleteWorkPoolSize, ReadWorkPoolSize: config.ReadWorkPoolSize, MetricsWorkPoolSize: config.MetricsWorkPoolSize, } depotClientProvider, err := depot.NewClientProvider( fetchCapacity(logger, gardenClient, config), allocationStore, gardenStore, hub, keyed_lock.NewLockManager(), workPoolSettings, ) if err != nil { return nil, grouper.Members{}, err } metricsLogger := logger.Session("metrics-reporter") containerMetricsLogger := logger.Session("container-metrics-reporter") return depotClientProvider.WithLogger(logger), grouper.Members{ {"metrics-reporter", &metrics.Reporter{ ExecutorSource: depotClientProvider.WithLogger(metricsLogger), Interval: metricsReportInterval, Logger: metricsLogger, }}, {"hub-closer", closeHub(hub)}, {"registry-pruner", allocationStore.RegistryPruner(logger, config.RegistryPruningInterval)}, {"container-metrics-reporter", containermetrics.NewStatsReporter( containerMetricsLogger, containerMetricsReportInterval, clock, depotClientProvider.WithLogger(containerMetricsLogger), )}, }, nil }
var logger = lagertest.NewTestLogger("test") var _ = Describe("Allocation Store", func() { var ( allocationStore *allocationstore.AllocationStore fakeClock *fakeclock.FakeClock fakeEventEmitter *fakes.FakeEventEmitter currentTime time.Time ) BeforeEach(func() { currentTime = time.Now() fakeClock = fakeclock.NewFakeClock(currentTime) fakeEventEmitter = &fakes.FakeEventEmitter{} allocationStore = allocationstore.NewAllocationStore(fakeClock, fakeEventEmitter) }) Describe("List", func() { Context("when a container is allocated", func() { var req executor.AllocationRequest BeforeEach(func() { resource := executor.NewResource(512, 512, "") req = executor.NewAllocationRequest("banana", &resource, nil) _, err := allocationStore.Allocate(logger, &req) Expect(err).NotTo(HaveOccurred()) }) It("is included in the list", func() { allocations := allocationStore.List()