Fix ordering problem in tests
The Zuul filter registry has to be cleareed (including a cache in a private field in FilterLoader, yuck).
This commit is contained in:
@@ -53,8 +53,8 @@ public class ZuulConfiguration {
|
|||||||
private Map<String, ZuulFilter> filters;
|
private Map<String, ZuulFilter> filters;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public FilterInitializer zuulFilterInitializer() {
|
public ZuulFilterInitializer zuulFilterInitializer() {
|
||||||
return new FilterInitializer(filters);
|
return new ZuulFilterInitializer(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.springframework.cloud.netflix.zuul;
|
package org.springframework.cloud.netflix.zuul;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
@@ -7,24 +8,25 @@ import javax.servlet.ServletContextListener;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
import com.netflix.zuul.FilterLoader;
|
||||||
import com.netflix.zuul.ZuulFilter;
|
import com.netflix.zuul.ZuulFilter;
|
||||||
import com.netflix.zuul.filters.FilterRegistry;
|
import com.netflix.zuul.filters.FilterRegistry;
|
||||||
import com.netflix.zuul.monitoring.MonitoringHelper;
|
import com.netflix.zuul.monitoring.MonitoringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: spencergibb
|
* @author Spencer Gibb
|
||||||
* Date: 4/24/14
|
*
|
||||||
* Time: 9:23 PM
|
|
||||||
* TODO: .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
* TODO: .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||||
*/
|
*/
|
||||||
public class FilterInitializer implements ServletContextListener {
|
public class ZuulFilterInitializer implements ServletContextListener {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(FilterInitializer.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ZuulFilterInitializer.class);
|
||||||
|
|
||||||
private Map<String, ZuulFilter> filters;
|
private Map<String, ZuulFilter> filters;
|
||||||
|
|
||||||
public FilterInitializer(Map<String, ZuulFilter> filters) {
|
public ZuulFilterInitializer(Map<String, ZuulFilter> filters) {
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,8 +48,22 @@ public class FilterInitializer implements ServletContextListener {
|
|||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
LOGGER.info("Stopping filter initializer context listener");
|
LOGGER.info("Stopping filter initializer context listener");
|
||||||
|
FilterRegistry registry = FilterRegistry.instance();
|
||||||
|
for (Map.Entry<String, ZuulFilter> entry : filters.entrySet()) {
|
||||||
|
registry.remove(entry.getKey());
|
||||||
|
}
|
||||||
|
clearLoaderCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clearLoaderCache() {
|
||||||
|
FilterLoader instance = FilterLoader.getInstance();
|
||||||
|
Field field = ReflectionUtils.findField(FilterLoader.class, "hashFiltersByType");
|
||||||
|
ReflectionUtils.makeAccessible(field);
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
Map cache = (Map) ReflectionUtils.getField(field, instance);
|
||||||
|
cache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/*private void initGroovyFilterManager() {
|
/*private void initGroovyFilterManager() {
|
||||||
|
|
||||||
//TODO: support groovy filters loaded from filesystem in proxy
|
//TODO: support groovy filters loaded from filesystem in proxy
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 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
|
||||||
|
*
|
||||||
|
* http://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;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Suite;
|
||||||
|
import org.junit.runners.Suite.SuiteClasses;
|
||||||
|
import org.springframework.cloud.netflix.zuul.SampleZuulProxyApplicationTests;
|
||||||
|
import org.springframework.cloud.netflix.zuul.SimpleZuulServerApplicationTests;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A test suite for probing weird ordering problems in the tests.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
@RunWith(Suite.class)
|
||||||
|
@SuiteClasses({ SimpleZuulServerApplicationTests.class, SampleZuulProxyApplicationTests.class })
|
||||||
|
@Ignore
|
||||||
|
public class AdhocTestSuite {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ server:
|
|||||||
port: 9999
|
port: 9999
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
org.springframework.web: DEBUG
|
# org.springframework.web: DEBUG
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: testclient
|
name: testclient
|
||||||
|
|||||||
Reference in New Issue
Block a user