--- ContactServiceTest refactoring
This commit is contained in:
parent
bf6fb98742
commit
aed45da642
2 changed files with 53 additions and 17 deletions
|
|
@ -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;
|
||||||
|
|
@ -16,6 +17,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.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.Matcher;
|
import ru.spcex.clearing.company.utils.MatcherFactory.Matcher;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
|
@ -81,10 +83,9 @@ class ClearingMemberCategoryServiceTest {
|
||||||
//ACT
|
//ACT
|
||||||
//service set up
|
//service set up
|
||||||
ClearingMemberCategoryService clearingMemberCategoryService = new ClearingMemberCategoryService(mockConsumer, hazelcastServiceTest);
|
ClearingMemberCategoryService clearingMemberCategoryService = new ClearingMemberCategoryService(mockConsumer, hazelcastServiceTest);
|
||||||
Thread.sleep(10000);
|
|
||||||
//callbacks set up
|
//callbacks set up
|
||||||
clearingMemberCategoryService.afterPropertiesSet();
|
clearingMemberCategoryService.afterPropertiesSet();
|
||||||
Thread.sleep(10000);
|
|
||||||
|
|
||||||
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(currentId, existsСlearingMemberCategory);
|
||||||
|
|
@ -100,13 +101,24 @@ class ClearingMemberCategoryServiceTest {
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
//ASSERT
|
//ASSERT
|
||||||
Thread.sleep(10000);
|
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(1000);
|
||||||
|
}
|
||||||
|
|
||||||
ClearingMemberCategory resultUpdating = iMap.get(currentId);
|
ClearingMemberCategory resultUpdating = iMap.get(currentId);
|
||||||
MEMBER_CATEGORY_MATCHER.assertMatch(resultUpdating, predictableClearingMemberCategory);
|
MEMBER_CATEGORY_MATCHER.assertMatch(resultUpdating, predictableClearingMemberCategory);
|
||||||
|
|
||||||
//preparing hazelcastImdgProvider for next test
|
//preparing hazelcastImdgProvider for next test
|
||||||
iMap.clear();
|
iMap.removeEntryListener(listenerID);
|
||||||
currentId++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -134,10 +146,9 @@ class ClearingMemberCategoryServiceTest {
|
||||||
//ACT
|
//ACT
|
||||||
//service set up
|
//service set up
|
||||||
ClearingMemberCategoryService clearingMemberCategoryService = new ClearingMemberCategoryService(mockConsumer, hazelcastServiceTest);
|
ClearingMemberCategoryService clearingMemberCategoryService = new ClearingMemberCategoryService(mockConsumer, hazelcastServiceTest);
|
||||||
Thread.sleep(10000);
|
|
||||||
//callbacks set up
|
//callbacks set up
|
||||||
clearingMemberCategoryService.afterPropertiesSet();
|
clearingMemberCategoryService.afterPropertiesSet();
|
||||||
Thread.sleep(10000);
|
|
||||||
|
|
||||||
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(currentId, existsСlearingMemberCategory);
|
||||||
|
|
@ -153,11 +164,22 @@ class ClearingMemberCategoryServiceTest {
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
//ASSERT
|
//ASSERT
|
||||||
Thread.sleep(10000);
|
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(1000);
|
||||||
|
}
|
||||||
|
|
||||||
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.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;
|
||||||
|
|
@ -37,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 Long currentId = 0L;
|
private static final Long currentId = 0L;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("hazelcastServiceTest")
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
|
@ -85,11 +86,9 @@ class ContactServiceTest {
|
||||||
//ACT
|
//ACT
|
||||||
//service set up
|
//service set up
|
||||||
ContactService contactService = new ContactService(mockConsumer, hazelcastServiceTest);
|
ContactService contactService = new ContactService(mockConsumer, hazelcastServiceTest);
|
||||||
Thread.sleep(10000);
|
|
||||||
//callbacks set up
|
|
||||||
contactService.afterPropertiesSet();
|
contactService.afterPropertiesSet();
|
||||||
Thread.sleep(10000);
|
|
||||||
|
|
||||||
|
//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(currentId, existsContact);
|
||||||
|
|
||||||
|
|
@ -104,12 +103,27 @@ class ContactServiceTest {
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
//ASSERT
|
//ASSERT
|
||||||
Thread.sleep(10000);
|
Object waiter = new Object();
|
||||||
|
String listenerID = iMap.addEntryListener((EntryRemovedListener<Long, Contact>) entryEvent -> {
|
||||||
|
System.out.println("Checking If removed..");
|
||||||
|
// resultUpdating = entryEvent.getValue();
|
||||||
|
// entryEvent.getKey();
|
||||||
|
// CONTACT_MATCHER.assertMatch(resultUpdating, predictableContact);
|
||||||
|
|
||||||
|
synchronized (waiter) {
|
||||||
|
waiter.notify();
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
synchronized (waiter) {
|
||||||
|
waiter.wait(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Contact resultUpdating = iMap.get(currentId);
|
Contact resultUpdating = iMap.get(currentId);
|
||||||
CONTACT_MATCHER.assertMatch(resultUpdating, predictableContact);
|
CONTACT_MATCHER.assertMatch(resultUpdating, predictableContact);
|
||||||
|
|
||||||
//preparing hazelcastImdgProvider for next test
|
//preparing hazelcastImdgProvider for next test
|
||||||
iMap.clear();
|
iMap.removeEntryListener(listenerID);
|
||||||
currentId++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue