Grails Integration Testing by default creating datasource using H2 instead of datasource config from TEST environment - spring

I have tried everything and every suggestion so far available.
Problem:
I'm trying to write integration test cases for Grails based application but while running tests it's picking by default H2 db for creating datasource instead of using DB config from Test Environment inside application.yml
Command used:
grails -Dgrails-env=test tesp-app -integration
Version:
grails=4.0.1
gorm=7.0.2.RELEASE
application.yml
---
grails:
profile: web
codegen:
defaultPackage: myApp
gorm:
autowire: true
reactor:
# Whether to translate GORM events into Reactor events
# Disabled by default for performance reasons
events: false
info:
app:
name: "my-grails-app"
version: "0.0.10"
grailsVersion: '4.0.1'
spring:
jmx:
unique-names: true
main:
banner-mode: "off"
groovy:
template:
check-template-location: false
devtools:
restart:
additional-exclude:
- '*.gsp'
- '**/*.gsp'
- '*.gson'
- '**/*.gson'
- 'logback.groovy'
- '*.properties'
management:
endpoints:
enabled-by-default: false
---
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
pdf: application/pdf
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
urlmapping:
cache:
maxsize: 1000
controllers:
defaultScope: singleton
converters:
encoding: UTF-8
views:
default:
codec: html
gsp:
encoding: UTF-8
htmlcodec: xml
codecs:
expression: html
scriptlet: html
taglib: none
staticparts: none
management:
endpoints:
jmx:
unique-names: true
---
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
# cache.provider_class: 'org.hibernate.cache.EhCacheProvider'
lazy: false
max_fetch_depth: '5'
environments:
development:
datasource:
pooled: true
dbCreate: update
driverClassName: 'com.mysql.jdbc.Driver'
url: 'jdbc:mysql://127.0.0.1:3306/mysqlDB_dev?useLegacyDatetimeCode=false&serverTimezone=UTC'
username: 'root'
password: 'root'
logSql: true
validationQuery: "SELECT 1"
test:
datasource:
pooled: true
dbCreate: create-drop
driverClassName: 'com.mysql.jdbc.Driver'
url: 'jdbc:mysql://127.0.0.1:3306/mysqlDB_test?useLegacyDatetimeCode=false&serverTimezone=UTC'
username: 'root'
password: 'root'
logSql: true
production:
datasource:
pooled: true
dbCreate: update
driverClassName: 'com.mysql.jdbc.Driver'
url: 'jdbc:mysql://127.0.0.1:3306/mysqlDB_prod?useLegacyDatetimeCode=false&serverTimezone=UTC'
username: 'xxxxx'
password: 'xxxxx'
logSql: true
validationQuery: "SELECT 1"
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

Related

org.axonframework.commandhandling.distributed.CommandDispatchException:An erroroccurredwhiletryingtodispatchacommandontheDistributedCommandBus:404null

***Facing below issue:
org.axonframework.commandhandling.distributed.CommandDispatchException: An error occurred while trying to dispatch a command on the DistributedCommandBus: 404 null
The application is deployed on open shift platform using K8s.
This issue is coming while increasing the number of pods to greater than 1 on a specific environment.***
Below is the configuration file:-
eventbus:
type: jms
eventBus:
server:
selector:
topicName: EventBus
queueName: EventBus.management-inventory-api
eventstore:
jdbc:
validateOnly: true
endpoints:
health:
sensitive: false
jmx:
uniqueNames: true
liquibase:
enabled: false
server:
port: 8087
http:
port: 8088
ssl:
enabled: false
keyStore: ${certs.path}/inventorydomain.jks
keyStoreType: JKS
trustStore: ${certs.path}/inventorydomain_truststore.jks
trustStoreType: JKS
keyAlias: inventorydomain
spring:
jmx:
default-domain: com.inventory.domain.inventory-command
jpa:
hibernate:
ddlAuto: validate
show-sql: true
messages:
basename: errors,platform-errors
autoconfigure.exclude: |
org.axonframework.boot.autoconfig.JpaAutoConfiguration,
org.axonframework.boot.autoconfig.AxonAutoConfiguration
annotation:
eventHandler:
lookupPrefix: com.consumercard.command.listener.external
eventMapping:
lookupPrefix: com.consumercard.command.event
jmsBrokers:
producer:
brokerUrl: vm://localhost?broker.persistent=false
consumer:
brokerUrl: vm://localhost?broker.persistent=false
spring.cloud.config.discovery.enabled: false
eureka:
instance:
preferIpAddress: true
nonSecurePort: ${server.http.port}
securePort: ${server.port}
nonSecurePortEnabled: true
securePortEnabled: false
metadata-map:
zone: zone-1
client:
enabled: false
serviceUrl:
defaultZone: https://localhost:8448/eureka
logging:
level: DEBUG
basicAuth.enabled: true
rest:
client:
connection:
defaultMaxPerRoute: 50
maxTotal: 100
connectionTimeout: 10000
readTimeout: 30000
NOTE:-
This was an additional property added:-
eureka:
instance:
metadata-map:
zone: zone-1

How to set the servers property of openapi with Apache Camel?

