コード例 #1
0
ファイル: unitagent_test.go プロジェクト: Pankov404/juju
func (s *UnitAgentSuite) TestSetUnitAgentStatusHistory(c *gc.C) {
	err := state.EraseUnitHistory(s.unit)
	c.Assert(err, jc.ErrorIsNil)

	agent := s.unit.Agent().(*state.UnitAgent)
	globalKey := state.UnitAgentGlobalKey(agent)
	err = agent.SetStatus(state.StatusIdle, "to push something to history", nil)
	c.Assert(err, jc.ErrorIsNil)
	statusInfo, err := agent.Status()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(statusInfo.Status, gc.Equals, state.StatusIdle)

	h, err := state.StatusHistory(10, globalKey, s.State)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(h, gc.HasLen, 1)
	c.Assert(h[0].Status, gc.Equals, state.StatusAllocating)
	c.Assert(h[0].Message, gc.Equals, "")

	err = agent.SetStatus(state.StatusExecuting, "executing first thing", nil)
	c.Assert(err, jc.ErrorIsNil)
	statusInfo, err = agent.Status()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(statusInfo.Status, gc.Equals, state.StatusExecuting)

	err = agent.SetStatus(state.StatusExecuting, "wow executing again", nil)
	c.Assert(err, jc.ErrorIsNil)
	statusInfo, err = agent.Status()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(statusInfo.Status, gc.Equals, state.StatusExecuting)

	h, err = state.StatusHistory(10, globalKey, s.State)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(h, gc.HasLen, 3)
	var message string
	for i := 0; i < 3; i++ {
		c.Logf("checking status %q", h[i].Status)
		switch h[i].Status {
		case state.StatusAllocating:
			message = ""
		case state.StatusExecuting:
			message = "executing first thing"
		case state.StatusIdle:
			message = "to push something to history"
		}
		c.Assert(h[i].Message, gc.Equals, message)
	}
}
コード例 #2
0
ファイル: status_test.go プロジェクト: Pankov404/juju
func (s *statusSuite) TestPruneStatusHistory(c *gc.C) {
	var oldDoc state.StatusDoc
	var err error
	st := s.State
	globalKey := "BogusKey"
	for changeno := 1; changeno <= 200; changeno++ {
		oldDoc = state.StatusDoc{
			Status:     "AGivenStatus",
			StatusInfo: fmt.Sprintf("Status change %d", changeno),
			StatusData: nil,
		}
		timestamp := state.NowToTheSecond()
		oldDoc.Updated = &timestamp

		hDoc := state.NewHistoricalStatusDoc(oldDoc, globalKey)

		h := txn.Op{
			C:      state.StatusesHistoryC,
			Id:     changeno,
			Insert: hDoc,
		}

		err = state.RunTransaction(st, []txn.Op{h})
		c.Logf("Adding a history entry attempt n: %d", changeno)
		c.Assert(err, jc.ErrorIsNil)
	}
	history, err := state.StatusHistory(500, globalKey, st)
	c.Assert(history, gc.HasLen, 200)
	c.Assert(history[0].Message, gc.Equals, "Status change 200")
	c.Assert(history[199].Message, gc.Equals, "Status change 1")

	err = state.PruneStatusHistory(st, 100)
	c.Assert(err, jc.ErrorIsNil)
	history, err = state.StatusHistory(500, globalKey, st)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(history, gc.HasLen, 100)
	c.Assert(history[0].Message, gc.Equals, "Status change 200")
	c.Assert(history[99].Message, gc.Equals, "Status change 101")
}
コード例 #3
0
ファイル: status_test.go プロジェクト: vonwenm/juju
func (s *statusSuite) TestPruneStatusHistory(c *gc.C) {
	var oldDoc state.StatusDoc
	var err error
	st := s.State
	globalKey := "BogusKey"
	for changeno := 1; changeno <= 200; changeno++ {
		oldDoc = state.StatusDoc{
			EnvUUID:    st.EnvironUUID(),
			Status:     "AGivenStatus",
			StatusInfo: fmt.Sprintf("Status change %d", changeno),
			StatusData: nil,
		}
		timestamp := state.NowToTheSecond()
		oldDoc.Updated = &timestamp

		hDoc := state.NewHistoricalStatusDoc(changeno, oldDoc, globalKey)

		history, closer := state.GetCollection(st, state.StatusesHistoryC)
		historyW := history.Writeable()
		err = historyW.Insert(hDoc)
		closer()

		c.Logf("Adding a history entry attempt n: %d", changeno)
		c.Assert(err, jc.ErrorIsNil)
	}
	history, err := state.StatusHistory(500, globalKey, st)
	c.Assert(history, gc.HasLen, 200)
	c.Assert(history[0].Message, gc.Equals, "Status change 200")
	c.Assert(history[199].Message, gc.Equals, "Status change 1")

	err = state.PruneStatusHistory(st, 100)
	c.Assert(err, jc.ErrorIsNil)
	history, err = state.StatusHistory(500, globalKey, st)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(history, gc.HasLen, 100)
	c.Assert(history[0].Message, gc.Equals, "Status change 200")
	c.Assert(history[99].Message, gc.Equals, "Status change 101")
}