Friday, April 6, 2018

Spring testing

spring-test

https://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html

spring-boot-test

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

@ContextConfiguration(locations = "/test-db-context.xml")

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.pierre.sourcing.dao, com.pierre.xcoll.dao" />

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@pippo:1521:PLUTO" />
        <property name="username" value="pippouser" />
        <property name="password" value="pippopassword" />
    </bean>

    <bean id="transManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
        <property name="dataSource" ref="dataSource" />
    </bean>

    <context:component-scan base-package="com.pierre.sourcing.dao" />
</beans>



Important annotations

org.springframework.test.annotation.Rollback; indicates whether the transaction for a transactional test method should be rolled back after the test method has completed.

org.springframework.transaction.annotation.Transactional

org.springframework.test.context.ContextConfiguration @ContextConfiguration("/test-config.xml") declares the application context resource locations or the annotated classes that will be used to load the context.

org.springframework.test.context.jdbc.Sql at class level, like in @Sql(scripts = "/preparation-sqls/cleanup-test-data.sql") , to run SQL BEFORE the test execution

org.springframework.test.context.junit4.SpringRunner (@RunWith(SpringRunner.class) )

org.springframework.beans.factory.annotation.Autowired



Docker resource control

systemd-cgls
systemd-cgtop

ls -ltr /sys/fs/cgroup/

https://goldmann.pl/blog/2014/09/11/resource-management-in-docker/


mkdir stress
cd stress/

cat <<EOT >> Dockerfile
FROM fedora:latest
RUN yum -y install stress && yum clean all
ENTRYPOINT ["stress"]
EOT

docker build . -t stress
docker run -d stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 30s
systemd-cgtop


To display the scope of a container:

docker ps --no-trunc
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80 ubuntu "/usr/bin/top -b" 38 hours ago Up 37 hours topdemo

systemctl show docker-c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80.scope


TimeoutStopUSec=1min 30s
Result=success
MemoryCurrent=18446744073709551615
TasksCurrent=18446744073709551615
Delegate=no
CPUAccounting=no
CPUShares=18446744073709551615
StartupCPUShares=18446744073709551615
CPUQuotaPerSecUSec=infinity
BlockIOAccounting=no
BlockIOWeight=18446744073709551615
StartupBlockIOWeight=18446744073709551615
MemoryAccounting=no
MemoryLimit=18446744073709551615
DevicePolicy=auto
TasksAccounting=no
TasksMax=18446744073709551615
KillMode=control-group
KillSignal=15
SendSIGKILL=yes
SendSIGHUP=no
Id=docker-c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80.scope
Names=docker-c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80.scope
Description=docker-c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80.scope
LoadState=not-found
ActiveState=inactive
SubState=dead
InactiveExitTimestampMonotonic=0
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=yes
CanStop=yes
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
IgnoreOnSnapshot=yes
NeedDaemonReload=no
JobTimeoutUSec=0
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
LoadError=org.freedesktop.DBus.Error.FileNotFound "No such file or directory"
Transient=no


cat /proc/meminfo

cat /proc/vmstat


#remove all containers with stress image
docker ps -a | awk '{ print $1,$2 }' | grep stress | awk '{print $1 }' | xargs -I {} docker rm {}
#or even better
docker ps -a -q --filter=ancestor=stress | xargs -I {} docker rm {}

dockerd --iptables=false



References

https://www.javacodegeeks.com/minibook/docker-containerization-cookbook

https://fralef.me/docker-and-iptables.html




Thursday, April 5, 2018

primefaces cookbook on wildfly

The book is covering in depth many examples available on the official PF showcase. Don't expect advanced programming techniques, it's purely about implement not-so-common use cases in PF


sample code is here https://github.com/ova2/primefaces-cookbook

git clone git://github.com/ova2/primefaces-cookbook.git
cd primefaces-cookbook
mvn install

copy $MAVEN_REPO/org/primefaces/cookbook/showcase/2.0.0/showcase-2.0.0.war to /opt/wildfly12/standalone/deployments

http://localhost:8180/pf-cookbook/ (or http://localhost:8080/pf-cookbook/ )