Skip to content

Instantly share code, notes, and snippets.

View kenwdelong's full-sized avatar

Ken DeLong kenwdelong

View GitHub Profile
@kenwdelong
kenwdelong / GraphiteWithChefAndVagrant.md
Last active August 29, 2015 14:09
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
kenwdelong / DbUnitWithGroovy.md
Last active August 8, 2018 02:30
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: http://www.jroller.com/kenwdelong/entry/groovy_based_dbdeploy_tests

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

@kenwdelong
kenwdelong / gist:35d3da0f6371d7299d40
Created May 1, 2015 03:50
Adding Ansible to a Docker image of Jenkins
FROM jenkins:1.596
# Adapted from https://github.com/ansible/ansible-docker-base/blob/master/devel-ubuntu14.04/Dockerfile
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 http://github.com/ansible/ansible.git /opt/ansible/ansible
@kenwdelong
kenwdelong / QuickAndDirtyThreadDumpAnalyzer.md
Last active June 6, 2016 12:55
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
kenwdelong / JGroupsHibernateAWS.md
Created July 13, 2015 18:25
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 https://github.com/meltmedia/jgroups-aws. 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
kenwdelong / README.md
Created November 17, 2015 20:32
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
kenwdelong / prog.java
Created May 31, 2017 01:01
Programmatic Thread Dump in Java
StringBuilder dump = new StringBuilder();
ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfos = threadMxBean.getThreadInfo(threadMxBean.getAllThreadIds(), 150);
for(ThreadInfo info : threadInfos)
{
dump.append('"').append(info.getThreadName()).append('"').append("\n");
Thread.State state = info.getThreadState();
dump.append(state);
StackTraceElement[] stes = info.getStackTrace();
for(StackTraceElement ste : stes)