From b9f327bc64cf9a441250a7f1ba26db3bb66c9fe2 Mon Sep 17 00:00:00 2001 From: Andrey Dyachkov Date: Wed, 29 Nov 2017 15:53:06 +0100 Subject: [PATCH 1/3] aruha-1335: take all timelines not only active --- .../org/zalando/nakadi/service/timeline/TimelineService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/zalando/nakadi/service/timeline/TimelineService.java b/src/main/java/org/zalando/nakadi/service/timeline/TimelineService.java index 588c7e2163..fcd4dd3ce2 100644 --- a/src/main/java/org/zalando/nakadi/service/timeline/TimelineService.java +++ b/src/main/java/org/zalando/nakadi/service/timeline/TimelineService.java @@ -271,7 +271,7 @@ public Multimap deleteAllTimelinesForEventType(final St NoSuchEventTypeException { LOG.info("Deleting all timelines for event type {}", eventTypeName); final Multimap topicsToDelete = ArrayListMultimap.create(); - for (final Timeline timeline : getActiveTimelinesOrdered(eventTypeName)) { + for (final Timeline timeline : getAllTimelinesOrdered(eventTypeName)) { topicsToDelete.put(getTopicRepository(timeline), timeline.getTopic()); timelineDbRepository.deleteTimeline(timeline.getId()); } From cb3f9ade4dd074a1e690b4b4ddb9467db2b180e0 Mon Sep 17 00:00:00 2001 From: Andrey Dyachkov Date: Wed, 29 Nov 2017 17:21:08 +0100 Subject: [PATCH 2/3] aruha-1335: regression test --- .../org/zalando/nakadi/webservice/EventTypeAT.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/acceptance-test/java/org/zalando/nakadi/webservice/EventTypeAT.java b/src/acceptance-test/java/org/zalando/nakadi/webservice/EventTypeAT.java index d851b2228e..096716a82d 100644 --- a/src/acceptance-test/java/org/zalando/nakadi/webservice/EventTypeAT.java +++ b/src/acceptance-test/java/org/zalando/nakadi/webservice/EventTypeAT.java @@ -289,6 +289,19 @@ public void whenUpdateETAuthObjectThen422() throws Exception { "Changing authorization object to `null` is not possible due to existing one")))); } + @Test + public void shouldDeleteEventTypeWhenOneTimelineWasDeleted() throws Exception { + final EventType eventType = NakadiTestUtils.createEventType(); + NakadiTestUtils.switchTimelineDefaultStorage(eventType); + + final List timelines = TIMELINE_REPOSITORY.listTimelinesOrdered(eventType.getName()); + final Timeline timeline = timelines.get(0); + timeline.setDeleted(true); + TIMELINE_REPOSITORY.updateTimelime(timeline); + + deleteEventTypeAndOK(eventType); + } + private void assertRetentionTime(final Long checkingRetentionTime, final String etName) throws IOException { final EventType eventType = NakadiTestUtils.getEventType(etName); Assert.assertEquals(checkingRetentionTime, eventType.getOptions().getRetentionTime()); From cf52676f996e35de4cbb03618554321502e07dfb Mon Sep 17 00:00:00 2001 From: Andrey Dyachkov Date: Wed, 29 Nov 2017 18:16:08 +0100 Subject: [PATCH 3/3] aruha-1335: replaced with unit test --- .../zalando/nakadi/webservice/EventTypeAT.java | 13 ------------- .../service/timeline/TimelineServiceTest.java | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/acceptance-test/java/org/zalando/nakadi/webservice/EventTypeAT.java b/src/acceptance-test/java/org/zalando/nakadi/webservice/EventTypeAT.java index 096716a82d..d851b2228e 100644 --- a/src/acceptance-test/java/org/zalando/nakadi/webservice/EventTypeAT.java +++ b/src/acceptance-test/java/org/zalando/nakadi/webservice/EventTypeAT.java @@ -289,19 +289,6 @@ public void whenUpdateETAuthObjectThen422() throws Exception { "Changing authorization object to `null` is not possible due to existing one")))); } - @Test - public void shouldDeleteEventTypeWhenOneTimelineWasDeleted() throws Exception { - final EventType eventType = NakadiTestUtils.createEventType(); - NakadiTestUtils.switchTimelineDefaultStorage(eventType); - - final List timelines = TIMELINE_REPOSITORY.listTimelinesOrdered(eventType.getName()); - final Timeline timeline = timelines.get(0); - timeline.setDeleted(true); - TIMELINE_REPOSITORY.updateTimelime(timeline); - - deleteEventTypeAndOK(eventType); - } - private void assertRetentionTime(final Long checkingRetentionTime, final String etName) throws IOException { final EventType eventType = NakadiTestUtils.getEventType(etName); Assert.assertEquals(checkingRetentionTime, eventType.getOptions().getRetentionTime()); diff --git a/src/test/java/org/zalando/nakadi/service/timeline/TimelineServiceTest.java b/src/test/java/org/zalando/nakadi/service/timeline/TimelineServiceTest.java index d4d817edbf..6e1238ba87 100644 --- a/src/test/java/org/zalando/nakadi/service/timeline/TimelineServiceTest.java +++ b/src/test/java/org/zalando/nakadi/service/timeline/TimelineServiceTest.java @@ -33,6 +33,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; +import static org.zalando.nakadi.utils.TestUtils.buildDefaultEventType; public class TimelineServiceTest { @@ -119,4 +120,20 @@ public void shouldDeleteTopicWhenTimelineCreationFails() throws Exception { Mockito.verify(repository, Mockito.times(1)).deleteTopic(any()); } + @Test + public void shouldDeleteAllTimelinesWhenOneTimelineWasMarkedAsDeleted() throws Exception { + final EventType eventType = buildDefaultEventType(); + final Timeline t1 = Timeline.createTimeline(eventType.getName(), 1, null, "topic1", new Date()); + t1.setDeleted(true); + t1.setSwitchedAt(new Date()); + final Timeline t2 = Timeline.createTimeline(eventType.getName(), 2, null, "topic2", new Date()); + t2.setSwitchedAt(new Date()); + Mockito.when(eventTypeCache.getTimelinesOrdered(eventType.getName())) + .thenReturn(ImmutableList.of(t1, t2)); + + timelineService.deleteAllTimelinesForEventType(eventType.getName()); + + Mockito.verify(timelineDbRepository, Mockito.times(2)).deleteTimeline(Mockito.any()); + } + }