Fix creating artifiact dir for integration tests (#2212)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -480,11 +480,9 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock
|
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock
|
||||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
|
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
|
||||||
void assignedDistributionSet() {
|
void assignedDistributionSet() {
|
||||||
|
|
||||||
final List<String> controllerIds = testdataFactory.createTargets(10).stream().map(Target::getControllerId)
|
|
||||||
.toList();
|
|
||||||
final List<Target> onlineAssignedTargets = testdataFactory.createTargets(10, "2");
|
final List<Target> onlineAssignedTargets = testdataFactory.createTargets(10, "2");
|
||||||
controllerIds.addAll(onlineAssignedTargets.stream().map(Target::getControllerId).toList());
|
final List<String> controllerIds = Stream.concat(testdataFactory.createTargets(10).stream(), onlineAssignedTargets.stream())
|
||||||
|
.map(Target::getControllerId).toList();
|
||||||
|
|
||||||
final DistributionSet ds = testdataFactory.createDistributionSet();
|
final DistributionSet ds = testdataFactory.createDistributionSet();
|
||||||
assignDistributionSet(testdataFactory.createDistributionSet("2"), onlineAssignedTargets);
|
assignDistributionSet(testdataFactory.createDistributionSet("2"), onlineAssignedTargets);
|
||||||
@@ -492,12 +490,11 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final long current = System.currentTimeMillis();
|
final long current = System.currentTimeMillis();
|
||||||
|
|
||||||
final List<Entry<String, Long>> offlineAssignments = controllerIds.stream()
|
final List<Entry<String, Long>> offlineAssignments = controllerIds.stream()
|
||||||
.map(targetId -> (Entry<String, Long>)new SimpleEntry<>(targetId, ds.getId())).toList();
|
.map(targetId -> (Entry<String, Long>) new SimpleEntry<>(targetId, ds.getId())).toList();
|
||||||
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
|
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
|
||||||
.offlineAssignedDistributionSets(offlineAssignments);
|
.offlineAssignedDistributionSets(offlineAssignments);
|
||||||
assertThat(assignmentResults).hasSize(1);
|
assertThat(assignmentResults).hasSize(1);
|
||||||
final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget)
|
final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget).toList();
|
||||||
.toList();
|
|
||||||
|
|
||||||
assertThat(actionRepository.count()).isEqualTo(20);
|
assertThat(actionRepository.count()).isEqualTo(20);
|
||||||
assertThat(findActionsByDistributionSet(PAGE, ds.getId())).as("Offline actions are not active")
|
assertThat(findActionsByDistributionSet(PAGE, ds.getId())).as("Offline actions are not active")
|
||||||
@@ -689,12 +686,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).toList();
|
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).toList();
|
||||||
targets.forEach(target ->
|
targets.forEach(target ->
|
||||||
deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> {
|
deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> {
|
||||||
assertThat(action.getDistributionSet().getId()).isIn(dsIds);
|
assertThat(action.getDistributionSet().getId()).isIn(dsIds);
|
||||||
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
|
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
|
||||||
.isEqualTo(tenantAware.getCurrentUsername());
|
.isEqualTo(tenantAware.getCurrentUsername());
|
||||||
deploymentManagement.cancelAction(action.getId());
|
deploymentManagement.cancelAction(action.getId());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -756,16 +753,16 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
assertThat(getResultingActionCount(results)).isEqualTo(controllerIds.size());
|
assertThat(getResultingActionCount(results)).isEqualTo(controllerIds.size());
|
||||||
|
|
||||||
controllerIds.forEach(controllerId ->
|
controllerIds.forEach(controllerId ->
|
||||||
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
|
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
|
||||||
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
|
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
|
||||||
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
|
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
|
||||||
.isEqualTo(tenantAware.getCurrentUsername());
|
.isEqualTo(tenantAware.getCurrentUsername());
|
||||||
if (confirmationRequired) {
|
if (confirmationRequired) {
|
||||||
assertThat(action.getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION);
|
assertThat(action.getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION);
|
||||||
} else {
|
} else {
|
||||||
assertThat(action.getStatus()).isEqualTo(RUNNING);
|
assertThat(action.getStatus()).isEqualTo(RUNNING);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@@ -870,12 +867,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
assertThat(getResultingActionCount(results)).isEqualTo(controllerIds.size());
|
assertThat(getResultingActionCount(results)).isEqualTo(controllerIds.size());
|
||||||
|
|
||||||
controllerIds.forEach(controllerId ->
|
controllerIds.forEach(controllerId ->
|
||||||
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
|
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
|
||||||
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
|
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
|
||||||
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
|
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
|
||||||
.isEqualTo(tenantAware.getCurrentUsername());
|
.isEqualTo(tenantAware.getCurrentUsername());
|
||||||
assertThat(action.getStatus()).isEqualTo(RUNNING);
|
assertThat(action.getStatus()).isEqualTo(RUNNING);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1557,9 +1554,9 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
deploymentManagement.assignDistributionSets(deploymentRequests);
|
deploymentManagement.assignDistributionSets(deploymentRequests);
|
||||||
implicitLock(ds);
|
implicitLock(ds);
|
||||||
|
|
||||||
final DistributionSet assignedDsTarget1 = ((JpaTarget)targetManagement
|
final DistributionSet assignedDsTarget1 = ((JpaTarget) targetManagement
|
||||||
.getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet();
|
.getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet();
|
||||||
final DistributionSet assignedDsTarget2 = ((JpaTarget)targetManagement
|
final DistributionSet assignedDsTarget2 = ((JpaTarget) targetManagement
|
||||||
.getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet();
|
.getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet();
|
||||||
|
|
||||||
assertThat(assignedDsTarget1).isEqualTo(ds);
|
assertThat(assignedDsTarget1).isEqualTo(ds);
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
@@ -99,14 +98,11 @@ import org.springframework.test.context.TestPropertySource;
|
|||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||||
@ContextConfiguration(classes = { TestConfiguration.class })
|
@ContextConfiguration(classes = { TestConfiguration.class })
|
||||||
@Import(TestChannelBinderConfiguration.class)
|
@Import(TestChannelBinderConfiguration.class)
|
||||||
// destroy the context after each test class because otherwise we get problem
|
// destroy the context after each test class because otherwise we get problem when context is
|
||||||
// when context is
|
// refreshed we e.g. get two instances of CacheManager which leads to very strange test failures.
|
||||||
// refreshed we e.g. get two instances of CacheManager which leads to very
|
|
||||||
// strange test failures.
|
|
||||||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
||||||
// Cleaning repository will fire "delete" events. We won't count them to the
|
// Cleaning repository will fire "delete" events. We won't count them to the
|
||||||
// test execution. So, the order execution between EventVerifier and Cleanup is
|
// test execution. So, the order execution between EventVerifier and Cleanup is important!
|
||||||
// important!
|
|
||||||
@TestExecutionListeners(
|
@TestExecutionListeners(
|
||||||
listeners = { EventVerifier.class, CleanupTestExecutionListener.class },
|
listeners = { EventVerifier.class, CleanupTestExecutionListener.class },
|
||||||
mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
|
mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
|
||||||
@@ -189,7 +185,7 @@ public abstract class AbstractIntegrationTest {
|
|||||||
protected ServiceMatcher serviceMatcher;
|
protected ServiceMatcher serviceMatcher;
|
||||||
@Autowired
|
@Autowired
|
||||||
protected ApplicationEventPublisher eventPublisher;
|
protected ApplicationEventPublisher eventPublisher;
|
||||||
private static final String ARTIFACT_DIRECTORY = createTempDir().toString();
|
private static final String ARTIFACT_DIRECTORY = createTempDir().getAbsolutePath() + "/" + randomString(20);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
@@ -209,7 +205,6 @@ public abstract class AbstractIntegrationTest {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void beforeAll() throws Exception {
|
public void beforeAll() throws Exception {
|
||||||
|
|
||||||
final String description = "Updated description.";
|
final String description = "Updated description.";
|
||||||
|
|
||||||
osType = SecurityContextSwitch
|
osType = SecurityContextSwitch
|
||||||
@@ -485,7 +480,7 @@ public abstract class AbstractIntegrationTest {
|
|||||||
|
|
||||||
private static File createTempDir() {
|
private static File createTempDir() {
|
||||||
try {
|
try {
|
||||||
final File file = Files.createTempFile(String.valueOf(System.currentTimeMillis()), "hawkbit_test").toFile();
|
final File file = Files.createTempDirectory(System.currentTimeMillis() + "_").toFile();
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
if (!file.setReadable(true, true) || !file.setWritable(true, true)) {
|
if (!file.setReadable(true, true) || !file.setWritable(true, true)) {
|
||||||
if (file.delete()) { // try to delete immediately, if failed - on exit
|
if (file.delete()) { // try to delete immediately, if failed - on exit
|
||||||
@@ -498,6 +493,9 @@ public abstract class AbstractIntegrationTest {
|
|||||||
if (!file.setExecutable(false)) {
|
if (!file.setExecutable(false)) {
|
||||||
log.debug("Can't remove executable permissions for temp file {}", file);
|
log.debug("Can't remove executable permissions for temp file {}", file);
|
||||||
}
|
}
|
||||||
|
if (!file.setExecutable(true, true)) {
|
||||||
|
log.debug("Can't set executable permissions for temp directory {} for the owner", file);
|
||||||
|
}
|
||||||
return file;
|
return file;
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new ArtifactStoreException("Cannot create temp file", e);
|
throw new ArtifactStoreException("Cannot create temp file", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user