@Test
public void testSetLocalValue() throws Exception {

    System.out.println("   setLocalValue");
    final String varName = "foo";
    final int[] values = {1, 2};
    final CountDownLatch latch = new CountDownLatch(2);
    class Task implements Runnable {
        private final int threadIndex;
        public Task(int threadIndex) {
            this.threadIndex = threadIndex;
        }
        public void run() {
            // set the local var then wait for the other thread
            // to do the same before testing
            EnvFunction.setLocalValue(varName, values[threadIndex]);
            latch.countDown();
            try {
                latch.await();
            } catch (InterruptedException ex) {
                throw new IllegalStateException(ex);
            }
            Object result = ff.function("env", ff.literal(varName)).evaluate(null);
            int value = ((Number) result).intValue();
            assertEquals(values[threadIndex], value);
        }
    }
    Future f1 = executor.submit(new Task(0));
    Future f2 = executor.submit(new Task(1));
    // calling get on the Futures ensures that this test method
    // completes before another starts
    f1.get();
    f2.get();
}