/** * Syncronizes with the eventId processed by sentry * @param eventId * @return current counter value that should be no smaller then the requested * value, returns 0 if there were an exception. */ long syncEventId(long eventId) { try { if (!SentryStateBank.isEnabled(FullUpdateInitializerState.COMPONENT, FullUpdateInitializerState.FULL_SNAPSHOT_INPROGRESS)) { return sentryStore.getCounterWait().waitFor(eventId); } else { LOGGER.info("HMS event synchronization is disabled temporarily as sentry is in the process of " + "fetching full snapshot. No action needed"); return eventId; } } catch (InterruptedException e) { String msg = String.format("wait request for id %d is interrupted", eventId); LOGGER.error(msg, e); Thread.currentThread().interrupt(); } catch (TimeoutException e) { String msg = String.format("timed out wait request for id %d", eventId); LOGGER.warn(msg, e); } return 0; } }
@Test public void testEnableState() { SentryStateBank.enableState(TestState.COMPONENT, TestState.FIRST_STATE); assertTrue("Expected FIRST_STATE to be enabled", SentryStateBank.isEnabled(TestState.COMPONENT, TestState.FIRST_STATE)); assertFalse("Expected SECOND_STATE to be disabled", SentryStateBank.isEnabled(TestState.COMPONENT, TestState.SECOND_STATE)); }
@Test public void testStatesGetDisabled() { SentryStateBank.enableState(TestState.COMPONENT, TestState.FIRST_STATE); assertTrue("Expected FIRST_STATE to be enabled", SentryStateBank.isEnabled(TestState.COMPONENT, TestState.FIRST_STATE)); SentryStateBank.disableState(TestState.COMPONENT, TestState.FIRST_STATE); assertFalse("Expected FIRST_STATE to be disabled", SentryStateBank.isEnabled(TestState.COMPONENT, TestState.FIRST_STATE)); }
Preconditions.checkState(!SentryStateBank.isEnabled(SentryServiceState.COMPONENT, SentryServiceState.FULL_UPDATE_RUNNING), "HMSFollower shown loading full snapshot when it should not be.");
/** * 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)))); }
/** * 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)))); }
Assert.assertEquals(snapshotInfo.getId(), mockClient.eventId); 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))));
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))));