DBUpdateForwarder { List<K> getAllUpdatesFrom(long seqNum, long imgNum) throws Exception { LOGGER.debug(String.format("(%s) GetAllUpdatesFrom sequence number %d, image number %d", retrieverType, seqNum, imgNum)); if (imgNum >= IMAGE_NUMBER_UPDATE_UNINITIALIZED) { long curImgNum = imageRetriever.getLatestImageID(); LOGGER.debug("({}) Current image number for is {}", retrieverType, curImgNum); if (curImgNum == IMAGE_NUMBER_UPDATE_UNINITIALIZED) { return Collections.emptyList(); } if (curImgNum > imgNum) { String logMessage = String.format("(%s) Current image num %d is greater than requested " + "image num %d. Request a full update", retrieverType, curImgNum, imgNum); LOGGER.info(logMessage); System.out.println(SentryServiceUtil.getCurrentTimeStampWithMessage(logMessage)); List<K>fullImage = retrieveFullImage(); if( !fullImage.isEmpty()) { logMessage = String.format("(%s) A newer full update with image number %d " + "is less than requested image number %d. Send full update to HDFS", retrieverType, curImgNum, imgNum); LOGGER.info(logMessage); System.out.println(SentryServiceUtil.getCurrentTimeStampWithMessage(logMessage)); } return fullImage; } } long curSeqNum = deltaRetriever.getLatestDeltaID(); LOGGER.debug("({}) Current sequence number is {}", retrieverType, curSeqNum); if (seqNum == curSeqNum + 1) { LOGGER.debug("{}, No new updates", retrieverType); return Collections.emptyList(); } if (seqNum > SEQUENCE_NUMBER_FULL_UPDATE_REQUEST && deltaRetriever.isDeltaAvailable(seqNum)) { List<K> deltas = deltaRetriever.retrieveDelta(seqNum, imgNum); if (!deltas.isEmpty()) { LOGGER.info("({}) Newer delta updates are found up to sequence number {} and being sent to HDFS", retrieverType, curSeqNum); return deltas; } } String logMessage = String.format("(%s) Requested sequence number %d is less than 0 or " + "requested deltas for that sequence number are not available. Fetch a full update", retrieverType, seqNum); LOGGER.info(logMessage); System.out.println(SentryServiceUtil.getCurrentTimeStampWithMessage(logMessage)); List<K>fullImage = retrieveFullImage(); if( fullImage != null && !fullImage.isEmpty()) { logMessage = String.format("(%s) A full update is returned due to an unavailable sequence number: %d", retrieverType, seqNum); LOGGER.info(logMessage); System.out.println(SentryServiceUtil.getCurrentTimeStampWithMessage(logMessage)); } return fullImage; } DBUpdateForwarder(final ImageRetriever<K> imageRetriever,
      final DeltaRetriever<K> deltaRetriever); static void translateOwnerPrivileges(Map<TPrivilegePrincipal,String> privMap);  }
@Test public void testEmptyListIsReturnedWhenImageNumIsZeroAndNoImagesArePersisted() throws Exception { Mockito.when(imageRetriever.getLatestImageID()).thenReturn(SentryConstants.EMPTY_PATHS_SNAPSHOT_ID); List updates = updater.getAllUpdatesFrom(1, SentryConstants.EMPTY_PATHS_SNAPSHOT_ID); assertTrue(updates.isEmpty()); }
@Test public void testEmptyListIsReturnedWhenFullUpdateRunningFromStart() throws Exception { SentryStateBank.enableState(SentryServiceState.COMPONENT, SentryServiceState.FULL_UPDATE_RUNNING); Mockito.when(imageRetriever.getLatestImageID()).thenReturn(1L); List updates = updater.getAllUpdatesFrom(SEQUENCE_NUMBER_UPDATE_UNINITIALIZED,1); assertTrue(updates.isEmpty()); }
@Test public void testEmptyListIsReturnedWhenFullUpdateRunning() throws Exception { SentryStateBank.enableState(SentryServiceState.COMPONENT, SentryServiceState.FULL_UPDATE_RUNNING); Mockito.when(imageRetriever.getLatestImageID()).thenReturn(2L); List updates = updater.getAllUpdatesFrom(SEQUENCE_NUMBER_UPDATE_UNINITIALIZED,1); assertTrue(updates.isEmpty()); }
@Test public void testEmptyListIsReturnedWhenImageIsUnusedAndNoDeltaChangesArePersisted() throws Exception { Mockito.when(deltaRetriever.getLatestDeltaID()).thenReturn(SentryConstants.EMPTY_NOTIFICATION_ID); List updates = updater.getAllUpdatesFrom(1, UNUSED_PATH_UPDATE_IMG_NUM); assertTrue(updates.isEmpty()); }
@Test public void testEmptyListReturnedWhenImageSeqIsEqualToLatest() throws Exception { Mockito.when(imageRetriever.getLatestImageID()).thenReturn(1L); Mockito.when(deltaRetriever.getLatestDeltaID()).thenReturn(10L); List<PathsUpdate> updates = updater.getAllUpdatesFrom(11, 1); assertTrue(updates.isEmpty()); }
@Test public void testNewDeltasAreReturnedWhenRequestedDeltaIsAvailable() throws Exception { Mockito.when(imageRetriever.getLatestImageID()).thenReturn(1L); Mockito.when(deltaRetriever.getLatestDeltaID()).thenReturn(3L); Mockito.when(deltaRetriever.isDeltaAvailable(2L)).thenReturn(true); Mockito.when(deltaRetriever.retrieveDelta(2L, 1L)) .thenReturn(Arrays.asList(new PathsUpdate(3, 1, false))); List<PathsUpdate> updates = updater.getAllUpdatesFrom(2, 1); assertEquals(1, updates.size()); assertEquals(3, updates.get(0).getSeqNum()); assertEquals(1, updates.get(0).getImgNum()); assertFalse(updates.get(0).hasFullImage()); }