PreloadEntryCacheTestCase.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* The entry cache pre-load test class.
*/
public class PreloadEntryCacheTestCase
extends ExtensionsTestCase
{
/**
* Number of unique dummy test entries.
*/
protected int NUMTESTENTRIES = 1000;
/**
* Dummy test entries.
*/
/**
* Entry cache configuration instance.
*/
protected EntryCacheCfg configuration;
/**
* Temporary folder to setup dummy JE backend environment in.
*/
private File jeBackendTempDir;
/**
* Initialize the entry cache pre-load test.
*
* @throws Exception If an unexpected problem occurs.
*/
public void preloadEntryCacheTestInit()
throws Exception
{
// Ensure that the server is running.
// Make sure JE directory exist.
// Create dummy JE backend for this test.
"base-dn:o=cachetest", "--set", "writability-mode:enabled", "--set",
"enabled:true");
// Configure the entry cache, use FileSystemEntryCache.
"dn: cn=Soft Reference,cn=Entry Caches,cn=config",
"objectClass: ds-cfg-soft-reference-entry-cache",
"objectClass: ds-cfg-entry-cache",
"objectClass: top",
"cn: Soft Reference",
"ds-cfg-cache-level: 1",
"ds-cfg-java-class: " +
"org.opends.server.extensions.SoftReferenceEntryCache",
"ds-cfg-enabled: true");
// Make parent entry.
"dn: o=cachetest",
"o: cachetest",
"objectClass: top",
"objectClass: organization");
// Make some dummy test entries.
for(int i = 0; i < NUMTESTENTRIES; i++ ) {
+ ",o=cachetest",
"objectClass: person",
"objectClass: inetorgperson",
"objectClass: top",
"objectClass: organizationalperson",
+ "@testdomain.net",
);
}
// Initialize the cache reflecting on DirectoryServer
// and EntryCacheConfigManager.
final Field[] directoryFields =
DirectoryServer.class.getDeclaredFields();
directoryFields[i].setAccessible(true);
final Method[] cacheManagerMethods =
"loadAndInstallEntryCache")) {
cacheManagerMethods[j].setAccessible(true);
}
}
}
}
// Attempt to force GC to possibly free some memory.
}
/**
* Tests the entry cache pre-load.
*/
@Test
public void testEntryCachePreload()
throws Exception
{
// Make sure the entry cache is empty.
toVerboseString());
// Preload.
// Check that all test entries are preloaded.
for(int i = 0; i < NUMTESTENTRIES; i++ ) {
" in the cache. Cache contents:" +
}
}
/**
* Finalize the entry cache pre-load test.
*
* @throws Exception If an unexpected problem occurs.
*/
public void preloadEntryCacheTestFini()
throws Exception
{
// Dummy JE backend cleanup.
// Sanity in-core restart.
}
/**
* Reflection of the toVerboseString implementation method.
*/
protected String toVerboseString()
throws Exception
{
final Method[] cacheMethods =
cacheMethods[i].setAccessible(true);
return (String) verboseString;
}
}
return null;
}
}