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
24 import static org.junit.Assert.assertNull;
25
26 import org.junit.Before;
27 import org.junit.Test;
28
29 /**
30 * Simple test that checks to see if the {@link ExpiringMap} can
31 * properly clean up itself.
32 *
33 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
34 */
35 public class ExpiringMapTest
36 {
37 private ExpiringMap<String,String> theMap;
38
39 /**
40 * Create the map, populate it and then kick off
41 * the Expirer, then sleep long enough so that the
42 * Expirer can clean up the map.
43 *
44 * @throws java.lang.Exception
45 */
46 @Before
47 public void setUp() throws Exception
48 {
49 theMap = new ExpiringMap<String,String>(1, 2);
50 theMap.put( "Apache", "MINA" );
51 theMap.getExpirer().startExpiringIfNotStarted();
52 Thread.sleep(3000);
53 }
54
55 /**
56 * Check to see if the map has been cleaned up.
57 *
58 */
59 @Test
60 public void testGet(){
61 assertNull( theMap.get( "Apache" ) );
62 }
63 }