-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
191 additions
and
27 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
...onkey-api/src/main/java/com/navercorp/fixturemonkey/api/container/ConcurrentLruCache.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,103 @@ | ||
/* | ||
* Fixture Monkey | ||
* | ||
* Copyright (c) 2021-present NAVER Corp. | ||
* | ||
* 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.navercorp.fixturemonkey.api.container; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.apiguardian.api.API; | ||
import org.apiguardian.api.API.Status; | ||
|
||
/** | ||
* It is the Concurrent Least Recently Used cache. | ||
* It would remove the least recently used element when it is full. | ||
* | ||
* @param <K> key of the cache | ||
* @param <V> value of the cache | ||
*/ | ||
@SuppressWarnings("NullableProblems") | ||
@API(since = "0.5.10", status = Status.EXPERIMENTAL) | ||
public final class ConcurrentLruCache<K, V> implements Map<K, V> { | ||
private final Map<K, V> lruCache; | ||
|
||
public ConcurrentLruCache(int maxSize) { | ||
lruCache = Collections.synchronizedMap(new LruCache<>(maxSize)); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return lruCache.size(); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return lruCache.isEmpty(); | ||
} | ||
|
||
@Override | ||
public boolean containsKey(Object key) { | ||
return lruCache.containsKey(key); | ||
} | ||
|
||
@Override | ||
public boolean containsValue(Object value) { | ||
return lruCache.containsValue(value); | ||
} | ||
|
||
@Override | ||
public V get(Object key) { | ||
return lruCache.get(key); | ||
} | ||
|
||
@Override | ||
public V put(K key, V value) { | ||
return lruCache.put(key, value); | ||
} | ||
|
||
@Override | ||
public V remove(Object key) { | ||
return lruCache.remove(key); | ||
} | ||
|
||
@Override | ||
public void putAll(Map<? extends K, ? extends V> map) { | ||
lruCache.putAll(map); | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
lruCache.clear(); | ||
} | ||
|
||
@Override | ||
public Set<K> keySet() { | ||
return lruCache.keySet(); | ||
} | ||
|
||
@Override | ||
public Collection<V> values() { | ||
return lruCache.values(); | ||
} | ||
|
||
@Override | ||
public Set<Entry<K, V>> entrySet() { | ||
return lruCache.entrySet(); | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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,7 @@ | ||
java { | ||
toolchain { languageVersion = JavaLanguageVersion.of(17) } | ||
} | ||
|
||
dependencies { | ||
testImplementation(project(":fixture-monkey-jackson")) | ||
} |
45 changes: 45 additions & 0 deletions
45
...rent-tests/src/test/java/com/navercorp/fixturemonkey/tests/concurrent/ConcurrentTest.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,45 @@ | ||
package com.navercorp.fixturemonkey.tests.concurrent; | ||
|
||
import static com.navercorp.fixturemonkey.tests.TestEnvironment.TEST_COUNT; | ||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.RepeatedTest; | ||
|
||
import com.navercorp.fixturemonkey.FixtureMonkey; | ||
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector; | ||
|
||
class ConcurrentTest { | ||
private static final FixtureMonkey SUT = FixtureMonkey.builder() | ||
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE) | ||
.build(); | ||
|
||
@RepeatedTest(TEST_COUNT) | ||
void test1() { | ||
JavaObject actual = SUT.giveMeOne(JavaObject.class); | ||
|
||
then(actual).isNotNull(); | ||
} | ||
|
||
@RepeatedTest(TEST_COUNT) | ||
void test2() { | ||
JavaObject actual = SUT.giveMeOne(JavaObject.class); | ||
|
||
then(actual).isNotNull(); | ||
} | ||
|
||
@RepeatedTest(TEST_COUNT) | ||
void test3() { | ||
JavaObject actual = SUT.giveMeOne(JavaObject.class); | ||
|
||
then(actual).isNotNull(); | ||
} | ||
|
||
public record JavaObject( | ||
String value, | ||
Map<String, String> map | ||
) { | ||
|
||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
fixture-monkey-tests/java-concurrent-tests/src/test/resources/junit-platform.properties
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,4 @@ | ||
junit.jupiter.execution.parallel.enabled=true | ||
junit.jupiter.execution.parallel.mode.default=CONCURRENT | ||
junit.jupiter.execution.parallel.config.strategy=fixed | ||
junit.jupiter.execution.parallel.config.fixed.parallelism=4 |
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
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