Skip to content

Commit

Permalink
fixed bug JPPF-606
Browse files Browse the repository at this point in the history
  • Loading branch information
lolocohen committed Oct 8, 2019
1 parent f44c5ce commit d5c552a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
Expand Up @@ -27,7 +27,7 @@ public final class TaskThreadLocals {
/**
* Uuid of the original task bundle that triggered a resource loading request.
*/
private static final ThreadLocal<String> requestUuid = new ThreadLocal<>();
private static final InheritableThreadLocal<String> requestUuid = new InheritableThreadLocal<>();

/**
* Instantiation not permitted.
Expand Down
Expand Up @@ -159,6 +159,28 @@ public void testClassLoadingInterruptionWithCallable() throws Exception {
testInterruption(true);
}

/**
* Test that class loading works from a thread created by a JPPF task.
* <br/>See <a href="http://www.jppf.org/tracker/tbg/jppf/issues/JPPF-606">JPPF-606 ClassNotFoundException when submitting a Callable to an ExecutorService from a JPPF task</a>
* @throws Exception if any error occurs
*/
@Test(timeout = TEST_TIMEOUT)
public void testClassLoadingFromSeparateThread() throws Exception {
final String name = ReflectionUtils.getCurrentMethodName();
final List<Task<?>> results = client.submit(BaseTestHelper.createJob(name + "1", false, 1, MyTestTask.class));
assertNotNull(results);
assertEquals(1, results.size());
final Task<?> task = results.get(0);
assertNotNull(task);
final Throwable throwable = task.getThrowable();
if (throwable != null) {
print(false, false, "task raised exception:\n%s", ExceptionUtils.getStackTrace(throwable));
fail("task raised exception: " + ExceptionUtils.getMessage(throwable));
}
assertNotNull(task.getResult());
assertEquals("hello from task", task.getResult());
}

/**
* @param callable .
* @throws Exception if any error occurs
Expand Down
57 changes: 57 additions & 0 deletions tests/src/tests/test/org/jppf/classloader/MyTestTask.java
@@ -0,0 +1,57 @@
/*
* JPPF.
* Copyright (C) 2005-2019 JPPF Team.
* http://www.jppf.org
*
* 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 test.org.jppf.classloader;

import java.util.concurrent.*;

import org.jppf.node.protocol.AbstractTask;
import org.jppf.utils.concurrent.JPPFThreadFactory;

/**
*
* @author Laurent Cohen
*/
public class MyTestTask extends AbstractTask<String> {
@Override
public void run() {
final ExecutorService executor = Executors.newFixedThreadPool(1, new JPPFThreadFactory("Test"));
try {
final Callable<String> callable = () -> "hello from " + new MyClass().getName();
final String msg = executor.submit(callable).get();
//final String msg = callable.call();
setResult(msg);
} catch (final Exception e) {
setThrowable(e);
} finally {
executor.shutdownNow();
}
}

/**
* Class loaded during the execution of a callable sublitted to an {@link ExecutorService}.
*/
public static class MyClass {
/**
* @return an arbiitrary string.
*/
public String getName() {
return "task";
}
}
}

0 comments on commit d5c552a

Please sign in to comment.