X509FederationClient implements FederationClient { @VisibleForTesting Response makeCall(Builder ib, URI requestUri, X509FederationRequest federationRequest) { BmcException lastException = null; final WrappedInvocationBuilder wrappedIb = new WrappedInvocationBuilder(ib, requestUri); for (int retry = 0; retry < 5; retry++) { try { return federationHttpClient.post(wrappedIb, federationRequest, new BmcRequest()); } catch (BmcException e) { lastException = e; try { Thread.sleep(250L); } catch (InterruptedException e1) { LOG.debug( "Thread interrupted while waiting to make next call to federation service", e1); Thread.currentThread().interrupt(); break; } } } throw lastException; } X509FederationClient(
            String federationEndpoint,
            String tenancyId,
            X509CertificateSupplier leafCertificateSupplier,
            SessionKeySupplier sessionKeySupplier,
            Set<X509CertificateSupplier> intermediateCertificateSuppliers,
            ClientConfigurator clientConfigurator,
            List<ClientConfigurator> additionalClientConfigurators,
            CircuitBreakerConfiguration circuitBreakerConfig);  X509FederationClient(
            String federationEndpoint,
            String tenancyId,
            X509CertificateSupplier leafCertificateSupplier,
            SessionKeySupplier sessionKeySupplier,
            Set<X509CertificateSupplier> intermediateCertificateSuppliers,
            ClientConfigurator clientConfigurator,
            List<ClientConfigurator> additionalClientConfigurators,
            CircuitBreakerConfiguration circuitBreakerConfig,
            String purpose); @Override String getSecurityToken(); @Override String getStringClaim(String key); @Override String refreshAndGetSecurityToken();  }
@Test public void makeCall_shouldReuseWrappedInvocationBuilderReference_whenBmcExceptionIsThrown() throws Exception { URI requestURI = PowerMockito.mock(URI.class); final WrappedInvocationBuilder expectedWIb = mock(WrappedInvocationBuilder.class); final Invocation.Builder ib = mock(Invocation.Builder.class); whenNew(WrappedInvocationBuilder.class) .withArguments(ib, requestURI) .thenReturn(expectedWIb); final Response expectedResponse = mock(Response.class); when( mockFederationClient.post( Mockito.<WrappedInvocationBuilder>any(), Mockito.<X509FederationClient.X509FederationRequest>any(), Mockito.<BmcRequest>any())) .thenThrow(new BmcException(409, "ServiceCode", "Exception 1", "RequestId")) .thenThrow(new BmcException(409, "ServiceCode", "Exception 2", "RequestId")) .thenThrow(new BmcException(409, "ServiceCode", "Exception 3", "RequestId")) .thenReturn(expectedResponse); final Response actualResponse = clientUnderTest.makeCall( ib, requestURI, mock(X509FederationClient.X509FederationRequest.class)); assertEquals("Response should be equal", expectedResponse, actualResponse); verify(mockFederationClient, times(4)) .post( wrappedIbCaptor.capture(), isA(X509FederationClient.X509FederationRequest.class), isA(BmcRequest.class)); final List<WrappedInvocationBuilder> wrappedIbsFromInvocation = wrappedIbCaptor.getAllValues(); assertFalse( "Captured list of WrappedInvocationBuilder should not be empty", wrappedIbsFromInvocation.isEmpty()); assertEquals( "Captured list of WrappedInvocationBuilder size should be 4", 4 , wrappedIbsFromInvocation.size()); for (WrappedInvocationBuilder actualWib : wrappedIbsFromInvocation) { assertEquals("Captured WIB should be the same", expectedWIb, actualWib); } }