SplitDeploymentUtil { public static void runWithClassLoader(ClassLoader classLoader, Class<?> originalRunnerClass, String runMethodName, String[] runMethodArgs) { Class<?> runnerClass; try { runnerClass = classLoader.loadClass(originalRunnerClass.getName()); } catch (ClassNotFoundException e) { throw new SamzaException(String.format( "Isolation was enabled, but unable to find %s in isolated classloader", originalRunnerClass.getName()), e); } ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); try { executeRunForRunnerClass(runnerClass, runMethodName, runMethodArgs); } finally { Thread.currentThread().setContextClassLoader(previousContextClassLoader); } }  static boolean isSplitDeploymentEnabled(); static void runWithClassLoader(ClassLoader classLoader, Class<?> originalRunnerClass, String runMethodName,
      String[] runMethodArgs);  }
@Test public void testRunWithIsolatingClassLoader() throws Exception { PowerMockito.spy(ClusterBasedJobCoordinatorRunner.class); ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = mock(ClassLoader.class); String[] args = new String[]{"arg0", "arg1"}; doReturn(ClusterBasedJobCoordinatorRunner.class).when(classLoader).loadClass(ClusterBasedJobCoordinatorRunner.class.getName()); PowerMockito.doAnswer(invocation -> { assertArrayEquals(args, invocation.getArgumentAt(0, String[].class)); assertEquals(classLoader, Thread.currentThread().getContextClassLoader()); return null; }).when(ClusterBasedJobCoordinatorRunner.class, "runClusterBasedJobCoordinator", any()); try { SplitDeploymentUtil.runWithClassLoader(classLoader, ClusterBasedJobCoordinatorRunner.class, "runClusterBasedJobCoordinator", args); assertEquals(previousContextClassLoader, Thread.currentThread().getContextClassLoader()); } finally { Thread.currentThread().setContextClassLoader(previousContextClassLoader); } verify(classLoader).loadClass(ClusterBasedJobCoordinatorRunner.class.getName()); verifyPrivate(ClusterBasedJobCoordinatorRunner.class).invoke("runClusterBasedJobCoordinator", new Object[]{aryEq(args)}); }