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>
|
||||
*/
|
||||
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;
|
||||
protected SimpleDateFormat DB_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
|
||||
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
protected final JdbcTemplate jdbcTemplate;
|
||||
protected SimpleDateFormat DB_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
protected SimpleObjectMapStore(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
|
|
@ -40,7 +39,7 @@ public abstract class SimpleObjectMapStore<T extends SpcexObjectBase> implements
|
|||
public abstract String[] getFields();
|
||||
|
||||
public boolean deleteIsSupported() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,14 +1,22 @@
|
|||
package ru.spcex.clearing.imdg;
|
||||
|
||||
import com.hazelcast.config.MapStoreConfig;
|
||||
import com.hazelcast.core.IMap;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.TestPropertySource;
|
||||
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.TestConfiguration;
|
||||
import ru.spcex.clearing.imdg.structure.ObjectForCheckMapStore;
|
||||
|
|
@ -17,6 +25,7 @@ import ru.spcex.platform.classes.base.SpcexObjectBase;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
import static ru.spcex.clearing.imdg.structure.GeneratorMapNamesForHazelcast.objectForCheckMapStores;
|
||||
|
||||
|
|
@ -31,6 +40,9 @@ public class AllMapStoreTest {
|
|||
@Autowired
|
||||
TestConfiguration testConfig;
|
||||
|
||||
@Autowired
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
@PostConstruct
|
||||
public void initTestObjects() {
|
||||
try {
|
||||
|
|
@ -47,19 +59,49 @@ public class AllMapStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void storeAllTest() {
|
||||
public void checkSavingForAllMapStoreTest() {
|
||||
saveObjectToMaps();
|
||||
testConfig.shutDownHazelcast();
|
||||
testConfig.reinitHazlecastInstance();
|
||||
|
||||
for (ObjectForCheckMapStore objectForCheck : objectForCheckMapStores) {
|
||||
SpcexObjectBase object = objectForCheck.getPredictableObj();
|
||||
IMap<Long, SpcexObjectBase> map = testConfig.getHazelcastInstance().getMap(objectForCheck.getMapName());
|
||||
SpcexObjectBase actual = map.get(ID);
|
||||
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() {
|
||||
for (ObjectForCheckMapStore objectForCheck : objectForCheckMapStores) {
|
||||
String mapName = objectForCheck.getMapName();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class GeneratorMapNamesForHazelcast {
|
|||
private static void init() {
|
||||
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() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue