Search in sources :

Example 1 with Origin

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

the class BackendServicesTest method derivesApplicationIdsOnOriginsWhenUsingYamlConstructor.

@Test
public void derivesApplicationIdsOnOriginsWhenUsingYamlConstructor() {
    BackendService before = BackendService.newBackendServiceBuilder().id("generic_app").origins(newOriginBuilder("localhost", 8080).id("origin1").build()).build();
    BackendServices backendServices = new BackendServices(singletonList(before));
    Origin origin = first(backendServices.first().origins());
    assertThat(origin.applicationId(), is(id("generic_app")));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) BackendService(com.hotels.styx.api.extension.service.BackendService) Test(org.junit.jupiter.api.Test)

Example 2 with Origin

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

the class DashboardDataSupplierTest method originsHaveStatuses.

@Test
public void originsHaveStatuses() throws JsonProcessingException {
    MemoryBackedRegistry<BackendService> registry = new MemoryBackedRegistry<>();
    DashboardDataSupplier supplier = new DashboardDataSupplier(registry, environment, styxConfig);
    Origin foo1 = origin("foo1");
    Origin foo2 = origin("foo2");
    registry.add(backend("foo", foo1, foo2));
    registry.add(backend("bar", origin("bar1")));
    // Set statuses
    environment.eventBus().post(new OriginsSnapshot(id("foo"), pools(foo1), pools(foo2), pools()));
    DashboardData.Downstream downstream = supplier.get().downstream();
    DashboardData.Backend fooBackend = downstream.backend("STYXPRES-foo");
    assertThat(downstream.backendIds(), containsInAnyOrder("STYXPRES-foo", "STYXPRES-bar"));
    assertThat(fooBackend.statusesByOriginId(), is(equalTo(Map.of("foo1", "active", "foo2", "inactive"))));
    assertThat(fooBackend.origin("foo1").status(), is("active"));
    // Set statuses again
    environment.eventBus().post(new OriginsSnapshot(id("foo"), pools(), pools(foo1), pools(foo2)));
    fooBackend = supplier.get().downstream().backend("STYXPRES-foo");
    assertThat(fooBackend.statusesByOriginId(), is(equalTo(Map.of("foo1", "inactive", "foo2", "disabled"))));
    assertThat(fooBackend.origin("foo1").status(), is("inactive"));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) BackendService(com.hotels.styx.api.extension.service.BackendService) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 3 with Origin

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

the class OriginRestrictionLoadBalancingStrategyTest method setUp.

@BeforeEach
public void setUp() {
    delegate = mock(LoadBalancer.class);
    when(delegate.choose(any(LoadBalancer.Preferences.class))).thenReturn(Optional.of(origins.get(0)));
    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);
    log = new LoggingTestSupport(OriginRestrictionLoadBalancingStrategy.class);
}
Also used : Origin(com.hotels.styx.api.extension.Origin) ActiveOrigins(com.hotels.styx.api.extension.ActiveOrigins) RemoteHost(com.hotels.styx.api.extension.RemoteHost) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) LoggingTestSupport(com.hotels.styx.support.matchers.LoggingTestSupport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Origin

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

the class OriginRestrictionLoadBalancingStrategyTest method logsInvalidPatterns.

@Test
public void logsInvalidPatterns() {
    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);
    strategy.choose(lbPreference(Optional.of("*-01")));
    assertThat(log.lastMessage(), is(loggingEvent(ERROR, "Invalid origin restriction cookie value=.*, Cause=Dangling meta character .*")));
}
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 5 with Origin

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

the class OriginRestrictionLoadBalancingStrategyTest method usesAllOriginsWhenRegularExpressionMatchesAll.

@Test
public void usesAllOriginsWhenRegularExpressionMatchesAll() {
    Random mockRandom = mock(Random.class);
    when(mockRandom.nextInt(any(Integer.class))).thenReturn(3);
    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(".*")));
    assertThat(chosenOne.get(), isOneOf(origins.get(3)));
    verify(mockRandom).nextInt(eq(7));
}
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)

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