@Test public void delete() throws Exception { SwiftDeleteService deleteService = new SwiftDeleteService(); deleteService.start(); Where where = mock(Where.class); SourceKey tableKey = new SourceKey("t"); List<SegmentKey> segKeys = Arrays.asList(mock(SegmentKey.class), mock(SegmentKey.class), mock(SegmentKey.class)); when(segmentService.getSegmentKeys(tableKey)).thenReturn(segKeys); when(segmentService.exist(ArgumentMatchers.any())).thenReturn(false, true, true); WhereDeleter whereDeleter = mock(WhereDeleter.class); when(SwiftContext.get().getBean(eq("decrementer"), any())).thenReturn(whereDeleter); when(whereDeleter.delete(ArgumentMatchers.<Where>any())).thenThrow(Exception.class).thenReturn(null); assertFalse(deleteService.delete(tableKey, where)); verify(SwiftContext.get(), never()).getBean("decrementer", segKeys.get(0)); verify(SwiftContext.get()).getBean("decrementer", segKeys.get(1)); verify(SwiftContext.get()).getBean("decrementer", segKeys.get(2)); verify(whereDeleter, times(2)).delete(where); verifyNoMoreInteractions(whereDeleter); }
@Override public boolean delete(final SourceKey tableKey, final Where where) { boolean success = true; try { WhereDeleter whereDeleter = (WhereDeleter) SwiftContext.get().getBean("decrementer", tableKey); whereDeleter.delete(where); } catch (Exception e) { SwiftLoggers.getLogger().error(e); success = false; } return success; }
SwiftDeleteService extends AbstractSwiftService implements DeleteService { @Override public boolean delete(final SourceKey tableKey, final Where where) { boolean success = true; try { WhereDeleter whereDeleter = (WhereDeleter) SwiftContext.get().getBean("decrementer", tableKey); whereDeleter.delete(where); } catch (Exception e) { SwiftLoggers.getLogger().error(e); success = false; } return success; } }
SwiftDeleteService extends AbstractSwiftService implements DeleteService { @Override public boolean delete(final SourceKey tableKey, final Where where) { boolean success = true; try { WhereDeleter whereDeleter = (WhereDeleter) SwiftContext.get().getBean("decrementer", tableKey); whereDeleter.delete(where); } catch (Exception e) { SwiftLoggers.getLogger().error(e); success = false; } return success; }  }
SwiftDeleteService extends AbstractSwiftService implements DeleteService { @Override public boolean delete(final SourceKey tableKey, final Where where) { boolean success = true; try { WhereDeleter whereDeleter = (WhereDeleter) SwiftContext.get().getBean("decrementer", tableKey); whereDeleter.delete(where); } catch (Exception e) { SwiftLoggers.getLogger().error(e); success = false; } return success; }  @Override boolean start(); @Override boolean shutdown(); @Override boolean delete(final SourceKey tableKey, final Where where); @Override ServiceType getServiceType(); }
SwiftDeleteService extends AbstractSwiftService implements DeleteService { @Override public boolean delete(final SourceKey tableKey, final Where where) { boolean success = true; try { WhereDeleter whereDeleter = (WhereDeleter) SwiftContext.get().getBean("decrementer", tableKey); whereDeleter.delete(where); } catch (Exception e) { SwiftLoggers.getLogger().error(e); success = false; } return success; }  @Override boolean start(); @Override boolean shutdown(); @Override boolean delete(final SourceKey tableKey, final Where where); @Override ServiceType getServiceType();  }