Skip to content

Commit d93a73e

Browse files
authored
Fix creating artifiact dir for integration tests (#2212)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
1 parent fe518fc commit d93a73e

File tree

2 files changed

+46
-51
lines changed

2 files changed

+46
-51
lines changed

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -472,32 +472,29 @@ void forceQuitNotAllowedThrowsException() {
472472
+ "is correctly executed for targets that do not have a running update already. Those are ignored.")
473473
@ExpectEvents({
474474
@Expect(type = TargetCreatedEvent.class, count = 20),
475-
@Expect(type = TargetUpdatedEvent.class, count = 20),
475+
@Expect(type = TargetUpdatedEvent.class, count = 20),
476476
@Expect(type = ActionCreatedEvent.class, count = 20),
477477
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
478478
@Expect(type = SoftwareModuleCreatedEvent.class, count = 6),
479479
@Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock
480480
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock
481481
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
482482
void assignedDistributionSet() {
483-
484-
final List<String> controllerIds = testdataFactory.createTargets(10).stream().map(Target::getControllerId)
485-
.toList();
486483
final List<Target> onlineAssignedTargets = testdataFactory.createTargets(10, "2");
487-
controllerIds.addAll(onlineAssignedTargets.stream().map(Target::getControllerId).toList());
484+
final List<String> controllerIds = Stream.concat(testdataFactory.createTargets(10).stream(), onlineAssignedTargets.stream())
485+
.map(Target::getControllerId).toList();
488486

489487
final DistributionSet ds = testdataFactory.createDistributionSet();
490488
assignDistributionSet(testdataFactory.createDistributionSet("2"), onlineAssignedTargets);
491489

492490
final long current = System.currentTimeMillis();
493491

494492
final List<Entry<String, Long>> offlineAssignments = controllerIds.stream()
495-
.map(targetId -> (Entry<String, Long>)new SimpleEntry<>(targetId, ds.getId())).toList();
493+
.map(targetId -> (Entry<String, Long>) new SimpleEntry<>(targetId, ds.getId())).toList();
496494
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
497495
.offlineAssignedDistributionSets(offlineAssignments);
498496
assertThat(assignmentResults).hasSize(1);
499-
final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget)
500-
.toList();
497+
final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget).toList();
501498

502499
assertThat(actionRepository.count()).isEqualTo(20);
503500
assertThat(findActionsByDistributionSet(PAGE, ds.getId())).as("Offline actions are not active")
@@ -518,7 +515,7 @@ void assignedDistributionSet() {
518515
@Description("Offline assign multiple DSs to a single Target in multiassignment mode.")
519516
@ExpectEvents({
520517
@Expect(type = TargetCreatedEvent.class, count = 1),
521-
@Expect(type = TargetUpdatedEvent.class, count = 4),
518+
@Expect(type = TargetUpdatedEvent.class, count = 4),
522519
@Expect(type = ActionCreatedEvent.class, count = 4),
523520
@Expect(type = DistributionSetCreatedEvent.class, count = 4),
524521
@Expect(type = SoftwareModuleCreatedEvent.class, count = 12),
@@ -554,7 +551,7 @@ void multiOfflineAssignment() {
554551
@Description("Verifies that if an account is set to action autoclose running actions in case of a new assigned set get closed and set to CANCELED.")
555552
@ExpectEvents({
556553
@Expect(type = TargetCreatedEvent.class, count = 10),
557-
@Expect(type = TargetUpdatedEvent.class, count = 20),
554+
@Expect(type = TargetUpdatedEvent.class, count = 20),
558555
@Expect(type = ActionCreatedEvent.class, count = 20),
559556
@Expect(type = ActionUpdatedEvent.class, count = 10),
560557
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
@@ -597,7 +594,7 @@ void assignDistributionSetAndAutoCloseActiveActions() {
597594
@Description("If multi-assignment is enabled, verify that the previous Distribution Set assignment is not canceled when a new one is assigned.")
598595
@ExpectEvents({
599596
@Expect(type = TargetCreatedEvent.class, count = 10),
600-
@Expect(type = TargetUpdatedEvent.class, count = 20),
597+
@Expect(type = TargetUpdatedEvent.class, count = 20),
601598
@Expect(type = ActionCreatedEvent.class, count = 20),
602599
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
603600
@Expect(type = SoftwareModuleCreatedEvent.class, count = 6),
@@ -628,7 +625,7 @@ void previousAssignmentsAreNotCanceledInMultiAssignMode() {
628625
@Description("Assign multiple DSs to a single Target in one request in multiassignment mode.")
629626
@ExpectEvents({
630627
@Expect(type = TargetCreatedEvent.class, count = 1),
631-
@Expect(type = TargetUpdatedEvent.class, count = 4),
628+
@Expect(type = TargetUpdatedEvent.class, count = 4),
632629
@Expect(type = ActionCreatedEvent.class, count = 4),
633630
@Expect(type = DistributionSetCreatedEvent.class, count = 4),
634631
@Expect(type = SoftwareModuleCreatedEvent.class, count = 12),
@@ -665,7 +662,7 @@ void multiAssignmentInOneRequest() {
665662
@Description("Assign multiple DSs to single Target in one request in multiAssignment mode and cancel each created action afterwards.")
666663
@ExpectEvents({
667664
@Expect(type = TargetCreatedEvent.class, count = 1),
668-
@Expect(type = TargetUpdatedEvent.class, count = 4),
665+
@Expect(type = TargetUpdatedEvent.class, count = 4),
669666
@Expect(type = ActionCreatedEvent.class, count = 4),
670667
@Expect(type = DistributionSetCreatedEvent.class, count = 4),
671668
@Expect(type = SoftwareModuleCreatedEvent.class, count = 12),
@@ -689,12 +686,12 @@ void cancelMultiAssignmentActions() {
689686

690687
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).toList();
691688
targets.forEach(target ->
692-
deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> {
693-
assertThat(action.getDistributionSet().getId()).isIn(dsIds);
694-
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
695-
.isEqualTo(tenantAware.getCurrentUsername());
696-
deploymentManagement.cancelAction(action.getId());
697-
}));
689+
deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> {
690+
assertThat(action.getDistributionSet().getId()).isIn(dsIds);
691+
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
692+
.isEqualTo(tenantAware.getCurrentUsername());
693+
deploymentManagement.cancelAction(action.getId());
694+
}));
698695
}
699696

700697
@Test
@@ -756,16 +753,16 @@ void assignmentWithConfirmationFlowActive(final boolean confirmationRequired) {
756753
assertThat(getResultingActionCount(results)).isEqualTo(controllerIds.size());
757754

758755
controllerIds.forEach(controllerId ->
759-
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
760-
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
761-
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
762-
.isEqualTo(tenantAware.getCurrentUsername());
763-
if (confirmationRequired) {
764-
assertThat(action.getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION);
765-
} else {
766-
assertThat(action.getStatus()).isEqualTo(RUNNING);
767-
}
768-
}));
756+
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
757+
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
758+
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
759+
.isEqualTo(tenantAware.getCurrentUsername());
760+
if (confirmationRequired) {
761+
assertThat(action.getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION);
762+
} else {
763+
assertThat(action.getStatus()).isEqualTo(RUNNING);
764+
}
765+
}));
769766
}
770767

771768
@ParameterizedTest
@@ -870,12 +867,12 @@ void verifyConfirmationRequiredFlagHaveNoInfluenceIfFlowIsDeactivated() {
870867
assertThat(getResultingActionCount(results)).isEqualTo(controllerIds.size());
871868

872869
controllerIds.forEach(controllerId ->
873-
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
874-
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
875-
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
876-
.isEqualTo(tenantAware.getCurrentUsername());
877-
assertThat(action.getStatus()).isEqualTo(RUNNING);
878-
}));
870+
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
871+
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
872+
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
873+
.isEqualTo(tenantAware.getCurrentUsername());
874+
assertThat(action.getStatus()).isEqualTo(RUNNING);
875+
}));
879876
}
880877

881878
@Test
@@ -887,7 +884,7 @@ void verifyConfirmationRequiredFlagHaveNoInfluenceIfFlowIsDeactivated() {
887884
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
888885
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock
889886
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
890-
@Expect(type = ActionCreatedEvent.class, count = 2),
887+
@Expect(type = ActionCreatedEvent.class, count = 2),
891888
@Expect(type = TargetUpdatedEvent.class, count = 2),
892889
@Expect(type = MultiActionAssignEvent.class, count = 1),
893890
@Expect(type = TenantConfigurationCreatedEvent.class, count = 1) })
@@ -968,7 +965,7 @@ void weightAllowedWhenMultiAssignmentModeNotEnabled() {
968965
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
969966
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
970967
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock
971-
@Expect(type = ActionCreatedEvent.class, count = 2),
968+
@Expect(type = ActionCreatedEvent.class, count = 2),
972969
@Expect(type = TargetUpdatedEvent.class, count = 2),
973970
@Expect(type = MultiActionAssignEvent.class, count = 2),
974971
@Expect(type = TenantConfigurationCreatedEvent.class, count = 1) })
@@ -1009,7 +1006,7 @@ void weightValidatedAndSaved() {
10091006
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
10101007
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
10111008
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock
1012-
@Expect(type = TargetCreatedEvent.class, count = 30),
1009+
@Expect(type = TargetCreatedEvent.class, count = 30),
10131010
@Expect(type = ActionCreatedEvent.class, count = 20),
10141011
@Expect(type = TargetUpdatedEvent.class, count = 20) })
10151012
void assignDistributionSet2Targets() {
@@ -1065,7 +1062,7 @@ void assignDistributionSet2Targets() {
10651062
@Expect(type = SoftwareModuleCreatedEvent.class, count = 2),
10661063
@Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock
10671064
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 2), // implicit lock
1068-
@Expect(type = TargetCreatedEvent.class, count = 10),
1065+
@Expect(type = TargetCreatedEvent.class, count = 10),
10691066
@Expect(type = ActionCreatedEvent.class, count = 10),
10701067
@Expect(type = TargetUpdatedEvent.class, count = 10) })
10711068
void failDistributionSetAssigmentThatIsNotComplete() {
@@ -1557,9 +1554,9 @@ void verifyDSAssignmentForMultipleTargetsWithDifferentTargetTypes() {
15571554
deploymentManagement.assignDistributionSets(deploymentRequests);
15581555
implicitLock(ds);
15591556

1560-
final DistributionSet assignedDsTarget1 = ((JpaTarget)targetManagement
1557+
final DistributionSet assignedDsTarget1 = ((JpaTarget) targetManagement
15611558
.getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet();
1562-
final DistributionSet assignedDsTarget2 = ((JpaTarget)targetManagement
1559+
final DistributionSet assignedDsTarget2 = ((JpaTarget) targetManagement
15631560
.getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet();
15641561

15651562
assertThat(assignedDsTarget1).isEqualTo(ds);

hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Comparator;
2323
import java.util.List;
2424
import java.util.NoSuchElementException;
25-
import java.util.stream.Collectors;
2625

2726
import lombok.extern.slf4j.Slf4j;
2827
import org.apache.commons.io.FileUtils;
@@ -99,14 +98,11 @@
9998
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
10099
@ContextConfiguration(classes = { TestConfiguration.class })
101100
@Import(TestChannelBinderConfiguration.class)
102-
// destroy the context after each test class because otherwise we get problem
103-
// when context is
104-
// refreshed we e.g. get two instances of CacheManager which leads to very
105-
// strange test failures.
101+
// destroy the context after each test class because otherwise we get problem when context is
102+
// refreshed we e.g. get two instances of CacheManager which leads to very strange test failures.
106103
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
107104
// Cleaning repository will fire "delete" events. We won't count them to the
108-
// test execution. So, the order execution between EventVerifier and Cleanup is
109-
// important!
105+
// test execution. So, the order execution between EventVerifier and Cleanup is important!
110106
@TestExecutionListeners(
111107
listeners = { EventVerifier.class, CleanupTestExecutionListener.class },
112108
mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
@@ -189,7 +185,7 @@ public abstract class AbstractIntegrationTest {
189185
protected ServiceMatcher serviceMatcher;
190186
@Autowired
191187
protected ApplicationEventPublisher eventPublisher;
192-
private static final String ARTIFACT_DIRECTORY = createTempDir().toString();
188+
private static final String ARTIFACT_DIRECTORY = createTempDir().getAbsolutePath() + "/" + randomString(20);
193189

194190
@BeforeAll
195191
public static void beforeClass() {
@@ -209,7 +205,6 @@ public static void afterClass() {
209205

210206
@BeforeEach
211207
public void beforeAll() throws Exception {
212-
213208
final String description = "Updated description.";
214209

215210
osType = SecurityContextSwitch
@@ -485,7 +480,7 @@ protected void waitNextMillis() {
485480

486481
private static File createTempDir() {
487482
try {
488-
final File file = Files.createTempFile(String.valueOf(System.currentTimeMillis()), "hawkbit_test").toFile();
483+
final File file = Files.createTempDirectory(System.currentTimeMillis() + "_").toFile();
489484
file.deleteOnExit();
490485
if (!file.setReadable(true, true) || !file.setWritable(true, true)) {
491486
if (file.delete()) { // try to delete immediately, if failed - on exit
@@ -498,6 +493,9 @@ private static File createTempDir() {
498493
if (!file.setExecutable(false)) {
499494
log.debug("Can't remove executable permissions for temp file {}", file);
500495
}
496+
if (!file.setExecutable(true, true)) {
497+
log.debug("Can't set executable permissions for temp directory {} for the owner", file);
498+
}
501499
return file;
502500
} catch (final IOException e) {
503501
throw new ArtifactStoreException("Cannot create temp file", e);

0 commit comments

Comments
 (0)