Merge branch 'master' into cache
# Conflicts: # spring-boot/hazelcast/hazelcast-client-server/src/test/java/io/reflectoring/cache/cleint/AbstractIntegrationTest.java
This commit is contained in:
@@ -22,7 +22,7 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
compile group: 'com.hazelcast', name: 'hazelcast-client', version: '3.12.7'
|
||||
compile group: 'com.hazelcast', name: 'hazelcast', version: '4.0.1'
|
||||
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package io.reflectoring.cache.cleint.client;
|
||||
|
||||
import com.hazelcast.client.HazelcastClient;
|
||||
import com.hazelcast.client.config.ClientConfig;
|
||||
import com.hazelcast.config.NearCacheConfig;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.IMap;
|
||||
import com.hazelcast.map.IMap;
|
||||
import io.reflectoring.cache.cleint.rest.Car;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -11,15 +13,29 @@ public class CacheClient {
|
||||
|
||||
private static final String CARS = "cars";
|
||||
|
||||
private HazelcastInstance client = HazelcastClient.newHazelcastClient();
|
||||
private HazelcastInstance client = HazelcastClient.newHazelcastClient(creatClientConfig());
|
||||
|
||||
public Car put(String key, Car car){
|
||||
public Car put(String key, Car car) {
|
||||
IMap<String, Car> map = client.getMap(CARS);
|
||||
return map.putIfAbsent(key, car);
|
||||
}
|
||||
|
||||
public Car get(String key){
|
||||
public Car get(String key) {
|
||||
IMap<String, Car> map = client.getMap(CARS);
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
private ClientConfig creatClientConfig() {
|
||||
ClientConfig clientConfig = new ClientConfig();
|
||||
clientConfig.addNearCacheConfig(createNearCacheConfig());
|
||||
return clientConfig;
|
||||
}
|
||||
|
||||
private NearCacheConfig createNearCacheConfig() {
|
||||
NearCacheConfig nearCacheConfig = new NearCacheConfig();
|
||||
nearCacheConfig.setName(CARS);
|
||||
nearCacheConfig.setTimeToLiveSeconds(360);
|
||||
nearCacheConfig.setMaxIdleSeconds(60);
|
||||
return nearCacheConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import org.testcontainers.containers.GenericContainer;
|
||||
|
||||
public class AbstractIntegrationTest {
|
||||
|
||||
static GenericContainer firstMember =
|
||||
new FixedHostPortGenericContainer("hazelcast/hazelcast:4.0.1")
|
||||
.withFixedExposedPort(5701, 5701);
|
||||
static GenericContainer firstMember =
|
||||
new FixedHostPortGenericContainer("hazelcast/hazelcast:4.0.1")
|
||||
.withFixedExposedPort(5701, 5701);
|
||||
|
||||
static GenericContainer secondMember =
|
||||
new FixedHostPortGenericContainer("hazelcast/hazelcast:4.0.1")
|
||||
.withFixedExposedPort(5702, 5701);
|
||||
static GenericContainer secondMember =
|
||||
new FixedHostPortGenericContainer("hazelcast/hazelcast:4.0.1")
|
||||
.withFixedExposedPort(5702, 5701);
|
||||
|
||||
@BeforeAll
|
||||
public static void init() {
|
||||
|
||||
Reference in New Issue
Block a user