Skip to content

Commit

Permalink
Add cache-cache2k smoke test
Browse files Browse the repository at this point in the history
See gh-40
  • Loading branch information
mhalbritter committed Aug 9, 2022
1 parent 45499ea commit 6a2d8a2
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions cache-cache2k/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tests if caching with Cache2k works
17 changes: 17 additions & 0 deletions cache-cache2k/build.gradle
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("org.cache2k:cache2k-spring")

testImplementation("org.springframework.boot:spring-boot-starter-test")

aotTestImplementation(project(":aot-smoke-test-support"))
aotTestImplementation("org.awaitility:awaitility:4.2.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.cache.cache2k;

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 CacheCache2kApplicationAotTests {

@Test
void methodIsCached(AssertableOutput output) {
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
assertThat(output).hasSingleLineContaining("invoke: 1").hasNoLinesContaining("invoke: 2");
});
}

}
21 changes: 21 additions & 0 deletions cache-cache2k/src/main/java/com/example/cache/cache2k/CLR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.cache.cache2k;

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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.cache.cache2k;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CacheCache2kApplication {

public static void main(String[] args) throws InterruptedException {
SpringApplication.run(CacheCache2kApplication.class, args);
Thread.currentThread().join(); // To be able to measure memory consumption
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.cache.cache2k;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@EnableCaching
class CacheConfiguration {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.cache.cache2k;

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++;
}

}
1 change: 1 addition & 0 deletions cache-cache2k/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.cache.type=cache2k
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.cache.cache2k;

import org.junit.jupiter.api.Test;

import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class CacheCache2kApplicationTests {

@Test
void contextLoads() {
}

}
1 change: 1 addition & 0 deletions ci/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ smoke_tests:
- aspect
- async
- batch
- cache-cache2k
- cache-caffeine
- cache-hazelcast
- cloud-function-web
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ include "actuator-webmvc-mgmt-port"
include "aspect"
include "async"
include "batch"
include "cache-cache2k"
include "cache-caffeine"
include "cache-hazelcast"
include "cloud-function-web"
Expand Down

0 comments on commit 6a2d8a2

Please sign in to comment.