/** * Test basic worker functionality. This is a serial not a concurrent test. * <p> * Just verify that the worker will go to the cache before asking the helper. * * @throws Exception * */ public void testSimpleGet() throws Exception { JCSWorker<String, Long> cachingWorker = new JCSWorker<String, Long>( "example region" ); // This is the helper. JCSWorkerHelper helper = new AbstractJCSWorkerHelper() { int timesCalled = 0; @Override public Object doWork() { Object results = Long.valueOf( ++timesCalled ); return results; } }; String key = "abc"; Long result = cachingWorker.getResult( key, helper ); assertEquals( "Called the wrong number of times", Long.valueOf( 1 ), result ); // should get it from the cache. Long result2 = cachingWorker.getResult( key, helper ); assertEquals( "Called the wrong number of times", Long.valueOf( 1 ), result2 ); }
/** * Test basic worker functionality. This is a serial not a concurrent test. * <p> * Just verify that the worker will go to the cache before asking the helper. * * @throws Exception * */ public void testSimpleGet() throws Exception { JCSWorker<String, Long> cachingWorker = new JCSWorker<String, Long>( "example region" ); // This is the helper. JCSWorkerHelper<Long> helper = new AbstractJCSWorkerHelper<Long>() { int timesCalled = 0; @Override public Long doWork() { return Long.valueOf( ++timesCalled ); } }; String key = "abc"; Long result = cachingWorker.getResult( key, helper ); assertEquals( "Called the wrong number of times", Long.valueOf( 1 ), result ); // should get it from the cache. Long result2 = cachingWorker.getResult( key, helper ); assertEquals( "Called the wrong number of times", Long.valueOf( 1 ), result2 ); }