diff --git a/pom.xml b/pom.xml index 03ae0af..9f601a9 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ wb-list-manager - 0.0.1-SNAPSHOT + 0.0.2-SNAPSHOT jar wb-list-manager @@ -24,7 +24,7 @@ bc95d0d6dc13c693acd2b274531a7d604b877bf3 dr2.rbkmoney.com 0.3.6 - 1.20-2c2fb6a + 1.21-aa59fcf 2.1.0 2.1.0 0.0.9 diff --git a/src/main/java/com/rbkmoney/wb/list/manager/handler/WbListServiceHandler.java b/src/main/java/com/rbkmoney/wb/list/manager/handler/WbListServiceHandler.java index bc76bde..b25c531 100644 --- a/src/main/java/com/rbkmoney/wb/list/manager/handler/WbListServiceHandler.java +++ b/src/main/java/com/rbkmoney/wb/list/manager/handler/WbListServiceHandler.java @@ -9,6 +9,8 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; +import java.util.List; + @Slf4j @RequiredArgsConstructor public class WbListServiceHandler implements WbListServiceSrv.Iface { @@ -19,10 +21,49 @@ public class WbListServiceHandler implements WbListServiceSrv.Iface { public boolean isExist(Row row) throws TException { String key = KeyGenerator.generateKey(row); try { - return listRepository.get(key).isPresent(); + boolean present = listRepository.get(key).isPresent(); + log.info("WbListServiceHandler isExist row: {} result: {}", row, present); + return present; } catch (RiakExecutionException e) { + log.info("WbListServiceHandler error when isExist row: {} e: ", row, e); throw new TException(e); } } + @Override + public boolean isAllExist(List list) throws TException { + if (list != null && !list.isEmpty()) { + for (Row row : list) { + if (!isExist(row)) { + return false; + } + } + } + return true; + } + + @Override + public boolean isAnyExist(List list) throws TException { + if (list != null && !list.isEmpty()) { + for (Row row : list) { + if (isExist(row)) { + return true; + } + } + } + return false; + } + + @Override + public boolean isNotOneExist(List list) throws TException { + if (list != null && !list.isEmpty()) { + for (Row row : list) { + if (isExist(row)) { + return false; + } + } + } + return true; + } + } diff --git a/src/main/java/com/rbkmoney/wb/list/manager/stream/WbListStreamFactory.java b/src/main/java/com/rbkmoney/wb/list/manager/stream/WbListStreamFactory.java index c0c858c..548e8f2 100644 --- a/src/main/java/com/rbkmoney/wb/list/manager/stream/WbListStreamFactory.java +++ b/src/main/java/com/rbkmoney/wb/list/manager/stream/WbListStreamFactory.java @@ -36,7 +36,7 @@ public class WbListStreamFactory { StreamsBuilder builder = new StreamsBuilder(); builder.stream(readTopic, Consumed.with(Serdes.String(), commandSerde)) .filter((s, changeCommand) -> changeCommand != null && changeCommand.getCommand() != null) - .peek((s, changeCommand) -> log.debug("Command stream check command: {}", changeCommand)) + .peek((s, changeCommand) -> log.info("Command stream check command: {}", changeCommand)) .mapValues(command -> retryTemplate.execute(args -> commandService.apply(command))) .to(resultTopic, Produced.with(Serdes.String(), eventSerde)); diff --git a/src/test/java/com/rbkmoney/wb/list/manager/handler/WbListServiceHandlerTest.java b/src/test/java/com/rbkmoney/wb/list/manager/handler/WbListServiceHandlerTest.java index a0eec98..1a3b93e 100644 --- a/src/test/java/com/rbkmoney/wb/list/manager/handler/WbListServiceHandlerTest.java +++ b/src/test/java/com/rbkmoney/wb/list/manager/handler/WbListServiceHandlerTest.java @@ -4,6 +4,7 @@ import com.rbkmoney.damsel.wb_list.ListType; import com.rbkmoney.wb.list.manager.model.Row; import com.rbkmoney.wb.list.manager.repository.ListRepository; import org.apache.thrift.TException; +import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -11,6 +12,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import java.util.ArrayList; import java.util.Optional; import static org.mockito.ArgumentMatchers.anyString; @@ -34,6 +36,72 @@ public class WbListServiceHandlerTest { @Test public void isExist() throws TException { + com.rbkmoney.damsel.wb_list.Row row = createRow(); + boolean exist = wbListServiceHandler.isExist(row); + Assert.assertTrue(exist); + + Mockito.when(listRepository.get(anyString())).thenReturn(Optional.empty()); + exist = wbListServiceHandler.isExist(row); + Assert.assertFalse(exist); + } + + @Test + public void isAllExist() throws TException { + ArrayList list = new ArrayList<>(); + boolean exist = wbListServiceHandler.isAllExist(list); + Assert.assertTrue(exist); + + list.add(createRow()); + list.add(createRow()); + Mockito.when(listRepository.get(anyString())).thenReturn(Optional.of(new Row())); + Assert.assertTrue(wbListServiceHandler.isAllExist(list)); + + Mockito.when(listRepository.get(anyString())) + .thenReturn(Optional.of(new Row())) + .thenReturn(Optional.empty()); + Assert.assertFalse(wbListServiceHandler.isAllExist(list)); + } + + @Test + public void isAnyExist() throws TException { + ArrayList list = new ArrayList<>(); + boolean exist = wbListServiceHandler.isAnyExist(list); + Assert.assertFalse(exist); + + list.add(createRow()); + list.add(createRow()); + Mockito.when(listRepository.get(anyString())) + .thenReturn(Optional.of(new Row())) + .thenReturn(Optional.empty()); + Assert.assertTrue(wbListServiceHandler.isAnyExist(list)); + + Mockito.when(listRepository.get(anyString())) + .thenReturn(Optional.empty()) + .thenReturn(Optional.empty()); + Assert.assertFalse(wbListServiceHandler.isAnyExist(list)); + } + + @Test + public void isNoOneExist() throws TException { + ArrayList list = new ArrayList<>(); + boolean exist = wbListServiceHandler.isNotOneExist(list); + Assert.assertTrue(exist); + + list.add(createRow()); + list.add(createRow()); + Mockito.when(listRepository.get(anyString())) + .thenReturn(Optional.empty()) + .thenReturn(Optional.empty()); + Assert.assertTrue(wbListServiceHandler.isNotOneExist(list)); + + Mockito.when(listRepository.get(anyString())) + .thenReturn(Optional.empty()) + .thenReturn(Optional.of(new Row())); + Assert.assertFalse(wbListServiceHandler.isNotOneExist(list)); + } + + @NotNull + private com.rbkmoney.damsel.wb_list.Row createRow() { Row value = new Row(); value.setValue(VALUE); Mockito.when(listRepository.get(anyString())).thenReturn(Optional.of(value)); @@ -43,11 +111,6 @@ public class WbListServiceHandlerTest { row.setListType(ListType.black); row.setListName(LIST_NAME); row.setValue(VALUE); - boolean exist = wbListServiceHandler.isExist(row); - Assert.assertTrue(exist); - - Mockito.when(listRepository.get(anyString())).thenReturn(Optional.empty()); - exist = wbListServiceHandler.isExist(row); - Assert.assertFalse(exist); + return row; } } \ No newline at end of file