25 Aralık 2018 Salı

SpringBoot spring.datasource Tomcat Connection Pool Ayarları

Giriş
Tomcat connection pool için kullanılır.

Genel
Örnek
Şöyle yaparız.
spring.datasource.driverClassName = org.postgresql.Driver
spring.datasource.url = jdbc:postgresql://xxx.xxx.xxx.xx:5432/mydb
spring.datasource.username = xxxx
spring.datasource.password = xxxx

spring.jpa.properties.hibernate.default_schema=test
# Number of ms to wait before throwing an exception if no connection is available.
spring.datasource.tomcat.max-wait=10000
# Maximum number of active connections that can be allocated from this pool at the
# same time.
spring.datasource.tomcat.max-active=150
spring.datasource.tomcat.max-idle=30
spring.datasource.tomcat.min-idle=2
spring.datasource.tomcat.initial-size=3
# Validate the connection before borrowing it from the pool.
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.test-on-connect=true
spring.datasource.time-between-eviction-runs-millis=60000
#spring.datasource.tomcat.validation-query-timeout=1000
spring.datasource.tomcat.validation-query=SELECT 1
spring.datasource.tomcat.validation-interval=1000
spring.datasource.tomcat.remove-abandoned=true
spring.datasource.tomcat.remove-abandoned-timeout=55
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.min-evictable-idle-time-millis = 55000
spring.datasource.tomcat.time-between-eviction-runs-millis = 34000
initial-size Alanı
Örnek
Şöyle yaparız
spring.datasource.tomcat.initial-size=2
connection-properties Alanı
Örnek
Şöyle yaparız.
spring.datasource.tomcat.connection-properties=useUnicode=true;characterEncoding=utf-8;
max-active Alanı
Örnek
Şöyle yaparız.
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.tomcat.max-active=1
Örnek
Şöyle yaparız
spring.datasource.url=jdbc:mysql://localhost/mydatabase
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=10
spring.datasource.tomcat.min-idle=5
spring.datasource.tomcat.test-on-borrow=true
max-wait Alanı
Örnek
Şöyle yaparız.
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=1

24 Aralık 2018 Pazartesi

SpringTest ResultActions Arayüzü

andExpect metodu - ResultMatcher
ResultMatcher arayüzünü gerçekleştiren tek sınıf MockMvcResultMatchers

Örnek
Şöyle yaparız.
@Mock
SecurityContext context;

@Mock
Authentication auth;


@Mock
Principal principal;

@Test
public void verifyCustomerInfoUnauthorized () throws Exception
{

  when(context.getAuthentication()).thenReturn(auth);
  when(context.getAuthentication().getPrincipal()).thenReturn(principal);
  SecurityContextHolder.setContext(context);
  mockMvc.perform(
    MockMvcRequestBuilders.post("/customer")
      .principal()
      .contentType(MediaType.APPLICATION_JSON)
      .content("{}")
      .accept(MediaType.APPLICATION_JSON))
  .andExpect(status().isUnauthorized()).andExpect(status().is(401));
}