Skip to content

Commit

Permalink
Add ut cases for command job classes in server module.
Browse files Browse the repository at this point in the history
  • Loading branch information
xianrenzw committed Feb 20, 2025
1 parent 3fc2812 commit 04079a1
Show file tree
Hide file tree
Showing 26 changed files with 3,600 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.bigtop.manager.dao.repository.ComponentDao;
import org.apache.bigtop.manager.server.command.job.AbstractJob;
import org.apache.bigtop.manager.server.command.job.JobContext;
import org.apache.bigtop.manager.server.command.stage.Stage;
import org.apache.bigtop.manager.server.holder.SpringContextHolder;

import java.util.ArrayList;
Expand Down Expand Up @@ -62,4 +63,9 @@ protected Map<String, List<String>> getComponentHostsMap() {

return componentHostsMap;
}

protected void setJobContextAndStagesForTest(JobContext jobContext, List<Stage> stages) {
this.jobContext = jobContext;
this.stages = stages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.bigtop.manager.dao.po.JobPO;
import org.apache.bigtop.manager.dao.po.StagePO;
import org.apache.bigtop.manager.dao.po.TaskPO;
import org.apache.bigtop.manager.server.command.job.AbstractJob;
import org.apache.bigtop.manager.server.command.job.JobContext;
import org.apache.bigtop.manager.server.command.stage.HostCheckStage;
import org.apache.bigtop.manager.server.command.stage.SetupJdkStage;
Expand All @@ -38,7 +37,7 @@

import java.util.List;

public class ClusterAddJob extends AbstractJob {
public class ClusterAddJob extends AbstractClusterJob {

private HostService hostService;

Expand Down Expand Up @@ -92,7 +91,7 @@ public String getName() {
return "Add cluster";
}

private void saveCluster() {
protected void saveCluster() {
CommandDTO commandDTO = jobContext.getCommandDTO();
ClusterDTO clusterDTO = ClusterConverter.INSTANCE.fromCommand2DTO(commandDTO.getClusterCommand());
clusterPO = clusterDao.findByName(clusterDTO.getName());
Expand All @@ -104,7 +103,7 @@ private void saveCluster() {
clusterDao.save(clusterPO);
}

private void saveHosts() {
protected void saveHosts() {
CommandDTO commandDTO = jobContext.getCommandDTO();
List<HostDTO> hostDTOList = commandDTO.getClusterCommand().getHosts();
for (HostDTO hostDTO : hostDTOList) {
Expand All @@ -113,7 +112,7 @@ private void saveHosts() {
}
}

private void linkJobToCluster() {
protected void linkJobToCluster() {
JobPO jobPO = getJobPO();
jobPO.setClusterId(clusterPO.getId());
jobDao.partialUpdateById(jobPO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.bigtop.manager.dao.repository.ServiceDao;
import org.apache.bigtop.manager.server.command.job.AbstractJob;
import org.apache.bigtop.manager.server.command.job.JobContext;
import org.apache.bigtop.manager.server.command.stage.Stage;
import org.apache.bigtop.manager.server.holder.SpringContextHolder;

import java.util.HashMap;
Expand Down Expand Up @@ -64,4 +65,9 @@ protected Map<String, List<String>> getComponentHostsMap() {

return componentHostsMap;
}

protected void setJobContextAndStagesForTest(JobContext jobContext, List<Stage> stages) {
this.jobContext = jobContext;
this.stages = stages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public String getName() {
return "Add components";
}

private void saveComponents(ComponentCommandDTO componentCommand) {
protected void saveComponents(ComponentCommandDTO componentCommand) {
Long clusterId = jobContext.getCommandDTO().getClusterId();
String componentName = componentCommand.getComponentName();
ServiceDTO serviceDTO = StackUtils.getServiceDTOByComponentName(componentName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.bigtop.manager.dao.repository.ComponentDao;
import org.apache.bigtop.manager.server.command.job.AbstractJob;
import org.apache.bigtop.manager.server.command.job.JobContext;
import org.apache.bigtop.manager.server.command.stage.Stage;
import org.apache.bigtop.manager.server.holder.SpringContextHolder;

import java.util.ArrayList;
Expand Down Expand Up @@ -71,4 +72,9 @@ private List<String> getHostnames() {
.flatMap(hostCommandDTO -> hostCommandDTO.getHostnames().stream())
.toList();
}

protected void setJobContextAndStagesForTest(JobContext jobContext, List<Stage> stages) {
this.jobContext = jobContext;
this.stages = stages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public String getName() {
return "Add hosts";
}

private void saveHosts() {
protected void saveHosts() {
CommandDTO commandDTO = jobContext.getCommandDTO();
List<HostDTO> hostDTOList = HostConverter.INSTANCE.fromCommand2DTO(commandDTO.getHostCommands());
for (HostDTO hostDTO : hostDTOList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.bigtop.manager.dao.repository.ServiceDao;
import org.apache.bigtop.manager.server.command.job.AbstractJob;
import org.apache.bigtop.manager.server.command.job.JobContext;
import org.apache.bigtop.manager.server.command.stage.Stage;
import org.apache.bigtop.manager.server.holder.SpringContextHolder;
import org.apache.bigtop.manager.server.model.dto.command.ServiceCommandDTO;

Expand Down Expand Up @@ -84,4 +85,9 @@ private List<String> getServiceNames() {
.map(ServiceCommandDTO::getServiceName)
.toList();
}

protected void setJobContextAndStagesForTest(JobContext jobContext, List<Stage> stages) {
this.jobContext = jobContext;
this.stages = stages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public String getName() {
return "Add services";
}

private void saveService(ServiceCommandDTO serviceCommand) {
protected void saveService(ServiceCommandDTO serviceCommand) {
CommandDTO commandDTO = jobContext.getCommandDTO();
Long clusterId = commandDTO.getClusterId();
String serviceName = serviceCommand.getServiceName();
Expand Down
Loading

0 comments on commit 04079a1

Please sign in to comment.