Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix creating artifiact dir for integration tests #2212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -472,32 +472,29 @@ void forceQuitNotAllowedThrowsException() {
+ "is correctly executed for targets that do not have a running update already. Those are ignored.")
@ExpectEvents({
@Expect(type = TargetCreatedEvent.class, count = 20),
@Expect(type = TargetUpdatedEvent.class, count = 20),
@Expect(type = TargetUpdatedEvent.class, count = 20),
@Expect(type = ActionCreatedEvent.class, count = 20),
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 6),
@Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
void assignedDistributionSet() {

final List<String> controllerIds = testdataFactory.createTargets(10).stream().map(Target::getControllerId)
.toList();
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();
assignDistributionSet(testdataFactory.createDistributionSet("2"), onlineAssignedTargets);

final long current = System.currentTimeMillis();

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
.offlineAssignedDistributionSets(offlineAssignments);
assertThat(assignmentResults).hasSize(1);
final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget)
.toList();
final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget).toList();

assertThat(actionRepository.count()).isEqualTo(20);
assertThat(findActionsByDistributionSet(PAGE, ds.getId())).as("Offline actions are not active")
Expand All @@ -518,7 +515,7 @@ void assignedDistributionSet() {
@Description("Offline assign multiple DSs to a single Target in multiassignment mode.")
@ExpectEvents({
@Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 4),
@Expect(type = TargetUpdatedEvent.class, count = 4),
@Expect(type = ActionCreatedEvent.class, count = 4),
@Expect(type = DistributionSetCreatedEvent.class, count = 4),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 12),
Expand Down Expand Up @@ -554,7 +551,7 @@ void multiOfflineAssignment() {
@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.")
@ExpectEvents({
@Expect(type = TargetCreatedEvent.class, count = 10),
@Expect(type = TargetUpdatedEvent.class, count = 20),
@Expect(type = TargetUpdatedEvent.class, count = 20),
@Expect(type = ActionCreatedEvent.class, count = 20),
@Expect(type = ActionUpdatedEvent.class, count = 10),
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
Expand Down Expand Up @@ -597,7 +594,7 @@ void assignDistributionSetAndAutoCloseActiveActions() {
@Description("If multi-assignment is enabled, verify that the previous Distribution Set assignment is not canceled when a new one is assigned.")
@ExpectEvents({
@Expect(type = TargetCreatedEvent.class, count = 10),
@Expect(type = TargetUpdatedEvent.class, count = 20),
@Expect(type = TargetUpdatedEvent.class, count = 20),
@Expect(type = ActionCreatedEvent.class, count = 20),
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 6),
Expand Down Expand Up @@ -628,7 +625,7 @@ void previousAssignmentsAreNotCanceledInMultiAssignMode() {
@Description("Assign multiple DSs to a single Target in one request in multiassignment mode.")
@ExpectEvents({
@Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 4),
@Expect(type = TargetUpdatedEvent.class, count = 4),
@Expect(type = ActionCreatedEvent.class, count = 4),
@Expect(type = DistributionSetCreatedEvent.class, count = 4),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 12),
Expand Down Expand Up @@ -665,7 +662,7 @@ void multiAssignmentInOneRequest() {
@Description("Assign multiple DSs to single Target in one request in multiAssignment mode and cancel each created action afterwards.")
@ExpectEvents({
@Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 4),
@Expect(type = TargetUpdatedEvent.class, count = 4),
@Expect(type = ActionCreatedEvent.class, count = 4),
@Expect(type = DistributionSetCreatedEvent.class, count = 4),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 12),
Expand All @@ -689,12 +686,12 @@ void cancelMultiAssignmentActions() {

final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).toList();
targets.forEach(target ->
deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> {
assertThat(action.getDistributionSet().getId()).isIn(dsIds);
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
.isEqualTo(tenantAware.getCurrentUsername());
deploymentManagement.cancelAction(action.getId());
}));
deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> {
assertThat(action.getDistributionSet().getId()).isIn(dsIds);
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
.isEqualTo(tenantAware.getCurrentUsername());
deploymentManagement.cancelAction(action.getId());
}));
}

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

controllerIds.forEach(controllerId ->
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
.isEqualTo(tenantAware.getCurrentUsername());
if (confirmationRequired) {
assertThat(action.getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION);
} else {
assertThat(action.getStatus()).isEqualTo(RUNNING);
}
}));
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
.isEqualTo(tenantAware.getCurrentUsername());
if (confirmationRequired) {
assertThat(action.getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION);
} else {
assertThat(action.getStatus()).isEqualTo(RUNNING);
}
}));
}

