@ -15,6 +15,7 @@
* /
package org.thingsboard.server.service.resource ;
import org.awaitility.Awaitility ;
import org.junit.Test ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean ;
@ -29,6 +30,8 @@ import org.thingsboard.server.dao.resource.ResourceService;
import org.thingsboard.server.dao.resource.TbResourceDataCache ;
import org.thingsboard.server.dao.service.DaoSqlTest ;
import java.util.concurrent.TimeUnit ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.mockito.Mockito.clearInvocations ;
import static org.mockito.Mockito.timeout ;
@ -61,6 +64,8 @@ public class DefaultResourceDataCacheTest extends AbstractControllerTest {
TbResourceInfo savedResource = tbResourceService . save ( resource ) ;
verify ( resourceDataCache , timeout ( 2000 ) . times ( 1 ) ) . evictResourceData ( tenantId , savedResource . getId ( ) ) ;
Awaitility . await ( ) . atMost ( 2 , TimeUnit . SECONDS ) . untilAsserted ( ( ) - >
assertThat ( resourceDataCache . getResourceDataInfoAsync ( tenantId , savedResource . getId ( ) ) . get ( ) ) . isNotNull ( ) ) ;
TbResourceDataInfo cachedData = resourceDataCache . getResourceDataInfoAsync ( tenantId , savedResource . getId ( ) ) . get ( ) ;
assertThat ( cachedData . getData ( ) ) . isEqualTo ( data ) ;
assertThat ( JacksonUtil . treeToValue ( cachedData . getDescriptor ( ) , GeneralFileDescriptor . class ) ) . isEqualTo ( descriptor ) ;
@ -76,8 +81,8 @@ public class DefaultResourceDataCacheTest extends AbstractControllerTest {
TbResource resourceById = resourceService . findResourceById ( tenantId , savedResource . getId ( ) ) ;
tbResourceService . delete ( resourceById , true , null ) ;
verify ( resourceDataCache , timeout ( 2000 ) . times ( 2 ) ) . evictResourceData ( tenantId , savedResource . getId ( ) ) ;
TbResourceDataInfo cachedDataAfterDeletion = resourceDataCache . getResourceDataInfoAsync ( tenantId , savedResource . getId ( ) ) . get ( ) ;
assertThat ( cachedDataAfterDeletion ) . isEqualTo ( null ) ;
Awaitility . await ( ) . atMost ( 2 , TimeUnit . SECONDS ) . untilAsserted ( ( ) - >
assertThat ( resourceDataCache . getResourceDataInfoAsync ( tenantId , savedResource . getId ( ) ) . get ( ) ) . isNull ( ) ) ;
}
}