Skip to content

Instantly share code, notes, and snippets.

@jhalterman
jhalterman / gist:9814465
Last active January 5, 2016 09:52
AbstractAppTest for testing Dropwizard Applications with TestNG. This implementation creates a single application for the entire test suite.
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.cli.ServerCommand;
import io.dropwizard.lifecycle.ServerLifecycleListener;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.testing.junit.ConfigOverride;
import java.util.Enumeration;
@jhalterman
jhalterman / gist:9814439
Last active January 5, 2016 09:52
AbstractResourceTest for testing resources in Dropwizard with TestNG
import io.dropwizard.Configuration;
import io.dropwizard.configuration.ConfigurationFactory;
import io.dropwizard.jackson.Jackson;
import io.dropwizard.jersey.DropwizardResourceConfig;
import io.dropwizard.jersey.jackson.JacksonMessageBodyProvider;
import io.dropwizard.logging.LoggingFactory;
import io.dropwizard.setup.Environment;
import java.io.File;
import java.io.FileNotFoundException;
@jhalterman
jhalterman / InterruptableWaiter.java
Created November 4, 2013 21:02
A waiter where waiting threads can be interrupted (as opposed to awakened).
/**
* A waiter where waiting threads can be interrupted (as opposed to awakened).
*
* @author Jonathan Halterman
*/
public class InterruptableWaiter {
private final Sync sync = new Sync();
private static final class Sync extends AbstractQueuedSynchronizer {
private static final long serialVersionUID = 4016766900138538852L;
@jhalterman
jhalterman / ReentrantCircuit.java
Last active December 27, 2015 10:09
A circuit that accepts re-entrant open and close calls, allows waiting threads to be interrupted, and ensures fairness when releasing threads.
/**
* A circuit that accepts re-entrant {@link #open()} and {@link #close()} calls and ensures fairness
* when releasing {@link #await() waiting} threads.
*
* @author Jonathan Halterman
*/
public class ReentrantCircuit {
private final Sync sync = new Sync();
/**