parent
aed45da642
commit
ab391739fa
5 changed files with 114 additions and 68 deletions
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.hazelcast.core.IMap;
|
import com.hazelcast.core.IMap;
|
||||||
import com.hazelcast.map.listener.EntryRemovedListener;
|
import com.hazelcast.map.listener.EntryRemovedListener;
|
||||||
|
import com.hazelcast.map.listener.EntryUpdatedListener;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||||
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
||||||
|
|
@ -42,7 +43,7 @@ class ClearingMemberCategoryServiceTest {
|
||||||
private static final int PARTITION = 0;
|
private static final int PARTITION = 0;
|
||||||
private static final String TOPIC_MEMBER_CATEGORY_UPDATE = Consts.DESTINATION_CLEARING_MEMBER_CATEGORY_UPDATE;
|
private static final String TOPIC_MEMBER_CATEGORY_UPDATE = Consts.DESTINATION_CLEARING_MEMBER_CATEGORY_UPDATE;
|
||||||
private static final String TOPIC_MEMBER_CATEGORY_DELETE = Consts.DESTINATION_CLEARING_MEMBER_CATEGORY_DELETE;
|
private static final String TOPIC_MEMBER_CATEGORY_DELETE = Consts.DESTINATION_CLEARING_MEMBER_CATEGORY_DELETE;
|
||||||
private static Long currentId = 0L;
|
private static final Long ID = 0L;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("hazelcastServiceTest")
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
|
@ -58,15 +59,15 @@ class ClearingMemberCategoryServiceTest {
|
||||||
void clearingMemberCategoryUpdate() throws InterruptedException {
|
void clearingMemberCategoryUpdate() throws InterruptedException {
|
||||||
//ARRANGE
|
//ARRANGE
|
||||||
ClearingMemberCategory existsСlearingMemberCategory = new ClearingMemberCategory();
|
ClearingMemberCategory existsСlearingMemberCategory = new ClearingMemberCategory();
|
||||||
existsСlearingMemberCategory.setId(currentId);
|
existsСlearingMemberCategory.setId(ID);
|
||||||
existsСlearingMemberCategory.setClearingMemberCategory("0000");
|
existsСlearingMemberCategory.setClearingMemberCategory("0000");
|
||||||
|
|
||||||
ClearingMemberCategoryUpdateRequest memberCategoryUpdateRequest = new ClearingMemberCategoryUpdateRequest();
|
ClearingMemberCategoryUpdateRequest memberCategoryUpdateRequest = new ClearingMemberCategoryUpdateRequest();
|
||||||
memberCategoryUpdateRequest.setId(currentId);
|
memberCategoryUpdateRequest.setId(ID);
|
||||||
memberCategoryUpdateRequest.setClearingMemberCategory("1234");
|
memberCategoryUpdateRequest.setClearingMemberCategory("1234");
|
||||||
BaseRequest<ClearingMemberCategoryUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
BaseRequest<ClearingMemberCategoryUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||||
baseUpdateRequest.setRequestPayload(memberCategoryUpdateRequest);
|
baseUpdateRequest.setRequestPayload(memberCategoryUpdateRequest);
|
||||||
baseUpdateRequest.setId(currentId);
|
baseUpdateRequest.setId(ID);
|
||||||
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
||||||
String jsonBaseForUpdatingRequest;
|
String jsonBaseForUpdatingRequest;
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
@ -77,7 +78,7 @@ class ClearingMemberCategoryServiceTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearingMemberCategory predictableClearingMemberCategory = new ClearingMemberCategory();
|
ClearingMemberCategory predictableClearingMemberCategory = new ClearingMemberCategory();
|
||||||
predictableClearingMemberCategory.setId(currentId);
|
predictableClearingMemberCategory.setId(ID);
|
||||||
predictableClearingMemberCategory.setClearingMemberCategory("1234");
|
predictableClearingMemberCategory.setClearingMemberCategory("1234");
|
||||||
|
|
||||||
//ACT
|
//ACT
|
||||||
|
|
@ -88,7 +89,7 @@ class ClearingMemberCategoryServiceTest {
|
||||||
clearingMemberCategoryService.afterPropertiesSet();
|
clearingMemberCategoryService.afterPropertiesSet();
|
||||||
|
|
||||||
IMap<Long, ClearingMemberCategory> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ClearingMemberCategory);
|
IMap<Long, ClearingMemberCategory> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ClearingMemberCategory);
|
||||||
iMap.put(currentId, existsСlearingMemberCategory);
|
iMap.put(ID, existsСlearingMemberCategory);
|
||||||
|
|
||||||
//KAFKA
|
//KAFKA
|
||||||
mockConsumer.schedulePollTask(() -> {
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
|
@ -100,21 +101,27 @@ class ClearingMemberCategoryServiceTest {
|
||||||
startOffsetsUpdating.put(tpUpdating, 0L);
|
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
//ASSERT
|
//waiting for hazelcast map item updates
|
||||||
Object waiter = new Object();
|
Object waiter = new Object();
|
||||||
String listenerID = iMap.addEntryListener((EntryRemovedListener<Long, Contact>) entryEvent -> {
|
String listenerID = iMap.addEntryListener((EntryUpdatedListener<Long, Contact>) entryEvent -> {
|
||||||
System.out.println("Checking If removed..");
|
System.out.println("Checking If removed..");
|
||||||
|
|
||||||
synchronized (waiter) {
|
synchronized (waiter) {
|
||||||
|
try {
|
||||||
|
waiter.wait(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
waiter.notify();
|
waiter.notify();
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
synchronized (waiter) {
|
synchronized (waiter) {
|
||||||
waiter.wait(1000);
|
waiter.wait(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearingMemberCategory resultUpdating = iMap.get(currentId);
|
//ASSERT
|
||||||
|
ClearingMemberCategory resultUpdating = iMap.get(ID);
|
||||||
MEMBER_CATEGORY_MATCHER.assertMatch(resultUpdating, predictableClearingMemberCategory);
|
MEMBER_CATEGORY_MATCHER.assertMatch(resultUpdating, predictableClearingMemberCategory);
|
||||||
|
|
||||||
//preparing hazelcastImdgProvider for next test
|
//preparing hazelcastImdgProvider for next test
|
||||||
|
|
@ -125,15 +132,15 @@ class ClearingMemberCategoryServiceTest {
|
||||||
void clearingMemberCategoryDelete() throws InterruptedException {
|
void clearingMemberCategoryDelete() throws InterruptedException {
|
||||||
//ARRANGE
|
//ARRANGE
|
||||||
ClearingMemberCategory existsСlearingMemberCategory = new ClearingMemberCategory();
|
ClearingMemberCategory existsСlearingMemberCategory = new ClearingMemberCategory();
|
||||||
existsСlearingMemberCategory.setId(currentId);
|
existsСlearingMemberCategory.setId(ID);
|
||||||
existsСlearingMemberCategory.setClearingMemberCategory("0000");
|
existsСlearingMemberCategory.setClearingMemberCategory("0000");
|
||||||
|
|
||||||
CommonDeleteRequest memberCategoryDeleteRequest = new CommonDeleteRequest();
|
CommonDeleteRequest memberCategoryDeleteRequest = new CommonDeleteRequest();
|
||||||
memberCategoryDeleteRequest.setId(currentId);
|
memberCategoryDeleteRequest.setId(ID);
|
||||||
|
|
||||||
BaseRequest<CommonDeleteRequest> baseDeleteRequest = new BaseRequest<>();
|
BaseRequest<CommonDeleteRequest> baseDeleteRequest = new BaseRequest<>();
|
||||||
baseDeleteRequest.setRequestPayload(memberCategoryDeleteRequest);
|
baseDeleteRequest.setRequestPayload(memberCategoryDeleteRequest);
|
||||||
baseDeleteRequest.setId(currentId);
|
baseDeleteRequest.setId(ID);
|
||||||
baseDeleteRequest.setActionType(ActionType.DELETE);
|
baseDeleteRequest.setActionType(ActionType.DELETE);
|
||||||
String jsonBaseForDeleteRequest;
|
String jsonBaseForDeleteRequest;
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
@ -151,7 +158,7 @@ class ClearingMemberCategoryServiceTest {
|
||||||
clearingMemberCategoryService.afterPropertiesSet();
|
clearingMemberCategoryService.afterPropertiesSet();
|
||||||
|
|
||||||
IMap<Long, ClearingMemberCategory> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ClearingMemberCategory);
|
IMap<Long, ClearingMemberCategory> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ClearingMemberCategory);
|
||||||
iMap.put(currentId, existsСlearingMemberCategory);
|
iMap.put(ID, existsСlearingMemberCategory);
|
||||||
|
|
||||||
//KAFKA
|
//KAFKA
|
||||||
mockConsumer.schedulePollTask(() -> {
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
|
@ -163,7 +170,7 @@ class ClearingMemberCategoryServiceTest {
|
||||||
startOffsetsUpdating.put(tpDeleting, 0L);
|
startOffsetsUpdating.put(tpDeleting, 0L);
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
//ASSERT
|
//waiting for hazelcast map item removes
|
||||||
Object waiter = new Object();
|
Object waiter = new Object();
|
||||||
String listenerID = iMap.addEntryListener((EntryRemovedListener<Long, Contact>) entryEvent -> {
|
String listenerID = iMap.addEntryListener((EntryRemovedListener<Long, Contact>) entryEvent -> {
|
||||||
System.out.println("Checking If removed..");
|
System.out.println("Checking If removed..");
|
||||||
|
|
@ -177,6 +184,7 @@ class ClearingMemberCategoryServiceTest {
|
||||||
waiter.wait(1000);
|
waiter.wait(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ASSERT
|
||||||
Assertions.assertEquals(0, iMap.size());
|
Assertions.assertEquals(0, iMap.size());
|
||||||
|
|
||||||
//preparing hazelcastImdgProvider for next test
|
//preparing hazelcastImdgProvider for next test
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package ru.spcex.clearing.company.service;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.hazelcast.core.IMap;
|
import com.hazelcast.core.IMap;
|
||||||
|
import com.hazelcast.map.listener.EntryUpdatedListener;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||||
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
||||||
|
|
@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import ru.clearing.classes.statics.data.profile.CompanyInfo;
|
import ru.clearing.classes.statics.data.profile.CompanyInfo;
|
||||||
|
import ru.clearing.classes.statics.data.profile.Contact;
|
||||||
import ru.spcex.clearing.company.config.HazelcastServiceTestConfiguration;
|
import ru.spcex.clearing.company.config.HazelcastServiceTestConfiguration;
|
||||||
import ru.spcex.clearing.company.utils.MatcherFactory;
|
import ru.spcex.clearing.company.utils.MatcherFactory;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
|
@ -37,7 +39,7 @@ class CompanyInfoServiceTest {
|
||||||
public static final MatcherFactory.Matcher<CompanyInfo> COMPANY_INFO_MATCHER = usingIgnoringFieldsComparator();
|
public static final MatcherFactory.Matcher<CompanyInfo> COMPANY_INFO_MATCHER = usingIgnoringFieldsComparator();
|
||||||
private static final int PARTITION = 0;
|
private static final int PARTITION = 0;
|
||||||
private static final String TOPIC_COMPANY_INFO_UPDATE = Consts.DESTINATION_COMPANY_INFO_UPDATE;
|
private static final String TOPIC_COMPANY_INFO_UPDATE = Consts.DESTINATION_COMPANY_INFO_UPDATE;
|
||||||
private static Long currentId = 0L;
|
private static final Long ID = 0L;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("hazelcastServiceTest")
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
|
@ -53,7 +55,8 @@ class CompanyInfoServiceTest {
|
||||||
void companyInfoUpdate() throws InterruptedException {
|
void companyInfoUpdate() throws InterruptedException {
|
||||||
//ARRANGE
|
//ARRANGE
|
||||||
CompanyInfo existsCompanyInfo = new CompanyInfo();
|
CompanyInfo existsCompanyInfo = new CompanyInfo();
|
||||||
existsCompanyInfo.setId(currentId);
|
existsCompanyInfo.setId(ID);
|
||||||
|
existsCompanyInfo.setCompanyId(ID);
|
||||||
existsCompanyInfo.setCorporationSoleType("0000");
|
existsCompanyInfo.setCorporationSoleType("0000");
|
||||||
existsCompanyInfo.setCountryCode("0000");
|
existsCompanyInfo.setCountryCode("0000");
|
||||||
existsCompanyInfo.setDescription("exists description");
|
existsCompanyInfo.setDescription("exists description");
|
||||||
|
|
@ -67,7 +70,7 @@ class CompanyInfoServiceTest {
|
||||||
existsCompanyInfo.setFullName("exists fullName");
|
existsCompanyInfo.setFullName("exists fullName");
|
||||||
|
|
||||||
CompanyInfoUpdateRequest companyInfoUpdateRequest = new CompanyInfoUpdateRequest();
|
CompanyInfoUpdateRequest companyInfoUpdateRequest = new CompanyInfoUpdateRequest();
|
||||||
companyInfoUpdateRequest.setId(currentId);
|
companyInfoUpdateRequest.setId(ID);
|
||||||
companyInfoUpdateRequest.setCorporationSoleType("1234");
|
companyInfoUpdateRequest.setCorporationSoleType("1234");
|
||||||
companyInfoUpdateRequest.setCountryCode("1234");
|
companyInfoUpdateRequest.setCountryCode("1234");
|
||||||
companyInfoUpdateRequest.setDescription("updated description");
|
companyInfoUpdateRequest.setDescription("updated description");
|
||||||
|
|
@ -82,7 +85,7 @@ class CompanyInfoServiceTest {
|
||||||
|
|
||||||
BaseRequest<CompanyInfoUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
BaseRequest<CompanyInfoUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||||
baseUpdateRequest.setRequestPayload(companyInfoUpdateRequest);
|
baseUpdateRequest.setRequestPayload(companyInfoUpdateRequest);
|
||||||
baseUpdateRequest.setId(currentId);
|
baseUpdateRequest.setId(ID);
|
||||||
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
||||||
String jsonBaseForUpdatingRequest;
|
String jsonBaseForUpdatingRequest;
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
@ -93,7 +96,8 @@ class CompanyInfoServiceTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
CompanyInfo predictableCompanyInfo = new CompanyInfo();
|
CompanyInfo predictableCompanyInfo = new CompanyInfo();
|
||||||
predictableCompanyInfo.setId(currentId);
|
predictableCompanyInfo.setId(ID);
|
||||||
|
predictableCompanyInfo.setCompanyId(ID);
|
||||||
predictableCompanyInfo.setCorporationSoleType("1234");
|
predictableCompanyInfo.setCorporationSoleType("1234");
|
||||||
predictableCompanyInfo.setCountryCode("1234");
|
predictableCompanyInfo.setCountryCode("1234");
|
||||||
predictableCompanyInfo.setDescription("updated description");
|
predictableCompanyInfo.setDescription("updated description");
|
||||||
|
|
@ -109,13 +113,12 @@ class CompanyInfoServiceTest {
|
||||||
//ACT
|
//ACT
|
||||||
//service set up
|
//service set up
|
||||||
CompanyInfoService clearingMemberCategoryService = new CompanyInfoService(mockConsumer, hazelcastServiceTest);
|
CompanyInfoService clearingMemberCategoryService = new CompanyInfoService(mockConsumer, hazelcastServiceTest);
|
||||||
Thread.sleep(10000);
|
|
||||||
//callbacks set up
|
//callbacks set up
|
||||||
clearingMemberCategoryService.afterPropertiesSet();
|
clearingMemberCategoryService.afterPropertiesSet();
|
||||||
Thread.sleep(10000);
|
|
||||||
|
|
||||||
IMap<Long, CompanyInfo> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Company);
|
IMap<Long, CompanyInfo> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Company);
|
||||||
iMap.put(currentId, existsCompanyInfo);
|
iMap.put(ID, existsCompanyInfo);
|
||||||
|
|
||||||
//KAFKA
|
//KAFKA
|
||||||
mockConsumer.schedulePollTask(() -> {
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
|
@ -127,13 +130,25 @@ class CompanyInfoServiceTest {
|
||||||
startOffsetsUpdating.put(tpUpdating, 0L);
|
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
|
//waiting for hazelcast map updates
|
||||||
|
Object waiter = new Object();
|
||||||
|
String listenerID = iMap.addEntryListener((EntryUpdatedListener<Long, Contact>) entryEvent -> {
|
||||||
|
System.out.println("Checking If removed..");
|
||||||
|
|
||||||
|
synchronized (waiter) {
|
||||||
|
waiter.notify();
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
synchronized (waiter) {
|
||||||
|
waiter.wait(1000);
|
||||||
|
}
|
||||||
|
|
||||||
//ASSERT
|
//ASSERT
|
||||||
Thread.sleep(10000);
|
CompanyInfo resultUpdating = iMap.get(ID);
|
||||||
CompanyInfo resultUpdating = iMap.get(currentId);
|
|
||||||
COMPANY_INFO_MATCHER.assertMatch(resultUpdating, predictableCompanyInfo);
|
COMPANY_INFO_MATCHER.assertMatch(resultUpdating, predictableCompanyInfo);
|
||||||
|
|
||||||
//preparing hazelcastImdgProvider for next test
|
//preparing hazelcastImdgProvider for next test
|
||||||
iMap.clear();
|
iMap.removeEntryListener(listenerID);
|
||||||
currentId++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package ru.spcex.clearing.company.service;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.hazelcast.core.IMap;
|
import com.hazelcast.core.IMap;
|
||||||
|
import com.hazelcast.map.listener.EntryRemovedListener;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||||
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
||||||
|
|
@ -17,6 +18,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import ru.clearing.classes.statics.data.company.Company;
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
import ru.clearing.classes.statics.data.generated.ClearingMemberCategory;
|
import ru.clearing.classes.statics.data.generated.ClearingMemberCategory;
|
||||||
|
import ru.clearing.classes.statics.data.profile.Contact;
|
||||||
import ru.spcex.clearing.company.config.HazelcastServiceTestConfiguration;
|
import ru.spcex.clearing.company.config.HazelcastServiceTestConfiguration;
|
||||||
import ru.spcex.clearing.company.utils.MatcherFactory;
|
import ru.spcex.clearing.company.utils.MatcherFactory;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
|
@ -39,7 +41,7 @@ class CompanyServiceTest {
|
||||||
public static final MatcherFactory.Matcher<ClearingMemberCategory> COMPANY_MATCHER = usingIgnoringFieldsComparator();
|
public static final MatcherFactory.Matcher<ClearingMemberCategory> COMPANY_MATCHER = usingIgnoringFieldsComparator();
|
||||||
private static final int PARTITION = 0;
|
private static final int PARTITION = 0;
|
||||||
private static final String TOPIC_COMPANY_DELETE = Consts.DESTINATION_COMPANY_DELETE;
|
private static final String TOPIC_COMPANY_DELETE = Consts.DESTINATION_COMPANY_DELETE;
|
||||||
private static Long currentId = 0L;
|
private static final Long ID = 0L;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("hazelcastServiceTest")
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
|
@ -55,14 +57,14 @@ class CompanyServiceTest {
|
||||||
void deleteCompany() throws InterruptedException {
|
void deleteCompany() throws InterruptedException {
|
||||||
//ARRANGE
|
//ARRANGE
|
||||||
Company existsCompany = new Company();
|
Company existsCompany = new Company();
|
||||||
existsCompany.setId(currentId);
|
existsCompany.setId(ID);
|
||||||
|
|
||||||
CommonDeleteRequest memberCategoryDeleteRequest = new CommonDeleteRequest();
|
CommonDeleteRequest memberCategoryDeleteRequest = new CommonDeleteRequest();
|
||||||
memberCategoryDeleteRequest.setId(currentId);
|
memberCategoryDeleteRequest.setId(ID);
|
||||||
|
|
||||||
BaseRequest<CommonDeleteRequest> baseDeleteRequest = new BaseRequest<>();
|
BaseRequest<CommonDeleteRequest> baseDeleteRequest = new BaseRequest<>();
|
||||||
baseDeleteRequest.setRequestPayload(memberCategoryDeleteRequest);
|
baseDeleteRequest.setRequestPayload(memberCategoryDeleteRequest);
|
||||||
baseDeleteRequest.setId(currentId);
|
baseDeleteRequest.setId(ID);
|
||||||
baseDeleteRequest.setActionType(ActionType.DELETE);
|
baseDeleteRequest.setActionType(ActionType.DELETE);
|
||||||
String jsonBaseForDeleteRequest;
|
String jsonBaseForDeleteRequest;
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
@ -75,13 +77,12 @@ class CompanyServiceTest {
|
||||||
//ACT
|
//ACT
|
||||||
//service set up
|
//service set up
|
||||||
CompanyService companyService = new CompanyService(mockConsumer, hazelcastServiceTest);
|
CompanyService companyService = new CompanyService(mockConsumer, hazelcastServiceTest);
|
||||||
Thread.sleep(10000);
|
|
||||||
//callbacks set up
|
//callbacks set up
|
||||||
companyService.afterPropertiesSet();
|
companyService.afterPropertiesSet();
|
||||||
Thread.sleep(10000);
|
|
||||||
|
|
||||||
IMap<Long, Company> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Company);
|
IMap<Long, Company> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Company);
|
||||||
iMap.put(currentId, existsCompany);
|
iMap.put(ID, existsCompany);
|
||||||
|
|
||||||
//KAFKA
|
//KAFKA
|
||||||
mockConsumer.schedulePollTask(() -> {
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
|
@ -93,12 +94,24 @@ class CompanyServiceTest {
|
||||||
startOffsetsUpdating.put(tpDeleting, 0L);
|
startOffsetsUpdating.put(tpDeleting, 0L);
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
|
//waiting for hazelcast map item removes
|
||||||
|
Object waiter = new Object();
|
||||||
|
String listenerID = iMap.addEntryListener((EntryRemovedListener<Long, Contact>) entryEvent -> {
|
||||||
|
System.out.println("Checking If removed..");
|
||||||
|
|
||||||
|
synchronized (waiter) {
|
||||||
|
waiter.notify();
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
synchronized (waiter) {
|
||||||
|
waiter.wait(100);
|
||||||
|
}
|
||||||
|
|
||||||
//ASSERT
|
//ASSERT
|
||||||
Thread.sleep(10000);
|
|
||||||
Assertions.assertEquals(0, iMap.size());
|
Assertions.assertEquals(0, iMap.size());
|
||||||
|
|
||||||
//preparing hazelcastImdgProvider for next test
|
//preparing hazelcastImdgProvider for next test
|
||||||
iMap.clear();
|
iMap.removeEntryListener(listenerID);
|
||||||
currentId++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package ru.spcex.clearing.company.service;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.hazelcast.core.IMap;
|
import com.hazelcast.core.IMap;
|
||||||
|
import com.hazelcast.map.listener.EntryUpdatedListener;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||||
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
||||||
|
|
@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||||
|
import ru.clearing.classes.statics.data.profile.Contact;
|
||||||
import ru.spcex.clearing.company.config.HazelcastServiceTestConfiguration;
|
import ru.spcex.clearing.company.config.HazelcastServiceTestConfiguration;
|
||||||
import ru.spcex.clearing.company.utils.MatcherFactory;
|
import ru.spcex.clearing.company.utils.MatcherFactory;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
|
@ -37,7 +39,7 @@ class CompanySymbolServiceTest {
|
||||||
public static final MatcherFactory.Matcher<CompanySymbols> COMPANY_SYMBOL_MATCHER = usingIgnoringFieldsComparator();
|
public static final MatcherFactory.Matcher<CompanySymbols> COMPANY_SYMBOL_MATCHER = usingIgnoringFieldsComparator();
|
||||||
private static final int PARTITION = 0;
|
private static final int PARTITION = 0;
|
||||||
private static final String TOPIC_COMPANY_SYMBOL_UPDATE = Consts.DESTINATION_COMPANY_SYMBOL_UPDATE;
|
private static final String TOPIC_COMPANY_SYMBOL_UPDATE = Consts.DESTINATION_COMPANY_SYMBOL_UPDATE;
|
||||||
private static Long currentId = 0L;
|
private static final Long ID = 0L;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("hazelcastServiceTest")
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
|
@ -53,20 +55,20 @@ class CompanySymbolServiceTest {
|
||||||
void companySymbolUpdate() throws InterruptedException {
|
void companySymbolUpdate() throws InterruptedException {
|
||||||
//ARRANGE
|
//ARRANGE
|
||||||
CompanySymbols existsCompanySymbols = new CompanySymbols();
|
CompanySymbols existsCompanySymbols = new CompanySymbols();
|
||||||
existsCompanySymbols.setId(currentId);
|
existsCompanySymbols.setId(ID);
|
||||||
existsCompanySymbols.setCompanyId(currentId);
|
existsCompanySymbols.setCompanyId(ID);
|
||||||
existsCompanySymbols.setCompanySymbol("0000");
|
existsCompanySymbols.setCompanySymbol("0000");
|
||||||
existsCompanySymbols.setCompanySymbolValue("exists companySymbolValue");
|
existsCompanySymbols.setCompanySymbolValue("exists companySymbolValue");
|
||||||
|
|
||||||
CompanySymbolUpdateRequest companySymbolUpdateRequest = new CompanySymbolUpdateRequest();
|
CompanySymbolUpdateRequest companySymbolUpdateRequest = new CompanySymbolUpdateRequest();
|
||||||
companySymbolUpdateRequest.setId(currentId);
|
companySymbolUpdateRequest.setId(ID);
|
||||||
companySymbolUpdateRequest.setCompanyId(currentId);
|
companySymbolUpdateRequest.setCompanyId(ID);
|
||||||
companySymbolUpdateRequest.setCompanySymbol("1234");
|
companySymbolUpdateRequest.setCompanySymbol("1234");
|
||||||
companySymbolUpdateRequest.setCompanySymbolValue("new companySymbolValue");
|
companySymbolUpdateRequest.setCompanySymbolValue("new companySymbolValue");
|
||||||
|
|
||||||
BaseRequest<CompanySymbolUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
BaseRequest<CompanySymbolUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||||
baseUpdateRequest.setRequestPayload(companySymbolUpdateRequest);
|
baseUpdateRequest.setRequestPayload(companySymbolUpdateRequest);
|
||||||
baseUpdateRequest.setId(currentId);
|
baseUpdateRequest.setId(ID);
|
||||||
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
||||||
String jsonBaseForUpdatingRequest;
|
String jsonBaseForUpdatingRequest;
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
@ -77,21 +79,20 @@ class CompanySymbolServiceTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
CompanySymbols predictableCompanySymbols = new CompanySymbols();
|
CompanySymbols predictableCompanySymbols = new CompanySymbols();
|
||||||
predictableCompanySymbols.setId(currentId);
|
predictableCompanySymbols.setId(ID);
|
||||||
predictableCompanySymbols.setCompanyId(currentId);
|
predictableCompanySymbols.setCompanyId(ID);
|
||||||
predictableCompanySymbols.setCompanySymbol("0000");
|
predictableCompanySymbols.setCompanySymbol("0000");
|
||||||
predictableCompanySymbols.setCompanySymbolValue("new companySymbolValue");
|
predictableCompanySymbols.setCompanySymbolValue("new companySymbolValue");
|
||||||
|
|
||||||
//ACT
|
//ACT
|
||||||
//service set up
|
//service set up
|
||||||
CompanySymbolService companySymbolService = new CompanySymbolService(mockConsumer, hazelcastServiceTest);
|
CompanySymbolService companySymbolService = new CompanySymbolService(mockConsumer, hazelcastServiceTest);
|
||||||
Thread.sleep(10000);
|
|
||||||
//callbacks set up
|
//callbacks set up
|
||||||
companySymbolService.afterPropertiesSet();
|
companySymbolService.afterPropertiesSet();
|
||||||
Thread.sleep(10000);
|
|
||||||
|
|
||||||
IMap<Long, CompanySymbols> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_CompanySymbols);
|
IMap<Long, CompanySymbols> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_CompanySymbols);
|
||||||
iMap.put(currentId, existsCompanySymbols);
|
iMap.put(ID, existsCompanySymbols);
|
||||||
|
|
||||||
//KAFKA
|
//KAFKA
|
||||||
mockConsumer.schedulePollTask(() -> {
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
|
@ -103,13 +104,25 @@ class CompanySymbolServiceTest {
|
||||||
startOffsetsUpdating.put(tpUpdating, 0L);
|
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
|
//waiting for hazelcast map item updates
|
||||||
|
Object waiter = new Object();
|
||||||
|
String listenerID = iMap.addEntryListener((EntryUpdatedListener<Long, Contact>) entryEvent -> {
|
||||||
|
System.out.println("Checking If removed..");
|
||||||
|
|
||||||
|
synchronized (waiter) {
|
||||||
|
waiter.notify();
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
synchronized (waiter) {
|
||||||
|
waiter.wait(1000);
|
||||||
|
}
|
||||||
|
|
||||||
//ASSERT
|
//ASSERT
|
||||||
Thread.sleep(10000);
|
CompanySymbols resultUpdating = iMap.get(ID);
|
||||||
CompanySymbols resultUpdating = iMap.get(currentId);
|
|
||||||
COMPANY_SYMBOL_MATCHER.assertMatch(resultUpdating, predictableCompanySymbols);
|
COMPANY_SYMBOL_MATCHER.assertMatch(resultUpdating, predictableCompanySymbols);
|
||||||
|
|
||||||
//preparing hazelcastImdgProvider for next test
|
//preparing hazelcastImdgProvider for next test
|
||||||
iMap.clear();
|
iMap.removeEntryListener(listenerID);
|
||||||
currentId++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ package ru.spcex.clearing.company.service;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.hazelcast.core.IMap;
|
import com.hazelcast.core.IMap;
|
||||||
import com.hazelcast.map.listener.EntryRemovedListener;
|
import com.hazelcast.map.listener.EntryUpdatedListener;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||||
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
||||||
|
|
@ -38,7 +38,7 @@ class ContactServiceTest {
|
||||||
public static final MatcherFactory.Matcher<Contact> CONTACT_MATCHER = usingIgnoringFieldsComparator();
|
public static final MatcherFactory.Matcher<Contact> CONTACT_MATCHER = usingIgnoringFieldsComparator();
|
||||||
private static final int PARTITION = 0;
|
private static final int PARTITION = 0;
|
||||||
private static final String TOPIC_CONTACT_UPDATE = Consts.DESTINATION_CONTACT_UPDATE;
|
private static final String TOPIC_CONTACT_UPDATE = Consts.DESTINATION_CONTACT_UPDATE;
|
||||||
private static final Long currentId = 0L;
|
private static final Long ID = 0L;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("hazelcastServiceTest")
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
|
@ -54,20 +54,20 @@ class ContactServiceTest {
|
||||||
void contactUpdate() throws InterruptedException {
|
void contactUpdate() throws InterruptedException {
|
||||||
//ARRANGE
|
//ARRANGE
|
||||||
Contact existsContact = new Contact();
|
Contact existsContact = new Contact();
|
||||||
existsContact.setId(currentId);
|
existsContact.setId(ID);
|
||||||
existsContact.setCompanyId(currentId);
|
existsContact.setCompanyId(ID);
|
||||||
existsContact.setContactType("0000");
|
existsContact.setContactType("0000");
|
||||||
existsContact.setContactValue("exists ContactValue");
|
existsContact.setContactValue("exists ContactValue");
|
||||||
|
|
||||||
ContactUpdateRequest contactUpdateRequest = new ContactUpdateRequest();
|
ContactUpdateRequest contactUpdateRequest = new ContactUpdateRequest();
|
||||||
contactUpdateRequest.setId(currentId);
|
contactUpdateRequest.setId(ID);
|
||||||
contactUpdateRequest.setCompanyId(1L);
|
contactUpdateRequest.setCompanyId(1L);
|
||||||
contactUpdateRequest.setContactType("1234");
|
contactUpdateRequest.setContactType("1234");
|
||||||
contactUpdateRequest.setContactValue("new ContactValue");
|
contactUpdateRequest.setContactValue("new ContactValue");
|
||||||
|
|
||||||
BaseRequest<ContactUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
BaseRequest<ContactUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||||
baseUpdateRequest.setRequestPayload(contactUpdateRequest);
|
baseUpdateRequest.setRequestPayload(contactUpdateRequest);
|
||||||
baseUpdateRequest.setId(currentId);
|
baseUpdateRequest.setId(ID);
|
||||||
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
||||||
String jsonBaseForUpdatingRequest;
|
String jsonBaseForUpdatingRequest;
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
@ -78,8 +78,8 @@ class ContactServiceTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact predictableContact = new Contact();
|
Contact predictableContact = new Contact();
|
||||||
predictableContact.setId(currentId);
|
predictableContact.setId(ID);
|
||||||
predictableContact.setCompanyId(currentId);
|
predictableContact.setCompanyId(ID);
|
||||||
predictableContact.setContactType("0000");
|
predictableContact.setContactType("0000");
|
||||||
predictableContact.setContactValue("new ContactValue");
|
predictableContact.setContactValue("new ContactValue");
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ class ContactServiceTest {
|
||||||
|
|
||||||
//callbacks set up
|
//callbacks set up
|
||||||
IMap<Long, Contact> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Contact);
|
IMap<Long, Contact> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Contact);
|
||||||
iMap.put(currentId, existsContact);
|
iMap.put(ID, existsContact);
|
||||||
|
|
||||||
//KAFKA
|
//KAFKA
|
||||||
mockConsumer.schedulePollTask(() -> {
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
|
@ -102,13 +102,10 @@ class ContactServiceTest {
|
||||||
startOffsetsUpdating.put(tpUpdating, 0L);
|
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
//ASSERT
|
//waiting for hazelcast map updates
|
||||||
Object waiter = new Object();
|
Object waiter = new Object();
|
||||||
String listenerID = iMap.addEntryListener((EntryRemovedListener<Long, Contact>) entryEvent -> {
|
String listenerID = iMap.addEntryListener((EntryUpdatedListener<Long, Contact>) entryEvent -> {
|
||||||
System.out.println("Checking If removed..");
|
System.out.println("Checking If removed..");
|
||||||
// resultUpdating = entryEvent.getValue();
|
|
||||||
// entryEvent.getKey();
|
|
||||||
// CONTACT_MATCHER.assertMatch(resultUpdating, predictableContact);
|
|
||||||
|
|
||||||
synchronized (waiter) {
|
synchronized (waiter) {
|
||||||
waiter.notify();
|
waiter.notify();
|
||||||
|
|
@ -119,8 +116,8 @@ class ContactServiceTest {
|
||||||
waiter.wait(1000);
|
waiter.wait(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ASSERT
|
||||||
Contact resultUpdating = iMap.get(currentId);
|
Contact resultUpdating = iMap.get(ID);
|
||||||
CONTACT_MATCHER.assertMatch(resultUpdating, predictableContact);
|
CONTACT_MATCHER.assertMatch(resultUpdating, predictableContact);
|
||||||
|
|
||||||
//preparing hazelcastImdgProvider for next test
|
//preparing hazelcastImdgProvider for next test
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue