Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenxinxing committed May 11, 2023
1 parent 3e2c806 commit cdfebd7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 156 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public Long createJob(String projectUrl,
log.debug("try to find built-in runtime for model:{}", modelVersion.getId());
runtimeVersionUrl = modelVersion.getBuiltInRuntime();
}
if (!StringUtils.hasText(runtimeVersionUrl)) {
throw new SwValidationException(ValidSubject.RUNTIME, "no runtime or built-in runtime");
}
runtimeVersion = runtimeService.findRuntimeVersion(runtimeVersionUrl);
var runtime = runtimeService.findRuntime(runtimeVersion.getRuntimeId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ private List<FileNode> parseManifestFiles(String manifest) throws JsonProcessing
}

public Boolean modifyModelVersion(String projectUrl, String modelUrl, String versionUrl, ModelVersion version) {
if (!StringUtils.hasText(version.getTag()) && !StringUtils.hasText(version.getBuiltInRuntime())) {
throw new SwValidationException(ValidSubject.MODEL, "no attributes set for model version");
}
Long versionId = bundleManager.getBundleVersionId(BundleVersionUrl
.create(projectUrl, modelUrl, versionUrl));
ModelVersionEntity entity = ModelVersionEntity.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,17 @@ public RuntimeEntity getRuntime(Long id) {
}

public RuntimeVersionEntity getRuntimeVersion(String versionUrl) {
RuntimeVersionEntity entity = getRuntimeVersionAllowNull(versionUrl);
if (entity == null) {
throw new SwNotFoundException(ResourceType.BUNDLE_VERSION,
String.format("Unable to find Runtime Version %s", versionUrl));
}
return entity;
}

public RuntimeVersionEntity getRuntimeVersionAllowNull(String versionUrl) {
RuntimeVersionEntity entity;
if (idConvertor.isId(versionUrl)) {
var id = idConvertor.revert(versionUrl);
entity = runtimeVersionMapper.find(id);
} else {
entity = runtimeVersionMapper.findByNameAndRuntimeId(versionUrl, null);
}
if (entity == null) {
throw new SwNotFoundException(ResourceType.BUNDLE_VERSION,
String.format("Unable to find Runtime Version %s", versionUrl));
}
return entity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@ public Runtime findRuntime(Long runtimeId) {
return Runtime.fromEntity(entity);
}

public RuntimeVersion findRuntimeVersionAllowNull(String versioUrl) {
RuntimeVersionEntity entity = runtimeDao.getRuntimeVersionAllowNull(versioUrl);
return RuntimeVersion.fromEntity(entity);
}

public RuntimeVersion findRuntimeVersion(String versioUrl) {
RuntimeVersionEntity entity = runtimeDao.getRuntimeVersion(versioUrl);
return RuntimeVersion.fromEntity(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ public void testCreateJob() {
assertThrows(StarwhaleApiException.class, () -> service.createJob("1", "3", "1", "2",
"", "1", "h", "s", JobType.EVALUATION));

assertThrows(SwValidationException.class, () -> service.createJob("1", "3", "1", "",
"", "1", "h", "s", JobType.EVALUATION));

var res = service.createJob("1", "3", "1", "2",
"", "1", "mnist.evaluator:MNISTInference.cmp", "", JobType.EVALUATION);
assertThat(res, is(1L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,12 @@ public void testModifyModelVersion() {
given(modelVersionMapper.update(argThat(entity -> entity.getId() == 1L)))
.willReturn(1);

var res = service.modifyModelVersion("1", "1", "v1", new ModelVersion());
assertThrows(SwValidationException.class, () -> service.modifyModelVersion("1", "1", "v1", new ModelVersion()));

var res = service.modifyModelVersion("1", "1", "v1", ModelVersion.builder().tag("v1").build());
assertThat(res, is(true));

res = service.modifyModelVersion("1", "1", "v2", new ModelVersion());
res = service.modifyModelVersion("1", "1", "v2", ModelVersion.builder().tag("v1").build());
assertThat(res, is(false));
}

Expand Down

0 comments on commit cdfebd7

Please sign in to comment.