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

matthew_swift
10.38.2009 3e8e32d7139c5f70a67f04e4e1337e8ee0b3a04b
Fix issue 3775: Intermittent unit test failure in NetworkGroupTest

Add support for finalizing the NetworkGroupConfigManager and finalize it when it is shutdown for auto routing mode.
4 files modified
126 ■■■■■ changed files
opends/resource/config/config.ldif 16 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/core/DirectoryServer.java 10 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/core/networkgroups/NetworkGroupConfigManager.java 29 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/core/networkgroups/NetworkGroupTest.java 71 ●●●●● patch | view | raw | blame | history
opends/resource/config/config.ldif
@@ -2460,6 +2460,20 @@
dn: cn=Extensions,cn=config
objectClass: top
objectClass: ds-cfg-branch
objectClass: ds-cfg-plugin-root
cn: Extensions
dn: cn=Network Groups,cn=config
objectClass: top
objectClass: ds-cfg-branch
cn: Network Groups
dn: cn=Workflows,cn=config
objectClass: top
objectClass: ds-cfg-branch
cn: Workflows
dn: cn=Workflow Elements,cn=config
objectClass: top
objectClass: ds-cfg-branch
cn: Workflow Elements
opends/src/server/org/opends/server/core/DirectoryServer.java
@@ -2569,9 +2569,12 @@
    workflowConfigManager = new WorkflowConfigManager();
    workflowConfigManager.initializeWorkflows();
    if (networkGroupConfigManager == null)
    {
    networkGroupConfigManager = new NetworkGroupConfigManager();
    networkGroupConfigManager.initializeNetworkGroups();
  }
  }
  /**
@@ -2583,6 +2586,13 @@
   */
  private void configureWorkflowsAuto() throws ConfigException
  {
    // Make sure that the network group config manager is finalized.
    if (networkGroupConfigManager != null)
    {
      networkGroupConfigManager.finalizeNetworkGroups();
      networkGroupConfigManager = null;
    }
    // First of all re-initialize the current workflow configuration
    NetworkGroup.resetConfig();
    WorkflowImpl.resetConfig();
opends/src/server/org/opends/server/core/networkgroups/NetworkGroupConfigManager.java
@@ -219,6 +219,35 @@
  /**
   * Finalizes all network groups currently defined in the Directory
   * Server configuration. This should only be called at Directory
   * Server shutdown.
   */
  public void finalizeNetworkGroups()
  {
    // Get the root configuration object.
    ServerManagementContext managementContext =
        ServerManagementContext.getInstance();
    RootCfg rootConfiguration =
        managementContext.getRootConfiguration();
    // Remove add / delete listeners.
    rootConfiguration.removeNetworkGroupAddListener(this);
    rootConfiguration.removeNetworkGroupDeleteListener(this);
    // Finalize the existing network groups.
    for (NetworkGroup networkGroup : networkGroups.values())
    {
      networkGroup.finalizeNetworkGroup();
    }
    // Clean up remaining state so that it is possible to reinitialize.
    networkGroups.clear();
  }
  /**
   * Initializes all network groups currently defined in the Directory
   * Server configuration. This should only be called at Directory
   * Server startup.
opends/tests/unit-tests-testng/src/server/org/opends/server/core/networkgroups/NetworkGroupTest.java
@@ -747,6 +747,77 @@
  }
  /**
   * Tests that routing mode changes cause the network group config
   * manager to be initialized, shutdown, and reinitialized correctly.
   *
   * @see <a
   *      href="https://opends.dev.java.net/issues/show_bug.cgi?id=3775">Issue 3775</a>
   * @throws Exception
   *           If an unexpected error occurred.
   */
  @Test
  public void testIssue3775() throws Exception
  {
    // Switch to and from manual mode twice in order to ensure that the
    // config manager is initialized twice. Then register a network
    // group. If the initialization has worked properly the network
    // group should be added successfully. In the case of issue 3775,
    // the config add listeners ended up being added twice so adding a
    // network group failed because the admin framework thought it had
    // been added twice.
    // Switch to manual mode once.
    TestCaseUtils.dsconfig(
        "set-global-configuration-prop",
        "--set", "workflow-configuration-mode:manual");
    try
    {
      // Switch back.
      TestCaseUtils.dsconfig(
          "set-global-configuration-prop",
          "--set", "workflow-configuration-mode:auto");
      // Switch to manual mode twice.
      TestCaseUtils.dsconfig(
          "set-global-configuration-prop",
          "--set", "workflow-configuration-mode:manual");
      // Now add network group.
      final String networkGroupID = "Network group issue 3775";
      TestCaseUtils.dsconfig(
          "create-network-group",
          "--group-name", networkGroupID,
          "--set", "enabled:true",
          "--set", "priority:" + 123);
      try
      {
        // Ensure that the network group was created ok.
        NetworkGroup networkGroup = NetworkGroup.getNetworkGroup(networkGroupID);
        assertNotNull(networkGroup, "The network group does not seem to be registered.");
      }
      finally
      {
        // Remove the network group.
        TestCaseUtils.dsconfig(
            "delete-network-group",
            "--group-name", networkGroupID);
      }
    }
    finally
    {
      TestCaseUtils.dsconfig(
          "set-global-configuration-prop",
          "--set", "workflow-configuration-mode:auto");
    }
  }
  /**
   * Tests the network group resource limits
   *