mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
14.07.2007 8b58a21edd905d8a3bfcacfab2717ab04632ca63
Update the server so that it is possible to call EmbeddedUtils.startServer to
start the server after having previously called EmbeddedUtils.stopServer.
Previously, the shutdown process did not leave the server in an adequate state
to allow it to be started again later, and only the EmbeddedUtils.restart
method would allow a functional restart.
1 files added
2 files modified
371 ■■■■■ changed files
opends/src/server/org/opends/server/core/DirectoryServer.java 76 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/types/Schema.java 166 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/util/EmbeddedUtilsTestCase.java 129 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/core/DirectoryServer.java
@@ -8501,8 +8501,80 @@
    shutdownMonitor.waitForMonitor();
    // At this point, the server is no longer running.
    directoryServer.isRunning = false;
    // At this point, the server is no longer running.  We should destroy the
    // handle to the previous instance, but we will want to get a new instance
    // in case the server is to be started again later in the same JVM.  Before
    // doing that, destroy the previous instance.
    DirectoryEnvironmentConfig envConfig = directoryServer.environmentConfig;
    directoryServer.destroy();
    directoryServer = getNewInstance(envConfig);
  }
  /**
   * Destroy key structures in the current Directory Server instance in a manner
   * that can help detect any inappropriate cached references to server
   * components.
   */
  private void destroy()
  {
    checkSchema                   = true;
    isBootstrapped                = false;
    isClientBootstrapped          = false;
    isRunning                     = false;
    lockdownMode                  = true;
    rejectUnauthenticatedRequests = true;
    shuttingDown                  = true;
    configClass              = null;
    configFile               = null;
    configHandler            = null;
    coreConfigManager        = null;
    compressedSchema         = null;
    cryptoManager            = null;
    defaultBinarySyntax      = null;
    defaultBooleanSyntax     = null;
    defaultDNSyntax          = null;
    defaultIntegerSyntax     = null;
    defaultStringSyntax      = null;
    defaultSyntax            = null;
    entryCache               = null;
    environmentConfig        = null;
    objectClassAttributeType = null;
    schemaDN                 = null;
    shutdownHook             = null;
    workQueue                = null;
    if (privateNamingContexts != null)
    {
      privateNamingContexts.clear();
      privateNamingContexts = null;
    }
    if (publicNamingContexts != null)
    {
      publicNamingContexts.clear();
      publicNamingContexts = null;
    }
    if (baseDNs != null)
    {
      baseDNs.clear();
      baseDNs = null;
    }
    if (backends != null)
    {
      backends.clear();
      backends = null;
    }
    if (schema != null)
    {
      schema.destroy();
      schema = null;
    }
  }
