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

Valery Kharseko
29.29.2025 9f31988371f42af4ec47680088b26a12d4ea7909
[#545] add IT test
2 files added
1 files modified
73 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/extensions/StaticGroup.java 5 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/extensions/StaticGroupIT.java 38 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/extensions/TestUtils.java 30 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/extensions/StaticGroup.java
@@ -86,6 +86,11 @@
 */
public class StaticGroup extends Group<StaticGroupImplementationCfg>
{
  // Геттеры для тестов
  HashSet<CompactDn> getMemberDNs() { return memberDNs; }
  LinkedList<DN> getNestedGroups() { return nestedGroups; }
  DN getGroupEntryDN() { return groupEntryDN; }
  AttributeType getMemberAttributeType() { return memberAttributeType; }
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /** The attribute type used to hold the membership list for this group. */
opendj-server-legacy/src/test/java/org/opends/server/extensions/StaticGroupIT.java
New file
@@ -0,0 +1,38 @@
package org.opends.server.extensions;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.opends.server.types.Modification;
import java.util.concurrent.*;
import java.util.*;
import static org.testng.Assert.*;
public class StaticGroupIT {
    private static final int THREAD_COUNT = 10;
    private static final int TOTAL_REQUESTS = 100;
    @Test
    public void testConcurrentUpdateMembersNoDeadlock() throws Exception {
        StaticGroup group = TestUtils.createNestedTestGroup();
        List<Modification> modifications = TestUtils.createAddUserModifications();
        ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
        List<Future<?>> futures = new ArrayList<>();
        for (int i = 0; i < TOTAL_REQUESTS; i++) {
            futures.add(executor.submit(() -> {
                try {
                    group.updateMembers(modifications);
                } catch (org.opends.server.types.DirectoryException e) {
                    throw new RuntimeException(e);
                }
            }));
        }
        for (Future<?> f : futures) {
            f.get(10, TimeUnit.SECONDS);
        }
        executor.shutdown();
    assertTrue(executor.awaitTermination(30, TimeUnit.SECONDS));
    // Проверяем, что группа содержит пользователя
    assertTrue(group.isMember(TestUtils.TEST_USER_DN, null));
    }
}
opendj-server-legacy/src/test/java/org/opends/server/extensions/TestUtils.java
New file
@@ -0,0 +1,30 @@
package org.opends.server.extensions;
import java.util.*;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ModificationType;
import org.opends.server.types.Modification;
import org.opends.server.types.Attribute;
import org.opends.server.types.Attributes;
public class TestUtils {
    public static final DN TEST_USER_DN = DN.valueOf("cn=Test User,ou=Users,dc=com,dc=example");
    public static final DN LEVEL1_DN = DN.valueOf("cn=Level1,ou=Groups,dc=com,dc=example");
    public static final DN LEVEL2_DN = DN.valueOf("cn=Level2,ou=Groups,dc=com,dc=example");
    public static StaticGroup createNestedTestGroup() {
        // Минимальная реализация для теста
        StaticGroup group = new StaticGroup();
    group.getMemberDNs().clear();
    group.getNestedGroups().clear();
    // Устанавливаем значения через рефлексию, если нужно, либо через конструктор/методы
    // Для теста достаточно очистить коллекции и использовать LEVEL2_DN
        return group;
    }
    public static List<Modification> createAddUserModifications() {
        Attribute attr = Attributes.create("member", TEST_USER_DN.toString());
        Modification mod = new Modification(ModificationType.ADD, attr);
        return Collections.singletonList(mod);
    }
}