-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Caffeine & Redis cache CompositeCache examples added * OpenAPI HTTP Client securitySchema example added
- Loading branch information
1 parent
8f0eb73
commit 62e3f2f
Showing
41 changed files
with
452 additions
and
41 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
groupId=ru.tinkoff.kora | ||
koraVersion=1.1.1 | ||
koraVersion=1.1.2 | ||
|
||
|
||
##### GRADLE ##### | ||
|
10 changes: 10 additions & 0 deletions
10
...a-cache-caffeine/src/main/java/ru/tinkoff/kora/example/cache/caffeine/CompositeCache.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,10 @@ | ||
package ru.tinkoff.kora.example.cache.caffeine; | ||
|
||
import ru.tinkoff.kora.cache.annotation.Cache; | ||
import ru.tinkoff.kora.cache.caffeine.CaffeineCache; | ||
|
||
@Cache("my-cache") | ||
public interface CompositeCache extends CaffeineCache<CompositeCache.Key, Long> { | ||
|
||
record Key(String userId, String traceId) { } | ||
} |
51 changes: 51 additions & 0 deletions
51
...cache-caffeine/src/main/java/ru/tinkoff/kora/example/cache/caffeine/CompositeService.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,51 @@ | ||
package ru.tinkoff.kora.example.cache.caffeine; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import ru.tinkoff.kora.cache.CacheKeyMapper; | ||
import ru.tinkoff.kora.cache.annotation.CacheInvalidate; | ||
import ru.tinkoff.kora.cache.annotation.CachePut; | ||
import ru.tinkoff.kora.cache.annotation.Cacheable; | ||
import ru.tinkoff.kora.common.Component; | ||
import ru.tinkoff.kora.common.Mapping; | ||
import ru.tinkoff.kora.common.annotation.Root; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
@Root | ||
@Component | ||
public class CompositeService { | ||
|
||
public record UserContext(String userId, String traceId) {} | ||
|
||
public static final class UserContextMapping implements CacheKeyMapper<CompositeCache.Key, UserContext> { | ||
|
||
@Nonnull | ||
@Override | ||
public CompositeCache.Key map(UserContext arg) { | ||
return new CompositeCache.Key(arg.userId(), arg.traceId()); | ||
} | ||
} | ||
|
||
@Mapping(UserContextMapping.class) | ||
@Cacheable(CompositeCache.class) | ||
public Long getMapping(UserContext context) { | ||
return ThreadLocalRandom.current().nextLong(0, 100_000_000L); | ||
} | ||
|
||
@Cacheable(CompositeCache.class) | ||
public Long get(String id, String traceId) { | ||
return ThreadLocalRandom.current().nextLong(0, 100_000_000L); | ||
} | ||
|
||
@CachePut(value = CompositeCache.class, parameters = { "id", "traceId" }) | ||
public Long put(BigDecimal arg2, String arg3, String id, String traceId) { | ||
return ThreadLocalRandom.current().nextLong(0, 100_000_000L); | ||
} | ||
|
||
@CacheInvalidate(CompositeCache.class) | ||
public void delete(String id, String traceId) {} | ||
|
||
@CacheInvalidate(value = CompositeCache.class, invalidateAll = true) | ||
public void deleteAll() {} | ||
} |
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
95 changes: 95 additions & 0 deletions
95
...e/src/test/java/ru/tinkoff/kora/example/cache/caffeine/CaffeineCompositeServiceTests.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,95 @@ | ||
package ru.tinkoff.kora.example.cache.caffeine; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import ru.tinkoff.kora.test.extension.junit5.KoraAppTest; | ||
import ru.tinkoff.kora.test.extension.junit5.TestComponent; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
@KoraAppTest(Application.class) | ||
class CaffeineCompositeServiceTests { | ||
|
||
@TestComponent | ||
private CompositeService service; | ||
@TestComponent | ||
private CompositeCache cache; | ||
|
||
@BeforeEach | ||
void cleanup() { | ||
cache.invalidateAll(); | ||
} | ||
|
||
@Test | ||
void get() { | ||
// when | ||
var origin = service.get("1", "1"); | ||
|
||
// then | ||
var cached = service.get("1", "1"); | ||
assertEquals(origin, cached); | ||
} | ||
|
||
@Test | ||
void getMapping() { | ||
// given | ||
var context = new CompositeService.UserContext("1", "2"); | ||
|
||
// when | ||
var origin = service.getMapping(context); | ||
|
||
// then | ||
var cached = service.getMapping(context); | ||
assertEquals(origin, cached); | ||
} | ||
|
||
@Test | ||
void put() { | ||
// when | ||
var origin = service.put(BigDecimal.ONE, "12345", "1", "1"); | ||
|
||
// then | ||
var cached = service.get("1", "1"); | ||
assertEquals(origin, cached); | ||
} | ||
|
||
@Test | ||
void delete() { | ||
// given | ||
var origin = service.put(BigDecimal.ONE, "12345", "1", "1"); | ||
var cached1 = service.get("1", "1"); | ||
assertEquals(origin, cached1); | ||
|
||
// when | ||
service.delete("1", "1"); | ||
|
||
// then | ||
var newValue = service.get("1", "1"); | ||
assertNotEquals(origin, newValue); | ||
} | ||
|
||
@Test | ||
void deleteAll() { | ||
// given | ||
var origin1 = service.put(BigDecimal.ONE, "12345", "1", "1"); | ||
var cached1 = service.get("1", "1"); | ||
assertEquals(origin1, cached1); | ||
|
||
var origin2 = service.put(BigDecimal.ONE, "12345", "2", "2"); | ||
var cached2 = service.get("2", "2"); | ||
assertEquals(origin2, cached2); | ||
|
||
// when | ||
service.deleteAll(); | ||
|
||
// then | ||
var newValue1 = service.get("1", "1"); | ||
assertNotEquals(origin1, newValue1); | ||
|
||
var newValue2 = service.get("2", "2"); | ||
assertNotEquals(origin2, newValue2); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...a/example/cache/caffeine/Application.java → ...kora/example/cache/redis/Application.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
10 changes: 10 additions & 0 deletions
10
kora-java-cache-redis/src/main/java/ru/tinkoff/kora/example/cache/redis/CompositeCache.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,10 @@ | ||
package ru.tinkoff.kora.example.cache.redis; | ||
|
||
import ru.tinkoff.kora.cache.annotation.Cache; | ||
import ru.tinkoff.kora.cache.redis.RedisCache; | ||
|
||
@Cache("my-cache") | ||
public interface CompositeCache extends RedisCache<CompositeCache.Key, Long> { | ||
|
||
record Key(String userId, String traceId) { } | ||
} |
51 changes: 51 additions & 0 deletions
51
...-java-cache-redis/src/main/java/ru/tinkoff/kora/example/cache/redis/CompositeService.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,51 @@ | ||
package ru.tinkoff.kora.example.cache.redis; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import ru.tinkoff.kora.cache.CacheKeyMapper; | ||
import ru.tinkoff.kora.cache.annotation.CacheInvalidate; | ||
import ru.tinkoff.kora.cache.annotation.CachePut; | ||
import ru.tinkoff.kora.cache.annotation.Cacheable; | ||
import ru.tinkoff.kora.common.Component; | ||
import ru.tinkoff.kora.common.Mapping; | ||
import ru.tinkoff.kora.common.annotation.Root; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
@Root | ||
@Component | ||
public class CompositeService { | ||
|
||
public record UserContext(String userId, String traceId) {} | ||
|
||
public static final class UserContextMapping implements CacheKeyMapper<CompositeCache.Key, UserContext> { | ||
|
||
@Nonnull | ||
@Override | ||
public CompositeCache.Key map(UserContext arg) { | ||
return new CompositeCache.Key(arg.userId(), arg.traceId()); | ||
} | ||
} | ||
|
||
@Mapping(UserContextMapping.class) | ||
@Cacheable(CompositeCache.class) | ||
public Long getMapping(UserContext context) { | ||
return ThreadLocalRandom.current().nextLong(0, 100_000_000L); | ||
} | ||
|
||
@Cacheable(CompositeCache.class) | ||
public Long get(String id, String traceId) { | ||
return ThreadLocalRandom.current().nextLong(0, 100_000_000L); | ||
} | ||
|
||
@CachePut(value = CompositeCache.class, parameters = { "id", "traceId" }) | ||
public Long put(BigDecimal arg2, String arg3, String id, String traceId) { | ||
return ThreadLocalRandom.current().nextLong(0, 100_000_000L); | ||
} | ||
|
||
@CacheInvalidate(CompositeCache.class) | ||
public void delete(String id, String traceId) {} | ||
|
||
@CacheInvalidate(value = CompositeCache.class, invalidateAll = true) | ||
public void deleteAll() {} | ||
} |
4 changes: 2 additions & 2 deletions
4
.../kora/example/cache/caffeine/MyCache.java → ...kora/example/cache/redis/SimpleCache.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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package ru.tinkoff.kora.example.cache.caffeine; | ||
package ru.tinkoff.kora.example.cache.redis; | ||
|
||
import ru.tinkoff.kora.cache.annotation.Cache; | ||
import ru.tinkoff.kora.cache.redis.RedisCache; | ||
|
||
@Cache("my-cache") | ||
public interface MyCache extends RedisCache<String, Long> { | ||
public interface SimpleCache extends RedisCache<String, Long> { | ||
|
||
} |
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
Oops, something went wrong.