From 1a2ab63f87bceaa08341c607c7237adcd19cd188 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 15 Dec 2009 00:51:07 +0000 Subject: [PATCH] Add missing file for HADOOP-6413. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@890588 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/util/TestReflectionUtils.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/test/core/org/apache/hadoop/util/TestReflectionUtils.java diff --git a/src/test/core/org/apache/hadoop/util/TestReflectionUtils.java b/src/test/core/org/apache/hadoop/util/TestReflectionUtils.java new file mode 100644 index 0000000000..71a49ce3f1 --- /dev/null +++ b/src/test/core/org/apache/hadoop/util/TestReflectionUtils.java @@ -0,0 +1,120 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.util; + +import java.net.URL; +import java.net.URLClassLoader; +import java.util.HashMap; + +import org.apache.hadoop.conf.Configuration; + +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; + +public class TestReflectionUtils { + + private static Class toConstruct[] = { String.class, TestReflectionUtils.class, HashMap.class }; + private Throwable failure = null; + + @Before + public void setUp() { + ReflectionUtils.clearCache(); + } + + @Test + public void testCache() throws Exception { + assertEquals(0, cacheSize()); + doTestCache(); + assertEquals(toConstruct.length, cacheSize()); + ReflectionUtils.clearCache(); + assertEquals(0, cacheSize()); + } + + + @SuppressWarnings("unchecked") + private void doTestCache() { + for (int i=0; i