Merge pull request #12601 from zzzeebra/refactor-long-to-int-LinkedHashMapRemoveEldest

Usage of long refactored to int in LinkedHashMapRemoveEldest class
This commit is contained in:
Viacheslav Klimov 2025-03-13 11:56:19 +02:00 committed by GitHub
commit c54dee2308
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 12 deletions

View File

@ -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

View File

@ -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());
}

View File

@ -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;
}

View File

@ -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)));
}
}