Merge branch 'master' of github.com:thingsboard/thingsboard
This commit is contained in:
		
						commit
						fb0ac70ec7
					
				@ -552,7 +552,7 @@ public class ActorSystemContext {
 | 
			
		||||
 | 
			
		||||
    @Value("${actors.session.max_concurrent_sessions_per_device:1}")
 | 
			
		||||
    @Getter
 | 
			
		||||
    private long maxConcurrentSessionsPerDevice;
 | 
			
		||||
    private int maxConcurrentSessionsPerDevice;
 | 
			
		||||
 | 
			
		||||
    @Value("${actors.session.sync.timeout:10000}")
 | 
			
		||||
    @Getter
 | 
			
		||||
 | 
			
		||||
@ -500,10 +500,9 @@ public class DefaultEntitiesVersionControlService implements EntitiesVersionCont
 | 
			
		||||
    @Override
 | 
			
		||||
    public ListenableFuture<EntityDataInfo> getEntityDataInfo(User user, EntityId entityId, String versionId) {
 | 
			
		||||
        return Futures.transform(gitServiceQueue.getEntity(user.getTenantId(), versionId, entityId),
 | 
			
		||||
                entity -> new EntityDataInfo(entity.hasRelations(), entity.hasAttributes(), entity.hasCredentials()), MoreExecutors.directExecutor());
 | 
			
		||||
                entity -> new EntityDataInfo(entity.hasRelations(), entity.hasAttributes(), entity.hasCredentials(), entity.hasCalculatedFields()), MoreExecutors.directExecutor());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ListenableFuture<List<BranchInfo>> listBranches(TenantId tenantId) {
 | 
			
		||||
        return gitServiceQueue.listBranches(tenantId);
 | 
			
		||||
 | 
			
		||||
@ -49,7 +49,7 @@ public class DeviceActorMessageProcessorTest {
 | 
			
		||||
    public void setUp() {
 | 
			
		||||
        systemContext = mock(ActorSystemContext.class);
 | 
			
		||||
        deviceService = mock(DeviceService.class);
 | 
			
		||||
        willReturn((long)MAX_CONCURRENT_SESSIONS_PER_DEVICE).given(systemContext).getMaxConcurrentSessionsPerDevice();
 | 
			
		||||
        willReturn(MAX_CONCURRENT_SESSIONS_PER_DEVICE).given(systemContext).getMaxConcurrentSessionsPerDevice();
 | 
			
		||||
        willReturn(deviceService).given(systemContext).getDeviceService();
 | 
			
		||||
        processor = new DeviceActorMessageProcessor(systemContext, tenantId, deviceId);
 | 
			
		||||
        willReturn(mock(TbCoreToTransportService.class)).given(systemContext).getTbCoreToTransportService();
 | 
			
		||||
@ -58,7 +58,7 @@ public class DeviceActorMessageProcessorTest {
 | 
			
		||||
    @Test
 | 
			
		||||
    public void givenSystemContext_whenNewInstance_thenVerifySessionMapMaxSize() {
 | 
			
		||||
        assertThat(processor.sessions, instanceOf(LinkedHashMapRemoveEldest.class));
 | 
			
		||||
        assertThat(processor.sessions.getMaxEntries(), is((long)MAX_CONCURRENT_SESSIONS_PER_DEVICE));
 | 
			
		||||
        assertThat(processor.sessions.getMaxEntries(), is(MAX_CONCURRENT_SESSIONS_PER_DEVICE));
 | 
			
		||||
        assertThat(processor.sessions.getRemovalConsumer(), notNullValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -26,4 +26,5 @@ public class EntityDataInfo {
 | 
			
		||||
    boolean hasRelations;
 | 
			
		||||
    boolean hasAttributes;
 | 
			
		||||
    boolean hasCredentials;
 | 
			
		||||
    boolean hasCalculatedFields;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -34,10 +34,10 @@ import java.util.function.BiConsumer;
 | 
			
		||||
@ToString(callSuper = true)
 | 
			
		||||
@EqualsAndHashCode(callSuper = true)
 | 
			
		||||
public class LinkedHashMapRemoveEldest<K, V> extends LinkedHashMap<K, V> {
 | 
			
		||||
    final long maxEntries;
 | 
			
		||||
    final int maxEntries;
 | 
			
		||||
    final BiConsumer<K, V> removalConsumer;
 | 
			
		||||
 | 
			
		||||
    public LinkedHashMapRemoveEldest(long maxEntries, BiConsumer<K, V> removalConsumer) {
 | 
			
		||||
    public LinkedHashMapRemoveEldest(int maxEntries, BiConsumer<K, V> removalConsumer) {
 | 
			
		||||
        this.maxEntries = maxEntries;
 | 
			
		||||
        this.removalConsumer = removalConsumer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -27,10 +27,10 @@ import static org.hamcrest.MatcherAssert.assertThat;
 | 
			
		||||
 | 
			
		||||
public class LinkedHashMapRemoveEldestTest {
 | 
			
		||||
 | 
			
		||||
    public static final long MAX_ENTRIES = 10L;
 | 
			
		||||
    long removeCount = 0;
 | 
			
		||||
    public static final int MAX_ENTRIES = 10;
 | 
			
		||||
    int removeCount = 0;
 | 
			
		||||
 | 
			
		||||
    void removalConsumer(Long id, String name) {
 | 
			
		||||
    void removalConsumer(Integer id, String name) {
 | 
			
		||||
        removeCount++;
 | 
			
		||||
        assertThat(id, is(Matchers.lessThan(MAX_ENTRIES)));
 | 
			
		||||
        assertThat(name, is(id.toString()));
 | 
			
		||||
@ -39,7 +39,7 @@ public class LinkedHashMapRemoveEldestTest {
 | 
			
		||||
    @Test
 | 
			
		||||
    public void givenMap_whenOverSized_thenVerifyRemovedEldest() {
 | 
			
		||||
        //given
 | 
			
		||||
        LinkedHashMapRemoveEldest<Long, String> map =
 | 
			
		||||
        LinkedHashMapRemoveEldest<Integer, String> map =
 | 
			
		||||
                new LinkedHashMapRemoveEldest<>(MAX_ENTRIES, this::removalConsumer);
 | 
			
		||||
 | 
			
		||||
        assertThat(map.getMaxEntries(), is(MAX_ENTRIES));
 | 
			
		||||
@ -49,14 +49,14 @@ public class LinkedHashMapRemoveEldestTest {
 | 
			
		||||
        assertThat(map.size(), is(0));
 | 
			
		||||
 | 
			
		||||
        //when
 | 
			
		||||
        for (long i = 0; i < MAX_ENTRIES * 2; i++) {
 | 
			
		||||
        for (int i = 0; i < MAX_ENTRIES * 2; i++) {
 | 
			
		||||
            map.put(i, String.valueOf(i));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //then
 | 
			
		||||
        assertThat((long) map.size(), is(MAX_ENTRIES));
 | 
			
		||||
        assertThat( map.size(), is(MAX_ENTRIES));
 | 
			
		||||
        assertThat(removeCount, is(MAX_ENTRIES));
 | 
			
		||||
        for (long i = MAX_ENTRIES; i < MAX_ENTRIES * 2; i++) {
 | 
			
		||||
        for (int i = MAX_ENTRIES; i < MAX_ENTRIES * 2; i++) {
 | 
			
		||||
            assertThat(map.get(i), is(String.valueOf(i)));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user