Test and build performance improvements (#552)
* Small build perf improvements. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Remove dead code. Stabilize test. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Further optimizations Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Upgrade mariadb driver. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Raise timeouts for more robustness on slower build environments. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Move webappcontext into rest tests. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Raised timeout. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Remove test dependency on target to groups distribution order. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Code reuse. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Context available to tests. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Typos fixed. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix PollEvent send. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix typos. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Test log readability and removed unused method from CM. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Remove empty payload. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Stabilize tests. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Raised timeout. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fixed fire directory change during one test class run. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -37,7 +37,6 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.eclipse.hawkbit.rest.util.JsonBuilder;
|
||||
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
|
||||
@@ -714,7 +713,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
|
||||
public void retrieveTargetsFromRolloutGroupWithQuery() throws Exception {
|
||||
// setup
|
||||
final int amountTargets = 10;
|
||||
final List<Target> targets = testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
@@ -724,11 +723,13 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
|
||||
.findRolloutGroupsByRolloutId(rollout.getId(), new PageRequest(0, 1, Direction.ASC, "id")).getContent()
|
||||
.get(0);
|
||||
|
||||
final String targetInGroup = rolloutGroupManagement.findRolloutGroupTargets(firstGroup.getId(), PAGE)
|
||||
.getContent().get(0).getControllerId();
|
||||
|
||||
// retrieve targets from the first rollout group with known ID
|
||||
mvc.perform(
|
||||
get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId())
|
||||
.accept(MediaType.APPLICATION_JSON).param("q",
|
||||
"controllerId==" + targets.get(0).getControllerId()))
|
||||
.accept(MediaType.APPLICATION_JSON).param("q", "controllerId==" + targetInGroup))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1)));
|
||||
|
||||
@@ -86,8 +86,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
final String updateVendor = "newVendor1";
|
||||
final String updateDescription = "newDescription1";
|
||||
|
||||
SoftwareModule sm = softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule().create().type(osType)
|
||||
.name(knownSWName).version(knownSWVersion).description(knownSWDescription).vendor(knownSWVendor));
|
||||
SoftwareModule sm = softwareModuleManagement
|
||||
.createSoftwareModule(entityFactory.softwareModule().create().type(osType).name(knownSWName)
|
||||
.version(knownSWVersion).description(knownSWDescription).vendor(knownSWVendor));
|
||||
|
||||
assertThat(sm.getName()).as("Wrong name of the software module").isEqualTo(knownSWName);
|
||||
|
||||
@@ -140,7 +141,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
// check rest of response compared to DB
|
||||
final MgmtArtifact artResult = ResourceUtility
|
||||
.convertArtifactResponse(mvcResult.getResponse().getContentAsString());
|
||||
final Long artId = softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts().get(0).getId();
|
||||
final Long artId = softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts().get(0)
|
||||
.getId();
|
||||
assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId);
|
||||
assertThat(JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.as("Link contains no self url")
|
||||
@@ -158,9 +160,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
assertThat(artifactManagement.countArtifactsAll()).as("Wrong artifact size").isEqualTo(1);
|
||||
|
||||
// binary
|
||||
try (InputStream fileInputStream = artifactManagement
|
||||
.loadArtifactBinary(
|
||||
softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts().get(0).getSha1Hash())
|
||||
try (InputStream fileInputStream = artifactManagement.loadArtifactBinary(
|
||||
softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts().get(0).getSha1Hash())
|
||||
.get().getFileInputStream()) {
|
||||
assertTrue("Wrong artifact content",
|
||||
IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream));
|
||||
@@ -174,8 +175,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
.isEqualTo(HashGeneratorUtils.generateMD5(random));
|
||||
|
||||
// metadata
|
||||
assertThat(softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts().get(0).getFilename())
|
||||
.as("wrong metadata of the filename").isEqualTo("origFilename");
|
||||
assertThat(
|
||||
softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts().get(0).getFilename())
|
||||
.as("wrong metadata of the filename").isEqualTo("origFilename");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -295,27 +297,24 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file2", false);
|
||||
|
||||
final MvcResult result = mvc
|
||||
.perform(
|
||||
get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(), artifact.getId()))
|
||||
.andExpect(header().string("ETag", artifact.getSha1Hash()))
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)).andReturn();
|
||||
|
||||
assertTrue("Wrong response content", Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
||||
|
||||
final MvcResult result2 = mvc
|
||||
.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(),
|
||||
artifact2.getId()))
|
||||
.andExpect(header().string("ETag", artifact2.getSha1Hash()))
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)).andReturn();
|
||||
|
||||
assertTrue("Response has wrong response content",
|
||||
Arrays.equals(result2.getResponse().getContentAsByteArray(), random));
|
||||
downloadAndVerify(sm, random, artifact);
|
||||
downloadAndVerify(sm, random, artifact2);
|
||||
|
||||
assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).as("Softwaremodule size is wrong").hasSize(1);
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2);
|
||||
}
|
||||
|
||||
private void downloadAndVerify(final SoftwareModule sm, final byte[] random, final Artifact artifact)
|
||||
throws Exception {
|
||||
final MvcResult result = mvc
|
||||
.perform(
|
||||
get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(), artifact.getId()))
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM))
|
||||
.andExpect(header().string("ETag", artifact.getSha1Hash())).andReturn();
|
||||
|
||||
assertTrue("Wrong response content", Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and download links.")
|
||||
public void getArtifact() throws Exception {
|
||||
@@ -444,10 +443,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
|
||||
final SoftwareModule toLongName = entityFactory.softwareModule().create().type(osType)
|
||||
.name(RandomStringUtils.randomAscii(80)).build();
|
||||
mvc.perform(
|
||||
post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Arrays.asList(toLongName)))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
|
||||
mvc.perform(post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Arrays.asList(toLongName)))
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// unsupported media type
|
||||
mvc.perform(post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(modules))
|
||||
@@ -707,14 +705,16 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId() + "/artifacts");
|
||||
|
||||
assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).as("Wrong softwaremodule size").hasSize(2);
|
||||
assertThat(softwareModuleManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0).getName())
|
||||
.as("Softwaremoudle name is wrong").isEqualTo(os.getName());
|
||||
assertThat(
|
||||
softwareModuleManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0).getName())
|
||||
.as("Softwaremoudle name is wrong").isEqualTo(os.getName());
|
||||
assertThat(softwareModuleManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0)
|
||||
.getCreatedBy()).as("Softwaremoudle created by is wrong").isEqualTo("uploadTester");
|
||||
assertThat(softwareModuleManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0)
|
||||
.getCreatedAt()).as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current);
|
||||
assertThat(softwareModuleManagement.findSoftwareModulesByType(PAGE, appType.getId()).getContent().get(0).getName())
|
||||
.as("Softwaremoudle name is wrong").isEqualTo(ah.getName());
|
||||
assertThat(
|
||||
softwareModuleManagement.findSoftwareModulesByType(PAGE, appType.getId()).getContent().get(0).getName())
|
||||
.as("Softwaremoudle name is wrong").isEqualTo(ah.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -819,10 +819,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
.andExpect(jsonPath("[1]key", equalTo(knownKey2)))
|
||||
.andExpect(jsonPath("[1]value", equalTo(knownValue2)));
|
||||
|
||||
final SoftwareModuleMetadata metaKey1 = softwareModuleManagement.findSoftwareModuleMetadata(sm.getId(), knownKey1)
|
||||
.get();
|
||||
final SoftwareModuleMetadata metaKey2 = softwareModuleManagement.findSoftwareModuleMetadata(sm.getId(), knownKey2)
|
||||
.get();
|
||||
final SoftwareModuleMetadata metaKey1 = softwareModuleManagement
|
||||
.findSoftwareModuleMetadata(sm.getId(), knownKey1).get();
|
||||
final SoftwareModuleMetadata metaKey2 = softwareModuleManagement
|
||||
.findSoftwareModuleMetadata(sm.getId(), knownKey2).get();
|
||||
|
||||
assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1);
|
||||
assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2);
|
||||
@@ -848,8 +848,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));
|
||||
|
||||
final SoftwareModuleMetadata assertDS = softwareModuleManagement.findSoftwareModuleMetadata(sm.getId(), knownKey)
|
||||
.get();
|
||||
final SoftwareModuleMetadata assertDS = softwareModuleManagement
|
||||
.findSoftwareModuleMetadata(sm.getId(), knownKey).get();
|
||||
assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -1322,7 +1323,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
private Target createSingleTarget(final String controllerId, final String name) {
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId).name(name)
|
||||
.description(TARGET_DESCRIPTION_TEST));
|
||||
return controllerManagement.updateLastTargetQuery(controllerId, null);
|
||||
return controllerManagement.findOrRegisterTargetIfItDoesNotexist(controllerId, LOCALHOST);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1331,13 +1332,14 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
*
|
||||
* @param amount
|
||||
* The number of targets to create
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
private void createTargetsAlphabetical(final int amount) {
|
||||
char character = 'a';
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final String str = String.valueOf(character);
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(str).name(str).description(str));
|
||||
controllerManagement.updateLastTargetQuery(str, null);
|
||||
controllerManagement.findOrRegisterTargetIfItDoesNotexist(str, LOCALHOST);
|
||||
character++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user