NIFI-7508: Reset classloader after running TestStandardControllerServiceInvocationHandler

and fix checkstyle violation on NiFiSystemIT
This commit is contained in:
Joey Frazee 2020-06-04 23:14:51 -05:00 committed by markap14
parent 359fd3ff29
commit dfefeb7b18
2 changed files with 11 additions and 2 deletions

View File

@ -20,6 +20,7 @@ package org.apache.nifi.controller.service;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.controller.ControllerService;
import org.apache.nifi.nar.ExtensionManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@ -35,13 +36,22 @@ import static org.junit.Assert.assertTrue;
public class TestStandardControllerServiceInvocationHandler {
private ClassLoader originalClassLoader;
@Before
public void setClassLoader() {
public void setEmptyClassLoader() {
this.originalClassLoader = Thread.currentThread().getContextClassLoader();
// Change context class loader to a new, empty class loader so that calls to Controller Service will need to proxy returned objects.
final URLClassLoader classLoader = new URLClassLoader(new URL[] {}, null);
Thread.currentThread().setContextClassLoader(classLoader);
}
@After
public void setOriginalClassLoaderBack() {
if (originalClassLoader != null) Thread.currentThread().setContextClassLoader(originalClassLoader);
}
@Test
public void testSimpleProxy() {
final BaseControllerService proxiedService = createProxyService();

View File

@ -40,7 +40,6 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BooleanSupplier;
import java.util.regex.Matcher;