"encoding/json"
	"fmt"
	. "github.com/cloudfoundry/hm9000/desiredstatefetcher"
	"github.com/cloudfoundry/hm9000/testhelpers/app"
	. "github.com/cloudfoundry/hm9000/testhelpers/custommatchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Desired State Server Response JSON", func() {
	var (
		a        app.App
		response DesiredStateServerResponse
	)
	BeforeEach(func() {
		a = app.NewApp()

		desired, _ := json.Marshal(a.DesiredState(0))
		responseJson := fmt.Sprintf(`
        {
            "results":{"%s":%s},
            "bulk_token":{"id":17}
        }
        `, a.AppGuid, string(desired))

		var err error
		response, err = NewDesiredStateServerResponse([]byte(responseJson))
		Ω(err).ShouldNot(HaveOccured())
	})

	It("can parse from JSON", func() {
Exemple #2
0
		etcdAdapter storeadapter.StoreAdapter
		conf        config.Config
		app1        app.App
		app2        app.App
		app3        app.App
	)

	BeforeEach(func() {
		var err error
		conf, err = config.DefaultConfig()
		Ω(err).ShouldNot(HaveOccured())
		etcdAdapter = storeadapter.NewETCDStoreAdapter(etcdRunner.NodeURLS(), conf.StoreMaxConcurrentRequests)
		err = etcdAdapter.Connect()
		Ω(err).ShouldNot(HaveOccured())

		app1 = app.NewApp()
		app2 = app.NewApp()
		app3 = app.NewApp()

		store = NewStore(conf, etcdAdapter)
	})

	AfterEach(func() {
		etcdAdapter.Disconnect()
	})

	Describe("Saving desired state ", func() {
		BeforeEach(func() {
			err := store.SaveDesiredState([]models.DesiredAppState{
				app1.DesiredState(0),
				app2.DesiredState(0),
		})

		It("should request a batch size with an empty bulk token", func() {
			query := httpClient.LastRequest().URL.Query()
			Ω(query.Get("batch_size")).Should(Equal(fmt.Sprintf("%d", conf.DesiredStateBatchSize)))
			Ω(query.Get("bulk_token")).Should(Equal("{}"))
		})

		Context("when a response with desired state is received", func() {
			var (
				a1 app.App
				a2 app.App
			)

			BeforeEach(func() {
				a1 = app.NewApp()
				a2 = app.NewApp()

				response = DesiredStateServerResponse{
					Results: map[string]models.DesiredAppState{
						a1.AppGuid: a1.DesiredState(0),
						a2.AppGuid: a2.DesiredState(0),
					},
					BulkToken: BulkToken{
						Id: 5,
					},
				}

				httpClient.LastRequest().Succeed(response.ToJson())
			})
Exemple #4
0
		etcdAdapter storeadapter.StoreAdapter
		conf        config.Config
		heartbeat1  models.InstanceHeartbeat
		heartbeat2  models.InstanceHeartbeat
		heartbeat3  models.InstanceHeartbeat
	)

	BeforeEach(func() {
		var err error
		conf, err = config.DefaultConfig()
		Ω(err).ShouldNot(HaveOccured())
		etcdAdapter = storeadapter.NewETCDStoreAdapter(etcdRunner.NodeURLS(), conf.StoreMaxConcurrentRequests)
		err = etcdAdapter.Connect()
		Ω(err).ShouldNot(HaveOccured())

		a := app.NewApp()
		heartbeat1 = a.GetInstance(0).Heartbeat(17)
		heartbeat2 = a.GetInstance(1).Heartbeat(12)
		heartbeat3 = a.GetInstance(2).Heartbeat(14)

		store = NewStore(conf, etcdAdapter)
	})

	AfterEach(func() {
		etcdAdapter.Disconnect()
	})

	Describe("Saving actual state ", func() {
		BeforeEach(func() {
			err := store.SaveActualState([]models.InstanceHeartbeat{
				heartbeat1,
Exemple #5
0
	"github.com/cloudfoundry/hm9000/models"
	"github.com/cloudfoundry/hm9000/storeadapter"
	"github.com/cloudfoundry/hm9000/testhelpers/app"
	. "github.com/cloudfoundry/hm9000/testhelpers/custommatchers"
	"time"
)

var _ = Describe("FakeStore", func() {
	var store *FakeStore
	var app1 app.App
	var app2 app.App

	BeforeEach(func() {
		store = NewFakeStore()
		app1 = app.NewApp()
		app2 = app.NewApp()
	})

	It("should start off empty", func() {
		desired, err := store.GetDesiredState()
		Ω(desired).Should(BeEmpty())
		Ω(err).ShouldNot(HaveOccured())

		actual, err := store.GetActualState()
		Ω(actual).Should(BeEmpty())
		Ω(err).ShouldNot(HaveOccured())

		Ω(store.DesiredIsFresh).Should(BeFalse())
		Ω(store.ActualIsFresh).Should(BeFalse())
	})
	. "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         app.App
		a2         app.App
		a3         app.App
		resultChan chan desiredstatefetcher.DesiredStateFetcherResult
	)

	BeforeEach(func() {
		resultChan = make(chan desiredstatefetcher.DesiredStateFetcherResult, 1)
		a1 = app.NewApp()
		a2 = app.NewApp()
		a3 = app.NewApp()

		stateServer.SetDesiredState([]models.DesiredAppState{
			a1.DesiredState(0),
			a2.DesiredState(0),
			a3.DesiredState(0),
		})

		fetcher = desiredstatefetcher.New(conf, natsRunner.MessageBus, store.NewStore(conf, storeAdapter), httpclient.NewHttpClient(), &timeprovider.RealTimeProvider{})
		fetcher.Fetch(resultChan)
	})

	It("requests for the first set of data from the CC and stores the response", func() {
		var node storeadapter.StoreNode