Skip to content

Commit

Permalink
using : datasource-micrometer starter
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 25, 2024
1 parent f0f59ba commit c8d8a54
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 77 deletions.
8 changes: 4 additions & 4 deletions jpa/boot-hibernate2ndlevelcache-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>net.ttddyy</groupId>
<artifactId>datasource-proxy</artifactId>
<version>1.10.1</version>
<groupId>net.ttddyy.observation</groupId>
<artifactId>datasource-micrometer-spring-boot</artifactId>
<version>1.0.6</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -266,7 +266,7 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.47.0</version>
<version>2.50.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

import com.example.hibernatecache.repositories.CustomerRepository;
import io.hypersistence.utils.spring.repository.BaseJpaRepositoryImpl;
import net.ttddyy.dsproxy.listener.DataSourceQueryCountListener;
import net.ttddyy.dsproxy.listener.QueryExecutionListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@EnableJpaRepositories(basePackageClasses = CustomerRepository.class, repositoryBaseClass = BaseJpaRepositoryImpl.class)
@Configuration(proxyBeanMethods = false)
class JpaConfiguration {}
class JpaConfiguration {

@Bean
QueryExecutionListener queryExecutionListener() {
return new DataSourceQueryCountListener();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ spring.cache.type=redis
spring.data.redis.host=localhost
spring.data.redis.port=6379


########### datasource micrometer ###########
jdbc.datasource-proxy.logging=slf4j
jdbc.datasource-proxy.slow-query.logger-name=slow-query-logger
jdbc.datasource-proxy.query.logger-name=query-logger
jdbc.datasource-proxy.query.enable-logging=true
jdbc.datasource-proxy.slow-query.enable-logging=true
jdbc.datasource-proxy.include-parameter-values=true
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@

<logger name="com.example.hibernatecache" level="DEBUG"/>
<logger name="org.springframework" level="INFO"/>
<logger name="query-logger" level="DEBUG" />
<logger name="slow-query-logger" level="WARN" />

</configuration>
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.example.hibernatecache;

import static io.hypersistence.utils.jdbc.validator.SQLStatementCountValidator.assertInsertCount;
import static io.hypersistence.utils.jdbc.validator.SQLStatementCountValidator.assertSelectCount;
import static org.hamcrest.CoreMatchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
Expand Down Expand Up @@ -32,9 +30,10 @@ void contextLoads() throws Exception {
.andExpect(jsonPath("$.lastName", is(customerRequest.lastName())))
.andExpect(jsonPath("$.email", is(customerRequest.email())))
.andExpect(jsonPath("$.phone", is(customerRequest.phone())));
assertInsertCount(1);
SQLStatementCountValidator.assertInsertCount(1);
// For selecting next sequence value
assertSelectCount(1);
SQLStatementCountValidator.assertSelectCount(1);
SQLStatementCountValidator.assertTotalCount(2);
SQLStatementCountValidator.reset();
for (int i = 0; i < 10; i++) {
this.mockMvc
Expand All @@ -46,6 +45,7 @@ void contextLoads() throws Exception {
.andExpect(jsonPath("$.email", is(customerRequest.email())))
.andExpect(jsonPath("$.phone", is(customerRequest.phone())));
}
assertSelectCount(1);
SQLStatementCountValidator.assertSelectCount(1);
SQLStatementCountValidator.assertTotalCount(1);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.example.hibernatecache.web.controllers;

import static io.hypersistence.utils.jdbc.validator.SQLStatementCountValidator.assertInsertCount;
import static io.hypersistence.utils.jdbc.validator.SQLStatementCountValidator.assertSelectCount;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.empty;
Expand Down Expand Up @@ -104,9 +102,10 @@ void shouldFindCustomerById() throws Exception {
.andExpect(jsonPath("$.phone", is(customer.getPhone())))
.andExpect(jsonPath("$.orders.size()", is(1)));

assertInsertCount(0);
SQLStatementCountValidator.assertInsertCount(0);
// For selecting customer and order
assertSelectCount(2);
SQLStatementCountValidator.assertSelectCount(2);
SQLStatementCountValidator.assertTotalCount(2);
}

@Test
Expand All @@ -126,9 +125,10 @@ void shouldFindCustomerByFirstname() throws Exception {
.andExpect(jsonPath("$.phone", is(customer.getPhone())))
.andExpect(jsonPath("$.orders.size()", is(1)));

assertInsertCount(0);
SQLStatementCountValidator.assertInsertCount(0);
// For selecting customer and then orderItems
assertSelectCount(2);
SQLStatementCountValidator.assertSelectCount(2);
SQLStatementCountValidator.assertTotalCount(2);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@

<logger name="org.testcontainers" level="INFO"/>
<logger name="com.github.dockerjava" level="WARN"/>
<logger name="query-logger" level="DEBUG" />
<logger name="slow-query-logger" level="WARN" />
</configuration>

0 comments on commit c8d8a54

Please sign in to comment.