Skip to content

Instantly share code, notes, and snippets.

@chids
Created November 1, 2012 14:23
Show Gist options
  • Select an option

  • Save chids/3993909 to your computer and use it in GitHub Desktop.

Select an option

Save chids/3993909 to your computer and use it in GitHub Desktop.

Revisions

  1. chids created this gist Nov 1, 2012.
    30 changes: 30 additions & 0 deletions DropwizardPorts.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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;
    }
    }