예제 #1
0
func New(apiClient bbs.Client, noaaClient lrpstats.NoaaClient, maxInFlight, bulkLRPStatusWorkers int, logger lager.Logger) (http.Handler, error) {
	semaphore := make(chan struct{}, maxInFlight)
	clock := clock.NewClock()

	handlers := map[string]http.Handler{
		tps.LRPStatus: tpsHandler{
			semaphore:       semaphore,
			delegateHandler: LogWrap(lrpstatus.NewHandler(apiClient, clock, logger), logger),
		},
		tps.LRPStats: tpsHandler{
			semaphore:       semaphore,
			delegateHandler: LogWrap(lrpstats.NewHandler(apiClient, noaaClient, clock, logger), logger),
		},
		tps.BulkLRPStatus: tpsHandler{
			semaphore:       semaphore,
			delegateHandler: LogWrap(bulklrpstatus.NewHandler(apiClient, clock, bulkLRPStatusWorkers, logger), logger),
		},
	}

	return rata.NewRouter(tps.Routes, handlers)
}
예제 #2
0
	"github.com/pivotal-golang/clock/fakeclock"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("LRPStatus", func() {
	var (
		fakeClient *fake_bbs.FakeClient

		server *httptest.Server
	)

	BeforeEach(func() {
		fakeClient = new(fake_bbs.FakeClient)
		fakeClock := fakeclock.NewFakeClock(time.Now())

		handler := lrpstatus.NewHandler(fakeClient, fakeClock, lagertest.NewTestLogger("test"))
		server = httptest.NewServer(handler)
	})

	AfterEach(func() {
		server.Close()
	})

	Describe("Instance state", func() {
		BeforeEach(func() {
			fakeClient.ActualLRPGroupsByProcessGuidStub = func(string) ([]*models.ActualLRPGroup, error) {
				return []*models.ActualLRPGroup{
					makeActualLRPGroup(1, models.ActualLRPStateUnclaimed, ""),
					makeActualLRPGroup(2, models.ActualLRPStateClaimed, ""),
					makeActualLRPGroup(3, models.ActualLRPStateRunning, ""),
					makeActualLRPGroup(4, models.ActualLRPStateCrashed, diego_errors.CELL_MISMATCH_MESSAGE),