SentryHDFSServiceProcessor implements SentryHDFSService.Iface { @Override public TAuthzUpdateResponse get_authz_updates(TAuthzUpdateRequest request) throws TException { TAuthzUpdateResponse retVal = new TAuthzUpdateResponse(); if (SentryPlugin.instance == null) { LOGGER.error("SentryPlugin not initialized yet !!"); retVal.setAuthzPathUpdate(Collections.<TPathsUpdate>emptyList()); retVal.setAuthzPermUpdate(Collections.<TPermissionsUpdate>emptyList()); return retVal; } try (Context timerContext = SentryHdfsMetricsUtil.getAllAuthzUpdatesTimer.time()) { retVal.setAuthzPermUpdate(getPermissionsUpdatesFrom(request)); retVal.setAuthzPathUpdate(getPathsUpdatesFrom(request)); } catch (Exception e) { LOGGER.error("Error Sending updates to downstream Cache", e); throw new TException(e); } return retVal; }  @Override TAuthzUpdateResponse get_all_authz_updates_from(long permSeqNum, long pathSeqNum); @Override TAuthzUpdateResponse get_authz_updates(TAuthzUpdateRequest request); @Override void handle_hms_notification(TPathsUpdate update); @Override long check_hms_seq_num(long pathSeqNum); @Override Map<String, List<String>> get_all_related_paths(String arg0,
      boolean arg1);  }