@ParameterizedTest
Expand Down Expand Up @@ -870,12 +867,12 @@ void verifyConfirmationRequiredFlagHaveNoInfluenceIfFlowIsDeactivated() {
assertThat(getResultingActionCount(results)).isEqualTo(controllerIds.size());

controllerIds.forEach(controllerId ->
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
.isEqualTo(tenantAware.getCurrentUsername());
assertThat(action.getStatus()).isEqualTo(RUNNING);
}));
deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> {
assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId());
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
.isEqualTo(tenantAware.getCurrentUsername());
assertThat(action.getStatus()).isEqualTo(RUNNING);
}));
}

@Test
Expand All @@ -887,7 +884,7 @@ void verifyConfirmationRequiredFlagHaveNoInfluenceIfFlowIsDeactivated() {
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionCreatedEvent.class, count = 2),
@Expect(type = ActionCreatedEvent.class, count = 2),
@Expect(type = TargetUpdatedEvent.class, count = 2),
@Expect(type = MultiActionAssignEvent.class, count = 1),
@Expect(type = TenantConfigurationCreatedEvent.class, count = 1) })
Expand Down Expand Up @@ -968,7 +965,7 @@ void weightAllowedWhenMultiAssignmentModeNotEnabled() {
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock
@Expect(type = ActionCreatedEvent.class, count = 2),
@Expect(type = ActionCreatedEvent.class, count = 2),
@Expect(type = TargetUpdatedEvent.class, count = 2),
@Expect(type = MultiActionAssignEvent.class, count = 2),
@Expect(type = TenantConfigurationCreatedEvent.class, count = 1) })
Expand Down Expand Up @@ -1009,7 +1006,7 @@ void weightValidatedAndSaved() {
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock
@Expect(type = TargetCreatedEvent.class, count = 30),
@Expect(type = TargetCreatedEvent.class, count = 30),
@Expect(type = ActionCreatedEvent.class, count = 20),
@Expect(type = TargetUpdatedEvent.class, count = 20) })
void assignDistributionSet2Targets() {
Expand Down Expand Up @@ -1065,7 +1062,7 @@ void assignDistributionSet2Targets() {
@Expect(type = SoftwareModuleCreatedEvent.class, count = 2),
@Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 2), // implicit lock
@Expect(type = TargetCreatedEvent.class, count = 10),
@Expect(type = TargetCreatedEvent.class, count = 10),
@Expect(type = ActionCreatedEvent.class, count = 10),
@Expect(type = TargetUpdatedEvent.class, count = 10) })
void failDistributionSetAssigmentThatIsNotComplete() {
Expand Down Expand Up @@ -1557,9 +1554,9 @@ void verifyDSAssignmentForMultipleTargetsWithDifferentTargetTypes() {
deploymentManagement.assignDistributionSets(deploymentRequests);
implicitLock(ds);

final DistributionSet assignedDsTarget1 = ((JpaTarget)targetManagement
final DistributionSet assignedDsTarget1 = ((JpaTarget) targetManagement
.getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet();
final DistributionSet assignedDsTarget2 = ((JpaTarget)targetManagement
final DistributionSet assignedDsTarget2 = ((JpaTarget) targetManagement
.getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet();

assertThat(assignedDsTarget1).isEqualTo(ds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;

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

@BeforeAll
public static void beforeClass() {
Expand All @@ -209,7 +205,6 @@ public static void afterClass() {

@BeforeEach
public void beforeAll() throws Exception {

final String description = "Updated description.";

osType = SecurityContextSwitch
Expand Down Expand Up @@ -485,7 +480,7 @@ protected void waitNextMillis() {

private static File createTempDir() {
try {
final File file = Files.createTempFile(String.valueOf(System.currentTimeMillis()), "hawkbit_test").toFile();
final File file = Files.createTempDirectory(System.currentTimeMillis() + "_").toFile();
file.deleteOnExit();
if (!file.setReadable(true, true) || !file.setWritable(true, true)) {
if (file.delete()) { // try to delete immediately, if failed - on exit
Expand All @@ -498,6 +493,9 @@ private static File createTempDir() {
if (!file.setExecutable(false)) {
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;
} catch (final IOException e) {
throw new ArtifactStoreException("Cannot create temp file", e);
Expand Down
Loading