test-api-clearing issues/31 интеграция тестового модуля к hazelcast как клиента (были ограничения), тестирование тестового модуля
This commit is contained in:
parent
2b3571ec85
commit
d78105c3b7
5 changed files with 65 additions and 47 deletions
|
|
@ -68,6 +68,11 @@
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>ru.spcex.clearing</groupId>-->
|
<!-- <groupId>ru.spcex.clearing</groupId>-->
|
||||||
<!-- <artifactId>test-clearing</artifactId>-->
|
<!-- <artifactId>test-clearing</artifactId>-->
|
||||||
|
|
@ -96,18 +101,6 @@
|
||||||
<groupId>ru.spcex.platform</groupId>
|
<groupId>ru.spcex.platform</groupId>
|
||||||
<artifactId>platform-imdg-api-hazelcast-impl</artifactId>
|
<artifactId>platform-imdg-api-hazelcast-impl</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.platform</groupId>
|
|
||||||
<artifactId>platform-messaging</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
|
|
@ -116,19 +109,18 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>org.springframework.boot</groupId>
|
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>io.springfox</groupId>
|
<!-- <groupId>io.springfox</groupId>-->
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
<!-- <artifactId>springfox-swagger2</artifactId>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>io.springfox</groupId>
|
<!-- <groupId>io.springfox</groupId>-->
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
<!-- <artifactId>springfox-swagger-ui</artifactId>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<!--<dependency>
|
<!--<dependency>
|
||||||
<groupId>org.keycloak</groupId>
|
<groupId>org.keycloak</groupId>
|
||||||
<artifactId>keycloak-spring-boot-starter</artifactId>
|
<artifactId>keycloak-spring-boot-starter</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
package ru.spcex.clearing.test;
|
package ru.spcex.clearing.test;
|
||||||
|
|
||||||
import com.hazelcast.config.MapStoreConfig;
|
import com.hazelcast.config.MapStoreConfig;
|
||||||
|
import com.hazelcast.core.DistributedObject;
|
||||||
import com.hazelcast.core.HazelcastInstance;
|
import com.hazelcast.core.HazelcastInstance;
|
||||||
import com.hazelcast.core.IMap;
|
import com.hazelcast.core.IMap;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.clearing.classes.objects.BusinessObject;
|
import ru.clearing.classes.objects.BusinessObject;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.platform.imdg.iml.hazelcast.util.HazelcastHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -21,6 +24,11 @@ public class ImdgService {
|
||||||
|
|
||||||
HazelcastInstance hazelcastServerInstance;
|
HazelcastInstance hazelcastServerInstance;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ImdgService(HazelcastInstance hazelcastServerInstance) {
|
||||||
|
this.hazelcastServerInstance = hazelcastServerInstance;
|
||||||
|
}
|
||||||
|
|
||||||
Collection<String> allMaps() {
|
Collection<String> allMaps() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -32,23 +40,37 @@ public class ImdgService {
|
||||||
|
|
||||||
HashSet<String> ignoreUpdateMap = new HashSet<>(); // Эти мапы не должны обновляться
|
HashSet<String> ignoreUpdateMap = new HashSet<>(); // Эти мапы не должны обновляться
|
||||||
ignoreUpdateMap.add(IMDGDistributedNames.Map_RequestInfo);
|
ignoreUpdateMap.add(IMDGDistributedNames.Map_RequestInfo);
|
||||||
|
ignoreUpdateMap.add(HazelcastHelper.CLEARING_SYSTEM_MAP);
|
||||||
|
ignoreUpdateMap.add(HazelcastHelper.STATE_OF_IMDG_SERVER);
|
||||||
|
|
||||||
|
// no mapstore:
|
||||||
|
ignoreUpdateMap.add(IMDGDistributedNames.Map_LiabilitiesClaimsAssets);
|
||||||
|
ignoreUpdateMap.add(IMDGDistributedNames.Map_AccountBalance);
|
||||||
|
ignoreUpdateMap.add(IMDGDistributedNames.Map_KeyRate);
|
||||||
|
ignoreUpdateMap.add(IMDGDistributedNames.Map_LiabilitiesClaimsMoney);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Callable<Long>> tasks = new ArrayList<>();
|
List<Callable<Long>> tasks = new ArrayList<>();
|
||||||
Collection<String> mapNames = hazelcastServerInstance.getConfig().getMapConfigs().keySet();
|
// На сервере так: Collection<String> mapNames = hazelcastServerInstance.getConfig().getMapConfigs().keySet();
|
||||||
|
// На клиенте:
|
||||||
|
List<String> mapNames = new ArrayList<>();
|
||||||
|
for (DistributedObject object : hazelcastServerInstance.getDistributedObjects()) {
|
||||||
|
if (object instanceof IMap) // MapProxyImpl
|
||||||
|
mapNames.add(((IMap) object).getName());
|
||||||
|
}
|
||||||
for (String mapName : mapNames) {
|
for (String mapName : mapNames) {
|
||||||
if (ignoreUpdateMap.contains(mapName)) {
|
if (ignoreUpdateMap.contains(mapName)) {
|
||||||
log.info("Ignore sync for map {}", mapName);
|
log.debug("Ignore sync for map {}", mapName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tasks.add(() -> {
|
tasks.add(() -> {
|
||||||
Long maxKey = null;
|
Long maxKey = null;
|
||||||
MapStoreConfig mapStoreConfig = hazelcastServerInstance.getConfig().getMapConfig(mapName).getMapStoreConfig();
|
// MapStoreConfig mapStoreConfig = hazelcastServerInstance.getConfig().getMapConfig(mapName).getMapStoreConfig();
|
||||||
if (mapStoreConfig != null && mapStoreConfig.isEnabled()) {
|
// if (mapStoreConfig != null && mapStoreConfig.isEnabled()) {
|
||||||
|
try {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
log.debug("evict map {}", mapName);
|
log.debug("evict map {}", mapName);
|
||||||
IMap<Long, BusinessObject> map = hazelcastServerInstance.getMap(mapName);
|
IMap<Long, BusinessObject> map = hazelcastServerInstance.getMap(mapName);
|
||||||
// todo проверить что ничего лишнего не попадет
|
|
||||||
int size1 = map.size();
|
int size1 = map.size();
|
||||||
map.evictAll();
|
map.evictAll();
|
||||||
log.debug("Load map {}", mapName);
|
log.debug("Load map {}", mapName);
|
||||||
|
|
@ -59,22 +81,12 @@ public class ImdgService {
|
||||||
if (size1 != size)
|
if (size1 != size)
|
||||||
log.warn("Map {} change size from {} to {}", mapName, size1, size);
|
log.warn("Map {} change size from {} to {}", mapName, size1, size);
|
||||||
|
|
||||||
Object mapStore = mapStoreConfig.getImplementation();
|
|
||||||
//todo проверить реализацию.
|
|
||||||
maxKey = map.keySet().stream().max(Long::compareTo).orElse(null);
|
maxKey = map.keySet().stream().max(Long::compareTo).orElse(null);
|
||||||
// if (mapStore instanceof SimpleObjectMapStore) {
|
|
||||||
// String tableName = ((SimpleObjectMapStore) mapStore).getTableName();
|
|
||||||
// maxKey = map.keySet().stream().max(Long::compareTo).orElse(null); // jdbcTemplate.queryForObject("select max(id) from " + tableName, Long.class);
|
|
||||||
// } else if (mapStore instanceof DictionaryMapStore) {
|
|
||||||
// // для Dictionary не используется общий id генератор
|
|
||||||
//// } else if (mapStore instanceof FrontendUserSessionMapStore) {
|
|
||||||
//// // не используется общий id генератор
|
|
||||||
// } else {
|
|
||||||
// throw new RuntimeException("unknown map store implementation " + mapStore);
|
|
||||||
// }
|
|
||||||
log.debug("{} max(id)={}", mapName, maxKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
log.trace("{} max(id)={}", mapName, maxKey);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new RuntimeException("Can not reload map " + mapName, e);
|
||||||
|
}
|
||||||
return maxKey;
|
return maxKey;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public class KafkaService {
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
private final KafkaSender kafkaSender;
|
private final KafkaSender kafkaSender;
|
||||||
|
|
||||||
@Autowired
|
@Autowired(required = false)
|
||||||
public KafkaService(KafkaSender kafkaSender) {
|
public KafkaService(KafkaSender kafkaSender) {
|
||||||
this.kafkaSender = kafkaSender;
|
this.kafkaSender = kafkaSender;
|
||||||
}
|
}
|
||||||
|
|
@ -29,6 +29,9 @@ public class KafkaService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long putMessage(String fullClassName, String topic, String jsonBody) throws ClassNotFoundException, JsonProcessingException {
|
public Long putMessage(String fullClassName, String topic, String jsonBody) throws ClassNotFoundException, JsonProcessingException {
|
||||||
|
if (kafkaSender == null) {
|
||||||
|
throw new IllegalStateException("Kafka action disabled");
|
||||||
|
}
|
||||||
log.info("Call test method for kafka, class=\"{}\"; topic=\"{}\"; message=\"{}\"", fullClassName, topic, jsonBody);
|
log.info("Call test method for kafka, class=\"{}\"; topic=\"{}\"; message=\"{}\"", fullClassName, topic, jsonBody);
|
||||||
if (StringUtils.isEmpty(fullClassName)) throw new IllegalArgumentException("Class was emppty");
|
if (StringUtils.isEmpty(fullClassName)) throw new IllegalArgumentException("Class was emppty");
|
||||||
if (StringUtils.isEmpty(topic)) throw new IllegalArgumentException("Topic was emppty");
|
if (StringUtils.isEmpty(topic)) throw new IllegalArgumentException("Topic was emppty");
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package ru.spcex.clearing.test.config;
|
||||||
import org.apache.kafka.clients.consumer.Consumer;
|
import org.apache.kafka.clients.consumer.Consumer;
|
||||||
import org.apache.kafka.clients.producer.Producer;
|
import org.apache.kafka.clients.producer.Producer;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
|
@ -24,6 +26,7 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class KafkaConfig {
|
public class KafkaConfig {
|
||||||
|
Logger log = LoggerFactory.getLogger(getClass());
|
||||||
// @Autowired
|
// @Autowired
|
||||||
// @Bean
|
// @Bean
|
||||||
// @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
// @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
|
|
@ -42,20 +45,29 @@ public class KafkaConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public ProducerFactory<String, Object> pf(TestServiceSettings settings) {
|
public ProducerFactory<String, Object> pf(TestServiceSettings settings) {
|
||||||
KafkaProducerSettings kafkaSettings = settings.getKafkaProducer();
|
KafkaProducerSettings kafkaSettings = settings.getKafkaProducer();
|
||||||
|
if (kafkaSettings == null) {
|
||||||
|
log.warn("Kafka config not set - disable kafca function");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return KafkaProducerFactory.producerFactory(kafkaSettings);
|
return KafkaProducerFactory.producerFactory(kafkaSettings);
|
||||||
// return Mockito.mock(ProducerFactory.class);
|
// return Mockito.mock(ProducerFactory.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
@Bean("kafkaTemplate")
|
@Bean("kafkaTemplate")
|
||||||
public KafkaTemplate<String, Object> kafkaTemplate(ProducerFactory<String, Object> pf) {
|
public KafkaTemplate<String, Object> kafkaTemplate(ProducerFactory<String, Object> pf) {
|
||||||
|
if (pf == null) return null;
|
||||||
return new KafkaTemplate<>(pf);
|
return new KafkaTemplate<>(pf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired(required = false)
|
||||||
@Bean
|
@Bean
|
||||||
public KafkaSender kafkaSender(@Qualifier("kafkaTemplate") KafkaTemplate<String, Object> kafkaTemplate,
|
public KafkaSender kafkaSender(@Qualifier("kafkaTemplate") KafkaTemplate<String, Object> kafkaTemplate,
|
||||||
ImdgProvider imdgProvider
|
ImdgProvider imdgProvider
|
||||||
) {
|
) {
|
||||||
|
if (kafkaTemplate == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator();
|
ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator();
|
||||||
return KafkaSender
|
return KafkaSender
|
||||||
.setup()
|
.setup()
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ public abstract class HttpServerSimpleFramework implements InitializingBean, Dis
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
Integer port = null; // 8080
|
|
||||||
try {
|
try {
|
||||||
log.info("Server star at port {} with url \"{}\"", port, baseUrl);
|
log.info("Server star at port {} with url \"{}\"", port, baseUrl);
|
||||||
this.server = HttpServer.create(new InetSocketAddress(port), 0);
|
this.server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue