/** * Reset(nullify) the authorization context on the host. * * Mainly used paired with {@link #setSystemAuthorizationContext}. * For setting system auth context for lambda code block, see {@link #executeWithSystemAuthContext}. * * @param host a host to reset auth context * @see #setSystemAuthorizationContext * @see #executeWithSystemAuthContext */ public static void resetAuthorizationContext(ServiceHost host) { ExceptionTestUtils.executeSafely(() -> { SET_SYSTEM_AUTH_CONTEXT_METHOD.invoke(host, new Object[]{null}); }); }
/** * Reset(nullify) the authorization context on the host. * * Mainly used paired with {@link #setSystemAuthorizationContext}. * For setting system auth context for lambda code block, see {@link #executeWithSystemAuthContext}. * * @param host a host to reset auth context * @see #setSystemAuthorizationContext * @see #executeWithSystemAuthContext */ public static void resetAuthorizationContext(ServiceHost host) { ExceptionTestUtils.executeSafely(() -> { SET_SYSTEM_AUTH_CONTEXT_METHOD.invoke(host, new Object[]{null}); }); }
/** * Set system auth context to the host. * * This method is used descriptively paired with {@link #resetAuthorizationContext}. * Please see {@link #executeWithSystemAuthContext} for functional way using lambda. * * @param host a host to set system auth context * @return system auth context * @see #resetAuthorizationContext * @see #executeWithSystemAuthContext */ public static AuthorizationContext setSystemAuthorizationContext(ServiceHost host) { // use reflection to set auth context AuthorizationContext[] result = new AuthorizationContext[]{null}; ExceptionTestUtils.executeSafely(() -> { AuthorizationContext systemAuthContext = (AuthorizationContext) GET_SYSTEM_AUTH_CONTEXT_METHOD.invoke(host); SET_SYSTEM_AUTH_CONTEXT_METHOD.invoke(host, systemAuthContext); result[0] = systemAuthContext; }); return result[0]; }
/** * Set system auth context to the host. * * This method is used descriptively paired with {@link #resetAuthorizationContext}. * Please see {@link #executeWithSystemAuthContext} for functional way using lambda. * * @param host a host to set system auth context * @return system auth context * @see #resetAuthorizationContext * @see #executeWithSystemAuthContext */ public static AuthorizationContext setSystemAuthorizationContext(ServiceHost host) { // use reflection to set auth context AuthorizationContext[] result = new AuthorizationContext[]{null}; ExceptionTestUtils.executeSafely(() -> { AuthorizationContext systemAuthContext = (AuthorizationContext) GET_SYSTEM_AUTH_CONTEXT_METHOD.invoke(host); SET_SYSTEM_AUTH_CONTEXT_METHOD.invoke(host, systemAuthContext); result[0] = systemAuthContext; }); return result[0]; }
public static void executeWithSystemAuthContext(Collection<ServiceHost> hosts, ExecutableBlock block) { // currently this method does not keep track of existing auth context. // If we need to recover existing auth context, retrieve and set them back in this method. Set<ServiceHost> authEnabledHosts = hosts.stream() .filter(ServiceHost::isAuthorizationEnabled) .collect(toSet()); authEnabledHosts.forEach(AuthTestUtils::setSystemAuthorizationContext); ExceptionTestUtils.executeSafely(block); authEnabledHosts.forEach(AuthTestUtils::resetAuthorizationContext); } }
public static void executeWithSystemAuthContext(Collection<ServiceHost> hosts, ExecutableBlock block) { // currently this method does not keep track of existing auth context. // If we need to recover existing auth context, retrieve and set them back in this method. Set<ServiceHost> authEnabledHosts = hosts.stream() .filter(ServiceHost::isAuthorizationEnabled) .collect(toSet()); authEnabledHosts.forEach(AuthTestUtils::setSystemAuthorizationContext); ExceptionTestUtils.executeSafely(block); authEnabledHosts.forEach(AuthTestUtils::resetAuthorizationContext); } }
public void waitFor(String timeoutMsg, WaitHandler wh) { ExceptionTestUtils.executeSafely(() -> { Date exp = getTestExpiration(); while (new Date().before(exp)) { if (wh.isReady()) { return; } // sleep for a tenth of the maintenance interval Thread.sleep(TimeUnit.MICROSECONDS.toMillis(getMaintenanceIntervalMicros()) / 10); } throw new TimeoutException(timeoutMsg); }); }
public void waitFor(String timeoutMsg, WaitHandler wh) { ExceptionTestUtils.executeSafely(() -> { Date exp = getTestExpiration(); while (new Date().before(exp)) { if (wh.isReady()) { return; } // sleep for a tenth of the maintenance interval Thread.sleep(TimeUnit.MICROSECONDS.toMillis(getMaintenanceIntervalMicros()) / 10); } throw new TimeoutException(timeoutMsg); }); }
public void await(ExecutableBlock beforeCheck) { ExceptionTestUtils.executeSafely(() -> {
public void await(ExecutableBlock beforeCheck) { ExceptionTestUtils.executeSafely(() -> {