Пример #1
0
func (s *LogsSuite) TestLastSentLogTrackerIndependentSinks(c *gc.C) {
	tracker0 := state.NewLastSentLogTracker(s.State, s.State.ModelUUID(), "test-sink0")
	defer tracker0.Close()
	tracker1 := state.NewLastSentLogTracker(s.State, s.State.ModelUUID(), "test-sink1")
	defer tracker1.Close()
	err := tracker0.Set(10, 100)
	c.Assert(err, jc.ErrorIsNil)
	id0, ts0, err := tracker0.Get()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(id0, gc.Equals, int64(10))
	c.Assert(ts0, gc.Equals, int64(100))

	_, _, errBefore := tracker1.Get()
	err = tracker1.Set(20, 200)
	c.Assert(err, jc.ErrorIsNil)
	id1, ts1, errAfter := tracker1.Get()
	c.Assert(errAfter, jc.ErrorIsNil)
	id0, ts0, err = tracker0.Get()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(errBefore, gc.ErrorMatches, state.ErrNeverForwarded.Error())
	c.Check(id1, gc.Equals, int64(20))
	c.Check(ts1, gc.Equals, int64(200))
	c.Check(id0, gc.Equals, int64(10))
	c.Check(ts0, gc.Equals, int64(100))
}
Пример #2
0
func (st logStreamState) getStart(sink string, allModels bool) (time.Time, error) {
	var tracker *state.LastSentLogTracker
	if allModels {
		var err error
		tracker, err = state.NewAllLastSentLogTracker(st, sink)
		if err != nil {
			return time.Time{}, errors.Trace(err)
		}
	} else {
		tracker = state.NewLastSentLogTracker(st, st.ModelUUID(), sink)
	}
	defer tracker.Close()

	// Resume for the sink...
	_, lastSentTimestamp, err := tracker.Get()
	if errors.Cause(err) == state.ErrNeverForwarded {
		// If we've never forwarded a message, we start from
		// position zero.
		lastSentTimestamp = 0
	} else if err != nil {
		return time.Time{}, errors.Trace(err)
	}

	// Using the same timestamp will cause at least 1 duplicate
	// entry, but that is better than dropping records.
	// TODO(ericsnow) Add 1 to start once we track by sequential int ID
	// instead of by timestamp.
	return time.Unix(0, lastSentTimestamp), nil
}
Пример #3
0
func (s *LogsSuite) TestLastSentLogTrackerGetNeverSet(c *gc.C) {
	tracker := state.NewLastSentLogTracker(s.State, s.State.ModelUUID(), "test")
	defer tracker.Close()

	_, _, err := tracker.Get()

	c.Check(err, gc.ErrorMatches, state.ErrNeverForwarded.Error())
}
Пример #4
0
func (s *LogsSuite) TestLastSentLogTrackerSetGet(c *gc.C) {
	tracker := state.NewLastSentLogTracker(s.State, s.State.ModelUUID(), "test-sink")
	defer tracker.Close()

	err := tracker.Set(10, 100)
	c.Assert(err, jc.ErrorIsNil)
	id1, ts1, err := tracker.Get()
	c.Assert(err, jc.ErrorIsNil)
	err = tracker.Set(20, 200)
	c.Assert(err, jc.ErrorIsNil)
	id2, ts2, err := tracker.Get()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(id1, gc.Equals, int64(10))
	c.Check(ts1, gc.Equals, int64(100))
	c.Check(id2, gc.Equals, int64(20))
	c.Check(ts2, gc.Equals, int64(200))
}
Пример #5
0
// NewLastSentTracker implements LogForwardingState.
func (st stateAdapter) NewLastSentTracker(tag names.ModelTag, sink string) LastSentTracker {
	return state.NewLastSentLogTracker(st, tag.Id(), sink)
}