Example #1
0
			})

			It("sets up logger", func() {
				logLevel = false
				_, logger := main.ParseConfig(&logLevel, &configFile, &logFilePath)
				Expect(logger.Level().String()).To(Equal("info"))

				logLevel = true
				_, logger = main.ParseConfig(&logLevel, &configFile, &logFilePath)
				Expect(logger.Level().String()).To(Equal("debug"))
			})
		})
	})

	Describe("StartHeartbeats", func() {
		var adapter *fakestoreadapter.FakeStoreAdapter

		BeforeEach(func() {
			adapter = fakestoreadapter.New()
		})

		Context("when store adapter is nil", func() {
			var conf config.Config
			var localIp string

			BeforeEach(func() {
				localIp, _ = localip.LocalIP()
				conf = config.Config{
					JobName: "doppler_z1",
					Index:   0,
					EtcdMaxConcurrentRequests: 10,
Example #2
0
import (
	"errors"
	"syslog_drain_binder/elector"
	"time"

	"github.com/cloudfoundry/gosteno"
	"github.com/cloudfoundry/storeadapter"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Elector", func() {
	var fakeStore *fakestoreadapter.FakeStoreAdapter
	var logger *gosteno.Logger
	var testingSink *gosteno.TestingSink

	BeforeEach(func() {
		gosteno.EnterTestMode()
		testingSink = gosteno.GetMeTheGlobalTestSink()

		fakeStore = fakestoreadapter.New()
		logger = gosteno.NewLogger("test")
	})

	Context("at initialization", func() {
		It("connects to the store", func() {
			elector.NewElector("name", fakeStore, 1*time.Millisecond, logger)
			Expect(fakeStore.DidConnect).To(BeTrue())
	"errors"
	"github.com/cloudfoundry/hm9000/config"
	. "github.com/cloudfoundry/hm9000/helpers/metricsaccountant"
	"github.com/cloudfoundry/hm9000/models"
	storepackage "github.com/cloudfoundry/hm9000/store"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"time"
)

var _ = Describe("Metrics Accountant", func() {
	var store storepackage.Store
	var accountant MetricsAccountant
	var fakeStoreAdapter *fakestoreadapter.FakeStoreAdapter

	conf, _ := config.DefaultConfig()

	BeforeEach(func() {
		fakeStoreAdapter = fakestoreadapter.New()
		store = storepackage.NewStore(conf, fakeStoreAdapter, fakelogger.NewFakeLogger())
		accountant = New(store)
	})

	Describe("Getting Metrics", func() {
		Context("when the store is empty", func() {
			It("should return a map of 0s", func() {
				metrics, err := accountant.GetMetrics()
				Ω(err).ShouldNot(HaveOccurred())
				Ω(metrics).Should(Equal(map[string]float64{
	"github.com/cloudfoundry/hm9000/config"
	"github.com/cloudfoundry/hm9000/models"
	storepackage "github.com/cloudfoundry/hm9000/store"
	"github.com/cloudfoundry/hm9000/testhelpers/appfixture"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	"github.com/cloudfoundry/yagnats"
	"github.com/cloudfoundry/yagnats/fakeyagnats"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"time"
)

var _ = Describe("Apiserver", func() {
	var store storepackage.Store
	var storeAdapter *fakestoreadapter.FakeStoreAdapter
	var timeProvider *faketimeprovider.FakeTimeProvider
	var messageBus *fakeyagnats.FakeYagnats

	conf, _ := config.DefaultConfig()

	makeRequest := func(request string) (response string) {
		replyToGuid := models.Guid()
		messageBus.Subscriptions["app.state"][0].Callback(&yagnats.Message{
			Payload: []byte(request),
			ReplyTo: replyToGuid,
		})

		Ω(messageBus.PublishedMessages[replyToGuid]).Should(HaveLen(1))
		return string(messageBus.PublishedMessages[replyToGuid][0].Payload)
	}
Example #5
0
	"errors"
	"time"

	"github.com/cloudfoundry/hm9000/config"
	"github.com/cloudfoundry/hm9000/models"
	storepackage "github.com/cloudfoundry/hm9000/store"
	"github.com/cloudfoundry/hm9000/testhelpers/appfixture"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
)

var _ = Describe("Analyzer", func() {
	var (
		analyzer     *Analyzer
		storeAdapter *fakestoreadapter.FakeStoreAdapter
		store        storepackage.Store
		clock        *fakeclock.FakeClock
		dea          appfixture.DeaFixture
		app          appfixture.AppFixture
	)

	conf, _ := config.DefaultConfig()

	BeforeEach(func() {
		storeAdapter = fakestoreadapter.New()
		store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger())

		clock = fakeclock.NewFakeClock(time.Unix(1000, 0))

		dea = appfixture.NewDeaFixture()
		app = dea.GetApp(0)
	"github.com/cloudfoundry/hm9000/models"
	storepackage "github.com/cloudfoundry/hm9000/store"
	"github.com/cloudfoundry/hm9000/testhelpers/appfixture"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/hm9000/testhelpers/fakemetricsaccountant"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Fetching from CC and storing the result in the Store", func() {
	var (
		fetcher      *desiredstatefetcher.DesiredStateFetcher
		a1           appfixture.AppFixture
		a2           appfixture.AppFixture
		a3           appfixture.AppFixture
		store        storepackage.Store
		resultChan   chan desiredstatefetcher.DesiredStateFetcherResult
		conf         *config.Config
		storeAdapter *fakestoreadapter.FakeStoreAdapter
	)

	BeforeEach(func() {
		storeAdapter = fakestoreadapter.New()
		resultChan = make(chan desiredstatefetcher.DesiredStateFetcherResult, 1)
		a1 = appfixture.NewAppFixture()
		a2 = appfixture.NewAppFixture()
		a3 = appfixture.NewAppFixture()

		stateServer.SetDesiredState([]models.DesiredAppState{
			a1.DesiredState(1),
			a2.DesiredState(1),
Example #7
0
	storepackage "github.com/cloudfoundry/hm9000/store"
	"github.com/cloudfoundry/hm9000/testhelpers/appfixture"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"

	"github.com/cloudfoundry/hm9000/cfcomponent/instrumentation"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotal-golang/clock/fakeclock"
)

var _ = Describe("Metrics Server", func() {
	var (
		store             storepackage.Store
		storeAdapter      *fakestoreadapter.FakeStoreAdapter
		timeProvider      *fakeclock.FakeClock
		metricsServer     *MetricsServer
		metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant
	)

	BeforeEach(func() {
		conf, _ := config.DefaultConfig()
		storeAdapter = fakestoreadapter.New()
		store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger())
		timeProvider = fakeclock.NewFakeClock(time.Unix(100, 0))

		metricsAccountant = &fakemetricsaccountant.FakeMetricsAccountant{}

		metricsServer = New(nil, nil, metricsAccountant, fakelogger.NewFakeLogger(), store, timeProvider, conf)
	})
type brokenReader struct{}

func (b *brokenReader) Read([]byte) (int, error) {
	return 0, errors.New("oh no you didn't!")
}

func (b *brokenReader) Close() error {
	return nil
}

var _ = Describe("DesiredStateFetcher", func() {
	var (
		conf              *config.Config
		fetcher           *DesiredStateFetcher
		httpClient        *fakehttpclient.FakeHttpClient
		timeProvider      *faketimeprovider.FakeTimeProvider
		store             storepackage.Store
		storeAdapter      *fakestoreadapter.FakeStoreAdapter
		resultChan        chan DesiredStateFetcherResult
		metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant
	)

	BeforeEach(func() {
		var err error
		conf, err = config.DefaultConfig()
		Ω(err).ShouldNot(HaveOccurred())

		metricsAccountant = fakemetricsaccountant.New()

		resultChan = make(chan DesiredStateFetcherResult, 1)
		timeProvider = &faketimeprovider.FakeTimeProvider{
			TimeToProvide: time.Unix(100, 0),
Example #9
0
package hm_test

import (
	"errors"
	. "github.com/cloudfoundry/hm9000/hm"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"time"
)

var _ = Describe("Daemon", func() {
	var adapter *fakestoreadapter.FakeStoreAdapter

	BeforeEach(func() {
		adapter = fakestoreadapter.New()
	})

	It("should call the function every PERIOD seconds, unless the function takes *longer* than PERIOD, and it should timeout when the function takes *too* long", func(done Done) {
		defer close(done)

		go func() {
			released := <-adapter.ReleaseNodeChannel
			released <- true
		}()

		callTimes := []float64{}
		startTime := time.Now()
		i := 0
		err := Daemonize("Daemon Test", func() error {
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/hm9000/testhelpers/fakemetricsaccountant"
	"github.com/cloudfoundry/hm9000/testhelpers/fakeusagetracker"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	"github.com/cloudfoundry/yagnats/fakeyagnats"
)

var _ = Describe("Actual state listener", func() {
	var (
		app               AppFixture
		anotherApp        AppFixture
		dea               DeaFixture
		store             storepackage.Store
		storeAdapter      *fakestoreadapter.FakeStoreAdapter
		listener          *ActualStateListener
		timeProvider      *faketimeprovider.FakeTimeProvider
		messageBus        *fakeyagnats.FakeYagnats
		logger            *fakelogger.FakeLogger
		conf              *config.Config
		freshByTime       time.Time
		usageTracker      *fakeusagetracker.FakeUsageTracker
		metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant
	)

	BeforeEach(func() {
		var err error
		conf, err = config.DefaultConfig()

		Ω(err).ShouldNot(HaveOccurred())

		timeProvider = faketimeprovider.New(time.Unix(100, 0))
package hm_test

import (
	"errors"
	. "github.com/cloudfoundry/hm9000/hm"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"time"
)

var _ = Describe("Daemon", func() {
	var adapter *fakestoreadapter.FakeStoreAdapter

	BeforeEach(func() {
		adapter = fakestoreadapter.New()
	})

	It("should call the function every PERIOD seconds, unless the function takes *longer* than PERIOD, and it should timeout when the function takes *too* long", func(done Done) {
		callTimes := []float64{}
		startTime := time.Now()
		i := 0
		err := Daemonize("Daemon Test", func() error {
			callTimes = append(callTimes, time.Since(startTime).Seconds())
			i += 1
			time.Sleep(time.Duration(i*10) * time.Millisecond)
			return nil
		}, 20*time.Millisecond, 35*time.Millisecond, fakelogger.NewFakeLogger(), adapter)

		Ω(callTimes).Should(HaveLen(4))
Example #12
0
package shredder_test

import (
	"github.com/cloudfoundry/hm9000/config"
	. "github.com/cloudfoundry/hm9000/shredder"
	storepackage "github.com/cloudfoundry/hm9000/store"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/storeadapter"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Shredder", func() {
	var (
		shredder     *Shredder
		storeAdapter *fakestoreadapter.FakeStoreAdapter
	)

	BeforeEach(func() {
		storeAdapter = fakestoreadapter.New()
		conf, _ := config.DefaultConfig()
		conf.StoreSchemaVersion = 2
		store := storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger())
		shredder = New(store)

		storeAdapter.SetMulti([]storeadapter.StoreNode{
			{Key: "/hm/v2/pokemon/geodude", Value: []byte{}},
			{Key: "/hm/v2/deep-pokemon/abra/kadabra/alakazam", Value: []byte{}},
			{Key: "/hm/v2/pokemonCount", Value: []byte("151")},
			{Key: "/hm/v1/nuke/me/cause/im/an/old/version", Value: []byte("abc")},
			{Key: "/hm/v3/leave/me/alone/since/im/a/new/version", Value: []byte("abc")},
	"github.com/cloudfoundry/hm9000/testhelpers/appfixture"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/hm9000/testhelpers/fakemetricsaccountant"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	"github.com/cloudfoundry/yagnats/fakeyagnats"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Sender", func() {
	var (
		storeAdapter      *fakestoreadapter.FakeStoreAdapter
		store             storepackage.Store
		sender            *Sender
		messageBus        *fakeyagnats.FakeYagnats
		timeProvider      *faketimeprovider.FakeTimeProvider
		dea               appfixture.DeaFixture
		app               appfixture.AppFixture
		conf              *config.Config
		metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant
	)

	BeforeEach(func() {
		messageBus = fakeyagnats.New()
		dea = appfixture.NewDeaFixture()
		app = dea.GetApp(0)
		conf, _ = config.DefaultConfig()
		metricsAccountant = fakemetricsaccountant.New()

		timeProvider = &faketimeprovider.FakeTimeProvider{
			TimeToProvide: time.Unix(int64(10+conf.ActualFreshnessTTL()), 0),
Example #14
0
		Context("without MonitorIntervalSeconds", func() {
			It("defaults MonitorIntervalSeconds to 60 seconds", func() {
				configFile := "./test_assets/loggregator_trafficcontroller.json"

				var config *main.Config

				config, _, _ = main.ParseConfig(&logLevel, &configFile, &logFilePath)
				Expect(config.MonitorIntervalSeconds).To(Equal(uint(60)))
			})
		})
	})
})

var _ = Describe("MakeProvider", func() {
	var (
		originalEtcdQueryInterval time.Duration
		fakeStoreAdapter          *fakestoreadapter.FakeStoreAdapter
	)

	BeforeEach(func() {
		originalEtcdQueryInterval = main.EtcdQueryInterval

		fakeStoreAdapter = fakestoreadapter.New()

		main.EtcdQueryInterval = 1 * time.Millisecond
	})

	AfterEach(func() {
		main.EtcdQueryInterval = originalEtcdQueryInterval
	})

	It("gets loggregator addresses (with port) from the store", func() {
Example #15
0
package hm_test

import (
	"errors"
	"time"

	. "github.com/cloudfoundry/hm9000/hm"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Daemon", func() {
	var adapter *fakestoreadapter.FakeStoreAdapter

	BeforeEach(func() {
		adapter = fakestoreadapter.New()
	})

	It("should call the function every PERIOD seconds, unless the function takes *longer* than PERIOD, and it should timeout when the function takes *too* long", func() {
		adapter.OnReleaseNodeChannel = func(releaseNodeChannel chan chan bool) {
			released := <-releaseNodeChannel
			released <- true
		}

		adapter.MaintainNodeStatus <- true

		callTimes := make(chan float64, 4)
		i := 0
		var startTime time.Time
Example #16
0
import (
	"doppler/announcer"
	"doppler/config"
	"errors"
	"fmt"
	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"time"
)

var _ = Describe("Announcer", func() {

	var adapter *fakestoreadapter.FakeStoreAdapter

	BeforeEach(func() {
		adapter = fakestoreadapter.New()
	})

	Context("with valid ETCD config", func() {
		var dopplerKey string

		BeforeEach(func() {
			dopplerKey = fmt.Sprintf("/doppler/meta/%s/%s/%d", conf.Zone, conf.JobName, conf.Index)
		})

		It("Panics if etcd returns error", func() {
			err := errors.New("some etcd time out error")
			adapter.MaintainNodeError = err