|
10 | 10 | import com.hazelcast.cache.ICache; |
11 | 11 | import com.hazelcast.client.HazelcastClient; |
12 | 12 | import com.hazelcast.client.config.ClientConfig; |
13 | | -import com.hazelcast.config.Config; |
14 | 13 | import com.hazelcast.config.GlobalSerializerConfig; |
15 | 14 | import com.hazelcast.config.SerializerConfig; |
16 | | -import com.hazelcast.core.Hazelcast; |
17 | 15 | import com.hazelcast.core.HazelcastInstance; |
18 | 16 | import com.hazelcast.cp.IAtomicLong; |
19 | 17 | import com.hazelcast.map.IMap; |
|
35 | 33 | import javax.cache.Cache; |
36 | 34 | import javax.cache.CacheManager; |
37 | 35 | import javax.cache.Caching; |
| 36 | +import javax.cache.configuration.CompleteConfiguration; |
38 | 37 | import javax.cache.configuration.MutableConfiguration; |
39 | 38 | import javax.cache.expiry.AccessedExpiryPolicy; |
40 | 39 | import javax.cache.expiry.Duration; |
| 40 | +import javax.cache.spi.CachingProvider; |
| 41 | +import java.io.File; |
| 42 | +import java.io.IOException; |
41 | 43 | import java.util.Collection; |
42 | 44 | import java.util.List; |
43 | 45 | import java.util.Set; |
|
51 | 53 | import static com.hazelcast.query.Predicates.equal; |
52 | 54 | import static com.hazelcast.query.Predicates.sql; |
53 | 55 | import static org.assertj.core.api.Assertions.assertThat; |
| 56 | +import static org.awaitility.Awaitility.await; |
54 | 57 |
|
55 | 58 | class HazelcastTest { |
56 | | - static HazelcastInstance hazelcastInstance; |
| 59 | + private static Process process; |
57 | 60 |
|
58 | 61 | @BeforeAll |
59 | | - static void beforeAll() { |
60 | | - hazelcastInstance = Hazelcast.newHazelcastInstance(new Config()); |
| 62 | + static void beforeAll() throws IOException { |
| 63 | + System.out.println("Starting Hazelcast ..."); |
| 64 | + process = new ProcessBuilder("docker", "run", "--rm", "-p", "5701:5701", |
| 65 | + "-e", "JAVA_OPTS=-Xmx1024M", "hazelcast/hazelcast:5.2.1") |
| 66 | + .redirectOutput(new File("hazelcast-stdout.txt")).redirectError(new File("hazelcast-stderr.txt")).start(); |
| 67 | + await().atMost(java.time.Duration.ofMinutes(5)).ignoreExceptions().until(() -> { |
| 68 | + HazelcastClient.newHazelcastClient().shutdown(); |
| 69 | + return true; |
| 70 | + }); |
| 71 | + System.out.println("Hazelcast started"); |
61 | 72 | } |
62 | 73 |
|
63 | 74 | @AfterAll |
64 | 75 | static void afterAll() { |
65 | | - hazelcastInstance.shutdown(); |
| 76 | + if (process != null && process.isAlive()) { |
| 77 | + System.out.println("Shutting down Hazelcast"); |
| 78 | + process.destroy(); |
| 79 | + } |
66 | 80 | } |
67 | 81 |
|
68 | 82 | @Test |
@@ -256,4 +270,21 @@ void testTopic() { |
256 | 270 | IntStream.range(0, 3).mapToObj(i -> "Hello to distributed world").forEach(topic::publish); |
257 | 271 | client.shutdown(); |
258 | 272 | } |
| 273 | + |
| 274 | + @Test |
| 275 | + void testJCacheOrigin() { |
| 276 | + CachingProvider cachingProvider = Caching.getCachingProvider(HazelcastCachingProvider.class.getName()); |
| 277 | + CacheManager cacheManager = cachingProvider.getCacheManager(); |
| 278 | + CompleteConfiguration<String, String> config = new MutableConfiguration<String, String>() |
| 279 | + .setTypes(String.class, String.class) |
| 280 | + .setStatisticsEnabled(true) |
| 281 | + .setReadThrough(false) |
| 282 | + .setManagementEnabled(true) |
| 283 | + .setStoreByValue(false) |
| 284 | + .setWriteThrough(false); |
| 285 | + Cache<String, String> cache = cacheManager.createCache("example", config); |
| 286 | + cache.put("world", "Hello World"); |
| 287 | + assertThat(cache.get("world")).isEqualTo("Hello World"); |
| 288 | + assertThat(cacheManager.getCache("example", String.class, String.class)).isNotNull(); |
| 289 | + } |
259 | 290 | } |
0 commit comments