opends/src/server/org/opends/server/types/Schema.java
@@ -3249,5 +3249,171 @@
                                      values)));
    }
  }
  /**
   * Destroys the structures maintained by the schema so that they are
   * no longer usable.  This should only be called at the end of the
   * server shutdown process, and it can help detect inappropriate
   * cached references.
   */
  @org.opends.server.types.PublicAPI(
       stability=org.opends.server.types.StabilityLevel.PRIVATE,
       mayInstantiate=false,
       mayExtend=false,
       mayInvoke=true)
  public synchronized void destroy()
  {
    if (approximateMatchingRules != null)
    {
      approximateMatchingRules.clear();
      approximateMatchingRules = null;
    }
    if (attributeTypes != null)
    {
      attributeTypes.clear();
      attributeTypes = null;
    }
    if (attributeTypeSet != null)
    {
      attributeTypeSet.clear();
      attributeTypeSet = null;
    }
    if (ditContentRules != null)
    {
      ditContentRules.clear();
      ditContentRules = null;
    }
    if (ditContentRuleSet != null)
    {
      ditContentRuleSet.clear();
      ditContentRuleSet = null;
    }
    if (ditStructureRulesByID != null)
    {
      ditStructureRulesByID.clear();
      ditStructureRulesByID = null;
    }
    if (ditStructureRulesByNameForm != null)
    {
      ditStructureRulesByNameForm.clear();
      ditStructureRulesByNameForm = null;
    }
    if (ditStructureRuleSet != null)
    {
      ditStructureRuleSet.clear();
      ditStructureRuleSet = null;
    }
    if (equalityMatchingRules != null)
    {
      equalityMatchingRules.clear();
      equalityMatchingRules = null;
    }
    if (matchingRules != null)
    {
      matchingRules.clear();
      matchingRules = null;
    }
    if (matchingRuleSet != null)
    {
      matchingRuleSet.clear();
      matchingRuleSet = null;
    }
    if (matchingRuleUses != null)
    {
      matchingRuleUses.clear();
      matchingRuleUses = null;
    }
    if (matchingRuleUseSet != null)
    {
      matchingRuleUseSet.clear();
      matchingRuleUseSet = null;
    }
    if (nameFormsByName != null)
    {
      nameFormsByName.clear();
      nameFormsByName = null;
    }
    if (nameFormsByOC != null)
    {
      nameFormsByOC.clear();
      nameFormsByOC = null;
    }
    if (nameFormSet != null)
    {
      nameFormSet.clear();
      nameFormSet = null;
    }
    if (objectClasses != null)
    {
      objectClasses.clear();
      objectClasses = null;
    }
    if (objectClassSet != null)
    {
      objectClassSet.clear();
      objectClassSet = null;
    }
    if (orderingMatchingRules != null)
    {
      orderingMatchingRules.clear();
      orderingMatchingRules = null;
    }
    if (subordinateTypes != null)
    {
      subordinateTypes.clear();
      subordinateTypes = null;
    }
    if (substringMatchingRules != null)
    {
      substringMatchingRules.clear();
      substringMatchingRules = null;
    }
    if (synchronizationGenerationId != null)
    {
      synchronizationGenerationId.clear();
      synchronizationGenerationId = null;
    }
    if (synchronizationState != null)
    {
      synchronizationState.clear();
      synchronizationState = null;
    }
    if (syntaxes != null)
    {
      syntaxes.clear();
      syntaxes = null;
    }
    if (syntaxSet != null)
    {
      syntaxSet.clear();
      syntaxSet = null;
    }
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/util/EmbeddedUtilsTestCase.java
New file
@@ -0,0 +1,129 @@
/*
 * 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
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * 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
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  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
 *
 *
 *      Portions Copyright 2007 Sun Microsystems, Inc.
 */
package org.opends.server.util;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.opends.messages.Message;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.DirectoryEnvironmentConfig;
import static org.testng.Assert.*;
/**
 * A set of generic test cases for the EmbeddedUtils class.
 */
public class EmbeddedUtilsTestCase
       extends UtilTestCase
{
  /**
   * Ensures that the Directory Server is running before running any tests.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @BeforeClass()
  public void setUp()
         throws Exception
  {
    TestCaseUtils.startServer();
    assertTrue(EmbeddedUtils.isRunning());
  }
  /**
   * Make sure that the server gets restarted by the
   * {@code TestCaseUtils.restartServer} method because it does a few things to
   * the server that aren't covered in the out-of-the-box configuration.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @AfterClass()
  public void cleanUp()
         throws Exception
  {
    TestCaseUtils.restartServer();
  }
  /**
   * Tests the ability to use EmbeddedUtils to restart the server.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(groups = "slow")
  public void testRestartServer()
         throws Exception
  {
    assertTrue(EmbeddedUtils.isRunning());
    DirectoryEnvironmentConfig environmentConfig =
         DirectoryServer.getEnvironmentConfig();
    assertNotNull(environmentConfig);
    EmbeddedUtils.restartServer(getClass().getName(),
                                Message.raw("testRestartServer"),
                                environmentConfig);
    assertTrue(EmbeddedUtils.isRunning());
  }
  /**
   * Tests the ability to use EmbeddedUtils to stop and then subsequently start
   * the server.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(groups = "slow")
  public void testStopAndStartServer()
         throws Exception
  {
    assertTrue(EmbeddedUtils.isRunning());
    DirectoryEnvironmentConfig environmentConfig =
         DirectoryServer.getEnvironmentConfig();
    assertNotNull(environmentConfig);
    EmbeddedUtils.stopServer(getClass().getName(),
                             Message.raw("testStopAndStartServer"));
    assertFalse(EmbeddedUtils.isRunning());
    EmbeddedUtils.startServer(environmentConfig);
    assertTrue(EmbeddedUtils.isRunning());
  }
}