Search in sources :

Example 26 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class OriginRestrictionLoadBalancingStrategyTest method usesNoOriginsWhenRegularExpressionMatchesNone.

@Test
public void usesNoOriginsWhenRegularExpressionMatchesNone() {
    Random mockRandom = mock(Random.class);
    strategy = new OriginRestrictionLoadBalancingStrategy(new ActiveOrigins() {

        @Override
        public Iterable<RemoteHost> snapshot() {
            return origins;
        }

        @Override
        public String getApplicationId() {
            return null;
        }

        @Override
        public List<Origin> origins() {
            return null;
        }
    }, delegate, mockRandom);
    Optional<RemoteHost> chosenOne = strategy.choose(lbPreference(Optional.of("foo")));
    assertThat(chosenOne, is(empty()));
    verify(mockRandom, never()).nextInt(any(Integer.class));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) ActiveOrigins(com.hotels.styx.api.extension.ActiveOrigins) RemoteHost(com.hotels.styx.api.extension.RemoteHost) Random(java.util.Random) Test(org.junit.jupiter.api.Test)

Example 27 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class OriginRestrictionLoadBalancingStrategyTest method usesMultipleOriginsMatchingRegularExpression.

@Test
public void usesMultipleOriginsMatchingRegularExpression() {
    Random mockRandom = mock(Random.class);
    when(mockRandom.nextInt(eq(3))).thenReturn(1);
    strategy = new OriginRestrictionLoadBalancingStrategy(new ActiveOrigins() {

        @Override
        public Iterable<RemoteHost> snapshot() {
            return origins;
        }

        @Override
        public String getApplicationId() {
            return null;
        }

        @Override
        public List<Origin> origins() {
            return null;
        }
    }, delegate, mockRandom);
    Optional<RemoteHost> chosenOne = strategy.choose(lbPreference(Optional.of("origin-[2-4]")));
    verify(mockRandom).nextInt(eq(3));
    assertThat(chosenOne.get(), is(origins.get(3)));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) ActiveOrigins(com.hotels.styx.api.extension.ActiveOrigins) RemoteHost(com.hotels.styx.api.extension.RemoteHost) Random(java.util.Random) Test(org.junit.jupiter.api.Test)

Example 28 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class OriginsInventoryTest method stopsAndRestartsMonitoringModifiedOrigins.

@Test
public void stopsAndRestartsMonitoringModifiedOrigins() {
    Origin originV1 = newOriginBuilder("acme01.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
    Origin originV2 = newOriginBuilder("acme02.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
    inventory.setOrigins(originV1);
    verify(monitor).monitor(singleton(originV1));
    inventory.setOrigins(originV2);
    verify(monitor).stopMonitoring(singleton(originV1));
    verify(monitor).monitor(singleton(originV2));
}
Also used : DisableOrigin(com.hotels.styx.client.origincommands.DisableOrigin) EnableOrigin(com.hotels.styx.client.origincommands.EnableOrigin) Origin(com.hotels.styx.api.extension.Origin) Test(org.junit.jupiter.api.Test)

Example 29 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class OriginsInventoryTest method updatesOriginHostName.

@Test
public void updatesOriginHostName() {
    Origin originV1 = newOriginBuilder("acme01.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
    Origin originV2 = newOriginBuilder("acme02.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
    inventory.setOrigins(originV1);
    assertThat(inventory.originCount(ACTIVE), is(1));
    verify(monitor).monitor(singleton(originV1));
    assertThat(gaugeValue("generic-app", "acme-01"), isValue(1.0));
    verify(eventBus).post(any(OriginsSnapshot.class));
    inventory.setOrigins(originV2);
    assertThat(inventory.originCount(ACTIVE), is(1));
    verify(monitor).stopMonitoring(singleton(originV1));
    verify(monitor).monitor(singleton(originV2));
    assertThat(gaugeValue("generic-app", "acme-01"), isValue(1.0));
    verify(eventBus, times(2)).post(any(OriginsSnapshot.class));
}
Also used : DisableOrigin(com.hotels.styx.client.origincommands.DisableOrigin) EnableOrigin(com.hotels.styx.client.origincommands.EnableOrigin) Origin(com.hotels.styx.api.extension.Origin) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 30 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class OriginsInventoryTest method shutsConnectionPoolForRemovedOrigin.

@Test
public void shutsConnectionPoolForRemovedOrigin() {
    Origin originV1 = newOriginBuilder("acme01.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
    Origin originV2 = newOriginBuilder("acme02.com", 80).applicationId(GENERIC_APP).id("acme-02").build();
    ConnectionPool.Factory connectionFactory = mock(ConnectionPool.Factory.class);
    ConnectionPool pool1 = mock(ConnectionPool.class);
    when(pool1.getOrigin()).thenReturn(originV1);
    ConnectionPool pool2 = mock(ConnectionPool.class);
    when(pool2.getOrigin()).thenReturn(originV2);
    when(connectionFactory.create(eq(originV1))).thenReturn(pool1);
    when(connectionFactory.create(eq(originV2))).thenReturn(pool2);
    inventory = new OriginsInventory(eventBus, GENERIC_APP, monitor, connectionFactory, hostClientFactory, new CentralisedMetrics(meterRegistry));
    inventory.setOrigins(originV1, originV2);
    inventory.setOrigins(originV2);
    verify(pool1).close();
}
Also used : DisableOrigin(com.hotels.styx.client.origincommands.DisableOrigin) EnableOrigin(com.hotels.styx.client.origincommands.EnableOrigin) Origin(com.hotels.styx.api.extension.Origin) ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Test(org.junit.jupiter.api.Test)

Aggregations

Origin (com.hotels.styx.api.extension.Origin)49 Test (org.junit.jupiter.api.Test)40 RemoteHost (com.hotels.styx.api.extension.RemoteHost)15 ActiveOrigins (com.hotels.styx.api.extension.ActiveOrigins)11 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)11 Random (java.util.Random)9 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)8 LoadBalancer (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer)8 HttpHandler (com.hotels.styx.api.HttpHandler)6 BackendService (com.hotels.styx.api.extension.service.BackendService)6 ConnectionSettings (com.hotels.styx.client.ConnectionSettings)6 Id (com.hotels.styx.api.Id)5 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)5 OriginUnreachableException (com.hotels.styx.api.exceptions.OriginUnreachableException)5 DisableOrigin (com.hotels.styx.client.origincommands.DisableOrigin)5 EnableOrigin (com.hotels.styx.client.origincommands.EnableOrigin)5 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)5 EventBus (com.google.common.eventbus.EventBus)4 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)4 Context (com.hotels.styx.api.HttpInterceptor.Context)4