Groovy
Create YAML With YamlBuilder
Groovy at its best.
Groovy 3 adds the YamlBuilder class to create YAML output using a Groovy syntax. The YamlBuilder is closely related to JsonBuilder that is described in a previous post. We define a hierarchy using a builder syntax where we can use primitive types, strings, collections and objects. Once we have build our structure we can use the toString() method to get a string representation in YAML format.
Gradle
Preventing Flaky Tests from Ruining your Test Suite
Great presentation by @eriwen about flaky tests.
A Flaky Test is a test that reports success and failure given the “same” execution environment.
Common causes, mitigation strategies, how to use Gradle retry plugin (more about this in the next link) and Gradle Enterprise to report flakiness.
Test Retry Gradle Plugin
Official plugin from the Gradle:
The plugin causes failed tests to be retried within the same task. After executing all tests, any failed tests are retried. The process repeats with tests that continue to fail until the maximum specified number of retries has been attempted, or there are no more failing tests.
Example:
plugins {
id 'java-library'
id "org.gradle.test-retry" version "1.1.2"
id "groovy"
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
}
test {
retry {
maxRetries = 10
maxFailures = 20
failOnPassedAfterRetry = false
}
}
package com.example
import spock.lang.Specification
class FooSpec extends Specification {
void "flaky test"() {
expect:
random().intValue() % 2 == 0
}
static int random() {
List<Integer> l = [2, 3]
Collections.shuffle(l)
l[0]
}
}
./gradlew cleanTest test
> Task :test
com.example.FooSpec > flaky test FAILED
org.spockframework.runtime.SpockComparisonFailure at FooSpec.groovy:9
com.example.FooSpec > flaky test FAILED
org.spockframework.runtime.SpockComparisonFailure at FooSpec.groovy:9
com.example.FooSpec > flaky test FAILED
org.spockframework.runtime.SpockComparisonFailure at FooSpec.groovy:9
com.example.FooSpec > flaky test FAILED
org.spockframework.runtime.SpockComparisonFailure at FooSpec.groovy:9
com.example.FooSpec > flaky test FAILED
org.spockframework.runtime.SpockComparisonFailure at FooSpec.groovy:9
com.example.FooSpec > flaky test FAILED
org.spockframework.runtime.SpockComparisonFailure at FooSpec.groovy:9
com.example.FooSpec > flaky test FAILED
org.spockframework.runtime.SpockComparisonFailure at FooSpec.groovy:9
com.example.FooSpec > flaky test FAILED
org.spockframework.runtime.SpockComparisonFailure at FooSpec.groovy:9
9 tests completed, 8 failed
There were failing tests. See the report at: file:///Users/sdelamo/Developer/github-issues/gradle-test-retry/build/reports/tests/test/index.html
BUILD SUCCESSFUL in 6s
See how my build was successful due to failOnPassedAfterRetry = false
even if the test needed to be retried multiple times.
Publishing Tools
Write Asciidoctor Extensions Using Groovy (or Java)
Great explanation about how to create a custom Asciidoctor extensions by @mrhaki:
We wrote custom extensions for Micronaut documentation to provide things such as code snippets in multiple languages, links to Java docs pages etc.
If you browse the Micronaut documentation's Asciidoc, you will find things such as:
snippet::com.amazon.ask.helloworld.handlers.AlexaApplication[tags="imports,class", project-base="examples/alexa-hello-world", source="main"]
Java
Java 8 — Functional Interfaces (SAM)
Have you ever heard the term SAM type and not really understand what they were referring to?
Java 8 has introduced the concept of “functional interfaces” that formalizes this idea. A functional interface specifies only one abstract method. Since functional interfaces specify only one abstract method, they are sometimes known as Single Abstract Method (SAM) types or interfaces.
There is another famous SAM acronym out there: AWS SAM ( Serverless Application Model).
Misc
Obtaining IP address programmatically
I needed to obtain the public IP address to log it in a Gradle task. @emfanitek pointed me to Ipify:
Ever needed to get your public IP address programmatically? Maybe you're provisioning new cloud servers and need to know your IP -- maybe you're behind a corporate firewall and need to tunnel information -- whatever the reason: sometimes having a public IP address API is useful!
IPv4
$ curl 'https://api.ipify.org?format=json'
{"ip":"83.39.137.234"}
Capturing Audio & Video in HTML5
As part of a project which I am working on, I need to take screenshots from a user's webcam.
This post by @ebidel shows how easy is to get it, with Javascript getUserMedia()
Setting up GSuite GMail Custom Domains With AWS Route53
I have setup Google Suite for greachconf.com, a domain whose DNS I manage in route 53. It is been challenging to set it up correctly. This blog post by @ andrewray is a good start to configure things correctly.
Comment
This issue is a mix of everyday chores: Yaml builder, flaky tests, Asciidoctor Extensions, Java SAM, ip address logging ...
Sergio del Amo