001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 021package org.apache.mina.util; 022 023import static org.junit.Assert.assertNull; 024 025import org.junit.Before; 026import org.junit.Test; 027 028/** 029 * Simple test that checks to see if the {@link ExpiringMap} can 030 * properly clean up itself. 031 * 032 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 033 */ 034public class ExpiringMapTest { 035 private ExpiringMap<String, String> theMap; 036 037 /** 038 * Create the map, populate it and then kick off 039 * the Expirer, then sleep long enough so that the 040 * Expirer can clean up the map. 041 * 042 * @throws java.lang.Exception 043 */ 044 @Before 045 public void setUp() throws Exception { 046 theMap = new ExpiringMap<String, String>(1, 2); 047 theMap.put("Apache", "MINA"); 048 theMap.getExpirer().startExpiringIfNotStarted(); 049 Thread.sleep(3000); 050 } 051 052 /** 053 * Check to see if the map has been cleaned up. 054 * 055 */ 056 @Test 057 public void testGet() { 058 assertNull(theMap.get("Apache")); 059 } 060}