Commit e623ad10 by Dave Syer

Fix ordering problem in tests

The Zuul filter registry has to be cleareed (including a cache in a private field in FilterLoader, yuck).
parent 311d8788
......@@ -53,8 +53,8 @@ public class ZuulConfiguration {
private Map<String, ZuulFilter> filters;
@Bean
public FilterInitializer zuulFilterInitializer() {
return new FilterInitializer(filters);
public ZuulFilterInitializer zuulFilterInitializer() {
return new ZuulFilterInitializer(filters);
}
}
......
package org.springframework.cloud.netflix.zuul;
import java.lang.reflect.Field;
import java.util.Map;
import javax.servlet.ServletContextEvent;
......@@ -7,24 +8,25 @@ import javax.servlet.ServletContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ReflectionUtils;
import com.netflix.zuul.FilterLoader;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.filters.FilterRegistry;
import com.netflix.zuul.monitoring.MonitoringHelper;
/**
* User: spencergibb
* Date: 4/24/14
* Time: 9:23 PM
* @author Spencer Gibb
*
* 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;
public FilterInitializer(Map<String, ZuulFilter> filters) {
public ZuulFilterInitializer(Map<String, ZuulFilter> filters) {
this.filters = filters;
}
......@@ -46,8 +48,22 @@ public class FilterInitializer implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent sce) {
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() {
//TODO: support groovy filters loaded from filesystem in proxy
......
/*
* 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
logging:
level:
org.springframework.web: DEBUG
# org.springframework.web: DEBUG
spring:
application:
name: testclient
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment