"code.cloudfoundry.org/bbs/db/sqldb"
	"code.cloudfoundry.org/bbs/migration"
	"code.cloudfoundry.org/clock/fakeclock"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Add Placement Tags to Desired LRPs", func() {
	var (
		mig       migration.Migration
		migErr    error
		fakeClock *fakeclock.FakeClock
	)

	BeforeEach(func() {
		fakeClock = fakeclock.NewFakeClock(time.Now())
		rawSQLDB.Exec("DROP TABLE domains;")
		rawSQLDB.Exec("DROP TABLE tasks;")
		rawSQLDB.Exec("DROP TABLE desired_lrps;")
		rawSQLDB.Exec("DROP TABLE actual_lrps;")

		mig = migrations.NewAddPlacementTagsToDesiredLRPs()
	})

	It("appends itself to the migration list", func() {
		Expect(migrations.Migrations).To(ContainElement(mig))
	})

	Describe("Version", func() {
		It("returns the timestamp from which it was created", func() {
			Expect(mig.Version()).To(BeEquivalentTo(1472757022))
		fakeDriverFactory *volmanfakes.FakeDriverFactory
		fakeDriver        *voldriverfakes.FakeDriver
		fakeClock         *fakeclock.FakeClock

		scanInterval time.Duration

		driverRegistry vollocal.DriverRegistry
		driverSyncer   vollocal.DriverSyncer

		process ifrit.Process
	)

	BeforeEach(func() {
		fakeDriverFactory = new(volmanfakes.FakeDriverFactory)
		fakeClock = fakeclock.NewFakeClock(time.Unix(123, 456))

		scanInterval = 1 * time.Second

		driverRegistry = vollocal.NewDriverRegistry()
	})

	Describe("ListDrivers", func() {
		BeforeEach(func() {
			driverSyncer = vollocal.NewDriverSyncerWithDriverFactory(logger, driverRegistry, []string{"/somePath"}, scanInterval, fakeClock, fakeDriverFactory)
			client = vollocal.NewLocalClient(logger, driverRegistry, fakeClock)

			process = ginkgomon.Invoke(driverSyncer.Runner())
		})

		It("should report empty list of drivers", func() {
Esempio n. 3
0
		lockKey = locket.LockSchemaPath("some-key")
		lockKeyMetric := strings.Replace(lockKey, "/", "-", -1)
		lockHeldMetricName = "LockHeld." + lockKeyMetric
		lockUptimeMetricName = "LockHeldDuration." + lockKeyMetric
		lockValue = []byte("some-value")

		retryInterval = 500 * time.Millisecond
		lockTTL = 5 * time.Second
		logger = lagertest.NewTestLogger("locket")

		sender = fake.NewFakeMetricSender()
		metrics.Initialize(sender, nil)
	})

	JustBeforeEach(func() {
		clock = fakeclock.NewFakeClock(time.Now())
		lockRunner = locket.NewLock(logger, consulClient, lockKey, lockValue, clock, retryInterval, lockTTL)
	})

	AfterEach(func() {
		ginkgomon.Kill(lockProcess)
	})

	var shouldEventuallyHaveNumSessions = func(numSessions int) {
		Eventually(func() int {
			sessions, _, err := consulClient.Session().List(nil)
			Expect(err).NotTo(HaveOccurred())
			return len(sessions)
		}).Should(Equal(numSessions))
	}
Esempio n. 4
0
var clock *fakeclock.FakeClock
var etcdHelper *etcd_helpers.ETCDHelper

var etcdDB db.DB
var etcdDBWithFakeStore db.DB
var workPoolCreateError error

var cryptor encryption.Cryptor

func TestDB(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "ETCD DB Suite")
}

var _ = BeforeSuite(func() {
	clock = fakeclock.NewFakeClock(time.Unix(0, 1138))

	etcdPort = 4001 + GinkgoParallelNode()
	etcdUrl = fmt.Sprintf("http://127.0.0.1:%d", etcdPort)
	etcdRunner = etcdstorerunner.NewETCDClusterRunner(etcdPort, 1, nil)

	etcdRunner.Start()

	Expect(workPoolCreateError).ToNot(HaveOccurred())

	encryptionKey, err := encryption.NewKey("label", "passphrase")
	Expect(err).NotTo(HaveOccurred())
	keyManager, err := encryption.NewKeyManager(encryptionKey, nil)
	Expect(err).NotTo(HaveOccurred())
	cryptor = encryption.NewCryptor(keyManager, rand.Reader)
})
Esempio n. 5
0
		taskSelector *fakes.FakeTaskSelector
		csSleep      time.Duration
		clk          *fakeclock.FakeClock
	)

	BeforeEach(func() {
		logger = &logrus.Logger{
			Out:       GinkgoWriter,
			Level:     logrus.DebugLevel,
			Formatter: new(logrus.TextFormatter),
		}
		taskSelector = new(fakes.FakeTaskSelector)
		csSleep = time.Millisecond * 5
		t, err := time.Parse(time.RFC3339, "2015-11-24T06:30:00+00:00")
		Expect(err).NotTo(HaveOccurred())
		clk = fakeclock.NewFakeClock(t)

		sched = scheduler.NewScheduler(
			logger,
			taskSelector,
			csSleep,
			clk,
		)
	})

	Describe("Close", func() {
		Context("when the scheduler is not running", func() {
			It("should return an error", func() {
				Expect(sched.Stop()).NotTo(Succeed())
			})
		})