forked from hazelcast/hazelcast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix copy constructor of EvictionConfig (hazelcast#18813)
- Loading branch information
1 parent
dedacb6
commit 6cac553
Showing
4 changed files
with
212 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...src/test/java/com/hazelcast/client/map/impl/nearcache/ClientMapNearCacheEvictionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.client.map.impl.nearcache; | ||
|
||
import com.hazelcast.client.config.ClientConfig; | ||
import com.hazelcast.client.test.TestHazelcastFactory; | ||
import com.hazelcast.config.EvictionPolicy; | ||
import com.hazelcast.config.NearCacheConfig; | ||
import com.hazelcast.core.HazelcastInstance; | ||
import com.hazelcast.map.IMap; | ||
import com.hazelcast.test.HazelcastParallelClassRunner; | ||
import com.hazelcast.test.HazelcastTestSupport; | ||
import com.hazelcast.test.annotation.ParallelJVMTest; | ||
import com.hazelcast.test.annotation.QuickTest; | ||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(HazelcastParallelClassRunner.class) | ||
@Category({QuickTest.class, ParallelJVMTest.class}) | ||
public class ClientMapNearCacheEvictionTest extends HazelcastTestSupport { | ||
|
||
private final TestHazelcastFactory factory = new TestHazelcastFactory(); | ||
|
||
@After | ||
public void tearDown() { | ||
factory.terminateAll(); | ||
} | ||
|
||
@Test | ||
public void near_cache_size_equals_map_size_when_eviction_policy_is_none() { | ||
String mapName = "test"; | ||
NearCacheConfig nearCacheConfig = new NearCacheConfig(mapName); | ||
nearCacheConfig.getEvictionConfig().setEvictionPolicy(EvictionPolicy.NONE); | ||
|
||
ClientConfig clientConfig = new ClientConfig(); | ||
clientConfig.addNearCacheConfig(nearCacheConfig); | ||
|
||
HazelcastInstance server = factory.newHazelcastInstance(); | ||
HazelcastInstance client = factory.newHazelcastClient(clientConfig); | ||
IMap<Integer, Integer> map = client.getMap(mapName); | ||
|
||
// populate map | ||
int mapSize = 99_999; | ||
for (int i = 0; i < mapSize; i++) { | ||
map.set(i, i); | ||
} | ||
|
||
// populate near-cache | ||
for (int i = 0; i < mapSize; i++) { | ||
map.get(i); | ||
} | ||
|
||
assertEquals(mapSize, map.getLocalMapStats() | ||
.getNearCacheStats().getOwnedEntryCount()); | ||
} | ||
|
||
@Test | ||
public void no_more_entries_than_max_near_cache_size_when_eviction_policy_is_not_none() { | ||
String mapName = "mapName"; | ||
NearCacheConfig nearCacheConfig = new NearCacheConfig(mapName); | ||
int maxNearCacheSize = 9_999; | ||
nearCacheConfig.getEvictionConfig() | ||
.setEvictionPolicy(EvictionPolicy.LRU) | ||
.setSize(maxNearCacheSize); | ||
|
||
ClientConfig clientConfig = new ClientConfig(); | ||
clientConfig.addNearCacheConfig(nearCacheConfig); | ||
|
||
HazelcastInstance server = factory.newHazelcastInstance(); | ||
HazelcastInstance client = factory.newHazelcastClient(clientConfig); | ||
IMap<Integer, Integer> map = client.getMap(mapName); | ||
|
||
// populate map | ||
int mapSize = 99_999; | ||
for (int i = 0; i < mapSize; i++) { | ||
map.set(i, i); | ||
} | ||
|
||
// populate near-cache | ||
for (int i = 0; i < mapSize; i++) { | ||
map.get(i); | ||
} | ||
|
||
assertEquals(maxNearCacheSize, map.getLocalMapStats() | ||
.getNearCacheStats().getOwnedEntryCount()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
hazelcast/src/test/java/com/hazelcast/map/impl/nearcache/MapNearCacheEvictionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.map.impl.nearcache; | ||
|
||
import com.hazelcast.config.Config; | ||
import com.hazelcast.config.EvictionPolicy; | ||
import com.hazelcast.config.NearCacheConfig; | ||
import com.hazelcast.core.HazelcastInstance; | ||
import com.hazelcast.map.IMap; | ||
import com.hazelcast.test.HazelcastParallelClassRunner; | ||
import com.hazelcast.test.HazelcastTestSupport; | ||
import com.hazelcast.test.annotation.ParallelJVMTest; | ||
import com.hazelcast.test.annotation.QuickTest; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(HazelcastParallelClassRunner.class) | ||
@Category({QuickTest.class, ParallelJVMTest.class}) | ||
public class MapNearCacheEvictionTest extends HazelcastTestSupport { | ||
|
||
@Test | ||
public void near_cache_size_equals_map_size_when_eviction_policy_is_none() { | ||
NearCacheConfig nearCacheConfig = new NearCacheConfig(); | ||
nearCacheConfig.setCacheLocalEntries(true); | ||
nearCacheConfig.getEvictionConfig().setEvictionPolicy(EvictionPolicy.NONE); | ||
|
||
Config config = getConfig(); | ||
String mapName = "mapName"; | ||
config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig); | ||
|
||
HazelcastInstance hazelcastInstance = createHazelcastInstance(config); | ||
IMap<Integer, Integer> map = hazelcastInstance.getMap(mapName); | ||
|
||
// populate map | ||
int mapSize = 99_999; | ||
for (int i = 0; i < mapSize; i++) { | ||
map.set(i, i); | ||
} | ||
|
||
// populate near-cache | ||
for (int i = 0; i < mapSize; i++) { | ||
map.get(i); | ||
} | ||
|
||
assertEquals(mapSize, map.getLocalMapStats() | ||
.getNearCacheStats().getOwnedEntryCount()); | ||
} | ||
|
||
@Test | ||
public void no_more_entries_than_max_near_cache_size_when_eviction_policy_is_not_none() { | ||
NearCacheConfig nearCacheConfig = new NearCacheConfig(); | ||
nearCacheConfig.setCacheLocalEntries(true); | ||
int maxNearCacheSize = 9_999; | ||
nearCacheConfig.getEvictionConfig() | ||
.setEvictionPolicy(EvictionPolicy.LRU) | ||
.setSize(maxNearCacheSize); | ||
|
||
Config config = getConfig(); | ||
String mapName = "mapName"; | ||
config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig); | ||
|
||
HazelcastInstance hazelcastInstance = createHazelcastInstance(config); | ||
IMap<Integer, Integer> map = hazelcastInstance.getMap(mapName); | ||
|
||
// populate map | ||
int mapSize = 99_999; | ||
for (int i = 0; i < mapSize; i++) { | ||
map.set(i, i); | ||
} | ||
|
||
// populate near-cache | ||
for (int i = 0; i < mapSize; i++) { | ||
map.get(i); | ||
} | ||
|
||
assertEquals(maxNearCacheSize, map.getLocalMapStats() | ||
.getNearCacheStats().getOwnedEntryCount()); | ||
} | ||
} |