|
|
@ -16,17 +16,25 @@ |
|
|
package org.thingsboard.server.dao.service; |
|
|
package org.thingsboard.server.dao.service; |
|
|
|
|
|
|
|
|
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|
|
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|
|
|
|
|
import com.google.common.util.concurrent.ListeningExecutorService; |
|
|
|
|
|
import com.google.common.util.concurrent.MoreExecutors; |
|
|
|
|
|
import org.junit.After; |
|
|
import org.junit.Assert; |
|
|
import org.junit.Assert; |
|
|
|
|
|
import org.junit.Before; |
|
|
import org.junit.Test; |
|
|
import org.junit.Test; |
|
|
import org.junit.jupiter.api.Assertions; |
|
|
import org.junit.jupiter.api.Assertions; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
import org.springframework.transaction.TransactionStatus; |
|
|
import org.springframework.transaction.TransactionStatus; |
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition; |
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition; |
|
|
|
|
|
import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils; |
|
|
|
|
|
import org.testcontainers.shaded.org.awaitility.Awaitility; |
|
|
|
|
|
import org.thingsboard.common.util.ThingsBoardThreadFactory; |
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
import org.thingsboard.server.common.data.EntitySubtype; |
|
|
import org.thingsboard.server.common.data.EntitySubtype; |
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
|
|
|
import org.thingsboard.server.common.data.TenantProfile; |
|
|
import org.thingsboard.server.common.data.asset.Asset; |
|
|
import org.thingsboard.server.common.data.asset.Asset; |
|
|
import org.thingsboard.server.common.data.asset.AssetInfo; |
|
|
import org.thingsboard.server.common.data.asset.AssetInfo; |
|
|
import org.thingsboard.server.common.data.asset.AssetProfile; |
|
|
import org.thingsboard.server.common.data.asset.AssetProfile; |
|
|
@ -44,6 +52,8 @@ import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|
|
|
|
|
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
|
|
|
|
|
import org.thingsboard.server.common.data.tenant.profile.TenantProfileData; |
|
|
import org.thingsboard.server.dao.asset.AssetDao; |
|
|
import org.thingsboard.server.dao.asset.AssetDao; |
|
|
import org.thingsboard.server.dao.asset.AssetProfileService; |
|
|
import org.thingsboard.server.dao.asset.AssetProfileService; |
|
|
import org.thingsboard.server.dao.asset.AssetService; |
|
|
import org.thingsboard.server.dao.asset.AssetService; |
|
|
@ -51,11 +61,14 @@ import org.thingsboard.server.dao.cf.CalculatedFieldService; |
|
|
import org.thingsboard.server.dao.customer.CustomerService; |
|
|
import org.thingsboard.server.dao.customer.CustomerService; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.relation.RelationService; |
|
|
import org.thingsboard.server.dao.relation.RelationService; |
|
|
|
|
|
import org.thingsboard.server.dao.tenant.TenantProfileService; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Collections; |
|
|
import java.util.Collections; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
|
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
|
|
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
|
|
@ -72,6 +85,8 @@ public class AssetServiceTest extends AbstractServiceTest { |
|
|
@Autowired |
|
|
@Autowired |
|
|
RelationService relationService; |
|
|
RelationService relationService; |
|
|
@Autowired |
|
|
@Autowired |
|
|
|
|
|
TenantProfileService tenantProfileService; |
|
|
|
|
|
@Autowired |
|
|
private AssetProfileService assetProfileService; |
|
|
private AssetProfileService assetProfileService; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private CalculatedFieldService calculatedFieldService; |
|
|
private CalculatedFieldService calculatedFieldService; |
|
|
@ -79,6 +94,18 @@ public class AssetServiceTest extends AbstractServiceTest { |
|
|
private PlatformTransactionManager platformTransactionManager; |
|
|
private PlatformTransactionManager platformTransactionManager; |
|
|
|
|
|
|
|
|
private IdComparator<Asset> idComparator = new IdComparator<>(); |
|
|
private IdComparator<Asset> idComparator = new IdComparator<>(); |
|
|
|
|
|
ListeningExecutorService executor; |
|
|
|
|
|
private TenantId anotherTenantId; |
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
|
public void before() { |
|
|
|
|
|
executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10, ThingsBoardThreadFactory.forName(getClass().getSimpleName() + "-test-scope"))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@After |
|
|
|
|
|
public void after() { |
|
|
|
|
|
executor.shutdownNow(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testSaveAsset() { |
|
|
public void testSaveAsset() { |
|
|
@ -105,6 +132,36 @@ public class AssetServiceTest extends AbstractServiceTest { |
|
|
assetService.deleteAsset(tenantId, savedAsset.getId()); |
|
|
assetService.deleteAsset(tenantId, savedAsset.getId()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void testAssetLimitOnTenantProfileLevel() { |
|
|
|
|
|
TenantProfile tenantProfile = new TenantProfile(); |
|
|
|
|
|
tenantProfile.setName("Test profile"); |
|
|
|
|
|
tenantProfile.setDescription("Test"); |
|
|
|
|
|
TenantProfileData profileData = new TenantProfileData(); |
|
|
|
|
|
profileData.setConfiguration(DefaultTenantProfileConfiguration.builder().maxAssets(5l).build()); |
|
|
|
|
|
tenantProfile.setProfileData(profileData); |
|
|
|
|
|
tenantProfile.setDefault(false); |
|
|
|
|
|
tenantProfile.setIsolatedTbRuleEngine(false); |
|
|
|
|
|
|
|
|
|
|
|
tenantProfile = tenantProfileService.saveTenantProfile(anotherTenantId, tenantProfile); |
|
|
|
|
|
anotherTenantId = createTenant(tenantProfile.getId()).getId(); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 20; i++) { |
|
|
|
|
|
executor.submit(() -> { |
|
|
|
|
|
Asset asset = new Asset(); |
|
|
|
|
|
asset.setTenantId(anotherTenantId); |
|
|
|
|
|
asset.setName(RandomStringUtils.randomAlphabetic(10)); |
|
|
|
|
|
asset.setType("default"); |
|
|
|
|
|
assetService.saveAsset(asset); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> { |
|
|
|
|
|
long countByTenantId = assetService.countByTenantId(anotherTenantId); |
|
|
|
|
|
return countByTenantId == 5; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testShouldNotPutInCacheRolledbackAssetProfile() { |
|
|
public void testShouldNotPutInCacheRolledbackAssetProfile() { |
|
|
AssetProfile assetProfile = new AssetProfile(); |
|
|
AssetProfile assetProfile = new AssetProfile(); |
|
|
|