Added testing delete for MapStore
This commit is contained in:
parent
7b237924dd
commit
b134b94dba
3 changed files with 48 additions and 7 deletions
|
|
@ -25,11 +25,10 @@ import java.util.stream.Collectors;
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public abstract class SimpleObjectMapStore<T extends SpcexObjectBase> implements MapStore<Long, T> {
|
public abstract class SimpleObjectMapStore<T extends SpcexObjectBase> implements MapStore<Long, T> {
|
||||||
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
|
||||||
|
|
||||||
private final static int BATCH_SIZE = 1000;
|
private final static int BATCH_SIZE = 1000;
|
||||||
protected SimpleDateFormat DB_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
|
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||||
protected final JdbcTemplate jdbcTemplate;
|
protected final JdbcTemplate jdbcTemplate;
|
||||||
|
protected SimpleDateFormat DB_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
protected SimpleObjectMapStore(JdbcTemplate jdbcTemplate) {
|
protected SimpleObjectMapStore(JdbcTemplate jdbcTemplate) {
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
|
@ -40,7 +39,7 @@ public abstract class SimpleObjectMapStore<T extends SpcexObjectBase> implements
|
||||||
public abstract String[] getFields();
|
public abstract String[] getFields();
|
||||||
|
|
||||||
public boolean deleteIsSupported() {
|
public boolean deleteIsSupported() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,22 @@
|
||||||
package ru.spcex.clearing.imdg;
|
package ru.spcex.clearing.imdg;
|
||||||
|
|
||||||
|
import com.hazelcast.config.MapStoreConfig;
|
||||||
import com.hazelcast.core.IMap;
|
import com.hazelcast.core.IMap;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
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.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.TestPropertySource;
|
import org.springframework.test.context.TestPropertySource;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
import ru.spcex.clearing.imdg.base.BusinessObjectMapStore;
|
||||||
|
import ru.spcex.clearing.imdg.base.DictionaryMapStore;
|
||||||
|
import ru.spcex.clearing.imdg.base.TemplateEventMapStore;
|
||||||
|
import ru.spcex.clearing.imdg.base.TemplateMapStore;
|
||||||
import ru.spcex.clearing.imdg.config.DbTestConnectionConfig;
|
import ru.spcex.clearing.imdg.config.DbTestConnectionConfig;
|
||||||
import ru.spcex.clearing.imdg.config.TestConfiguration;
|
import ru.spcex.clearing.imdg.config.TestConfiguration;
|
||||||
import ru.spcex.clearing.imdg.structure.ObjectForCheckMapStore;
|
import ru.spcex.clearing.imdg.structure.ObjectForCheckMapStore;
|
||||||
|
|
@ -17,6 +25,7 @@ import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static ru.spcex.clearing.imdg.structure.GeneratorMapNamesForHazelcast.objectForCheckMapStores;
|
import static ru.spcex.clearing.imdg.structure.GeneratorMapNamesForHazelcast.objectForCheckMapStores;
|
||||||
|
|
||||||
|
|
@ -31,6 +40,9 @@ public class AllMapStoreTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
TestConfiguration testConfig;
|
TestConfiguration testConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initTestObjects() {
|
public void initTestObjects() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -47,19 +59,49 @@ public class AllMapStoreTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void storeAllTest() {
|
public void checkSavingForAllMapStoreTest() {
|
||||||
saveObjectToMaps();
|
saveObjectToMaps();
|
||||||
testConfig.shutDownHazelcast();
|
testConfig.shutDownHazelcast();
|
||||||
testConfig.reinitHazlecastInstance();
|
testConfig.reinitHazlecastInstance();
|
||||||
|
|
||||||
for (ObjectForCheckMapStore objectForCheck : objectForCheckMapStores) {
|
for (ObjectForCheckMapStore objectForCheck : objectForCheckMapStores) {
|
||||||
SpcexObjectBase object = objectForCheck.getPredictableObj();
|
|
||||||
IMap<Long, SpcexObjectBase> map = testConfig.getHazelcastInstance().getMap(objectForCheck.getMapName());
|
IMap<Long, SpcexObjectBase> map = testConfig.getHazelcastInstance().getMap(objectForCheck.getMapName());
|
||||||
SpcexObjectBase actual = map.get(ID);
|
SpcexObjectBase actual = map.get(ID);
|
||||||
objectForCheck.getMATCHER().assertMatch(actual, objectForCheck.getPredictableObj());
|
objectForCheck.getMATCHER().assertMatch(actual, objectForCheck.getPredictableObj());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkDeletingForAllMapStoreTest() {
|
||||||
|
saveObjectToMaps();
|
||||||
|
|
||||||
|
for (ObjectForCheckMapStore objectForCheck : objectForCheckMapStores) {
|
||||||
|
IMap<Long, SpcexObjectBase> map = testConfig.getHazelcastInstance().getMap(objectForCheck.getMapName());
|
||||||
|
map.remove(ID);
|
||||||
|
String sql = String.format("SELECT FROM %s WHERE id = %d", getTableNameFromMapStore(objectForCheck.getMapName()), ID);
|
||||||
|
List<SpcexObjectBase> obj = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(objectForCheck.getClazz()));
|
||||||
|
|
||||||
|
Assertions.assertNull(map.get(ID));
|
||||||
|
Assertions.assertEquals(0, obj.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTableNameFromMapStore(String mapName) {
|
||||||
|
MapStoreConfig mapStoreConfig = testConfig.getHazelcastInstance().getConfig().getMapConfig(mapName).getMapStoreConfig();
|
||||||
|
Object mapStore = mapStoreConfig.getImplementation();
|
||||||
|
String tableName = null;
|
||||||
|
if (mapStore instanceof TemplateMapStore) {
|
||||||
|
tableName = ((TemplateMapStore<?>) mapStore).getTableName();
|
||||||
|
} else if (mapStore instanceof DictionaryMapStore) {
|
||||||
|
tableName = ((DictionaryMapStore<?>) mapStore).getTableName();
|
||||||
|
} else if (mapStore instanceof TemplateEventMapStore) {
|
||||||
|
tableName = ((TemplateEventMapStore<?>) mapStore).getTableName();
|
||||||
|
} else if (mapStore instanceof BusinessObjectMapStore) {
|
||||||
|
tableName = ((BusinessObjectMapStore<?>) mapStore).getTableName();
|
||||||
|
}
|
||||||
|
return tableName;
|
||||||
|
}
|
||||||
|
|
||||||
private void saveObjectToMaps() {
|
private void saveObjectToMaps() {
|
||||||
for (ObjectForCheckMapStore objectForCheck : objectForCheckMapStores) {
|
for (ObjectForCheckMapStore objectForCheck : objectForCheckMapStores) {
|
||||||
String mapName = objectForCheck.getMapName();
|
String mapName = objectForCheck.getMapName();
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public class GeneratorMapNamesForHazelcast {
|
||||||
private static void init() {
|
private static void init() {
|
||||||
objectForCheckMapStores = new LinkedList<>();
|
objectForCheckMapStores = new LinkedList<>();
|
||||||
|
|
||||||
objectForCheckMapStores.add(new ObjectForCheckMapStore<Account>(IMDGDistributedNames.Map_Account, Account.class));
|
objectForCheckMapStores.add(new ObjectForCheckMapStore<>(IMDGDistributedNames.Map_Account, Account.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Class> createClassByMapStoreName() {
|
public static Map<String, Class> createClassByMapStoreName() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue