Skip to content

Commit

Permalink
MODLD-613: Delete kafka topics after deleting tenant (#71)
Browse files Browse the repository at this point in the history
* MODLD-613: Delete kafka topics after deleting tenant

* rename LinkedTenantService -> LinkedDataTenantService

---------

Co-authored-by: PBobylev <[email protected]>
  • Loading branch information
pkjacob and PBobylev authored Dec 10, 2024
1 parent c9a0d1a commit faddcb0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
@Primary
@Service
@Profile("!" + STANDALONE_PROFILE)
public class LinkedTenantService extends TenantService {
public class LinkedDataTenantService extends TenantService {

private final Collection<TenantServiceWorker> workers;

@Autowired
public LinkedTenantService(
public LinkedDataTenantService(
JdbcTemplate jdbcTemplate,
FolioExecutionContext context,
FolioSpringLiquibase folioSpringLiquibase,
Expand All @@ -36,13 +36,19 @@ public LinkedTenantService(

@Override
public void beforeTenantUpdate(TenantAttributes tenantAttributes) {
log.debug("Start before actions for the tenant [{}]", context.getTenantId());
log.debug("Start before update actions for the tenant [{}]", context.getTenantId());
workers.forEach(worker -> worker.beforeTenantUpdate(context.getTenantId(), tenantAttributes));
}

@Override
public void afterTenantUpdate(TenantAttributes tenantAttributes) {
log.info("Start after actions for the tenant [{}]", context.getTenantId());
log.info("Start after update actions for the tenant [{}]", context.getTenantId());
workers.forEach(worker -> worker.afterTenantUpdate(context.getTenantId(), tenantAttributes));
}

@Override
public void afterTenantDeletion(TenantAttributes tenantAttributes) {
log.info("Start after delete actions for the tenant [{}]", context.getTenantId());
workers.forEach(worker -> worker.afterTenantDeletion(context.getTenantId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public void afterTenantUpdate(String tenantId, TenantAttributes tenantAttributes
kafkaAdminService.createTopics(tenantId);
kafkaAdminService.restartEventListeners();
}

@Override
public void afterTenantDeletion(String tenantId) {
kafkaAdminService.deleteTopics(tenantId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ default void beforeTenantUpdate(String tenantId, TenantAttributes tenantAttribut
default void afterTenantUpdate(String tenantId, TenantAttributes tenantAttributes) {
// no action by default
}

default void afterTenantDeletion(String tenantId) {
// no action by default
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@UnitTest
@ExtendWith(MockitoExtension.class)
class LinkedTenantServiceTest {
class LinkedDataTenantServiceTest {

@Mock
private JdbcTemplate jdbcTemplate;
Expand All @@ -30,12 +30,12 @@ class LinkedTenantServiceTest {
@Mock
private TenantServiceWorker testWorker;

private LinkedTenantService tenantService;
private LinkedDataTenantService tenantService;
private final String tenantId = "tenant-01";

@BeforeEach
void init() {
tenantService = new LinkedTenantService(
tenantService = new LinkedDataTenantService(
jdbcTemplate,
context,
folioSpringLiquibase,
Expand Down Expand Up @@ -69,4 +69,17 @@ void shouldCallWorker_afterTenantUpdate() {
verify(testWorker)
.afterTenantUpdate(tenantId, attributes);
}

@Test
void shouldCallWorker_afterTenantDeletion() {
//given
var attributes = mock(TenantAttributes.class);

//when
tenantService.afterTenantDeletion(attributes);

//then
verify(testWorker)
.afterTenantDeletion(tenantId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@ void shouldCreateTopics() {
verify(kafkaAdminService).createTopics(tenantId);
verify(kafkaAdminService).restartEventListeners();
}

@Test
void shouldDeleteTopics() {
// given
var tenantId = "tenant-01";

// when
kafkaAdminWorker.afterTenantDeletion(tenantId);

// then
verify(kafkaAdminService).deleteTopics(tenantId);
}
}

0 comments on commit faddcb0

Please sign in to comment.