Added support for different version schemes depending on the provider (#2124)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-12-06 14:40:13 +02:00
committed by GitHub
parent 2a476d1268
commit be6a58a38a
19 changed files with 106 additions and 73 deletions

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository.jpa;
public class JpaConstants {
public enum JpaVendor {
ECLIPSELINK,
HIBERNATE // NOT SUPPORTED!
}
public static final JpaVendor JPA_VENDOR = JpaVendor.ECLIPSELINK;
}

View File

@@ -615,9 +615,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
public List<Statistic> countRolloutsByStatusForDistributionSet(final Long id) {
assertDistributionSetExists(id);
return distributionSetRepository.countRolloutsByStatusForDistributionSet(id).stream()
.map(Statistic.class::cast).toList();
return distributionSetRepository.countRolloutsByStatusForDistributionSet(id).stream().map(Statistic.class::cast).toList();
}
@Override

View File

@@ -28,7 +28,6 @@ import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.eclipse.persistence.annotations.Multitenant;
import org.eclipse.persistence.annotations.MultitenantType;
import org.eclipse.persistence.annotations.TenantDiscriminatorColumn;
import org.hibernate.annotations.TenantId;
/**
* Holder of the base attributes common to all tenant aware entities.
@@ -45,11 +44,9 @@ public abstract class AbstractJpaTenantAwareBaseEntity extends AbstractJpaBaseEn
@Serial
private static final long serialVersionUID = 1L;
@Column(name = "tenant", nullable = false, insertable = false, updatable = false, length = 40) // eclipselink
// @Column(name = "tenant", nullable = false, updatable = false, length = 40) // hibernate
@Column(name = "tenant", nullable = false, insertable = false, updatable = false, length = 40)
@Size(min = 1, max = 40)
@NotNull
@TenantId // Hibernate MultiTenant support
private String tenant;
/**

View File

@@ -244,6 +244,14 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
return rolloutGroupRepository.findById(group.getId()).get();
}
// version is 1, 2 ... based
protected int version(final int version) {
return switch (JpaConstants.JPA_VENDOR) {
case ECLIPSELINK -> version;
case HIBERNATE -> version - 1;
};
}
private JpaRollout refresh(final Rollout rollout) {
return rolloutRepository.findById(rollout.getId()).get();
}

View File

@@ -508,13 +508,13 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// create a DS
final DistributionSet ds = testdataFactory.createDistributionSet("testDs");
// initial opt lock revision must be zero
assertThat(ds.getOptLockRevision()).isEqualTo(1);
assertThat(ds.getOptLockRevision()).isEqualTo(version(1));
// create an DS meta data entry
createDistributionSetMetadata(ds.getId(), new JpaDistributionSetMetadata(knownKey, ds, knownValue));
final DistributionSet changedLockRevisionDS = getOrThrow(distributionSetManagement.get(ds.getId()));
assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(2);
assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(version(2));
// update the DS metadata
final JpaDistributionSetMetadata updated = (JpaDistributionSetMetadata) distributionSetManagement
@@ -522,7 +522,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// we are updating the sw metadata so also modifying the base software
// module so opt lock revision must be three
final DistributionSet reloadedDS = getOrThrow(distributionSetManagement.get(ds.getId()));
assertThat(reloadedDS.getOptLockRevision()).isEqualTo(3);
assertThat(reloadedDS.getOptLockRevision()).isEqualTo(version(3));
assertThat(reloadedDS.getLastModifiedAt()).isPositive();
// verify updated meta data contains the updated value

View File

@@ -38,11 +38,11 @@ public class LazyControllerManagementTest extends AbstractJpaIntegrationTest {
private RepositoryProperties repositoryProperties;
@Test
@Description("Verfies that lazy target poll update is executed as specified.")
@Description("Verifies that lazy target poll update is executed as specified.")
@ExpectEvents({
@Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 2) })
public void lazyFindOrRegisterTargetIfItDoesNotexist() throws InterruptedException {
public void lazyFindOrRegisterTargetIfItDoesNotExist() throws InterruptedException {
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST);
assertThat(target).as("target should not be null").isNotNull();

View File

@@ -458,7 +458,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that all undeleted software modules are found in the repository.")
@Description("Verifies that all undeleted software modules are found in the repository.")
public void countSoftwareModuleTypesAll() {
testdataFactory.createSoftwareModuleOs();
@@ -472,7 +472,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that software modules are returned that are assigned to given DS.")
@Description("Verifies that software modules are returned that are assigned to given DS.")
public void findSoftwareModuleByAssignedTo() {
// test modules
final SoftwareModule one = testdataFactory.createSoftwareModuleOs();
@@ -499,7 +499,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
assertThat(ah.getOptLockRevision()).isEqualTo(1);
assertThat(ah.getOptLockRevision()).isEqualTo(version(1));
final SoftwareModuleMetadataCreate swMetadata1 = entityFactory.softwareModuleMetadata().create(ah.getId())
.key(knownKey1).value(knownValue1);
@@ -511,7 +511,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
.createMetaData(Arrays.asList(swMetadata1, swMetadata2));
final SoftwareModule changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get();
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(version(2));
assertThat(softwareModuleMetadata).hasSize(2);
assertThat(softwareModuleMetadata.get(0)).isNotNull();
@@ -604,7 +604,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
// create a base software module
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
// initial opt lock revision must be 1
assertThat(ah.getOptLockRevision()).isEqualTo(1);
assertThat(ah.getOptLockRevision()).isEqualTo(version(1));
// create an software module meta data entry
final SoftwareModuleMetadata softwareModuleMetadata = softwareModuleManagement.createMetaData(
@@ -615,7 +615,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
// base software module should have now the opt lock revision one
// because we are modifying the base software module
SoftwareModule changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get();
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(version(2));
// update the software module metadata
final SoftwareModuleMetadata updated = softwareModuleManagement.updateMetaData(entityFactory
@@ -624,7 +624,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
// we are updating the sw metadata so also modifying the base software
// module so opt lock revision must be two
changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get();
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(3);
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(version(3));
// verify updated meta data contains the updated value
assertThat(updated).isNotNull();

View File

@@ -151,7 +151,7 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
}
@Test
@Description("Verfies that it is not possible to create a type that alrady exists.")
@Description("Verifies that it is not possible to create a type that alrady exists.")
public void createSoftwareModuleTypeFailsWithExistingEntity() {
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
@@ -165,7 +165,7 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
}
@Test
@Description("Verfies that it is not possible to create a list of types where one already exists.")
@Description("Verifies that it is not possible to create a list of types where one already exists.")
public void createSoftwareModuleTypesFailsWithExistingEntity() {
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
@@ -191,7 +191,7 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
}
@Test
@Description("Verfies that multiple types are created as requested.")
@Description("Verifies that multiple types are created as requested.")
public void createMultipleSoftwareModuleTypes() {
final List<SoftwareModuleType> created = softwareModuleTypeManagement
.create(Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),

View File

@@ -327,7 +327,7 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that targets with given assigned DS are returned from repository.")
@Description("Verifies that targets with given assigned DS are returned from repository.")
void findTargetByAssignedDistributionSet() {
final DistributionSet assignedSet = testdataFactory.createDistributionSet("");
testdataFactory.createTargets(10, "unassigned", "unassigned");

View File

@@ -840,14 +840,14 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// create a target
final Target target = testdataFactory.createTarget("target1");
// initial opt lock revision must be zero
assertThat(target.getOptLockRevision()).isEqualTo(1);
assertThat(target.getOptLockRevision()).isEqualTo(version(1));
// create target meta data entry
insertTargetMetadata(knownKey, knownValue, target);
Target changedLockRevisionTarget = targetManagement.get(target.getId())
.orElseThrow(NoSuchElementException::new);
assertThat(changedLockRevisionTarget.getOptLockRevision()).isEqualTo(2);
assertThat(changedLockRevisionTarget.getOptLockRevision()).isEqualTo(version(2));
// Unsure if needed maybe to wait for a db flush?
// Thread.sleep(100);
@@ -858,7 +858,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// we are updating the target meta data so also modifying the base
// software module so opt lock revision must be three
changedLockRevisionTarget = targetManagement.get(target.getId()).orElseThrow(NoSuchElementException::new);
assertThat(changedLockRevisionTarget.getOptLockRevision()).isEqualTo(3);
assertThat(changedLockRevisionTarget.getOptLockRevision()).isEqualTo(version(3));
assertThat(changedLockRevisionTarget.getLastModifiedAt()).isPositive();
// verify updated meta data contains the updated value
@@ -881,7 +881,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// initial opt lock revision must be one
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
assertThat(targetFound).isPresent();
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1);
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(version(1));
assertThat(targetFound.get().getTargetType().getId()).isEqualTo(targetTypes.get(0).getId());
// update the target type
@@ -892,7 +892,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// opt lock revision must be changed
final Optional<JpaTarget> targetFound1 = targetRepository.findById(target.getId());
assertThat(targetFound1).isPresent();
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(2);
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(version(2));
assertThat(targetFound1.get().getTargetType().getId()).isEqualTo(targetTypes.get(1).getId());
// unassign the target type
@@ -901,7 +901,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// opt lock revision must be changed
final Optional<JpaTarget> targetFound2 = targetRepository.findById(target.getId());
assertThat(targetFound2).isPresent();
assertThat(targetFound2.get().getOptLockRevision()).isEqualTo(3);
assertThat(targetFound2.get().getOptLockRevision()).isEqualTo(version(3));
assertThat(targetFound2.get().getTargetType()).isNull();
}
@@ -914,7 +914,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// initial opt lock revision must be one
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
assertThat(targetFound).isPresent();
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1);
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(version(1));
assertThat(targetFound.get().getTargetType()).isNull();
// create a target type
@@ -927,7 +927,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// opt lock revision must be changed
final Optional<JpaTarget> targetFound1 = targetRepository.findById(target.getId());
assertThat(targetFound1).isPresent();
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(2);
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(version(2));
assertThat(targetFound1.get().getTargetType().getId()).isEqualTo(targetType.getId());
}
@@ -1003,7 +1003,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// initial opt lock revision must be one
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
assertThat(targetFound).isPresent();
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1);
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(version(1));
assertThat(targetFound.get().getTargetType()).isNull();
// assign target type to target
@@ -1017,7 +1017,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// opt lock revision is not changed
final Optional<JpaTarget> targetFound1 = targetRepository.findById(target.getId());
assertThat(targetFound1).isPresent();
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(1);
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(version(1));
}
@Test
@@ -1032,7 +1032,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// initial opt lock revision must be one
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
assertThat(targetFound).isPresent();
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1);
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(version(1));
assertThat(targetFound.get().getTargetType().getName()).isEqualTo(targetType.getName());
// un-assign target type from target
@@ -1041,7 +1041,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
// opt lock revision must be changed
final Optional<JpaTarget> targetFound1 = targetRepository.findById(target.getId());
assertThat(targetFound1).isPresent();
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(2);
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(version(2));
assertThat(targetFound1.get().getTargetType()).isNull();
}

View File

@@ -35,19 +35,19 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that the pre persist is called after a entity creation.")
@Description("Verifies that the pre persist is called after a entity creation.")
public void prePersistIsCalledWhenPersistingATarget() {
executePersistAndAssertCallbackResult(new PrePersistEntityListener());
}
@Test
@Description("Verfies that the post persist is called after a entity creation.")
@Description("Verifies that the post persist is called after a entity creation.")
public void postPersistIsCalledWhenPersistingATarget() {
executePersistAndAssertCallbackResult(new PostPersistEntityListener());
}
@Test
@Description("Verfies that the post load is called after a entity is loaded.")
@Description("Verifies that the post load is called after a entity is loaded.")
public void postLoadIsCalledWhenLoadATarget() {
final PostLoadEntityListener postLoadEntityListener = new PostLoadEntityListener();
EntityInterceptorHolder.getInstance().getEntityInterceptors().add(postLoadEntityListener);
@@ -60,25 +60,25 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that the pre update is called after a entity update.")
@Description("Verifies that the pre update is called after a entity update.")
public void preUpdateIsCalledWhenUpdateATarget() {
executeUpdateAndAssertCallbackResult(new PreUpdateEntityListener());
}
@Test
@Description("Verfies that the post update is called after a entity update.")
@Description("Verifies that the post update is called after a entity update.")
public void postUpdateIsCalledWhenUpdateATarget() {
executeUpdateAndAssertCallbackResult(new PostUpdateEntityListener());
}
@Test
@Description("Verfies that the pre remove is called after a entity deletion.")
@Description("Verifies that the pre remove is called after a entity deletion.")
public void preRemoveIsCalledWhenDeletingATarget() {
executeDeleteAndAssertCallbackResult(new PreRemoveEntityListener());
}
@Test
@Description("Verfies that the post remove is called after a entity deletion.")
@Description("Verifies that the post remove is called after a entity deletion.")
public void postRemoveIsCalledWhenDeletingATarget() {
executeDeleteAndAssertCallbackResult(new PostRemoveEntityListener());
}

View File

@@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verfies that different objects even with identical primary key, version and tenant "
@Description("Verifies that different objects even with identical primary key, version and tenant "
+ "return different hash codes.")
public void differentEntitiesReturnDifferentHashCodes() {
assertThat(new JpaAction().hashCode()).as("action should have different hashcode than action status")
@@ -40,7 +40,7 @@ public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that different object even with identical primary key, version and tenant "
@Description("Verifies that different object even with identical primary key, version and tenant "
+ "are not equal.")
public void differentEntitiesAreNotEqual() {
assertThat(new JpaAction().equals(new JpaActionStatus())).as("action equals action status").isFalse();
@@ -53,7 +53,7 @@ public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that updated entities are not equal.")
@Description("Verifies that updated entities are not equal.")
public void changedEntitiesAreNotEqual() {
final SoftwareModuleType type = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("test").name("test"));