-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
162 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Tests if caching with Caffeine works |
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,17 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' | ||
id 'org.springframework.aot.smoke-test' | ||
id 'org.graalvm.buildtools.native' | ||
} | ||
|
||
dependencies { | ||
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) | ||
implementation("org.springframework.boot:spring-boot-starter-cache") | ||
implementation("com.github.ben-manes.caffeine:caffeine") | ||
|
||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
|
||
aotTestImplementation(project(":aot-smoke-test-support")) | ||
aotTestImplementation("org.awaitility:awaitility:4.2.0") | ||
} |
31 changes: 31 additions & 0 deletions
31
...affeine/src/aotTest/java/com/example/cache/caffeine/CacheCaffeineApplicationAotTests.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,31 @@ | ||
package com.example.cache.caffeine; | ||
|
||
import java.time.Duration; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.aot.smoketest.support.assertj.AssertableOutput; | ||
import org.springframework.aot.smoketest.support.junit.AotSmokeTest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@AotSmokeTest | ||
class CacheCaffeineApplicationAotTests { | ||
|
||
@Test | ||
void methodIsCachedOnClasses(AssertableOutput output) { | ||
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> { | ||
assertThat(output).hasSingleLineContaining("class.invoke: 1").hasNoLinesContaining("class.invoke: 2"); | ||
}); | ||
} | ||
|
||
@Test | ||
void methodIsCachedOnInterfaces(AssertableOutput output) { | ||
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> { | ||
assertThat(output).hasSingleLineContaining("interface.invoke: 1") | ||
.hasNoLinesContaining("interface.invoke: 2"); | ||
}); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
cache-caffeine/src/main/java/com/example/cache/caffeine/CLR.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,30 @@ | ||
package com.example.cache.caffeine; | ||
|
||
import com.example.cache.caffeine.clazz.TestServiceClass; | ||
import com.example.cache.caffeine.iface.TestServiceInterface; | ||
|
||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
class CLR implements CommandLineRunner { | ||
|
||
private final TestServiceClass testServiceClass; | ||
|
||
private final TestServiceInterface testServiceInterface; | ||
|
||
public CLR(TestServiceClass testServiceClass, TestServiceInterface testServiceInterface) { | ||
this.testServiceClass = testServiceClass; | ||
this.testServiceInterface = testServiceInterface; | ||
} | ||
|
||
@Override | ||
public void run(String... args) { | ||
this.testServiceClass.invoke(); | ||
this.testServiceClass.invoke(); | ||
|
||
this.testServiceInterface.invoke(); | ||
this.testServiceInterface.invoke(); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
cache-caffeine/src/main/java/com/example/cache/caffeine/CacheCaffeineApplication.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,14 @@ | ||
package com.example.cache.caffeine; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class CacheCaffeineApplication { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
SpringApplication.run(CacheCaffeineApplication.class, args); | ||
Thread.currentThread().join(); // To be able to measure memory consumption | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
cache-caffeine/src/main/java/com/example/cache/caffeine/CacheConfiguration.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 com.example.cache.caffeine; | ||
|
||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@EnableCaching | ||
class CacheConfiguration { | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
cache-caffeine/src/main/java/com/example/cache/caffeine/clazz/TestServiceClass.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,17 @@ | ||
package com.example.cache.caffeine.clazz; | ||
|
||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class TestServiceClass { | ||
|
||
private int counter = 1; | ||
|
||
@Cacheable(cacheNames = "class.invoke") | ||
public void invoke() { | ||
System.out.printf("class.invoke: %d%n", this.counter); | ||
this.counter++; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
cache-caffeine/src/main/java/com/example/cache/caffeine/iface/TestServiceInterface.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,7 @@ | ||
package com.example.cache.caffeine.iface; | ||
|
||
public interface TestServiceInterface { | ||
|
||
void invoke(); | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
cache-caffeine/src/main/java/com/example/cache/caffeine/iface/TestServiceWithInterface.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,18 @@ | ||
package com.example.cache.caffeine.iface; | ||
|
||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
class TestServiceWithInterface implements TestServiceInterface { | ||
|
||
private int counter = 1; | ||
|
||
@Override | ||
@Cacheable(cacheNames = "interface.invoke") | ||
public void invoke() { | ||
System.out.printf("interface.invoke: %d%n", this.counter); | ||
this.counter++; | ||
} | ||
|
||
} |
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 @@ | ||
spring.cache.type=caffeine |
14 changes: 14 additions & 0 deletions
14
cache-caffeine/src/test/java/com/example/cache/caffeine/CacheCaffeineApplicationTests.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,14 @@ | ||
package com.example.cache.caffeine; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class CacheCaffeineApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
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