diff --git a/cache-hazelcast/README.adoc b/cache-hazelcast/README.adoc new file mode 100644 index 00000000..4ee6b3f7 --- /dev/null +++ b/cache-hazelcast/README.adoc @@ -0,0 +1 @@ +Tests if caching with Hazelcast works diff --git a/cache-hazelcast/build.gradle b/cache-hazelcast/build.gradle new file mode 100644 index 00000000..77aff9ee --- /dev/null +++ b/cache-hazelcast/build.gradle @@ -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.hazelcast:hazelcast-spring") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + aotTestImplementation(project(":aot-smoke-test-support")) + aotTestImplementation("org.awaitility:awaitility:4.2.0") +} diff --git a/cache-hazelcast/src/aotTest/java/com/example/cache/hazelcast/CacheHazelcastApplicationAotTests.java b/cache-hazelcast/src/aotTest/java/com/example/cache/hazelcast/CacheHazelcastApplicationAotTests.java new file mode 100644 index 00000000..aec80a2e --- /dev/null +++ b/cache-hazelcast/src/aotTest/java/com/example/cache/hazelcast/CacheHazelcastApplicationAotTests.java @@ -0,0 +1,23 @@ +package com.example.cache.hazelcast; + +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 CacheHazelcastApplicationAotTests { + + @Test + void methodIsCached(AssertableOutput output) { + Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> { + assertThat(output).hasSingleLineContaining("invoke: 1").hasNoLinesContaining("invoke: 2"); + }); + } + +} diff --git a/cache-hazelcast/src/main/java/com/example/cache/hazelcast/CLR.java b/cache-hazelcast/src/main/java/com/example/cache/hazelcast/CLR.java new file mode 100644 index 00000000..b1950465 --- /dev/null +++ b/cache-hazelcast/src/main/java/com/example/cache/hazelcast/CLR.java @@ -0,0 +1,21 @@ +package com.example.cache.hazelcast; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +class CLR implements CommandLineRunner { + + private final TestService testService; + + public CLR(TestService testService) { + this.testService = testService; + } + + @Override + public void run(String... args) { + this.testService.invoke(); + this.testService.invoke(); + } + +} diff --git a/cache-hazelcast/src/main/java/com/example/cache/hazelcast/CacheConfiguration.java b/cache-hazelcast/src/main/java/com/example/cache/hazelcast/CacheConfiguration.java new file mode 100644 index 00000000..c40c7840 --- /dev/null +++ b/cache-hazelcast/src/main/java/com/example/cache/hazelcast/CacheConfiguration.java @@ -0,0 +1,10 @@ +package com.example.cache.hazelcast; + +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@EnableCaching +class CacheConfiguration { + +} diff --git a/cache-hazelcast/src/main/java/com/example/cache/hazelcast/CacheHazelcastApplication.java b/cache-hazelcast/src/main/java/com/example/cache/hazelcast/CacheHazelcastApplication.java new file mode 100644 index 00000000..9cb36b97 --- /dev/null +++ b/cache-hazelcast/src/main/java/com/example/cache/hazelcast/CacheHazelcastApplication.java @@ -0,0 +1,14 @@ +package com.example.cache.hazelcast; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CacheHazelcastApplication { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(CacheHazelcastApplication.class, args); + Thread.currentThread().join(); // To be able to measure memory consumption + } + +} diff --git a/cache-hazelcast/src/main/java/com/example/cache/hazelcast/TestService.java b/cache-hazelcast/src/main/java/com/example/cache/hazelcast/TestService.java new file mode 100644 index 00000000..273f80f1 --- /dev/null +++ b/cache-hazelcast/src/main/java/com/example/cache/hazelcast/TestService.java @@ -0,0 +1,17 @@ +package com.example.cache.hazelcast; + +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +@Service +class TestService { + + private int counter = 1; + + @Cacheable(cacheNames = "invoke") + public void invoke() { + System.out.printf("invoke: %d%n", this.counter); + this.counter++; + } + +} diff --git a/cache-hazelcast/src/main/resources/application.properties b/cache-hazelcast/src/main/resources/application.properties new file mode 100644 index 00000000..7b96b1c0 --- /dev/null +++ b/cache-hazelcast/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.cache.type=hazelcast diff --git a/cache-hazelcast/src/main/resources/hazelcast.yaml b/cache-hazelcast/src/main/resources/hazelcast.yaml new file mode 100644 index 00000000..b952a33d --- /dev/null +++ b/cache-hazelcast/src/main/resources/hazelcast.yaml @@ -0,0 +1,8 @@ +hazelcast: + cluster-name: cache-hazelcast + network: + join: + auto-detection: + enabled: false + multicast: + enabled: false diff --git a/cache-hazelcast/src/test/java/com/example/cache/hazelcast/CacheHazelcastApplicationTests.java b/cache-hazelcast/src/test/java/com/example/cache/hazelcast/CacheHazelcastApplicationTests.java new file mode 100644 index 00000000..05bc116f --- /dev/null +++ b/cache-hazelcast/src/test/java/com/example/cache/hazelcast/CacheHazelcastApplicationTests.java @@ -0,0 +1,14 @@ +package com.example.cache.hazelcast; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class CacheHazelcastApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index b4777370..485798c7 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -6,6 +6,7 @@ smoke_tests: - aspect - async - batch + - cache-hazelcast - cloud-function-web - cloud-function-webflux - cloud-task diff --git a/settings.gradle b/settings.gradle index 831c0151..d1eac0cb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -34,6 +34,7 @@ include "actuator-webmvc-mgmt-port" include "aspect" include "async" include "batch" +include "cache-hazelcast" include "cloud-function-web" include "cloud-function-webflux" include "cloud-task"