Skip to content

Commit

Permalink
Fix some sonar warnings (hazelcast#3203)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: c79b18c95b2fea91ff48c3e50db15896fb25bdbe
  • Loading branch information
orcunc authored and actions-user committed Sep 10, 2024
1 parent 6cf577d commit 4f70dce
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ private static long getTotalBackupEntryCount(IMap... maps) {

/**
* Eviction starts if a partitions' size exceeds this number:
*
* <p>
* double maxPartitionSize = 1D * nodeCount * perNodeMaxSize / PARTITION_COUNT;
*
* <p>
* when calculated `maxPartitionSize` is under 1, we should forcibly set it
* to 1, otherwise all puts will immediately be removed by eviction.
*/
Expand Down
4 changes: 2 additions & 2 deletions hazelcast/src/test/java/com/hazelcast/map/EvictionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private void testMaxIdle_readThroughIndex(IndexType type) {
assertEquals(entryCount, valuesNullCity.size() + valuesNotNullCity.size());
// check that evaluating the predicate didn't update the last access time of the returned records
for (int i = 0; i < entryCount; ++i) {
EntryView view = map.getEntryView(i);
EntryView<Integer, Employee> view = map.getEntryView(i);
assertNotNull(view);
long lastAccessTime = view.getLastAccessTime();
long prevLastAccessTime = lastAccessTimes.get(i);
Expand Down Expand Up @@ -361,7 +361,7 @@ private void sleepAndAssertTtlExpirationCorrectness(IMap<Integer, String> map, l
}

private void assertTtlExpirationCorrectness(IMap<Integer, String> map, long expected) {
EntryView view = map.getEntryView(1);
EntryView<Integer, String> view = map.getEntryView(1);
assertEquals(expected, view.getExpirationTime());
assertTrue(map.containsKey(1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ public void test_replicated_entries_view_equal_after_cluster_scale_up() {
map.put(i, i, 112, SECONDS, 223, SECONDS);
}

Map<Integer, EntryView> entryViewsBefore = new HashMap<>();
Map<Integer, EntryView<Integer, Integer>> entryViewsBefore = new HashMap<>();
for (int i = 0; i < keyCount; i++) {
entryViewsBefore.put(i, map.getEntryView(i));
}

HazelcastInstance node2 = factory.newHazelcastInstance(config);

IMap<Integer, Integer> map2 = node2.getMap(mapName);
Map<Integer, EntryView> entryViewsAfter = new HashMap<>();
Map<Integer, EntryView<Integer, Integer>> entryViewsAfter = new HashMap<>();
for (int i = 0; i < keyCount; i++) {
entryViewsAfter.put(i, map2.getEntryView(i));
}
Expand Down Expand Up @@ -550,7 +550,6 @@ public void replace_does_not_shift_expiration_time_when_failed() {
assertEquals(expirationTimeAfterReplace, expirationTimeAfterPut);
}

@SuppressWarnings("rawtypes")
@Test
public void last_access_time_updated_on_primary_when_read_backup_data_enabled() {
String mapName = "test";
Expand All @@ -564,7 +563,7 @@ public void last_access_time_updated_on_primary_when_read_backup_data_enabled()
mapConfig.setMaxIdleSeconds(20);
mapConfig.setInMemoryFormat(inMemoryFormat());

IMap map = createHazelcastInstance(config).getMap(mapName);
IMap<Integer, Integer> map = createHazelcastInstance(config).getMap(mapName);
map.put(1, 1);

long lastAccessTimeBefore = map.getEntryView(1).getLastAccessTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testNullValueIsNotAccepted_withExpiration() {

@Test
public void testWithNoDate() {
MetadataAwareValue entry = new MetadataAwareValue<>("value");
MetadataAwareValue<String> entry = new MetadataAwareValue<>("value");
assertEquals(NO_TIME_SET, entry.getExpirationTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void readData(final ObjectDataInput in) throws IOException {
}

@Test(expected = InvalidConfigurationException.class)
public void testNativeIMap_throwsException() throws Exception {
public void testNativeIMap_throwsException() {
Config config = getConfig();
config.getMapConfig("default").setInMemoryFormat(InMemoryFormat.NATIVE);

Expand All @@ -217,7 +217,7 @@ public void testNativeIMap_throwsException() throws Exception {
}

@Test(expected = InvalidConfigurationException.class)
public void testNativeNearCache_throwsException() throws Exception {
public void testNativeNearCache_throwsException() {
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setInMemoryFormat(InMemoryFormat.NATIVE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void testIndexStatsQueryingChangingNumberOfMembers() {
assertEquals(4 * queriesBulk, valueStats(map3).getQueryCount());

// This work correctly only due to we stored data from shutdown member and uses this data for counting
// originalOverallAverageHitSelectivity. However this not represent real scenario. This check is here just for ensure
// originalOverallAverageHitSelectivity. However, this not represent real scenario. This check is here just for ensure
// that AverageHitSelectivity is still counted correctly on live members.
originalOverallAverageHitSelectivity = calculateOverallSelectivity(map2Hits, map2TotalHitSelectivity, map1, map3);
assertEquals((expectedEqual + expectedGreaterEqual) / 2, originalOverallAverageHitSelectivity, 0.015);
Expand Down Expand Up @@ -481,7 +481,7 @@ private Map<UUID, PartitionIdSet> toMemberToPartitionsMap(HazelcastInstance inst
for (Partition partition : partitions) {
UUID member = partition.getOwner().getUuid();

memberToPartitions.computeIfAbsent(member, (key) -> new PartitionIdSet(partitions.size()))
memberToPartitions.computeIfAbsent(member, key -> new PartitionIdSet(partitions.size()))
.add(partition.getPartitionId());
}
return memberToPartitions;
Expand Down
17 changes: 6 additions & 11 deletions hazelcast/src/test/java/com/hazelcast/map/ListenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ public void testEntryListenerEvent_getValueWhenEntryRemoved() {
final CountDownLatch latch = new CountDownLatch(1);

map.addEntryListener(new EntryAdapter<String, String>() {
@Override
public void entryRemoved(EntryEvent<String, String> event) {
valueRef.set(event.getValue());
oldValueRef.set(event.getOldValue());
Expand Down Expand Up @@ -483,6 +484,7 @@ public void testEntryEvent_includesOldValue_afterRemoveIfSameOperation() {
final ConcurrentMap<String, String> resultHolder = new ConcurrentHashMap<>(1);

map.addEntryListener(new EntryAdapter<String, String>() {
@Override
public void entryRemoved(EntryEvent<String, String> event) {
final String oldValue = event.getOldValue();
resultHolder.put(key, oldValue);
Expand Down Expand Up @@ -643,12 +645,7 @@ public void updates_with_putTransient_triggers_entryUpdatedListener() {
HazelcastInstance hz = createHazelcastInstance(getConfig());
IMap<String, String> map = hz.getMap("updates_with_putTransient_triggers_entryUpdatedListener");
final CountDownLatch updateEventCounterLatch = new CountDownLatch(1);
map.addEntryListener(new EntryUpdatedListener<String, String>() {
@Override
public void entryUpdated(EntryEvent<String, String> event) {
updateEventCounterLatch.countDown();
}
}, true);
map.addEntryListener((EntryUpdatedListener<String, String>) event -> updateEventCounterLatch.countDown(), true);

map.putTransient("hello", "world", 0, TimeUnit.SECONDS);
map.putTransient("hello", "another world", 0, TimeUnit.SECONDS);
Expand All @@ -670,7 +667,7 @@ private Predicate<String, String> nonMatchingPredicate() {
return mapEntry -> false;
}

private class UpdateListenerRecordingOldValue<K, V> implements EntryUpdatedListener<K, V> {
private static class UpdateListenerRecordingOldValue<K, V> implements EntryUpdatedListener<K, V> {

private volatile V oldValue;
private final CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -691,6 +688,7 @@ private EntryListener<String, String> createEntryListener(final boolean isLocal)
return new EntryAdapter<>() {
private final boolean local = isLocal;

@Override
public void entryAdded(EntryEvent<String, String> event) {
if (local) {
localCount.incrementAndGet();
Expand Down Expand Up @@ -761,17 +759,14 @@ public void mapEvicted(MapEvent event) {
}
}

public class CounterEntryListener implements EntryListener<Object, Object> {
private static class CounterEntryListener implements EntryListener<Object, Object> {

final AtomicLong addCount = new AtomicLong();
final AtomicLong removeCount = new AtomicLong();
final AtomicLong updateCount = new AtomicLong();
final AtomicLong evictCount = new AtomicLong();
final AtomicLong expiryCount = new AtomicLong();

public CounterEntryListener() {
}

@Override
public void entryAdded(EntryEvent<Object, Object> objectObjectEntryEvent) {
addCount.incrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ private void injectLogger(HazelcastInstance instance,
setFieldValueReflectively(mapEventPublisher, "logger", mapEventPublisherLogger);
}

private class MapEventPublisherLogger extends AbstractLogger {
private static class MapEventPublisherLogger extends AbstractLogger {

private final CopyOnWriteArrayList logCollector
= new CopyOnWriteArrayList<>();
private final CopyOnWriteArrayList<Object> logCollector = new CopyOnWriteArrayList<>();

@Override
public void log(Level level, String message) {
Expand Down

0 comments on commit 4f70dce

Please sign in to comment.