--- 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.databind.ObjectMapper;
|
||||
import com.hazelcast.core.IMap;
|
||||
import com.hazelcast.map.listener.EntryRemovedListener;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
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.junit.jupiter.SpringExtension;
|
||||
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.utils.MatcherFactory.Matcher;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
|
@ -81,10 +83,9 @@ class ClearingMemberCategoryServiceTest {
|
|||
//ACT
|
||||
//service set up
|
||||
ClearingMemberCategoryService clearingMemberCategoryService = new ClearingMemberCategoryService(mockConsumer, hazelcastServiceTest);
|
||||
Thread.sleep(10000);
|
||||
|
||||
//callbacks set up
|
||||
clearingMemberCategoryService.afterPropertiesSet();
|
||||
Thread.sleep(10000);
|
||||
|
||||
IMap<Long, ClearingMemberCategory> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ClearingMemberCategory);
|
||||
iMap.put(currentId, existsСlearingMemberCategory);
|
||||
|
|
@ -100,13 +101,24 @@ class ClearingMemberCategoryServiceTest {
|
|||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||
|
||||
//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);
|
||||
MEMBER_CATEGORY_MATCHER.assertMatch(resultUpdating, predictableClearingMemberCategory);
|
||||
|
||||
//preparing hazelcastImdgProvider for next test
|
||||
iMap.clear();
|
||||
currentId++;
|
||||
iMap.removeEntryListener(listenerID);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -134,10 +146,9 @@ class ClearingMemberCategoryServiceTest {
|
|||
//ACT
|
||||
//service set up
|
||||
ClearingMemberCategoryService clearingMemberCategoryService = new ClearingMemberCategoryService(mockConsumer, hazelcastServiceTest);
|
||||
Thread.sleep(10000);
|
||||
|
||||
//callbacks set up
|
||||
clearingMemberCategoryService.afterPropertiesSet();
|
||||
Thread.sleep(10000);
|
||||
|
||||
IMap<Long, ClearingMemberCategory> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ClearingMemberCategory);
|
||||
iMap.put(currentId, existsСlearingMemberCategory);
|
||||
|
|
@ -153,11 +164,22 @@ class ClearingMemberCategoryServiceTest {
|
|||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||
|
||||
//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());
|
||||
|
||||
//preparing hazelcastImdgProvider for next test
|
||||
iMap.clear();
|
||||
currentId++;
|
||||
iMap.removeEntryListener(listenerID);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package ru.spcex.clearing.company.service;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.hazelcast.core.IMap;
|
||||
import com.hazelcast.map.listener.EntryRemovedListener;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
||||
|
|
@ -37,7 +38,7 @@ class ContactServiceTest {
|
|||
public static final MatcherFactory.Matcher<Contact> CONTACT_MATCHER = usingIgnoringFieldsComparator();
|
||||
private static final int PARTITION = 0;
|
||||
private static final String TOPIC_CONTACT_UPDATE = Consts.DESTINATION_CONTACT_UPDATE;
|
||||
private static Long currentId = 0L;
|
||||
private static final Long currentId = 0L;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
|
|
@ -85,11 +86,9 @@ class ContactServiceTest {
|
|||
//ACT
|
||||
//service set up
|
||||
ContactService contactService = new ContactService(mockConsumer, hazelcastServiceTest);
|
||||
Thread.sleep(10000);
|
||||
//callbacks set up
|
||||
contactService.afterPropertiesSet();
|
||||
Thread.sleep(10000);
|
||||
|
||||
//callbacks set up
|
||||
IMap<Long, Contact> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Contact);
|
||||
iMap.put(currentId, existsContact);
|
||||
|
||||
|
|
@ -104,12 +103,27 @@ class ContactServiceTest {
|
|||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||
|
||||
//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_MATCHER.assertMatch(resultUpdating, predictableContact);
|
||||
|
||||
//preparing hazelcastImdgProvider for next test
|
||||
iMap.clear();
|
||||
currentId++;
|
||||
iMap.removeEntryListener(listenerID);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue