예제 #1
0
func (cache AppServiceCache) Remove(appService domain.AppService) {
	appCache := cache.appServicesByAppId[appService.AppId]
	delete(appCache, appService.Id())
	if len(appCache) == 0 {
		delete(cache.appServicesByAppId, appService.AppId)
	}
}
예제 #2
0
func (cache AppServiceCache) Exists(appService domain.AppService) bool {
	serviceExists := false
	appServices, appExists := cache.appServicesByAppId[appService.AppId]
	if appExists {
		_, serviceExists = appServices[appService.Id()]
	}
	return serviceExists
}
예제 #3
0
func (c *appServiceCache) Remove(appService domain.AppService) {
	c.Lock()
	defer c.Unlock()
	appCache := c.appServicesByAppId[appService.AppId]
	delete(appCache, appService.Id())
	if len(appCache) == 0 {
		delete(c.appServicesByAppId, appService.AppId)
	}
}
예제 #4
0
func (cache AppServiceCache) Add(appService domain.AppService) {
	appServicesById, ok := cache.appServicesByAppId[appService.AppId]
	if !ok {
		appServicesById = make(map[string]domain.AppService)
		cache.appServicesByAppId[appService.AppId] = appServicesById
	}

	appServicesById[appService.Id()] = appService
}
예제 #5
0
func (c *appServiceCache) Exists(appService domain.AppService) bool {
	c.RLock()
	defer c.RUnlock()
	serviceExists := false
	appServices, appExists := c.appServicesByAppId[appService.AppId]
	if appExists {
		_, serviceExists = appServices[appService.Id()]
	}
	return serviceExists
}
예제 #6
0
func (c *appServiceCache) Add(appService domain.AppService) {
	c.Lock()
	defer c.Unlock()
	appServicesById, ok := c.appServicesByAppId[appService.AppId]
	if !ok {
		appServicesById = make(map[string]domain.AppService)
		c.appServicesByAppId[appService.AppId] = appServicesById
	}

	appServicesById[appService.Id()] = appService
}
예제 #7
0
func buildNode(appService domain.AppService) storeadapter.StoreNode {
	return storeadapter.StoreNode{
		Key:   path.Join("/loggregator/services", appService.AppId, appService.Id()),
		Value: []byte(appService.Url),
	}
}
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "loggregator/store"
	"path"

	"loggregator/domain"
	"time"
)

var _ = Describe("AppServiceStoreWatcher", func() {
	var listener *AppServiceStoreWatcher
	var adapter storeadapter.StoreAdapter
	var outAddChan <-chan domain.AppService
	var outRemoveChan <-chan domain.AppService

	var app1Service1 domain.AppService
	var app1Service2 domain.AppService
	var app2Service1 domain.AppService

	drainOutgoingChannel := func(c <-chan domain.AppService, count int) []domain.AppService {
		appServices := []domain.AppService{}
		for i := 0; i < count; i++ {
			appService, ok := <-c
			if !ok {
				break
			}
			appServices = append(appServices, appService)
		}
		return appServices
	}