View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package net.sf.ehcache.loader;
18  
19  
20  import org.junit.After;
21  import org.junit.Before;
22  import org.junit.Test;
23  
24  
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  
29  /***
30   * ComponentA is composed of ComponentB and some other fields. Tests the interactions between two loaders, where the first component's
31   * loader loads component B by using getWithLoader, which in turn invokes component B's loader.
32   *
33   * @author <a href="mailto:gluck@gregluck.com">Greg Luck</a>
34   * @version $Id: CompositeLoaderTest.html 13146 2011-08-01 17:12:39Z oletizi $
35   */
36  public class CompositeLoaderTest {
37  
38      private static final Logger LOG = LoggerFactory.getLogger(CompositeLoaderTest.class.getName());
39  
40      /***
41       * Sets up the fixture, for example, open a network connection.
42       * This method is called before a test is executed.
43       */
44      @Before
45      public void setUp() throws Exception {
46          CacheHelper.init();
47      }
48  
49      /***
50       * Tears down the fixture, for example, close a network connection.
51       * This method is called after a test is executed.
52       */
53      @After
54      public void tearDown() throws Exception {
55          CacheHelper.shutdown();
56      }
57  
58      /***
59       * This test reproduces a deadlock found in 1.4-beta1 around loading interactions and getWithLoader. Now fixed.
60       */
61      @Test
62      public void testCompositeLoad() {
63          LOG.info("Getting from cache");
64          ComponentA compA = (ComponentA) CacheHelper.get("ehcache-loaderinteractions.xml", "ACache", "key1");
65          LOG.info(compA.toString());
66  
67      }
68  
69  }