示例#1
0
func (c *concurrentWriteRequestSimulator) concurrentWriteRequests(count int, writer syslogwriter.Writer) {
	wg := &sync.WaitGroup{}
	wg.Add(count)

	for i := 0; i < count; i++ {
		go func() {
			writer.Write(standardErrorPriority, []byte("Message"), "just a test", "TEST", time.Now().UnixNano())
			wg.Done()
		}()
	}

	wg.Wait()
}
示例#2
0
		sysLogWriter, _ = syslogwriter.NewSyslogWriter(outputURL, "appId", dialer, 0)

		Eventually(func() error {
			err := sysLogWriter.Connect()
			return err
		}, 5, 1).ShouldNot(HaveOccurred())
	}, 10)

	AfterEach(func() {
		sysLogWriter.Close()
		syslogServerSession.Kill().Wait()
	})

	Context("Message Format", func() {
		It("sends messages in the proper format", func() {
			sysLogWriter.Write(standardOutPriority, []byte("just a test"), "App", "2", time.Now().UnixNano())

			Eventually(syslogServerSession, 5).Should(gbytes.Say(`\d <\d+>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,6}([-+]\d{2}:\d{2}) loggregator appId \[App/2\] - - just a test\n`))
		}, 10)

		It("strips null termination char from message", func() {
			sysLogWriter.Write(standardOutPriority, []byte(string(0)+" hi"), "appId", "", time.Now().UnixNano())

			Expect(syslogServerSession).ToNot(gbytes.Say("\000"))
		})
	})

	Context("won't write to invalid syslog drains", func() {
		It("returns an error when unable to send the log message", func() {
			syslogServerSession.Kill().Wait()
示例#3
0
			Expect(err).ToNot(HaveOccurred())
		}, 5)

		AfterEach(func() {
			syslogServerSession.Terminate().Wait()
			syslogWriter.Close()
		})

		It("connects and writes", func() {
			ts := time.Now().UnixNano()
			Eventually(func() error {
				err := syslogWriter.Connect()
				return err
			}, 5, 1).ShouldNot(HaveOccurred())

			_, err := syslogWriter.Write(standardOutPriority, []byte("just a test"), "test", "", ts)
			Expect(err).ToNot(HaveOccurred())

			Eventually(syslogServerSession, 3).Should(gbytes.Say("just a test"))
		}, 10)

		Context("when an i/o timeout is set", func() {
			BeforeEach(func() {
				// cause an immediate write timeout
				ioTimeout = -1 * time.Second
			})

			It("returns a timeout error", func() {
				Eventually(func() error {
					err := syslogWriter.Connect()
					return err