Beispiel #1
0
func (s *LogForwarderSuite) TestConfigChange(c *gc.C) {
	rec2 := s.rec
	rec2.ID = 11
	s.stream.setRecords(c, []logfwd.Record{
		s.rec,
		rec2,
	})

	api := &mockLogForwardConfig{
		enabled: true,
		host:    "10.0.0.1",
	}
	lf, err := logforwarder.NewLogForwarder(s.newLogForwarderArgsWithAPI(c, api, s.stream, s.sender))
	c.Assert(err, jc.ErrorIsNil)
	defer s.checkClose(c, lf, nil)

	s.checkNext(c, s.rec)

	api.host = "10.0.0.2"
	api.changes <- struct{}{}
	s.sender.waitBeforeClose(c)
	s.stream.waitBeforeNext(c)
	s.stream.waitAfterNext(c)
	s.sender.waitAfterSend(c)
	// Check that the config change has been picked up and
	// that the second record is sent.
	rec2.Message = "send to 10.0.0.2"
	s.stub.CheckCall(c, 2, "Send", []logfwd.Record{rec2})
	s.stub.ResetCalls()
}
Beispiel #2
0
func (s *LogForwarderSuite) TestOne(c *gc.C) {
	s.stream.setRecords(c, []logfwd.Record{
		s.rec,
	})

	lf, err := logforwarder.NewLogForwarder(s.newLogForwarderArgs(c, s.stream, s.sender))
	c.Assert(err, jc.ErrorIsNil)
	defer s.checkClose(c, lf, nil)

	s.checkNext(c, s.rec)
}
Beispiel #3
0
func (s *LogForwarderSuite) TestNotEnabled(c *gc.C) {
	lf, err := logforwarder.NewLogForwarder(s.newLogForwarderArgs(c, nil, s.sender))
	c.Assert(err, jc.ErrorIsNil)

	time.Sleep(coretesting.ShortWait)
	workertest.CleanKill(c, lf)

	// There should be no stream or sender activity when log
	// forwarding is disabled.
	s.stream.stub.CheckCallNames(c)
	s.sender.stub.CheckCallNames(c)
}
Beispiel #4
0
func (s *LogForwarderSuite) TestOne(c *gc.C) {
	s.stream.addRecords(c, s.rec)
	lf, err := logforwarder.NewLogForwarder(s.newLogForwarderArgs(c, s.stream, s.sender))
	c.Assert(err, jc.ErrorIsNil)
	defer workertest.DirtyKill(c, lf)

	s.sender.waitForSend(c)
	workertest.CleanKill(c, lf)
	s.sender.stub.CheckCalls(c, []testing.StubCall{
		{"Send", []interface{}{[]logfwd.Record{s.rec}}},
		{"Close", nil},
	})
}
Beispiel #5
0
func (s *LogForwarderSuite) TestSenderError(c *gc.C) {
	failure := errors.New("<failure>")
	s.stub.SetErrors(nil, nil, nil, failure)
	rec2 := s.rec
	rec2.ID = 11
	s.stream.setRecords(c, []logfwd.Record{
		s.rec,
		rec2,
	})
	lf, err := logforwarder.NewLogForwarder(s.newLogForwarderArgs(c, s.stream, s.sender))
	c.Assert(err, jc.ErrorIsNil)

	s.checkNext(c, s.rec)
	s.checkNext(c, rec2)
	s.checkClose(c, lf, failure)
}
Beispiel #6
0
func (s *LogForwarderSuite) TestStreamError(c *gc.C) {
	failure := errors.New("<failure>")
	s.stub.SetErrors(nil, nil, failure)
	s.stream.setRecords(c, []logfwd.Record{
		s.rec,
	})
	lf, err := logforwarder.NewLogForwarder(s.newLogForwarderArgs(c, s.stream, s.sender))
	c.Assert(err, jc.ErrorIsNil)

	s.checkNext(c, s.rec)
	s.stream.waitBeforeNext(c)
	s.stream.waitAfterNext(c)
	s.stub.CheckCallNames(c, "Next")
	s.stub.ResetCalls()
	s.checkClose(c, lf, failure)
}
Beispiel #7
0
func (s *LogForwarderSuite) TestStreamError(c *gc.C) {
	failure := errors.New("<failure>")
	s.stream.stub.SetErrors(nil, failure)
	s.stream.addRecords(c, s.rec)

	lf, err := logforwarder.NewLogForwarder(s.newLogForwarderArgs(c, s.stream, s.sender))
	c.Assert(err, jc.ErrorIsNil)
	defer workertest.DirtyKill(c, lf)

	err = workertest.CheckKilled(c, lf)
	c.Check(errors.Cause(err), gc.Equals, failure)

	s.sender.stub.CheckCalls(c, []testing.StubCall{
		{"Send", []interface{}{[]logfwd.Record{s.rec}}},
		{"Close", nil},
	})
}
Beispiel #8
0
func (s *LogForwarderSuite) TestConfigChange(c *gc.C) {
	rec0 := s.rec
	rec1 := s.rec
	rec1.ID = 11

	api := &mockLogForwardConfig{
		enabled: true,
		host:    "10.0.0.1",
	}
	lf, err := logforwarder.NewLogForwarder(s.newLogForwarderArgsWithAPI(c, api, s.stream, s.sender))
	c.Assert(err, jc.ErrorIsNil)
	defer workertest.DirtyKill(c, lf)

	// Send the first record.
	s.stream.addRecords(c, rec0)
	s.sender.waitForSend(c)

	// Config change.
	api.host = "10.0.0.2"
	api.changes <- struct{}{}
	s.sender.waitForClose(c)

	// Send the second record.
	s.stream.addRecords(c, rec1)
	s.sender.waitForSend(c)

	workertest.CleanKill(c, lf)

	// Check that both records were sent with the config change
	// applied for the second send.
	rec1.Message = "send to 10.0.0.2"
	s.sender.stub.CheckCalls(c, []testing.StubCall{
		{"Send", []interface{}{[]logfwd.Record{rec0}}},
		{"Close", nil},
		{"Send", []interface{}{[]logfwd.Record{rec1}}},
		{"Close", nil},
	})
}
Beispiel #9
0
func (s *LogForwarderSuite) TestNotEnabled(c *gc.C) {
	lf, err := logforwarder.NewLogForwarder(s.newLogForwarderArgs(c, nil, s.sender))
	c.Assert(err, jc.ErrorIsNil)
	workertest.CleanKill(c, lf)
}