StickyEndpointSelectionStrategy implements EndpointSelectionStrategy { @Override public EndpointSelector newSelector(EndpointGroup endpointGroup) { return new StickyEndpointSelector(endpointGroup, requestContextHasher); } StickyEndpointSelectionStrategy(ToLongFunction<? super ClientRequestContext> requestContextHasher); @Override EndpointSelector newSelector(EndpointGroup endpointGroup);  }
@Test void select() { assertThat(strategy.newSelector(staticGroup)).isNotNull(); final int selectTime = 5; final Endpoint ep1 = staticGroup.selectNow(contextWithHeader(STICKY_HEADER_NAME, "armeria1")); final Endpoint ep2 = staticGroup.selectNow(contextWithHeader(STICKY_HEADER_NAME, "armeria2")); final Endpoint ep3 = staticGroup.selectNow(contextWithHeader(STICKY_HEADER_NAME, "armeria3")); for (int i = 0; i < selectTime; i++) { assertThat(staticGroup.selectNow(contextWithHeader(STICKY_HEADER_NAME, "armeria1"))).isEqualTo(ep1); assertThat(staticGroup.selectNow(contextWithHeader(STICKY_HEADER_NAME, "armeria2"))).isEqualTo(ep2); assertThat(staticGroup.selectNow(contextWithHeader(STICKY_HEADER_NAME, "armeria3"))).isEqualTo(ep3); } final Endpoint ep4 = Endpoint.parse("localhost:9494"); dynamicGroup.addEndpoint(ep4); assertThat(dynamicGroup.selectNow(contextWithHeader(STICKY_HEADER_NAME, "armeria1"))).isEqualTo(ep4); dynamicGroup.removeEndpoint(ep4); assertThat(dynamicGroup.selectNow(contextWithHeader(STICKY_HEADER_NAME, "armeria1"))).isNull(); }