I am trying to setup a openapi specification and publish the API with Apache Camel and Spring. I tried using restConfiguration, adding the property in the application.yaml, and using the #OpenApiProperty on the app. Everytime the generated yaml reads:
- servers
- url: ""
platform:
# not used
urlrewrite:
enabled: false
token: ${LOCAL_TOKEN:}
apim:
token_ep: ${x/token}
client:
username: ${apim_client_username:}
password: ${apim_client_password:}
consumerKey: ${apim_client_id:}
consumerSecret: ${apim_client_secret:}
endpointsOrchestrated:
server: myServer
emr-endpoint: xxxxxxxx
triggerName: ${PLATFORM_MODULE_ID}
env: dev
domain: ${PLATFORM_MODULE_DOMAIN}
openapi:
title: My Sample api
version: 1.0.0
camel:
dataformat:
jackson:
auto-discover-object-mapper: true
springboot:
tracing: false
rest:
host: myhost.com
port: 8080
spring:
application:
name: aaa
profiles:
active: ${ENV:local}
server:
servlet:
context-path: /
port: ${TOMCAT_PORT:8080}
host: localhost
# MAX HTTP THREADS
tomcat:
threads:
max: ${MAIN_HTTP_THREADS:200}

Witnessing strange surge in RDS aurora mysql RDS

