From e67361f8211316647b9b20434d428ed2c5d3d044 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Tue, 7 Apr 2020 11:40:45 -0400 Subject: [PATCH] Removes concurrency-limits module. fixes gh-3768 --- pom.xml | 1 - .../pom.xml | 70 ------------ .../micrometer/MicrometerMetricRegistry.java | 55 ---------- .../reactive/ConcurrencyLimitsWebFilter.java | 56 ---------- ...iveConcurrencyLimitsAutoConfiguration.java | 69 ------------ .../ServerWebExchangeLimiterBuilder.java | 102 ------------------ .../ConcurrencyLimitsHandlerInterceptor.java | 93 ---------------- ...MvcConcurrencyLimitsAutoConfiguration.java | 80 -------------- .../main/resources/META-INF/spring.factories | 3 - .../MicrometerMetricRegistryTests.java | 56 ---------- .../ConcurrencyLimitsWebFilterTests.java | 75 ------------- .../test/AbstractConcurrencyLimitsTests.java | 80 -------------- .../concurrency/limits/test/Responses.java | 37 ------- ...currencyLimitsHandlerInterceptorTests.java | 70 ------------ spring-cloud-netflix-dependencies/pom.xml | 11 -- 15 files changed, 858 deletions(-) delete mode 100644 spring-cloud-netflix-concurrency-limits/pom.xml delete mode 100644 spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/micrometer/MicrometerMetricRegistry.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ConcurrencyLimitsWebFilter.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ReactiveConcurrencyLimitsAutoConfiguration.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ServerWebExchangeLimiterBuilder.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/web/ConcurrencyLimitsHandlerInterceptor.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/web/MvcConcurrencyLimitsAutoConfiguration.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/main/resources/META-INF/spring.factories delete mode 100644 spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/micrometer/MicrometerMetricRegistryTests.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ConcurrencyLimitsWebFilterTests.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/test/AbstractConcurrencyLimitsTests.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/test/Responses.java delete mode 100644 spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/web/ConcurrencyLimitsHandlerInterceptorTests.java diff --git a/pom.xml b/pom.xml index c13e9ef44..c5aac1995 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,6 @@ spring-cloud-netflix-dependencies - spring-cloud-netflix-concurrency-limits spring-cloud-netflix-eureka-client spring-cloud-netflix-eureka-server spring-cloud-starter-netflix-eureka-client diff --git a/spring-cloud-netflix-concurrency-limits/pom.xml b/spring-cloud-netflix-concurrency-limits/pom.xml deleted file mode 100644 index 84a7a4fc0..000000000 --- a/spring-cloud-netflix-concurrency-limits/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - 4.0.0 - - org.springframework.cloud - spring-cloud-netflix - 3.0.0.BUILD-SNAPSHOT - .. - - spring-cloud-netflix-concurrency-limits - jar - Spring Cloud Netflix Concurrency Limits - https://projects.spring.io/spring-cloud/ - - - com.netflix.concurrency-limits - concurrency-limits-core - - - com.netflix.concurrency-limits - concurrency-limits-servlet - true - - - org.springframework.boot - spring-boot-starter-web - true - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - org.springframework.boot - spring-boot-starter-webflux - true - - - org.springframework.boot - spring-boot-starter-actuator - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.cloud - spring-cloud-test-support - test - - - io.projectreactor - reactor-test - test - - - diff --git a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/micrometer/MicrometerMetricRegistry.java b/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/micrometer/MicrometerMetricRegistry.java deleted file mode 100644 index 4273e3f3c..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/micrometer/MicrometerMetricRegistry.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.micrometer; - -import java.util.function.Supplier; - -import com.netflix.concurrency.limits.MetricRegistry; -import io.micrometer.core.instrument.DistributionSummary; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tags; - -/** - * A Micrometer-specific {@link MetricRegistry} implementation. - * - * @author Spencer Gibb - * @deprecated to be removed in 3.0.0 - */ -@Deprecated -public class MicrometerMetricRegistry implements MetricRegistry { - - private final MeterRegistry meterRegistry; - - // TODO: baseId? - - public MicrometerMetricRegistry(MeterRegistry meterRegistry) { - this.meterRegistry = meterRegistry; - } - - @Override - public SampleListener registerDistribution(String id, String... tagNameValuePairs) { - DistributionSummary summary = this.meterRegistry.summary(id, tagNameValuePairs); - return value -> summary.record(value.longValue()); - } - - @Override - public void registerGauge(String id, Supplier supplier, - String... tagNameValuePairs) { - this.meterRegistry.gauge(id, Tags.of(tagNameValuePairs), supplier.get()); - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ConcurrencyLimitsWebFilter.java b/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ConcurrencyLimitsWebFilter.java deleted file mode 100644 index a0b7a0c37..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ConcurrencyLimitsWebFilter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.reactive; - -import com.netflix.concurrency.limits.Limiter; -import reactor.core.publisher.Mono; - -import org.springframework.http.HttpStatus; -import org.springframework.web.server.ServerWebExchange; -import org.springframework.web.server.WebFilter; -import org.springframework.web.server.WebFilterChain; - -/** - * A {@link WebFilter} implementation providing the possibility to use Netflix - * {@link Limiter} to handle requests. - * - * @author Spencer Gibb - * @deprecated to be removed in 3.0.0 - */ -@Deprecated -public class ConcurrencyLimitsWebFilter implements WebFilter { - - private final Limiter limiter; - - public ConcurrencyLimitsWebFilter(Limiter limiter) { - this.limiter = limiter; - } - - @Override - public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { - return limiter.acquire(exchange) - .map(listener -> chain.filter(exchange) - .doOnSuccess(v -> listener.onSuccess()) - .doOnError(throwable -> listener.onIgnore())) - .orElseGet(() -> { - exchange.getResponse().setStatusCode(HttpStatus.TOO_MANY_REQUESTS); - // TODO: set body - return exchange.getResponse().setComplete(); - }); - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ReactiveConcurrencyLimitsAutoConfiguration.java b/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ReactiveConcurrencyLimitsAutoConfiguration.java deleted file mode 100644 index d8223330f..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ReactiveConcurrencyLimitsAutoConfiguration.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.reactive; - -import java.util.function.Consumer; - -import com.netflix.concurrency.limits.Limiter; -import reactor.core.publisher.Mono; - -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.server.ServerWebExchange; -import org.springframework.web.server.WebFilter; - -/** - * Reactive autoconfiguration class for registering Netflix {@link Limiter} bean. - * - * @author Spencer Gibb - * @deprecated to be removed in 3.0.0 - */ -@Deprecated -@Configuration(proxyBeanMethods = false) -@ConditionalOnWebApplication(type = Type.REACTIVE) -@ConditionalOnClass({ WebFilter.class, Mono.class }) -public class ReactiveConcurrencyLimitsAutoConfiguration { - - private final ObjectProvider> configurerProvider; - - public ReactiveConcurrencyLimitsAutoConfiguration( - ObjectProvider> configurerProvider) { - this.configurerProvider = configurerProvider; - } - - @Bean - @ConditionalOnMissingBean - public Limiter webfluxLimiter() { - ServerWebExchangeLimiterBuilder builder = new ServerWebExchangeLimiterBuilder(); - - this.configurerProvider.ifAvailable(consumer -> consumer.accept(builder)); - - return builder.build(); - } - - @Bean - public ConcurrencyLimitsWebFilter concurrencyLimitsWebFilter( - Limiter limiter) { - return new ConcurrencyLimitsWebFilter(limiter); - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ServerWebExchangeLimiterBuilder.java b/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ServerWebExchangeLimiterBuilder.java deleted file mode 100644 index a355ec154..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ServerWebExchangeLimiterBuilder.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.reactive; - -import java.util.Optional; -import java.util.function.Function; - -import com.netflix.concurrency.limits.limiter.AbstractPartitionedLimiter; - -import org.springframework.web.server.ServerWebExchange; - -/** - * Builder for ServerWebExchange Limiter. - * - * @author Spencer Gibb - * @deprecated to be removed in 3.0.0 - */ -@Deprecated -public class ServerWebExchangeLimiterBuilder extends - AbstractPartitionedLimiter.Builder { - - /** - * Partition the limit by header. - * @param name header name - * @return Chainable builder - */ - public ServerWebExchangeLimiterBuilder partitionByHeader(String name) { - return partitionResolver( - exchange -> exchange.getRequest().getHeaders().getFirst(name)); - } - - /** - * Partition the limit by {@link Principal}. Percentages of the limit are partitioned - * to named groups. Group membership is derived from the provided mapping function. - * @param principalToGroup Mapping function from {@link Principal} to a named group. - * @param configurer Configuration function though which group percentages may be - * specified Unspecified group values may only use excess capacity. - * @return Chainable builder - */ - /* - * public ServerWebExchangeLimiterBuilder partitionByUserPrincipal(Function principalToGroup, - * Consumer> configurer) { return - * partitionResolver( exchange -> - * Optional.ofNullable(request.getUserPrincipal()).map(principalToGroup).orElse(null), - * configurer); } - */ - - /** - * Partition the limit by request attribute. - * @param name attribute name - * @return Chainable builder - */ - public ServerWebExchangeLimiterBuilder partitionByAttribute(String name) { - return partitionResolver(exchange -> exchange.getAttribute(name)); - } - - /** - * Partition the limit by request parameter. - * @param name parameter name - * @return Chainable builder - */ - public ServerWebExchangeLimiterBuilder partitionByParameter(String name) { - return partitionResolver( - exchange -> exchange.getRequest().getQueryParams().getFirst(name)); - } - - /** - * Partition the limit by the full path. Percentages of the limit are partitioned to - * named groups. Group membership is derived from the provided mapping function. - * @param pathToGroup Mapping function from full path to a named group. - * @return Chainable builder - */ - public ServerWebExchangeLimiterBuilder partitionByPathInfo( - Function pathToGroup) { - return partitionResolver(exchange -> { - // TODO: pathWithinApplication? - String path = exchange.getRequest().getPath().contextPath().value(); - return Optional.ofNullable(path).map(pathToGroup).orElse(null); - }); - } - - @Override - protected ServerWebExchangeLimiterBuilder self() { - return this; - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/web/ConcurrencyLimitsHandlerInterceptor.java b/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/web/ConcurrencyLimitsHandlerInterceptor.java deleted file mode 100644 index 5ef100cd9..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/web/ConcurrencyLimitsHandlerInterceptor.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.web; - -import java.io.IOException; -import java.util.Optional; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import com.netflix.concurrency.limits.Limiter; -import com.netflix.concurrency.limits.Limiter.Listener; - -import org.springframework.http.HttpStatus; -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.ModelAndView; - -/** - * A {@link HandlerInterceptor} implementation providing the possibility to use Netflix - * {@link Limiter} to handle requests. - * - * @author Spencer Gibb - * @deprecated to be removed in 3.0.0 - */ -@Deprecated -public class ConcurrencyLimitsHandlerInterceptor implements HandlerInterceptor { - - private final Limiter limiter; - - public ConcurrencyLimitsHandlerInterceptor(Limiter limiter) { - this.limiter = limiter; - } - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, - Object handler) throws Exception { - Optional listener = limiter.acquire(request); - if (listener.isPresent()) { - request.setAttribute("concurrency_limiter_listener", listener.get()); - return true; - } - - try { - // TODO: headers with information? - /* - * response.sendError(HttpStatus.TOO_MANY_REQUESTS.value()); - * response.getWriter().print("Concurrency limit exceeded"); - */ - response.sendError(HttpStatus.TOO_MANY_REQUESTS.value(), - "Concurrency limit exceeded"); - } - catch (IOException e) { - // ignore - } - return false; - } - - @Override - public void postHandle(HttpServletRequest request, HttpServletResponse response, - Object handler, ModelAndView modelAndView) throws Exception { - - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, - Object handler, Exception ex) throws Exception { - Listener listener = (Listener) request - .getAttribute("concurrency_limiter_listener"); - if (listener != null) { - if (ex != null) { - listener.onIgnore(); - } - else { - listener.onSuccess(); - } - } - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/web/MvcConcurrencyLimitsAutoConfiguration.java b/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/web/MvcConcurrencyLimitsAutoConfiguration.java deleted file mode 100644 index fb40d30c0..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/main/java/org/springframework/cloud/netflix/concurrency/limits/web/MvcConcurrencyLimitsAutoConfiguration.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.web; - -import java.util.function.Consumer; - -import javax.servlet.http.HttpServletRequest; - -import com.netflix.concurrency.limits.Limiter; -import com.netflix.concurrency.limits.servlet.ServletLimiterBuilder; - -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -/** - * MVC autoconfiguration class for registering Netflix {@link Limiter} bean. - * - * @author Spencer Gibb - * @deprecated to be removed in 3.0.0 - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnWebApplication(type = Type.SERVLET) -@ConditionalOnClass({ HttpServletRequest.class, HandlerInterceptor.class }) -@Deprecated -public class MvcConcurrencyLimitsAutoConfiguration implements WebMvcConfigurer { - - private final ObjectProvider> configurerProvider; - - public MvcConcurrencyLimitsAutoConfiguration( - ObjectProvider> configurerProvider) { - this.configurerProvider = configurerProvider; - } - - @Bean - @ConditionalOnMissingBean - public Limiter servletLimiter() { - ServletLimiterBuilder builder = new ServletLimiterBuilder(); - - this.configurerProvider.ifAvailable(consumer -> consumer.accept(builder)); - - return builder.build(); - } - - @Configuration(proxyBeanMethods = false) - protected static class HandlerInterceptorConfiguration implements WebMvcConfigurer { - - @Autowired - private Limiter limiter; - - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new ConcurrencyLimitsHandlerInterceptor(limiter)); - } - - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/main/resources/META-INF/spring.factories b/spring-cloud-netflix-concurrency-limits/src/main/resources/META-INF/spring.factories deleted file mode 100644 index f7336e13e..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.springframework.cloud.netflix.concurrency.limits.reactive.ReactiveConcurrencyLimitsAutoConfiguration,\ -org.springframework.cloud.netflix.concurrency.limits.web.MvcConcurrencyLimitsAutoConfiguration diff --git a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/micrometer/MicrometerMetricRegistryTests.java b/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/micrometer/MicrometerMetricRegistryTests.java deleted file mode 100644 index 73c266d2b..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/micrometer/MicrometerMetricRegistryTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.micrometer; - -import io.micrometer.core.instrument.Gauge; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Ignore; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class MicrometerMetricRegistryTests { - - @Test - public void testGuage() { - MeterRegistry registry = new SimpleMeterRegistry(); - MicrometerMetricRegistry metricRegistry = new MicrometerMetricRegistry(registry); - - metricRegistry.registerGauge("bar", () -> 10); - - Gauge bar = registry.get("bar").gauge(); - - assertThat(bar.value()).isEqualTo(10.0); - } - - @Test - @Ignore // FIXME: micrometer doesn't allow recreating a gauge - public void testUnregister() { - MeterRegistry registry = new SimpleMeterRegistry(); - MicrometerMetricRegistry metricRegistry = new MicrometerMetricRegistry(registry); - - metricRegistry.registerGauge("bar", () -> 10); - metricRegistry.registerGauge("bar", () -> 20); - - Gauge bar = registry.get("bar").gauge(); - - assertThat(bar.value()).isEqualTo(20.0); - - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ConcurrencyLimitsWebFilterTests.java b/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ConcurrencyLimitsWebFilterTests.java deleted file mode 100644 index 589fa27b2..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/reactive/ConcurrencyLimitsWebFilterTests.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.reactive; - -import java.util.function.Consumer; - -import com.netflix.concurrency.limits.limit.FixedLimit; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.cloud.netflix.concurrency.limits.test.AbstractConcurrencyLimitsTests; -import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Import; -import org.springframework.util.SocketUtils; -import org.springframework.web.reactive.function.client.WebClient; - -@RunWith(ModifiedClassPathRunner.class) -@ClassPathExclusions({ "spring-boot-starter-tomcat-*", "tomcat-embed-*" }) -public class ConcurrencyLimitsWebFilterTests extends AbstractConcurrencyLimitsTests { - - private int port; - - @Before - public void init() { - port = SocketUtils.findAvailableTcpPort(); - client = WebClient.create("http://localhost:" + port); - } - - @Test - @SuppressWarnings("Duplicates") - public void webFilterWorks() { - - try (ConfigurableApplicationContext context = new SpringApplicationBuilder() - .properties("server.port=" + port, - "spring.main.web-application-type=reactive") - .sources(TestConfig.class).run()) { - - assertLimiter(client); - } - } - - @SpringBootConfiguration - @EnableAutoConfiguration - @Import(HelloControllerConfiguration.class) - protected static class TestConfig { - - @Bean - public Consumer limiterBuilderConfigurer() { - return limiterBuilder -> limiterBuilder.limit(FixedLimit.of(1)); - } - - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/test/AbstractConcurrencyLimitsTests.java b/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/test/AbstractConcurrencyLimitsTests.java deleted file mode 100644 index 5a8852baf..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/test/AbstractConcurrencyLimitsTests.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.test; - -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; -import reactor.util.function.Tuple2; - -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.client.WebClient; - -import static org.assertj.core.api.Assertions.assertThat; - -public class AbstractConcurrencyLimitsTests { - - protected WebClient client; - - protected void assertLimiter(WebClient client) { - // TODO: assert the body - Flux> flux = Flux.range(1, 100) - .flatMap(integer -> client.get().uri("/").exchange(), 4) - // .log("reqs", Level.INFO) - .flatMap(response -> response.bodyToMono(String.class).defaultIfEmpty("") - /* .log("body2mono", Level.INFO) */ - .zipWith(Mono.just(response.statusCode()))); - - Responses responses = new Responses(); - StepVerifier.create(flux).thenConsumeWhile(response -> true, response -> { - HttpStatus status = response.getT2(); - if (status.equals(HttpStatus.OK)) { - responses.success.incrementAndGet(); - } - else if (status.equals(HttpStatus.TOO_MANY_REQUESTS)) { - responses.tooManyReqs.incrementAndGet(); - String body = response.getT1(); - // TODO: body from handler isn't coming thru - // assertThat(body).isEqualTo("Concurrency limit exceeded"); - } - else { - responses.other.incrementAndGet(); - } - }).verifyComplete(); - - System.out.println("Responses: " + responses); - - assertThat(responses.other).hasValue(0); - assertThat(responses.tooManyReqs).hasValueGreaterThanOrEqualTo(1); - - } - - @Configuration(proxyBeanMethods = false) - @RestController - protected static class HelloControllerConfiguration { - - @GetMapping - public String get() { - return "Hello"; - } - - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/test/Responses.java b/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/test/Responses.java deleted file mode 100644 index 49c16ccdd..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/test/Responses.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.test; - -import java.util.concurrent.atomic.AtomicInteger; - -import org.springframework.core.style.ToStringCreator; - -public class Responses { - - public AtomicInteger success = new AtomicInteger(0); - - public AtomicInteger tooManyReqs = new AtomicInteger(0); - - public AtomicInteger other = new AtomicInteger(0); - - @Override - public String toString() { - return new ToStringCreator(this).append("success", success) - .append("tooManyReqs", tooManyReqs).append("other", other).toString(); - } - -} diff --git a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/web/ConcurrencyLimitsHandlerInterceptorTests.java b/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/web/ConcurrencyLimitsHandlerInterceptorTests.java deleted file mode 100644 index 64fad1155..000000000 --- a/spring-cloud-netflix-concurrency-limits/src/test/java/org/springframework/cloud/netflix/concurrency/limits/web/ConcurrencyLimitsHandlerInterceptorTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2013-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.netflix.concurrency.limits.web; - -import java.util.function.Consumer; - -import com.netflix.concurrency.limits.limit.FixedLimit; -import com.netflix.concurrency.limits.servlet.ServletLimiterBuilder; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.cloud.netflix.concurrency.limits.test.AbstractConcurrencyLimitsTests; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.reactive.function.client.WebClient; - -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -@RunWith(SpringRunner.class) -@SpringBootTest(properties = "logging.level.reactor.netty=DEBUG", - webEnvironment = RANDOM_PORT) -public class ConcurrencyLimitsHandlerInterceptorTests - extends AbstractConcurrencyLimitsTests { - - @LocalServerPort - public int port; - - @Before - public void init() { - client = WebClient.create("http://localhost:" + port); - } - - @Test - public void handlerInterceptorWorks() { - assertLimiter(client); - } - - @SpringBootConfiguration - @EnableAutoConfiguration - @Import(HelloControllerConfiguration.class) - protected static class TestConfig { - - @Bean - public Consumer limiterBuilderConfigurer() { - return servletLimiterBuilder -> servletLimiterBuilder.limit(FixedLimit.of(1)); - } - - } - -} diff --git a/spring-cloud-netflix-dependencies/pom.xml b/spring-cloud-netflix-dependencies/pom.xml index fae2f3520..46dec7377 100644 --- a/spring-cloud-netflix-dependencies/pom.xml +++ b/spring-cloud-netflix-dependencies/pom.xml @@ -14,7 +14,6 @@ spring-cloud-netflix-dependencies Spring Cloud Netflix Dependencies - 0.1.12 1.9.17 @@ -44,16 +43,6 @@ netflix-commons-util 0.3.0 --> - - com.netflix.concurrency-limits - concurrency-limits-core - ${concurrency-limits.version} - - - com.netflix.concurrency-limits - concurrency-limits-servlet - ${concurrency-limits.version} - com.netflix.eureka eureka-client