Created
November 1, 2012 14:23
-
-
Save chids/3993909 to your computer and use it in GitHub Desktop.
Runtime setting of Dropwizard HTTP and admin port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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