I have a springboot based microservice application.
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id "com.palantir.docker" version "0.26.0"
id "com.palantir.docker-run" version "0.26.0"
id 'pl.allegro.tech.build.axion-release' version '1.13.2'
Database is mysql5.7 aurora rds
'mysql', name: 'mysql-connector-java', version: '8.0.28'
hikaricp - 4.0.3
I am witnessing one strange surge in cpu utilisation stats on RDS performance insight dashboard is that even when there are no requests on my app server, mysql still shows high cpu utilization.
Here are the screen shots:
we can observe from the logs that there are no requests on server but when the connection passes its max life, surge in cpu utilization on RDS aurora mysql:
"connection has passed maxLifetime" -> and the top sql shows set autocommit = 0 is the highest number of queries being fired.
Here are my configurations:
application.yml
spring:
application:
name: catalogue
profiles:
# The commented value for `active` can be replaced with valid Spring profiles to load.
# Otherwise, it will be filled in by gradle when building the JAR file
# Either way, it can be overridden by `--spring.profiles.active` value passed in the commandline or `-Dspring.profiles.active` set in `JAVA_OPTS`
active: dev
group:
dev:
- dev
- api-docs
# Uncomment to activate TLS for the dev profile
#- tls
prod:
- prod
- api-docs
# Uncomment to activate TLS for the dev profile
#- tls
stage:
- stage
jmx:
enabled: false
data:
web:
pageable:
default-page-size: 20
max-page-size: 20
jpa:
repositories:
bootstrap-mode: deferred
jpa:
open-in-view: false
properties:
hibernate.jdbc.time_zone: UTC
hibernate.id.new_generator_mappings: true
hibernate.connection.provider_disables_autocommit: true #https://vladmihalcea.com/why-you-should-always-use-hibernate-connection-provider_disables_autocommit-for-resource-local-jpa-transactions/
hibernate.cache.use_second_level_cache: true
hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
hibernate.cache.use_query_cache: false
hibernate.javax.cache.missing_cache_strategy: create
# modify batch size as necessary
hibernate.jdbc.batch_size: 20
hibernate.order_inserts: true
hibernate.order_updates: true
hibernate.batch_versioned_data: true
hibernate.query.fail_on_pagination_over_collection_fetch: true
hibernate.query.in_clause_parameter_padding: true
hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect
javax.persistent.sharedCache.mode: ENABLE_SELECTIVE
hibernate:
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
messages:
basename: i18n/messages
main:
allow-bean-definition-overriding: true
task:
execution:
thread-name-prefix: catalogue-task-
pool:
core-size: 2
max-size: 50
queue-capacity: 10000
scheduling:
thread-name-prefix: catalogue-scheduling-
pool:
size: 2
thymeleaf:
mode: HTML
output:
ansi:
console-available: true
server:
servlet:
session:
cookie:
http-only: true
tomcat:
mbeanregistry:
enabled: true
threads:
max: 100
compression:
enabled: true
mime-types: "text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json"
min-response-size: 1024
port: 8080
# Properties to be exposed on the /info management endpoint
info:
# Comma separated list of profiles that will trigger the ribbon to show
display-ribbon-on-profiles: 'dev'
management:
endpoints:
web:
exposure:
include: "health,info,metrics,prometheus"
endpoint:
health:
probes:
enabled: true
show-details: always
show-components: always
application-prod.yml
logging:
level:
ROOT: ERROR
org.hibernate.SQL: ERROR
com.pitstop.catalogue: ERROR
com.zaxxer.hikari: ERROR
config: classpath:logback-prod.xml
spring:
devtools:
restart:
enabled: true
additional-exclude: static/**
jackson:
serialization:
indent-output: true
datasource:
auto-commit: false
type: com.zaxxer.hikari.HikariDataSource
url: ${SPRING_DATASOURCE_URL}
username: ${SPRING_DATASOURCE_USERNAME}
password: ${SPRING_DATASOURCE_PASSWORD}
hikari:
poolName: CatalogJPAHikariCP
minimumIdle: 10
maximumPoolSize: 120
connectionTimeout: 30000
idleTimeout: 300000
maxLifetime: 600000
auto-commit: false
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
useLocalSessionState: true
rewriteBatchedStatements: true
cacheResultSetMetadata: true
cacheServerConfiguration: true
maintainTimeStats: true
servlet:
multipart:
location: /data/tmp
jpa:
hibernate:
ddl-auto: none
properties:
spring.jpa.show-sql: true
hibernate.generate_statistics: true
liquibase:
contexts: prod
messages:
cache-duration: PT1S # 1 second, see the ISO 8601 standard
thymeleaf:
cache: false
sleuth:
sampler:
probability: 1 # report 100% of traces

JHipster test: NoCacheRegionFactoryAvailableException when second level cache is disabled

When I use jhipster generate an app, I disabled the second level cache. However, when I run either "gradle test" or "run as junit test" to test the app, it is failed because the "NoCacheRegionFactoryAvailableException". I have checked the application.yml in directory "src/test/resources/config", and be sure that the second cache is disabled. I do not know why the app is still looking for second-cache. Is there any clue how this happen? or how to disable second level cache completely?
Except the test failure, everything else works well, the app can run successfully.
application.yml in src/test/resources/config
spring:
application:
name: EMS
datasource:
url: jdbc:h2:mem:EMS;DB_CLOSE_DELAY=-1
name:
username:
password:
jpa:
database-platform: com.espion.ems.domain.util.FixedH2Dialect
database: H2
open-in-view: false
show_sql: true
hibernate:
ddl-auto: none
naming-strategy: org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy
properties:
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.hbm2ddl.auto: validate
data:
elasticsearch:
cluster-name:
cluster-nodes:
properties:
path:
logs: target/elasticsearch/log
data: target/elasticsearch/data
mail:
host: localhost
mvc:
favicon:
enabled: false
thymeleaf:
mode: XHTML
liquibase:
contexts: test
security:
basic:
enabled: false
server:
port: 10344
address: localhost
jhipster:
async:
corePoolSize: 2
maxPoolSize: 50
queueCapacity: 10000
security:
rememberMe:
# security key (this key should be unique for your application, and kept secret)
key: jhfasdhflasdhfasdkfhasdjkf
metrics: # DropWizard Metrics configuration, used by MetricsConfiguration
jmx.enabled: true
swagger:
title: EMS API
description: EMS API documentation
version: 0.0.1
termsOfServiceUrl:
contactName:
contactUrl:
contactEmail:
license:
licenseUrl:
enabled: false
Move src/test/resources/config/application.yml to src/test/resources directory.
You can find that solution from https://github.com/jhipster/generator-jhipster/issues/3730

Connect Oracle database to Grails 3

I am trying to use an Oracle database to a Grails project. I work with the command line tool.
So far:
I have put the ojdb6 into a lib directory I had to create myself, at the root of my application
I modified application.yml as follow:
dataSource:
pooled: true
jmxExport: true
driverClassName: oracle.jdbc.OracleDriver
username: usrname
password: pwd
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:oracle:thin:#//url:port/db
test:
dataSource:
dbCreate: update
url: jdbc:oracle:thin:#//url:port/db
production:
dataSource:
dbCreate: update
url: jdbc:oracle:thin:#//url:port/db
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
I also created a domain-class with an Integer attribute, just to give it a try.
However, it doesn't seem to work. I get a huge error message that doesn't even fit in my command window. When I use --stacktrace, the first message is "Failed to start server".
I've been trying to solve this problem for three days, any idea/comment will be welcome. Thank you kindly.
Side note: everythink works perfectly when I use the default database, not changing anything in the configuration.
Try below, it should work. if it doesn't post the stack trace. below snippet worked for me.
Add dependency:
runtime 'oracle:ojdbc6:11.2.0.4.0'
Changes in application.yml:
environments:
dataSource:
pooled: true
jmxExport: true
driverClassName: org.h2.Driver
username: sa
password:
development:
dataSource:
dbCreate: validate
url: jdbc:oracle:thin:#xxxx:1521:xx
driverClassName: oracle.jdbc.OracleDriver
dialect: org.hibernate.dialect.Oracle10gDialect
username: "XXXXXX"
password: "XXXXXX"
properties:
***: **
***: **
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
dbCreate: update
url: jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
On Oracle DB the validation statement (property validationQuery: SELECT 1) should be something like:
"SELECT 1 FROM DUAL"
Oracle does not support SELECT 1
I was having a similar issue recently and in my case it was due to using a format that did not match with my Oracle database configuration; this is what I found:
If your database uses an SID, your url should be in the form:
url: jdbc:oracle:thin:#url:port:sid,
e.g. url: jdbc:oracle:thin:#192.168.1.44:1521:testdb
If your database uses a Service Name, your url should be in the form:
url: jdbc:oracle:thin:#//url:port/servicename
e.g. url: jdbc:oracle:thin:#//localhost:1521/testdb
Hope this helps

Resources