Friday, May 25, 2018

Nginx with LUA and Java handlers

sudo yum install epel-release
sudo yum install nginx
sudo systemctl start nginx

nginx should now be running, enter http://localhost to test

documents in /usr/share/nginx/html

configuration in /etc/nginx/nginx.conf

logs in /var/log/nginx/access.log

sudo ausearch -c 'nginx' --raw | audit2allow -M my-nginx
sudo semodule -i my-nginx.pp
#disable selinux
setenforce 0

nginx with Docker
docker pull nginx
docker run --name nginx -d -p 10080:80 nginx

Setup a reverse proxy:
sudo vi /etc/nginx/conf.d/mynexus.conf

    listen 18081;
    location / {
        proxy_pass "http://localhost:8081";

systemctl stop nginx
systemctl start nginx

you can now point your maven mirror in settings.xml to point to 18081 and intercept all requests to Nexus

How to embed a Java handler in the loop ?

Handlers in Java implement this interface NginxJavaRingHandler

Ref: quick quide to configure

nginx as reverse proxy

Thursday, May 24, 2018

Testcontainers, using Docker containers in JUnit tests

Junit sucks, use at least 5.0 or better switch to TestNG (see for comparison)

To keep it really minimalistic, I have created a Maven Java project:

<project xmlns=""


and copied this example

package org.pierre.testcontainer;

import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testcontainers.containers.BrowserWebDriverContainer;


import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;
import static org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL;

public class SeleniumContainerTest {

    public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
                                                    .withRecordingMode(RECORD_ALL, new File("target"));

    public void simplePlainSeleniumTest() {
        RemoteWebDriver driver = chrome.getWebDriver();

        WebElement searchInput = driver.findElementByName("search");

        searchInput.sendKeys("Rick Astley");

        WebElement otherPage = driver.findElementByLinkText("Rickrolling");;

        boolean expectedTextFound = driver.findElementsByCssSelector("p")
                .anyMatch(element -> element.getText().contains("meme"));

        assertTrue("The word 'meme' is found on a page about rickrolling", expectedTextFound);


The first time it failed with a SocketTimeoutException.... the second time it succeeded... I guess simply the Docker container was taking too much time to start.

If I do "docker images" I see richnorth/vnc-recorder and selenium/standalone-chrome-debug. If I do "docker ps -a" I see no trace of containers, probably they are removed at the end of test.

It looks really interesting! Convenient way to prepare a test environment in a fully automated way.

Wednesday, May 23, 2018

sudo systemctl hibernate

on Centos, I was trying to hibernate my machine:

sudo systemctl hibernate

A dependency job for failed. See 'journalctl -xe' for details.

journalctl -xe

Failed to write mode to /sys/power/disk: Operation not permitted

I removed "safe boot" option in the BIOS settings, and now I am able to hibernate! Amazing!

See also this, maybe "suspend" is cheaper safer and faster than hibernate...