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>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>ru.spcex.clearing</groupId>-->
|
||||
<!-- <artifactId>test-clearing</artifactId>-->
|
||||
|
|
@ -96,18 +101,6 @@
|
|||
<groupId>ru.spcex.platform</groupId>
|
||||
<artifactId>platform-imdg-api-hazelcast-impl</artifactId>
|
||||
</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>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
|
|
@ -116,19 +109,18 @@
|
|||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>io.springfox</groupId>-->
|
||||
<!-- <artifactId>springfox-swagger2</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>io.springfox</groupId>-->
|
||||
<!-- <artifactId>springfox-swagger-ui</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!--<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-spring-boot-starter</artifactId>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
package ru.spcex.clearing.test;
|
||||
|
||||
import com.hazelcast.config.MapStoreConfig;
|
||||
import com.hazelcast.core.DistributedObject;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.IMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.objects.BusinessObject;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.util.HazelcastHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -21,6 +24,11 @@ public class ImdgService {
|
|||
|
||||
HazelcastInstance hazelcastServerInstance;
|
||||
|
||||
@Autowired
|
||||
public ImdgService(HazelcastInstance hazelcastServerInstance) {
|
||||
this.hazelcastServerInstance = hazelcastServerInstance;
|
||||
}
|
||||
|
||||
Collection<String> allMaps() {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -32,23 +40,37 @@ public class ImdgService {
|
|||
|
||||
HashSet<String> ignoreUpdateMap = new HashSet<>(); // Эти мапы не должны обновляться
|
||||
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 {
|
||||
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) {
|
||||
if (ignoreUpdateMap.contains(mapName)) {
|
||||
log.info("Ignore sync for map {}", mapName);
|
||||
log.debug("Ignore sync for map {}", mapName);
|
||||
continue;
|
||||
}
|
||||
tasks.add(() -> {
|
||||
Long maxKey = null;
|
||||
MapStoreConfig mapStoreConfig = hazelcastServerInstance.getConfig().getMapConfig(mapName).getMapStoreConfig();
|
||||
if (mapStoreConfig != null && mapStoreConfig.isEnabled()) {
|
||||
// MapStoreConfig mapStoreConfig = hazelcastServerInstance.getConfig().getMapConfig(mapName).getMapStoreConfig();
|
||||
// if (mapStoreConfig != null && mapStoreConfig.isEnabled()) {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
log.debug("evict map {}", mapName);
|
||||
IMap<Long, BusinessObject> map = hazelcastServerInstance.getMap(mapName);
|
||||
// todo проверить что ничего лишнего не попадет
|
||||
int size1 = map.size();
|
||||
map.evictAll();
|
||||
log.debug("Load map {}", mapName);
|
||||
|
|
@ -59,22 +81,12 @@ public class ImdgService {
|
|||
if (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);
|
||||
// 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;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class KafkaService {
|
|||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final KafkaSender kafkaSender;
|
||||
|
||||
@Autowired
|
||||
@Autowired(required = false)
|
||||
public KafkaService(KafkaSender kafkaSender) {
|
||||
this.kafkaSender = kafkaSender;
|
||||
}
|
||||
|
|
@ -29,6 +29,9 @@ public class KafkaService {
|
|||
}
|
||||
|
||||
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);
|
||||
if (StringUtils.isEmpty(fullClassName)) throw new IllegalArgumentException("Class 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.producer.Producer;
|
||||
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.Qualifier;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
|
@ -24,6 +26,7 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
|||
|
||||
@Configuration
|
||||
public class KafkaConfig {
|
||||
Logger log = LoggerFactory.getLogger(getClass());
|
||||
// @Autowired
|
||||
// @Bean
|
||||
// @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
|
|
@ -42,20 +45,29 @@ public class KafkaConfig {
|
|||
@Bean
|
||||
public ProducerFactory<String, Object> pf(TestServiceSettings settings) {
|
||||
KafkaProducerSettings kafkaSettings = settings.getKafkaProducer();
|
||||
if (kafkaSettings == null) {
|
||||
log.warn("Kafka config not set - disable kafca function");
|
||||
return null;
|
||||
}
|
||||
return KafkaProducerFactory.producerFactory(kafkaSettings);
|
||||
// return Mockito.mock(ProducerFactory.class);
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
@Bean("kafkaTemplate")
|
||||
public KafkaTemplate<String, Object> kafkaTemplate(ProducerFactory<String, Object> pf) {
|
||||
if (pf == null) return null;
|
||||
return new KafkaTemplate<>(pf);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Autowired(required = false)
|
||||
@Bean
|
||||
public KafkaSender kafkaSender(@Qualifier("kafkaTemplate") KafkaTemplate<String, Object> kafkaTemplate,
|
||||
ImdgProvider imdgProvider
|
||||
) {
|
||||
if (kafkaTemplate == null) {
|
||||
return null;
|
||||
}
|
||||
ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator();
|
||||
return KafkaSender
|
||||
.setup()
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ public abstract class HttpServerSimpleFramework implements InitializingBean, Dis
|
|||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Integer port = null; // 8080
|
||||
try {
|
||||
log.info("Server star at port {} with url \"{}\"", port, baseUrl);
|
||||
this.server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue