Skip to content

Commit

Permalink
Add support for javax.cache:cache-api:1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian committed Jan 16, 2023
1 parent 073495d commit 3fb8fd2
Show file tree
Hide file tree
Showing 24 changed files with 1,033 additions and 0 deletions.
4 changes: 4 additions & 0 deletions metadata/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
"directory": "org.flywaydb/flyway-core",
"module": "org.flywaydb:flyway-core"
},
{
"directory": "javax.cache/cache-api",
"module": "javax.cache:cache-api"
},
{
"directory": "com.sun.mail/jakarta.mail",
"module": "com.sun.mail:jakarta.mail"
Expand Down
4 changes: 4 additions & 0 deletions metadata/javax.cache/cache-api/1.1.1/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"resource-config.json",
"serialization-config.json"
]
13 changes: 13 additions & 0 deletions metadata/javax.cache/cache-api/1.1.1/resource-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"resources": {
"includes": [
{
"condition": {
"typeReachable": "javax.cache.Caching$CachingProviderRegistry$1"
},
"pattern": "\\QMETA-INF/services/javax.cache.spi.CachingProvider\\E"
}
]
},
"bundles": []
}
48 changes: 48 additions & 0 deletions metadata/javax.cache/cache-api/1.1.1/serialization-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"lambdaCapturingTypes": [],
"proxies": [],
"types": [
{
"condition": {
"typeReachable": "java.lang.Object"
},
"name": "javax.cache.configuration.FactoryBuilder$SingletonFactory"
},
{
"condition": {
"typeReachable": "java.lang.Object"
},
"name": "javax.cache.expiry.AccessedExpiryPolicy"
},
{
"condition": {
"typeReachable": "java.lang.Object"
},
"name": "javax.cache.expiry.Duration"
},
{
"condition": {
"typeReachable": "java.lang.Object"
},
"name": "javax.cache.expiry.EternalExpiryPolicy"
},
{
"condition": {
"typeReachable": "java.lang.Object"
},
"name": "java.lang.String"
},
{
"condition": {
"typeReachable": "java.lang.Object"
},
"name": "java.lang.Number"
},
{
"condition": {
"typeReachable": "java.lang.Object"
},
"name": "java.lang.Integer"
}
]
}
10 changes: 10 additions & 0 deletions metadata/javax.cache/cache-api/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"latest": true,
"metadata-version": "1.1.1",
"module": "javax.cache:cache-api",
"tested-versions": [
"1.1.1"
]
}
]
11 changes: 11 additions & 0 deletions tests/src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@
}
]
},
{
"test-project-path": "javax.cache/cache-api/1.1.1",
"libraries": [
{
"name": "javax.cache:cache-api",
"versions": [
"1.1.1"
]
}
]
},
{
"test-project-path": "com.sun.mail/jakarta.mail/2.0.1",
"libraries": [
Expand Down
4 changes: 4 additions & 0 deletions tests/src/javax.cache/cache-api/1.1.1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gradlew.bat
gradlew
gradle/
build/
34 changes: 34 additions & 0 deletions tests/src/javax.cache/cache-api/1.1.1/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

plugins {
id "org.graalvm.internal.tck"
}

String libraryVersion = tck.testedLibraryVersion.get()

dependencies {
testImplementation "javax.cache:cache-api:$libraryVersion"
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation "org.jsr107.ri:cache-ri-impl:$libraryVersion"
}

graalvmNative {
agent {
defaultMode = "conditional"
modes {
conditional {
userCodeFilterPath = "user-code-filter.json"
}
}
metadataCopy {
mergeWithExisting = true
inputTaskNames.add("test")
outputDirectories.add("src/test/resources/META-INF/native-image/javax.cache/cache-api")
}
}
}
2 changes: 2 additions & 0 deletions tests/src/javax.cache/cache-api/1.1.1/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library.version = 1.1.1
metadata.dir = javax.cache/cache-api/1.1.1/
13 changes: 13 additions & 0 deletions tests/src/javax.cache/cache-api/1.1.1/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pluginManagement {
def tckPath = Objects.requireNonNullElse(
System.getenv("GVM_TCK_TCKDIR"),
"../../../../tck-build-logic"
)
includeBuild(tckPath)
}

plugins {
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT"
}

rootProject.name = 'javax.cache.cache-api_tests'
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package javax_cache.cache_api.core;

import org.junit.jupiter.api.Test;

import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.configuration.Configuration;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.expiry.AccessedExpiryPolicy;

import static javax.cache.expiry.Duration.ONE_HOUR;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class CacheTest {
@Test
public void simpleCache() {
CacheManager manager = Caching.getCachingProvider().getCacheManager();
Configuration<Integer, String> configuration = new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class);
assertThat(manager.getCache("simpleCache22")).isNull();
Cache<Integer, String> simpleCache = manager.createCache("simpleCache22", configuration);
simpleCache.put(2, "value");
assertThat(simpleCache.get(2)).isEqualTo("value");
}

@Test
public void simpleAPITypeEnforcement() {
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
MutableConfiguration<String, Integer> config = new MutableConfiguration<String, Integer>()
.setStoreByValue(true).setTypes(String.class, Integer.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR)).setStatisticsEnabled(true);
cacheManager.createCache("simpleCache", config);
Cache<String, Integer> cache = Caching.getCache("simpleCache", String.class, Integer.class);
cache.put("key", 1);
assertEquals(1, cache.get("key"));
cache.remove("key");
assertNull(cache.get("key"));
}

@Test
public void simpleAPITypeEnforcementUsingCaching() {
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
MutableConfiguration<String, Integer> config = new MutableConfiguration<>();
config.setTypes(String.class, Integer.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR)).setStatisticsEnabled(true);
cacheManager.createCache("simpleCache2", config);
Cache<String, Integer> cache = Caching.getCache("simpleCache2", String.class, Integer.class);
cache.put("key", 1);
assertEquals(1, cache.get("key"));
cache.remove("key");
assertNull(cache.get("key"));
}

@Test
public void simpleAPIWithGenericsAndNoTypeEnforcement() {
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
MutableConfiguration<String, Integer> config = new MutableConfiguration<>();
config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR)).setStatisticsEnabled(true);
cacheManager.createCache("sampleCache3", config);
Cache<String, Integer> cache = cacheManager.getCache("sampleCache3");
cache.put("key", 1);
assertThat(cache.get("key")).isEqualTo(1);
cache.remove("key");
assertNull(cache.get("key"));
}


@Test
public void simpleAPINoGenericsAndNoTypeEnforcement() {
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
String cacheName = "sampleCache";
MutableConfiguration<Object, Object> config = new MutableConfiguration<>()
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR)).setStatisticsEnabled(true);
cacheManager.createCache(cacheName, config);
Cache<Object, Object> cache = cacheManager.getCache(cacheName);
cache.put("key", 1);
cache.put(1, "key");
assertEquals(1, (Integer) cache.get("key"));
cache.remove("key");
assertNull(cache.get("key"));
}

@Test
public void simpleAPITypeEnforcementObject() {
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
MutableConfiguration<Object, Object> config = new MutableConfiguration<>()
.setTypes(Object.class, Object.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR)).setStatisticsEnabled(true);
cacheManager.createCache("simpleCache4", config);
Cache<Object, Object> cache = Caching.getCache("simpleCache4", Object.class, Object.class);
cache.put("key", 1);
assertEquals(1, cache.get("key"));
cache.remove("key");
assertNull(cache.get("key"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package javax_cache.cache_api.core;

import org.junit.jupiter.api.Test;

import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.expiry.AccessedExpiryPolicy;
import javax.cache.integration.CompletionListenerFuture;
import java.util.HashSet;
import java.util.concurrent.ExecutionException;

import static javax.cache.expiry.Duration.ONE_HOUR;
import static org.assertj.core.api.Assertions.assertThat;

public class CompletionListenerTest {
@Test
public void testCompletionListener() {
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
MutableConfiguration<String, Integer> config = new MutableConfiguration<String, Integer>()
.setTypes(String.class, Integer.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR)).setStatisticsEnabled(true);
Cache<String, Integer> cache = cacheManager.createCache("simpleCache3", config);
HashSet<String> keys = new HashSet<>();
keys.add("23432lkj");
keys.add("4fsdldkj");
CompletionListenerFuture future = new CompletionListenerFuture();
cache.loadAll(keys, true, future);
try {
future.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.getCause();
}
assertThat(future.isDone()).isEqualTo(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package javax_cache.cache_api.core;

import org.junit.jupiter.api.Test;

import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.processor.EntryProcessor;
import javax.cache.processor.MutableEntry;
import java.io.Serializable;

import static org.assertj.core.api.Assertions.assertThat;

public class EntryProcessorTest {
@Test
public void incrementValue() {
CacheManager manager = Caching.getCachingProvider().getCacheManager();
MutableConfiguration<String, Integer> configuration = new MutableConfiguration<String, Integer>().setTypes(String.class, Integer.class);
Cache<String, Integer> cache = manager.createCache("example", configuration);
String key = "counter";
cache.put(key, 1);
assertThat(cache.invoke(key, new IncrementProcessor<>())).isEqualTo(1);
assertThat(cache.get(key)).isEqualTo(2);
}

public static class IncrementProcessor<K> implements EntryProcessor<K, Integer, Integer>, Serializable {
public static final long serialVersionUID = 201306211238L;

@Override
public Integer process(MutableEntry<K, Integer> entry, Object... arguments) {
if (entry.exists()) {
Integer current = entry.getValue();
entry.setValue(current + 1);
return current;
} else {
entry.setValue(0);
return -1;
}
}
}
}
Loading

0 comments on commit 3fb8fd2

Please sign in to comment.