Skip to content

Commit 717200e

Browse files
committed
Use Hazelcast's Docker Image instead of an embedded Hazelcast instance
1 parent 6f3eb79 commit 717200e

File tree

3 files changed

+39
-67
lines changed

3 files changed

+39
-67
lines changed

tests/src/com.hazelcast/hazelcast/5.2.1/build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ dependencies {
1515
testImplementation "com.hazelcast:hazelcast:$libraryVersion"
1616
testImplementation 'org.assertj:assertj-core:3.22.0'
1717
testImplementation 'javax.cache:cache-api:1.1.1'
18-
}
19-
20-
test {
21-
jvmArgs = Arrays.asList("-Xmx4g")
18+
testImplementation 'org.awaitility:awaitility:4.2.0'
19+
testImplementation 'ch.qos.logback:logback-classic:1.2.11'
2220
}
2321

2422
graalvmNative {

tests/src/com.hazelcast/hazelcast/5.2.1/src/test/java/com_hazelcast/hazelcast/HazelcastTest.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
import com.hazelcast.cache.ICache;
1111
import com.hazelcast.client.HazelcastClient;
1212
import com.hazelcast.client.config.ClientConfig;
13-
import com.hazelcast.config.Config;
1413
import com.hazelcast.config.GlobalSerializerConfig;
1514
import com.hazelcast.config.SerializerConfig;
16-
import com.hazelcast.core.Hazelcast;
1715
import com.hazelcast.core.HazelcastInstance;
1816
import com.hazelcast.cp.IAtomicLong;
1917
import com.hazelcast.map.IMap;
@@ -35,9 +33,13 @@
3533
import javax.cache.Cache;
3634
import javax.cache.CacheManager;
3735
import javax.cache.Caching;
36+
import javax.cache.configuration.CompleteConfiguration;
3837
import javax.cache.configuration.MutableConfiguration;
3938
import javax.cache.expiry.AccessedExpiryPolicy;
4039
import javax.cache.expiry.Duration;
40+
import javax.cache.spi.CachingProvider;
41+
import java.io.File;
42+
import java.io.IOException;
4143
import java.util.Collection;
4244
import java.util.List;
4345
import java.util.Set;
@@ -51,18 +53,30 @@
5153
import static com.hazelcast.query.Predicates.equal;
5254
import static com.hazelcast.query.Predicates.sql;
5355
import static org.assertj.core.api.Assertions.assertThat;
56+
import static org.awaitility.Awaitility.await;
5457

5558
class HazelcastTest {
56-
static HazelcastInstance hazelcastInstance;
59+
private static Process process;
5760

5861
@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");
6172
}
6273

6374
@AfterAll
6475
static void afterAll() {
65-
hazelcastInstance.shutdown();
76+
if (process != null && process.isAlive()) {
77+
System.out.println("Shutting down Hazelcast");
78+
process.destroy();
79+
}
6680
}
6781

6882
@Test
@@ -256,4 +270,21 @@ void testTopic() {
256270
IntStream.range(0, 3).mapToObj(i -> "Hello to distributed world").forEach(topic::publish);
257271
client.shutdown();
258272
}
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+
}
259290
}

tests/src/com.hazelcast/hazelcast/5.2.1/src/test/java/com_hazelcast/hazelcast/JCacheTest.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)