Refactor for better naming of go producer
Issue-ID: NONRTRIC-639
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: I8cfd139f3d6886d12ef8977fadd2077c24835bf9
diff --git a/dmaap-mediator-producer/internal/jobs/jobs.go b/dmaap-mediator-producer/internal/jobs/jobs.go
index d4694bf..6dad5fd 100644
--- a/dmaap-mediator-producer/internal/jobs/jobs.go
+++ b/dmaap-mediator-producer/internal/jobs/jobs.go
@@ -52,8 +52,8 @@
}
type JobsManager interface {
- AddJob(JobInfo) error
- DeleteJob(jobId string)
+ AddJobFromRESTCall(JobInfo) error
+ DeleteJobFromRESTCall(jobId string)
}
type JobsManagerImpl struct {
@@ -74,7 +74,7 @@
}
}
-func (jm *JobsManagerImpl) AddJob(ji JobInfo) error {
+func (jm *JobsManagerImpl) AddJobFromRESTCall(ji JobInfo) error {
if err := jm.validateJobInfo(ji); err == nil {
typeData := jm.allTypes[ji.InfoTypeIdentity]
typeData.jobsHandler.addJobCh <- ji
@@ -85,7 +85,7 @@
}
}
-func (jm *JobsManagerImpl) DeleteJob(jobId string) {
+func (jm *JobsManagerImpl) DeleteJobFromRESTCall(jobId string) {
for _, typeData := range jm.allTypes {
log.Debugf("Deleting job %v from type %v", jobId, typeData.TypeId)
typeData.jobsHandler.deleteJobCh <- jobId
@@ -137,10 +137,10 @@
return supportedTypes
}
-func (jm *JobsManagerImpl) StartJobs() {
+func (jm *JobsManagerImpl) StartJobsForAllTypes() {
for _, jobType := range jm.allTypes {
- go jobType.jobsHandler.start(jm.mrAddress)
+ go jobType.jobsHandler.startPollingAndDistribution(jm.mrAddress)
}
}
@@ -168,7 +168,7 @@
}
}
-func (jh *jobsHandler) start(mRAddress string) {
+func (jh *jobsHandler) startPollingAndDistribution(mRAddress string) {
go func() {
for {
jh.pollAndDistributeMessages(mRAddress)
diff --git a/dmaap-mediator-producer/internal/jobs/jobs_test.go b/dmaap-mediator-producer/internal/jobs/jobs_test.go
index 066823d..e48e68d 100644
--- a/dmaap-mediator-producer/internal/jobs/jobs_test.go
+++ b/dmaap-mediator-producer/internal/jobs/jobs_test.go
@@ -83,7 +83,7 @@
var err error
go func() {
- err = managerUnderTest.AddJob(wantedJob)
+ err = managerUnderTest.AddJobFromRESTCall(wantedJob)
}()
assertions.Nil(err)
@@ -98,7 +98,7 @@
InfoTypeIdentity: "type1",
}
- err := managerUnderTest.AddJob(jobInfo)
+ err := managerUnderTest.AddJobFromRESTCall(jobInfo)
assertions.NotNil(err)
assertions.Equal("type not supported: type1", err.Error())
}
@@ -113,7 +113,7 @@
jobInfo := JobInfo{
InfoTypeIdentity: "type1",
}
- err := managerUnderTest.AddJob(jobInfo)
+ err := managerUnderTest.AddJobFromRESTCall(jobInfo)
assertions.NotNil(err)
assertions.Equal("missing required job identity: { <nil> type1}", err.Error())
}
@@ -129,7 +129,7 @@
InfoTypeIdentity: "type1",
InfoJobIdentity: "job1",
}
- err := managerUnderTest.AddJob(jobInfo)
+ err := managerUnderTest.AddJobFromRESTCall(jobInfo)
assertions.NotNil(err)
assertions.Equal("missing required target URI: { job1 <nil> type1}", err.Error())
}
@@ -144,7 +144,7 @@
jobsHandler: &jobsHandler,
}
- go managerUnderTest.DeleteJob("job2")
+ go managerUnderTest.DeleteJobFromRESTCall("job2")
assertions.Equal("job2", <-jobsHandler.deleteJobCh)
}
@@ -199,7 +199,7 @@
jobsHandler: jobsHandler,
}
- jobsManager.StartJobs()
+ jobsManager.StartJobsForAllTypes()
jobInfo := JobInfo{
InfoTypeIdentity: "type1",
@@ -208,7 +208,7 @@
}
wg.Add(1) // Wait till the distribution has happened
- jobsManager.AddJob(jobInfo)
+ jobsManager.AddJobFromRESTCall(jobInfo)
if waitTimeout(&wg, 2*time.Second) {
t.Error("Not all calls to server were made")
diff --git a/dmaap-mediator-producer/internal/server/server.go b/dmaap-mediator-producer/internal/server/server.go
index 8bed1f9..79646c2 100644
--- a/dmaap-mediator-producer/internal/server/server.go
+++ b/dmaap-mediator-producer/internal/server/server.go
@@ -71,7 +71,7 @@
http.Error(w, fmt.Sprintf("Invalid json body. Cause: %v", unmarshalErr), http.StatusBadRequest)
return
}
- if err := h.jobsManager.AddJob(jobInfo); err != nil {
+ if err := h.jobsManager.AddJobFromRESTCall(jobInfo); err != nil {
http.Error(w, fmt.Sprintf("Invalid job info. Cause: %v", err), http.StatusBadRequest)
}
}
@@ -84,7 +84,7 @@
return
}
- h.jobsManager.DeleteJob(id)
+ h.jobsManager.DeleteJobFromRESTCall(id)
}
type notFoundHandler struct{}
diff --git a/dmaap-mediator-producer/main.go b/dmaap-mediator-producer/main.go
index 74f4edf..194ed75 100644
--- a/dmaap-mediator-producer/main.go
+++ b/dmaap-mediator-producer/main.go
@@ -60,7 +60,7 @@
if err := registerTypesAndProducer(jobsManager, configuration.InfoCoordinatorAddress, callbackAddress, retryClient); err != nil {
log.Fatalf("Stopping producer due to: %v", err)
}
- jobsManager.StartJobs()
+ jobsManager.StartJobsForAllTypes()
log.Debug("Starting DMaaP Mediator Producer")
go func() {
diff --git a/dmaap-mediator-producer/mocks/jobhandler/JobHandler.go b/dmaap-mediator-producer/mocks/jobhandler/JobHandler.go
index 8e30b1c..ad20752 100644
--- a/dmaap-mediator-producer/mocks/jobhandler/JobHandler.go
+++ b/dmaap-mediator-producer/mocks/jobhandler/JobHandler.go
@@ -13,7 +13,7 @@
}
// AddJob provides a mock function with given fields: _a0
-func (_m *JobHandler) AddJob(_a0 jobs.JobInfo) error {
+func (_m *JobHandler) AddJobFromRESTCall(_a0 jobs.JobInfo) error {
ret := _m.Called(_a0)
var r0 error
@@ -27,6 +27,6 @@
}
// DeleteJob provides a mock function with given fields: jobId
-func (_m *JobHandler) DeleteJob(jobId string) {
+func (_m *JobHandler) DeleteJobFromRESTCall(jobId string) {
_m.Called(jobId)
}