コード例 #1
0
ファイル: tracker.go プロジェクト: bac/juju
func newLastSentTracker(sink string, caller base.APICaller) *lastSentTracker {
	client := logfwdapi.NewLastSentClient(func(name string) logfwdapi.FacadeCaller {
		return base.NewFacadeCaller(caller, name)
	})
	return &lastSentTracker{
		sink:   sink,
		client: client,
	}
}
コード例 #2
0
ファイル: lastsent_test.go プロジェクト: bac/juju
func (s *LastSentSuite) TestGetLastSent(c *gc.C) {
	stub := &testing.Stub{}
	caller := &stubFacadeCaller{stub: stub}
	caller.ReturnFacadeCallGet = params.LogForwardingGetLastSentResults{
		Results: []params.LogForwardingGetLastSentResult{{
			RecordID:        10,
			RecordTimestamp: 100,
		}, {
			RecordID:        20,
			RecordTimestamp: 200,
		}, {
			Error: common.ServerError(errors.NewNotFound(state.ErrNeverForwarded, "")),
		}},
	}
	client := logfwd.NewLastSentClient(caller.newFacadeCaller)
	model := "deadbeef-2f18-4fd2-967d-db9663db7bea"
	modelTag := names.NewModelTag(model)

	results, err := client.GetLastSent([]logfwd.LastSentID{{
		Model: modelTag,
		Sink:  "spam",
	}, {
		Model: modelTag,
		Sink:  "eggs",
	}, {
		Model: modelTag,
		Sink:  "ham",
	}})
	c.Assert(err, jc.ErrorIsNil)

	c.Check(results, jc.DeepEquals, []logfwd.LastSentResult{{
		LastSentInfo: logfwd.LastSentInfo{
			LastSentID: logfwd.LastSentID{
				Model: modelTag,
				Sink:  "spam",
			},
			RecordID:        10,
			RecordTimestamp: time.Unix(0, 100),
		},
	}, {
		LastSentInfo: logfwd.LastSentInfo{
			LastSentID: logfwd.LastSentID{
				Model: modelTag,
				Sink:  "eggs",
			},
			RecordID:        20,
			RecordTimestamp: time.Unix(0, 200),
		},
	}, {
		LastSentInfo: logfwd.LastSentInfo{
			LastSentID: logfwd.LastSentID{
				Model: modelTag,
				Sink:  "ham",
			},
		},
		Error: common.RestoreError(&params.Error{
			Message: `cannot find ID of the last forwarded record`,
			Code:    params.CodeNotFound,
		}),
	}})
	stub.CheckCallNames(c, "newFacadeCaller", "FacadeCall")
	stub.CheckCall(c, 0, "newFacadeCaller", "LogForwarding")
	stub.CheckCall(c, 1, "FacadeCall", "GetLastSent", params.LogForwardingGetLastSentParams{
		IDs: []params.LogForwardingID{{
			ModelTag: modelTag.String(),
			Sink:     "spam",
		}, {
			ModelTag: modelTag.String(),
			Sink:     "eggs",
		}, {
			ModelTag: modelTag.String(),
			Sink:     "ham",
		}},
	})
}
コード例 #3
0
ファイル: lastsent_test.go プロジェクト: bac/juju
func (s *LastSentSuite) TestSetLastSent(c *gc.C) {
	stub := &testing.Stub{}
	caller := &stubFacadeCaller{stub: stub}
	apiError := common.ServerError(errors.New("<failed>"))
	caller.ReturnFacadeCallSet = params.ErrorResults{
		Results: []params.ErrorResult{{
			Error: nil,
		}, {
			Error: nil,
		}, {
			Error: apiError,
		}},
	}
	client := logfwd.NewLastSentClient(caller.newFacadeCaller)
	model := "deadbeef-2f18-4fd2-967d-db9663db7bea"
	modelTag := names.NewModelTag(model)

	results, err := client.SetLastSent([]logfwd.LastSentInfo{{
		LastSentID: logfwd.LastSentID{
			Model: modelTag,
			Sink:  "spam",
		},
		RecordID:        10,
		RecordTimestamp: time.Unix(0, 100),
	}, {
		LastSentID: logfwd.LastSentID{
			Model: modelTag,
			Sink:  "eggs",
		},
		RecordID:        20,
		RecordTimestamp: time.Unix(0, 200),
	}, {
		LastSentID: logfwd.LastSentID{
			Model: modelTag,
			Sink:  "ham",
		},
		RecordID:        15,
		RecordTimestamp: time.Unix(0, 150),
	}})
	c.Assert(err, jc.ErrorIsNil)

	c.Check(results, jc.DeepEquals, []logfwd.LastSentResult{{
		LastSentInfo: logfwd.LastSentInfo{
			LastSentID: logfwd.LastSentID{
				Model: modelTag,
				Sink:  "spam",
			},
			RecordID:        10,
			RecordTimestamp: time.Unix(0, 100),
		},
	}, {
		LastSentInfo: logfwd.LastSentInfo{
			LastSentID: logfwd.LastSentID{
				Model: modelTag,
				Sink:  "eggs",
			},
			RecordID:        20,
			RecordTimestamp: time.Unix(0, 200),
		},
	}, {
		LastSentInfo: logfwd.LastSentInfo{
			LastSentID: logfwd.LastSentID{
				Model: modelTag,
				Sink:  "ham",
			},
			RecordID:        15,
			RecordTimestamp: time.Unix(0, 150),
		},
		Error: common.RestoreError(apiError),
	}})
	stub.CheckCallNames(c, "newFacadeCaller", "FacadeCall")
	stub.CheckCall(c, 0, "newFacadeCaller", "LogForwarding")
	stub.CheckCall(c, 1, "FacadeCall", "SetLastSent", params.LogForwardingSetLastSentParams{
		Params: []params.LogForwardingSetLastSentParam{{
			LogForwardingID: params.LogForwardingID{
				ModelTag: modelTag.String(),
				Sink:     "spam",
			},
			RecordID:        10,
			RecordTimestamp: 100,
		}, {
			LogForwardingID: params.LogForwardingID{
				ModelTag: modelTag.String(),
				Sink:     "eggs",
			},
			RecordID:        20,
			RecordTimestamp: 200,
		}, {
			LogForwardingID: params.LogForwardingID{
				ModelTag: modelTag.String(),
				Sink:     "ham",
			},
			RecordID:        15,
			RecordTimestamp: 150,
		}},
	})
}