Skip to content

Instantly share code, notes, and snippets.

@chids
Created November 1, 2012 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chids/3993909 to your computer and use it in GitHub Desktop.
Save chids/3993909 to your computer and use it in GitHub Desktop.
Runtime setting of Dropwizard HTTP and admin port
package omni.backend.pipeline.service.ports;
import static com.google.common.collect.Maps.immutableEntry;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import org.elasticsearch.common.collect.ImmutableMap;
import com.yammer.dropwizard.config.HttpConfiguration;
public class DropwizardPorts {
private static final String ADMIN_PORT = "admin";
private static final String HTTP_PORT = "port";
private final ImmutableMap<String, Integer> ports;
public DropwizardPorts(final int baseport) {
final ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder();
builder.put(immutableEntry(HTTP_PORT, baseport));
builder.put(immutableEntry(ADMIN_PORT, baseport + 1));
this.ports = builder.build();
}
public HttpConfiguration wrap(final HttpConfiguration original) {
final HttpConfiguration spy = spy(original);
when(spy.getPort()).thenReturn(this.ports.get(HTTP_PORT));
when(spy.getAdminPort()).thenReturn(this.ports.get(ADMIN_PORT));
return spy;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment