Beispiel #1
0
func New(host string, config *Config, logger *gosteno.Logger) *Loggregator {
	cfcomponent.Logger = logger
	keepAliveInterval := 30 * time.Second
	listener, incomingLogChan := agentlistener.NewAgentListener(fmt.Sprintf("%s:%d", host, config.IncomingPort), logger)
	unmarshaller, messageChan := unmarshaller.NewLogMessageUnmarshaller(config.SharedSecret, incomingLogChan)
	blacklist := blacklist.New(config.BlackListIps)
	sinkManager, appStoreInputChan := sinkmanager.NewSinkManager(config.MaxRetainedLogMessages, config.SkipCertVerify, blacklist, logger)
	workerPool := workerpool.NewWorkerPool(config.EtcdMaxConcurrentRequests)

	storeAdapter := etcdstoreadapter.NewETCDStoreAdapter(config.EtcdUrls, workerPool)
	appStoreCache := cache.NewAppServiceCache()
	appStoreWatcher, newAppServiceChan, deletedAppServiceChan := store.NewAppServiceStoreWatcher(storeAdapter, appStoreCache)
	appStore := store.NewAppServiceStore(storeAdapter, appStoreWatcher)
	return &Loggregator{
		Logger:                logger,
		listener:              listener,
		unmarshaller:          unmarshaller,
		sinkManager:           sinkManager,
		messageChan:           messageChan,
		appStoreInputChan:     appStoreInputChan,
		appStore:              appStore,
		messageRouter:         sinkserver.NewMessageRouter(sinkManager, logger),
		websocketServer:       websocketserver.New(fmt.Sprintf("%s:%d", host, config.OutgoingPort), sinkManager, keepAliveInterval, config.WSMessageBufferSize, logger),
		newAppServiceChan:     newAppServiceChan,
		deletedAppServiceChan: deletedAppServiceChan,
		appStoreWatcher:       appStoreWatcher,
		storeAdapter:          storeAdapter,
	}
}
	"loggregator/sinkserver/unmarshaller"
)

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

	var inChan chan []byte
	var secret string

	BeforeEach(func() {
		inChan = make(chan []byte)
		secret = "mySecretEncryptionKey"
	})

	Describe("New", func() {
		It("should return the unmarshaller stage and the open output channel", func() {
			anUnmarshaller, outChan := unmarshaller.NewLogMessageUnmarshaller(secret, inChan)
			Expect(anUnmarshaller).ToNot(BeZero())
			Expect(outChan).ToNot(BeClosed())
		})
	})

	Context("With an unmarshaller", func() {
		var anUnmarshaller *unmarshaller.LogMessageUnmarshaller
		var outChan <-chan *logmessage.Message
		var errorChan chan error

		BeforeEach(func() {
			errorChan = make(chan error)
			anUnmarshaller, outChan = unmarshaller.NewLogMessageUnmarshaller(secret, inChan)
			go anUnmarshaller.Start(errorChan)
		})