client = new SentryHMSClient(authzConf, hiveConnectionFactory);
/** * Closes the HMS client. * * <p>This is similar to disconnect. As this class implements AutoClosable, close should be * implemented. */ public void close() { disconnect(); }
/** * Creating snapshot when HMS doesn't have any data */ @Test public void testSnapshotCreationWithNoHmsData() throws Exception { MockClient mockClient = new MockClient(new HiveSnapshot(), 1); client.setClient(mockClient.client); // Make sure that client is connected Assert.assertTrue(client.isConnected()); PathsImage snapshotInfo = client.getFullSnapshot(); Assert.assertTrue(snapshotInfo.getPathImage().isEmpty()); Assert.assertFalse("FullUpdateInitializer is not expected to be in progress", SentryStateBank.isEnabled(FullUpdateInitializerState.COMPONENT, FullUpdateInitializerState.FULL_SNAPSHOT_INPROGRESS)); Assert.assertTrue(SentryStateBank.wereStatesEnabled(FullUpdateInitializerState.COMPONENT, new HashSet<SentryState>( Arrays.asList(FullUpdateInitializerState.FULL_SNAPSHOT_INPROGRESS)))); }
if(!isConnected()) { try { connect(); } catch (Exception e) { LOGGER.warn("Failed to connect to HMS Server. HMS may not be up. Will try again ", e); Map<String, Collection<String>> pathsFullSnapshot = fetchFullUpdate(); if (pathsFullSnapshot.isEmpty()) { LOGGER.info("Received empty paths when getting full snapshot. NotificationID Before Snapshot: {}", eventIdBefore.getEventId()); close(); return new PathsImage(Collections.<String, Collection<String>>emptyMap(), SentryConstants.EMPTY_NOTIFICATION_ID, SentryConstants.EMPTY_PATHS_SNAPSHOT_ID);
.enableState(SentryServiceState.COMPONENT, SentryServiceState.FULL_UPDATE_RUNNING); PathsImage snapshotInfo = client.getFullSnapshot(); if (snapshotInfo.getPathImage().isEmpty()) { LOGGER.debug("Received empty path image from HMS while taking a full snapshot");
/** * Creating snapshot when SentryHMSClient is not connected to HMS */ @Test public void testSnapshotCreationWithOutClientConnected() throws Exception { // Make sure that client is not connected Assert.assertFalse(client.isConnected()); PathsImage snapshotInfo = client.getFullSnapshot(); Assert.assertTrue(snapshotInfo.getPathImage().isEmpty()); Assert.assertFalse("FullUpdateInitializer is not expected to be in progress", SentryStateBank.isEnabled(FullUpdateInitializerState.COMPONENT, FullUpdateInitializerState.FULL_SNAPSHOT_INPROGRESS)); Assert.assertFalse(SentryStateBank.wereStatesEnabled(FullUpdateInitializerState.COMPONENT, new HashSet<SentryState>( Arrays.asList(FullUpdateInitializerState.FULL_SNAPSHOT_INPROGRESS)))); }
client.connect(); connectedToHms = true; SentryStateBank.enableState(HMSFollowerState.COMPONENT,HMSFollowerState.CONNECTED);
Mockito.when(mockClient.client.getCurrentNotificationEventId()). thenReturn(new CurrentNotificationEventId(mockClient.eventId)); client.setClient(mockClient.client); hiveConnectionFactory.setClient(mockClient); Assert.assertTrue(client.isConnected()); PathsImage snapshotInfo = client.getFullSnapshot(); Assert.assertEquals(5, snapshotInfo.getPathImage().size()); Assert.assertEquals(Sets.newHashSet("db1"), snapshotInfo.getPathImage().get("db1"));
when(sentryHmsClient.getFullSnapshot()).thenReturn(fullSnapshot);
final MockClient mockClient = new MockClient(snap, 1); client.setClient(mockClient.client); hiveConnectionFactory.setClient(mockClient); Assert.assertTrue(client.isConnected()); PathsImage snapshotInfo = client.getFullSnapshot(); snapshotInfo = client.getFullSnapshot(); Assert.assertTrue(snapshotInfo.getPathImage().isEmpty()); Assert.assertFalse("FullUpdateInitializer is not expected to be in progress",
when(sentryHmsClient.getFullSnapshot()).thenReturn(fullSnapshot);
@BeforeClass static public void initialize() throws IOException, LoginException { hiveConnectionFactory = new MockHMSClientFactory(); client = new SentryHMSClient(conf, (HiveConnectionFactory)hiveConnectionFactory); }
@Override public void close() { if (client != null) { // Close any outstanding connections to HMS try { client.disconnect(); SentryStateBank.disableState(HMSFollowerState.COMPONENT,HMSFollowerState.CONNECTED); } catch (Exception failure) { LOGGER.error("Failed to close the Sentry Hms Client", failure); } } notificationFetcher.close(); }
when(sentryHmsClient.getFullSnapshot()).thenReturn(fullSnapshot);
PathsImage fullSnapshot = new PathsImage(snapshotObjects, HMS_PROCESSED_EVENT_ID, 1); when(sentryHmsClient.getFullSnapshot()).thenReturn(fullSnapshot);
when(sentryHmsClient.getFullSnapshot()).thenReturn(fullSnapshot);
when(sentryHmsClient.getFullSnapshot()).thenReturn(fullSnapshot);
when(sentryHmsClient.getFullSnapshot()).thenReturn(fullSnapshot);