View Javadoc

1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  
21  package org.apache.mina.util;
22  
23  import static org.junit.Assert.assertNull;
24  
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  /**
29   * Simple test that checks to see if the {@link ExpiringMap} can
30   * properly clean up itself.
31   *
32   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
33   */
34  public class ExpiringMapTest {
35      private ExpiringMap<String, String> theMap;
36  
37      /**
38       * Create the map, populate it and then kick off 
39       * the Expirer, then sleep long enough so that the
40       * Expirer can clean up the map.
41       *
42       * @throws java.lang.Exception
43       */
44      @Before
45      public void setUp() throws Exception {
46          theMap = new ExpiringMap<String, String>(1, 2);
47          theMap.put("Apache", "MINA");
48          theMap.getExpirer().startExpiringIfNotStarted();
49          Thread.sleep(3000);
50      }
51  
52      /**
53       * Check to see if the map has been cleaned up.
54       *
55       */
56      @Test
57      public void testGet() {
58          assertNull(theMap.get("Apache"));
59      }
60  }