|
|
|
@ -16,6 +16,8 @@ |
|
|
|
package org.thingsboard.server.dao.service; |
|
|
|
|
|
|
|
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|
|
|
import com.google.common.util.concurrent.Futures; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
@ -31,6 +33,7 @@ import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|
|
|
import org.thingsboard.server.common.data.relation.RelationsSearchParameters; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
@ -84,6 +87,23 @@ public abstract class BaseRelationServiceTest extends AbstractServiceTest { |
|
|
|
Assert.assertTrue(relationService.deleteRelationAsync(SYSTEM_TENANT_ID, childId, subChildId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteRelationConcurrently() throws ExecutionException, InterruptedException { |
|
|
|
AssetId parentId = new AssetId(Uuids.timeBased()); |
|
|
|
AssetId childId = new AssetId(Uuids.timeBased()); |
|
|
|
|
|
|
|
EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE); |
|
|
|
|
|
|
|
saveRelation(relationA); |
|
|
|
|
|
|
|
List<ListenableFuture<Boolean>> futures = new ArrayList<>(); |
|
|
|
for (int i = 0; i < 2; i++) { |
|
|
|
futures.add(relationService.deleteRelationAsync(SYSTEM_TENANT_ID, relationA)); |
|
|
|
} |
|
|
|
List<Boolean> results = Futures.allAsList(futures).get(); |
|
|
|
Assert.assertTrue(results.contains(true)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteEntityRelations() throws ExecutionException, InterruptedException { |
|
|
|
AssetId parentId = new AssetId(Uuids.timeBased()); |
|
|
|
|