From b134b94dbaa3e6d97ed917a6d3792f911bcc132d Mon Sep 17 00:00:00 2001 From: psemenkov Date: Thu, 6 Oct 2022 12:15:22 +0300 Subject: [PATCH] Added testing delete for MapStore --- .../imdg/base/SimpleObjectMapStore.java | 7 ++- .../spcex/clearing/imdg/AllMapStoreTest.java | 46 ++++++++++++++++++- .../GeneratorMapNamesForHazelcast.java | 2 +- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/base/SimpleObjectMapStore.java b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/base/SimpleObjectMapStore.java index 7cdc489b8..da6cc1fac 100644 --- a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/base/SimpleObjectMapStore.java +++ b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/base/SimpleObjectMapStore.java @@ -25,11 +25,10 @@ import java.util.stream.Collectors; * @param */ public abstract class SimpleObjectMapStore implements MapStore { - 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 implements public abstract String[] getFields(); public boolean deleteIsSupported() { - return false; + return true; } @Override diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/AllMapStoreTest.java b/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/AllMapStoreTest.java index ec72032fe..952614bb3 100644 --- a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/AllMapStoreTest.java +++ b/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/AllMapStoreTest.java @@ -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 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 map = testConfig.getHazelcastInstance().getMap(objectForCheck.getMapName()); + map.remove(ID); + String sql = String.format("SELECT FROM %s WHERE id = %d", getTableNameFromMapStore(objectForCheck.getMapName()), ID); + List 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(); diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/GeneratorMapNamesForHazelcast.java b/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/GeneratorMapNamesForHazelcast.java index 642076a33..c86ebe749 100644 --- a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/GeneratorMapNamesForHazelcast.java +++ b/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/GeneratorMapNamesForHazelcast.java @@ -17,7 +17,7 @@ public class GeneratorMapNamesForHazelcast { private static void init() { objectForCheckMapStores = new LinkedList<>(); - objectForCheckMapStores.add(new ObjectForCheckMapStore(IMDGDistributedNames.Map_Account, Account.class)); + objectForCheckMapStores.add(new ObjectForCheckMapStore<>(IMDGDistributedNames.Map_Account, Account.class)); } public static Map createClassByMapStoreName() {