Skip to content

Instantly share code, notes, and snippets.


Ken DeLong kenwdelong

View GitHub Profile
kenwdelong /
Last active Aug 29, 2015
Create a Graphite and Statsd server with Chef and Vagrant. This one provisions the VM and starts the services.

Creating a Graphite and Statsd Server

First install the pre-reqs

  • Install VirtualBox
  • Install Vagrant
  • gem install librarian-chef
  • librarian-chef install
  • vagrant plugin install vagrant-vbguest
  • vagrant plugin install vagrant-omnibus
kenwdelong /
Last active Aug 8, 2018
Use Groovy to assign test data with DbUnit

DbUnit with Groovy

This little extension to DbUnit allows you to write the test data using Groovy lists and maps rather than XML or Excel. That way you can keep your test data in the same file as your db integration test, which will be easier to grok and maintain.

GroovyDataset is the DbUnit extension that you need to put in your project. GroovyDatasetTest is the unit test for it. UserIntegrationTest is an example, where the "data" attribute is the test data that is inserted into the database. (In real life, you'd create a superclass and move the SessionFactory, the definition of the data field, the setup() method, etc. there).

This was all described in a blog post:

For how to use it, see the UserIntegrationTest below. You can specify the data for the test in a List of Maps

kenwdelong / gist:35d3da0f6371d7299d40
Created May 1, 2015
Adding Ansible to a Docker image of Jenkins
View gist:35d3da0f6371d7299d40
FROM jenkins:1.596
# Adapted from
USER root
RUN apt-get -y update && \
apt-get install -y python-yaml python-jinja2 python-httplib2 python-keyczar python-paramiko python-setuptools python-pkg-resources git python-pip
RUN pip install boto
RUN mkdir /etc/ansible/
RUN echo '[local]\nlocalhost\n' > /etc/ansible/hosts
RUN mkdir /opt/ansible/
RUN git clone /opt/ansible/ansible
kenwdelong /
Last active Jun 6, 2016
Quick and Dirty Java ThreadDump Analyzer in Groovy

Thread Dump Analyzer

Just take your thread dump, and put it in the file threaddump.txt. The script will count the number of stack traces which are identical and sort them by the most common to the least common.

kenwdelong /
Created Jul 13, 2015
Using JGroups for Hibernate Second-Level Cache in AWS EC2

Configuring a Hibernate second-level cache in AWS is something of a challenge, as the EhCache multicast discovery mechanism doesn't work there. JGroups is another option, but can be difficult to configure. Here's how I got it working.

I'm using the very nice JGroups-AWS project In my configuration, you can see that I use "tags=Env,Role". This means that any given server will query EC2 to find out the values of those tags for itself. For example, suppose the server wakes up and finds that it has Env=Production and Role=API_Server. It will look for other servers with the same tag values (using the AWS webservice endpoints) and form a cluster with them. It checks back periodically so that if servers enter or leave the group it will adjust periodically. Very nice.

The 1.3.0 jgroups-aws uses JGroups 3.1.0, which is a bit out of date. I have not tried forcing a later version in the POM yet. I also cannot completely vouch for all the protocols set up in the ehcache.

kenwdelong /
Created Nov 17, 2015
Script to Determine order of Servlet Filters in Spring application

A short Groovy script that you can use to filter out the noise from a stack trace to see what order the servlet filters are actually configured with.

A simple way to do this is throw a RuntimeException from a controller, hit that URL, and copy and paste the stack trace into the script below.

kenwdelong /
Created May 31, 2017
Programmatic Thread Dump in Java
StringBuilder dump = new StringBuilder();
ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfos = threadMxBean.getThreadInfo(threadMxBean.getAllThreadIds(), 150);
for(ThreadInfo info : threadInfos)
Thread.State state = info.getThreadState();
StackTraceElement[] stes = info.getStackTrace();
for(StackTraceElement ste : stes)