Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #264: Remove unnecessary calls to freePort. #265

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.github.tomakehurst.wiremock.client.WireMock._
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import com.hotels.styx.api.extension.Origin
import com.hotels.styx.api.extension.Origin._
import com.hotels.styx.common.FreePorts._
import com.hotels.styx.support.server.FakeHttpServer

trait OriginSupport {
Expand All @@ -33,7 +32,7 @@ trait OriginSupport {
}

def originAndWireMockServer(applicationId: String, originId: String): (Origin, WireMockServer) = {
val server = new WireMockServer(wireMockConfig.port(freePort()))
val server = new WireMockServer(wireMockConfig.dynamicPort())
server.start()

val origin = newOriginBuilder("localhost", server.port()).applicationId(applicationId).id(originId).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import static com.hotels.styx.api.Id.GENERIC_APP;
import static com.hotels.styx.api.Id.id;
import static com.hotels.styx.api.extension.Origin.newOriginBuilder;
import static com.hotels.styx.common.FreePorts.freePort;
import static com.hotels.styx.client.OriginsInventory.OriginState.ACTIVE;
import static com.hotels.styx.client.OriginsInventory.OriginState.DISABLED;
import static com.hotels.styx.api.extension.service.ConnectionPoolSettings.defaultConnectionPoolSettings;
Expand All @@ -61,8 +60,8 @@
import static org.mockito.Mockito.when;

public class OriginsInventoryTest {
private static final Origin ORIGIN_1 = newOriginBuilder("localhost", freePort()).applicationId(GENERIC_APP).id("app-01").build();
private static final Origin ORIGIN_2 = newOriginBuilder("localhost", freePort()).applicationId(GENERIC_APP).id("app-02").build();
private static final Origin ORIGIN_1 = newOriginBuilder("localhost", 8001).applicationId(GENERIC_APP).id("app-01").build();
private static final Origin ORIGIN_2 = newOriginBuilder("localhost", 8002).applicationId(GENERIC_APP).id("app-02").build();

private final ConnectionPool.Factory connectionFactory = connectionPoolFactory();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import static com.hotels.styx.api.extension.Origin.newOriginBuilder;
import static com.hotels.styx.api.extension.RemoteHost.remoteHost;
import static com.hotels.styx.common.FreePorts.freePort;
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
Expand All @@ -38,9 +37,9 @@
import static org.mockito.Mockito.when;

public class BusyConnectionsStrategyTest {
private static final Origin ORIGIN_ONE = newOriginBuilder("localhost", freePort()).id("one").build();
private static final Origin ORIGIN_TWO = newOriginBuilder("localhost", freePort()).id("two").build();
private static final Origin ORIGIN_THREE = newOriginBuilder("localhost", freePort()).id("three").build();
private static final Origin ORIGIN_ONE = newOriginBuilder("localhost", 8001).id("one").build();
private static final Origin ORIGIN_TWO = newOriginBuilder("localhost", 8002).id("two").build();
private static final Origin ORIGIN_THREE = newOriginBuilder("localhost", 8003).id("three").build();

private final ActiveOrigins activeOrigins = mock(ActiveOrigins.class);
private final BusyConnectionsStrategy strategy = new BusyConnectionsStrategy(activeOrigins);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@

import static com.hotels.styx.api.extension.Origin.newOriginBuilder;
import static com.hotels.styx.api.extension.RemoteHost.remoteHost;
import static com.hotels.styx.common.FreePorts.freePort;
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class PowerOfTwoStrategyTest {
final Origin ORIGIN_ONE = newOriginBuilder("localhost", freePort()).id("one").build();
final Origin ORIGIN_TWO = newOriginBuilder("localhost", freePort()).id("two").build();
final Origin ORIGIN_THREE = newOriginBuilder("localhost", freePort()).id("three").build();
final Origin ORIGIN_FOUR = newOriginBuilder("localhost", freePort()).id("four").build();
final Origin ORIGIN_ONE = newOriginBuilder("localhost", 8001).id("one").build();
final Origin ORIGIN_TWO = newOriginBuilder("localhost", 8002).id("two").build();
final Origin ORIGIN_THREE = newOriginBuilder("localhost", 8003).id("three").build();
final Origin ORIGIN_FOUR = newOriginBuilder("localhost", 8004).id("four").build();

private final RemoteHost HOST_ONE = remoteHost(ORIGIN_ONE, mock(HttpHandler.class), lbMetrics(5));
private final RemoteHost HOST_TWO = remoteHost(ORIGIN_TWO, mock(HttpHandler.class), lbMetrics(6));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.util.concurrent.Service.State.FAILED;
import static com.hotels.styx.api.configuration.Configuration.EMPTY_CONFIGURATION;
import static com.hotels.styx.common.FreePorts.freePort;
import static com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin;
import static com.hotels.styx.support.matchers.LoggingEventMatcher.loggingEvent;
import static io.netty.util.ResourceLeakDetector.Level.DISABLED;
Expand Down Expand Up @@ -220,11 +219,11 @@ private static StyxServer styxServerWithBackendServiceRegistry(StyxService backe

private static StyxConfig styxConfig(Configuration baseConfiguration) {
ProxyServerConfig proxyConfig = new ProxyServerConfig.Builder()
.setHttpConnector(new HttpConnectorConfig(freePort()))
.setHttpConnector(new HttpConnectorConfig(0))
.build();

AdminServerConfig adminConfig = new AdminServerConfig.Builder()
.setHttpConnector(new HttpConnectorConfig(freePort()))
.setHttpConnector(new HttpConnectorConfig(0))
.build();

Configuration config = new MapBackedConfiguration(baseConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import static com.hotels.styx.api.Id.id;
import static com.hotels.styx.api.extension.Origin.newOriginBuilder;
import static com.hotels.styx.api.extension.RemoteHost.remoteHost;
import static com.hotels.styx.common.FreePorts.freePort;
import static com.hotels.styx.support.api.BlockingObservables.getFirst;
import static com.hotels.styx.support.api.matchers.HttpResponseBodyMatcher.hasBody;
import static com.hotels.styx.support.api.matchers.HttpResponseStatusMatcher.hasStatus;
Expand All @@ -50,13 +49,13 @@
import static org.mockito.Mockito.mock;

public class OriginsCommandHandlerTest {
final Origin activeOrigin = newOriginBuilder("localhost", freePort()).applicationId("activeAppId").id("activeOriginId").build();
final Origin activeOrigin = newOriginBuilder("localhost", 8081).applicationId("activeAppId").id("activeOriginId").build();
final Set<RemoteHost> activeOrigins = singleton(remoteHost(activeOrigin, mock(HttpHandler.class), mock(LoadBalancingMetricSupplier.class)));

final Origin disabledOrigin = newOriginBuilder("localhost", freePort()).applicationId("activeAppId").id("disabledOriginId").build();
final Origin disabledOrigin = newOriginBuilder("localhost", 8082).applicationId("activeAppId").id("disabledOriginId").build();
final Set<RemoteHost> disabledOrigins = singleton(remoteHost(disabledOrigin, mock(HttpHandler.class), mock(LoadBalancingMetricSupplier.class)));

final Origin inactiveOrigin = newOriginBuilder("localhost", freePort()).applicationId("activeAppId").id("inactiveOriginId").build();
final Origin inactiveOrigin = newOriginBuilder("localhost", 8083).applicationId("activeAppId").id("inactiveOriginId").build();
final Set<RemoteHost> inactiveOrigins = singleton(remoteHost(inactiveOrigin, mock(HttpHandler.class), mock(LoadBalancingMetricSupplier.class)));

final EventBus eventBus = new EventBus();
Expand Down
Loading