This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Runnable connectionPoolMetricsLogger(final PoolingHttpClientConnectionManager connectionManager) { | |
return new Runnable() { | |
@Override | |
@Scheduled(fixedDelay = 30000) | |
public void run() { | |
final StringBuilder buffer = new StringBuilder(); | |
try { | |
if (connectionManager != null) { | |
final PoolStats totalPoolStats = connectionManager.getTotalStats(); | |
log.info(" ** HTTP Client Connection Pool Stats : Available = {}, Leased = {}, Pending = {}, Max = {} **", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Retryable(value = {RemoteServiceUnavailableException.class}, maxAttempts = 8, | |
backoff = @Backoff(delay = 1000, multiplier = 2), label = "generate-alias-retry-label") | |
String generateAlias(String cardNo); | |
@Recover | |
String fallbackForGenerateAlias(Throwable th, String cardNo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Runnable idleAndExpiredConnectionProcessor(final PoolingHttpClientConnectionManager connectionManager) { | |
return new Runnable() { | |
@Override | |
@Scheduled(fixedDelay = 20000) | |
public void run() { | |
try { | |
if (connectionManager != null) { | |
connectionManager.closeExpiredConnections(); | |
connectionManager.closeIdleConnections(IDLE_CONNECTION_WAIT_TIME_SECS, TimeUnit.SECONDS); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ConnectionKeepAliveStrategy connectionKeepAliveStrategy() { | |
return new DefaultConnectionKeepAliveStrategy() { | |
@Override | |
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) { | |
long keepAliveDuration = super.getKeepAliveDuration(response, context); | |
if (keepAliveDuration < 0) { | |
keepAliveDuration = DEFAULT_KEEP_ALIVE_TIME_MILLIS; | |
} else if (keepAliveDuration > MAX_KEEP_ALIVE_TIME_MILLIS) { | |
keepAliveDuration = MAX_KEEP_ALIVE_TIME_MILLIS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public PoolingHttpClientConnectionManager poolingConnectionManager() { | |
PoolingHttpClientConnectionManager poolingConnectionManager = | |
new PoolingHttpClientConnectionManager(getConnectionSocketFactoryRegistry()); | |
poolingConnectionManager.setMaxTotal(MAX_CONNECTIONS); | |
poolingConnectionManager.setDefaultMaxPerRoute(MAX_PER_ROUTE_CONNECTION); | |
poolingConnectionManager.setValidateAfterInactivity(VALIDATE_AFTER_INACTIVITY_IN_MILLIS); | |
return poolingConnectionManager; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private RequestConfig prepareHttpClientRequestConfig() { | |
RequestConfig requestConfig = RequestConfig | |
.custom() | |
.setConnectTimeout(CONNECT_TIMEOUT) | |
.setConnectionRequestTimeout(CONNECTION_REQUEST_TIMEOUT) | |
.setSocketTimeout(SOCKET_TIMEOUT) | |
.build(); | |
return requestConfig; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class ReservationService { | |
private ReservationRepository reservationRepository; | |
public ReservationService(ReservationRepository reservationRepository) { | |
this.reservationRepository = reservationRepository; | |
} | |
@Cacheable("reservation") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.cache.annotation.EnableCaching; | |
@SpringBootApplication | |
@EnableCaching | |
public class BootifulTddApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(BootifulTddApplication.class, args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringRunner.class) | |
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | |
public class ReservationEndToEndTest { | |
@Autowired | |
TestRestTemplate testRestTemplate; | |
@Test | |
public void getReservation_shouldReturnReservationDetails() { | |
// Arrange | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.its.reservation; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.ArgumentMatchers; | |
import org.mockito.BDDMockito; | |
import org.mockito.Mockito; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | |
import org.springframework.boot.test.context.SpringBootTest; |
NewerOlder