@Test @Ignore public void testInitialHDFSSyncReturnsAFullImage() throws Exception { Mockito.when(sentryStoreMock.getLastProcessedImageID()) .thenReturn(1L); String[]prefixes = {"/"}; Mockito.when(sentryStoreMock.retrieveFullPathsImageUpdate(prefixes)) .thenReturn(new PathsUpdate(1, 1, true)); Mockito.when(sentryStoreMock.getLastProcessedPermChangeID()) .thenReturn(1L); Mockito.when(sentryStoreMock.retrieveFullPermssionsImage()) .thenReturn(new PermissionsImage(new HashMap<String, List<String>>(), new HashMap<String, Map<TPrivilegePrincipal, String>>(), 1)); TAuthzUpdateRequest updateRequest = new TAuthzUpdateRequest(1, 1, 0); TAuthzUpdateResponse sentryUpdates= serviceProcessor.get_authz_updates(updateRequest); assertEquals(1, sentryUpdates.getAuthzPathUpdateSize()); assertEquals(1, sentryUpdates.getAuthzPathUpdate().get(0).getImgNum()); assertEquals(1, sentryUpdates.getAuthzPathUpdate().get(0).getSeqNum()); assertTrue(sentryUpdates.getAuthzPathUpdate().get(0).isHasFullImage()); assertEquals(1, sentryUpdates.getAuthzPermUpdateSize()); assertEquals(1, sentryUpdates.getAuthzPermUpdate().get(0).getSeqNum()); assertTrue(sentryUpdates.getAuthzPermUpdate().get(0).isHasfullImage()); }
@Test @Ignore public void testRequestSyncUpdatesWhenNewImagesArePersistedReturnsANewFullImage() throws Exception { Mockito.when(sentryStoreMock.getLastProcessedImageID()) .thenReturn(2L); String[]prefixes = {"/"}; Mockito.when(sentryStoreMock.retrieveFullPathsImageUpdate(prefixes)) .thenReturn(new PathsUpdate(3, 2, true)); Mockito.when(sentryStoreMock.getLastProcessedPermChangeID()) .thenReturn(3L); Mockito.when(sentryStoreMock.retrieveFullPermssionsImage()) .thenReturn(new PermissionsImage(new HashMap<String, List<String>>(), new HashMap<String, Map<TPrivilegePrincipal, String>>(), 3)); TAuthzUpdateRequest updateRequest = new TAuthzUpdateRequest(2, 2, 1); TAuthzUpdateResponse sentryUpdates= serviceProcessor.get_authz_updates(updateRequest); assertEquals(1, sentryUpdates.getAuthzPathUpdateSize()); assertEquals(2, sentryUpdates.getAuthzPathUpdate().get(0).getImgNum()); assertEquals(3, sentryUpdates.getAuthzPathUpdate().get(0).getSeqNum()); assertTrue(sentryUpdates.getAuthzPathUpdate().get(0).isHasFullImage()); assertEquals(1, sentryUpdates.getAuthzPermUpdateSize()); assertEquals(3, sentryUpdates.getAuthzPermUpdate().get(0).getSeqNum()); assertTrue(sentryUpdates.getAuthzPermUpdate().get(0).isHasfullImage()); }
@Test public void testRequestSyncUpdatesWhenNewDeltasArePersistedReturnsDeltaChanges() throws Exception { Mockito.when(sentryStoreMock.getLastProcessedImageID()) .thenReturn(1L); Mockito.when(sentryStoreMock.getLastProcessedPathChangeID()) .thenReturn(3L); Mockito.when(sentryStoreMock.pathChangeExists(2)) .thenReturn(true); Mockito.when(sentryStoreMock.getMSentryPathChanges(2)) .thenReturn(Arrays.asList(new MSentryPathChange(3, "u3", new PathsUpdate(3, 1, false)))); Mockito.when(sentryStoreMock.getLastProcessedPermChangeID()) .thenReturn(3L); Mockito.when(sentryStoreMock.permChangeExists(2)) .thenReturn(true); Mockito.when(sentryStoreMock.getMSentryPermChanges(2)) .thenReturn(Arrays.asList(new MSentryPermChange(3, new PermissionsUpdate(3, false)))); TAuthzUpdateRequest updateRequest = new TAuthzUpdateRequest(2, 2, 1); TAuthzUpdateResponse sentryUpdates= serviceProcessor.get_authz_updates(updateRequest); assertEquals(1, sentryUpdates.getAuthzPathUpdateSize()); assertEquals(1, sentryUpdates.getAuthzPathUpdate().get(0).getImgNum()); assertEquals(3, sentryUpdates.getAuthzPathUpdate().get(0).getSeqNum()); assertFalse(sentryUpdates.getAuthzPathUpdate().get(0).isHasFullImage()); assertEquals(1, sentryUpdates.getAuthzPermUpdateSize()); assertEquals(3, sentryUpdates.getAuthzPermUpdate().get(0).getSeqNum()); assertFalse(sentryUpdates.getAuthzPermUpdate().get(0).isHasfullImage()); }
@Test public void testRequestSyncUpdatesWhenPubSubNotifyReturnsFullPathsUpdate() throws Exception { Mockito.when(sentryStoreMock.getLastProcessedImageID()) .thenReturn(1L); Mockito.when(sentryStoreMock.getLastProcessedPathChangeID()) .thenReturn(2L); Mockito.when(sentryStoreMock.getLastProcessedPermChangeID()) .thenReturn(2L); Mockito.when(sentryStoreMock.retrieveFullPathsImageUpdate(Mockito.any())) .thenReturn(new PathsUpdate(8, 5, true)) .thenThrow(new RuntimeException("Not supposed to ask for full path update first time")); TAuthzUpdateRequest updateRequest = new TAuthzUpdateRequest(3, 3, 1); TAuthzUpdateResponse sentryUpdates= serviceProcessor.get_authz_updates(updateRequest); assertEquals(0, sentryUpdates.getAuthzPermUpdateSize()); assertEquals(0, sentryUpdates.getAuthzPathUpdateSize()); PubSub.getInstance().publish(PubSub.Topic.HDFS_SYNC_NN, "test message"); sentryUpdates= serviceProcessor.get_authz_updates(updateRequest); assertEquals(0, sentryUpdates.getAuthzPermUpdateSize()); assertEquals(1, sentryUpdates.getAuthzPathUpdateSize()); assertEquals(5, sentryUpdates.getAuthzPathUpdate().get(0).getImgNum()); assertEquals(8, sentryUpdates.getAuthzPathUpdate().get(0).getSeqNum()); assertTrue(sentryUpdates.getAuthzPathUpdate().get(0).isHasFullImage()); }
@Test public void testRequestSyncUpdatesWhenNoUpdatesExistReturnsEmptyResults() throws Exception { Mockito.when(sentryStoreMock.getLastProcessedImageID()) .thenReturn(1L); Mockito.when(sentryStoreMock.getLastProcessedPathChangeID()) .thenReturn(2L); Mockito.when(sentryStoreMock.getLastProcessedPermChangeID()) .thenReturn(2L); TAuthzUpdateRequest updateRequest = new TAuthzUpdateRequest(3, 3, 1); TAuthzUpdateResponse sentryUpdates= serviceProcessor.get_authz_updates(updateRequest); assertEquals(0, sentryUpdates.getAuthzPathUpdateSize()); assertEquals(0, sentryUpdates.getAuthzPermUpdateSize()); }