Skip to content
Permalink
Browse files
Fixed random failures in tests (due to some Junit 5 concurrent tests
initialisation badly done)
  • Loading branch information
elecharny committed May 6, 2019
1 parent e8a4e86 commit a6d42bdeca875f78e676541bb3f1a8780e4fc978
Show file tree
Hide file tree
Showing 24 changed files with 230 additions and 134 deletions.
@@ -20,8 +20,10 @@
package org.apache.directory.api.ldap.codec.osgi;


import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
import org.apache.directory.api.ldap.codec.api.LdapEncoder;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
@@ -37,38 +39,45 @@
public abstract class AbstractCodecServiceTest
{
protected DefaultLdapCodecService codec;

/** The encoder instance */
protected static LdapEncoder encoder;


private static Lock lock = new ReentrantLock();

/**
* Initialize the codec service
*/
@BeforeEach
public void setupLdapCodecService()
{
codec = new DefaultLdapCodecService();
lock.lock();

codec.registerProtocolCodecFactory( new ProtocolCodecFactory()
try
{
@Override
public ProtocolEncoder getEncoder( IoSession session ) throws Exception
codec = new DefaultLdapCodecService();

codec.registerProtocolCodecFactory( new ProtocolCodecFactory()
{
return null;
}


@Override
public ProtocolDecoder getDecoder( IoSession session ) throws Exception
@Override
public ProtocolEncoder getEncoder( IoSession session ) throws Exception
{
return null;
}


@Override
public ProtocolDecoder getDecoder( IoSession session ) throws Exception
{
return null;
}
} );

if ( LdapApiServiceFactory.isInitialized() == false )
{
return null;
LdapApiServiceFactory.initialize( codec );
}
} );

if ( LdapApiServiceFactory.isInitialized() == false )
}
finally
{
LdapApiServiceFactory.initialize( codec );
lock.unlock();
}
}
}
@@ -31,5 +31,10 @@
*/
public abstract class AbstractCodecServiceTest
{
protected static LdapApiService codec = new DefaultLdapCodecService();
protected static LdapApiService codec;

public static void initBase()
{
codec = new DefaultLdapCodecService();
}
}
@@ -29,11 +29,11 @@
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.extras.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncRequestFactory;
import org.apache.directory.api.util.Strings;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -45,11 +45,14 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution( ExecutionMode.CONCURRENT)
public class AdDirSyncRequestControlTest extends AbstractCodecServiceTest
public class AdDirSyncRequestControlTest
{
private static LdapApiService codec;

@BeforeAll
public static void init()
{
codec = new DefaultLdapCodecService();
codec.registerRequestControl( new AdDirSyncRequestFactory( codec ) );
}

@@ -30,10 +30,11 @@
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.extras.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncResponseFactory;
import org.apache.directory.api.util.Strings;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -45,11 +46,14 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution( ExecutionMode.CONCURRENT)
public class AdDirSyncResponseControlTest extends AbstractCodecServiceTest
public class AdDirSyncResponseControlTest
{
@BeforeEach
public void init()
private static LdapApiService codec;

@BeforeAll
public static void init()
{
codec = new DefaultLdapCodecService();
codec.registerResponseControl( new AdDirSyncResponseFactory( codec ) );
}

@@ -29,9 +29,10 @@
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.extras.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.extras.controls.ad_impl.AdPolicyHintsFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -43,11 +44,14 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution( ExecutionMode.CONCURRENT)
public class AdPolicyHintsControlTest extends AbstractCodecServiceTest
public class AdPolicyHintsControlTest
{
@BeforeEach
public void init()
private static LdapApiService codec;

@BeforeAll
public static void init()
{
codec = new DefaultLdapCodecService();
codec.registerRequestControl( new AdPolicyHintsFactory( codec ) );
}

@@ -30,9 +30,10 @@
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.extras.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyResponseFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -43,11 +44,14 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution( ExecutionMode.CONCURRENT)
public class PasswordPolicyResponseTest extends AbstractCodecServiceTest
public class PasswordPolicyResponseTest
{
@BeforeEach
public void init()
private static LdapApiService codec;

@BeforeAll
public static void init()
{
codec = new DefaultLdapCodecService();
codec.registerResponseControl( new PasswordPolicyResponseFactory( codec ) );
}

@@ -31,10 +31,11 @@
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.extras.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.extras.controls.syncrepl.syncDone.SyncDoneValue;
import org.apache.directory.api.util.Strings;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -46,11 +47,14 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution( ExecutionMode.CONCURRENT)
public class SyncDoneValueControlTest extends AbstractCodecServiceTest
public class SyncDoneValueControlTest
{
@BeforeEach
public void init()
private static LdapApiService codec;

@BeforeAll
public static void init()
{
codec = new DefaultLdapCodecService();
codec.registerResponseControl( new SyncDoneValueFactory( codec ) );
}

@@ -30,11 +30,12 @@
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.extras.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.extras.controls.SynchronizationModeEnum;
import org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue;
import org.apache.directory.api.util.Strings;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -45,11 +46,14 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution( ExecutionMode.CONCURRENT)
public class SyncRequestValueControlTest extends AbstractCodecServiceTest
public class SyncRequestValueControlTest
{
@BeforeEach
public void init()
private static LdapApiService codec;

@BeforeAll
public static void init()
{
codec = new DefaultLdapCodecService();
codec.registerRequestControl( new SyncRequestValueFactory( codec ) );
}

@@ -30,11 +30,12 @@
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.extras.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.extras.controls.syncrepl.syncState.SyncStateTypeEnum;
import org.apache.directory.api.ldap.extras.controls.syncrepl.syncState.SyncStateValue;
import org.apache.directory.api.util.Strings;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -45,11 +46,14 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution( ExecutionMode.CONCURRENT)
public class SyncStateValueControlTest extends AbstractCodecServiceTest
public class SyncStateValueControlTest
{
@BeforeEach
public void init()
private static LdapApiService codec;

@BeforeAll
public static void init()
{
codec = new DefaultLdapCodecService();
codec.registerResponseControl( new SyncStateValueFactory( codec ) );
}

@@ -32,10 +32,11 @@
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.extras.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.extras.controls.vlv_impl.VirtualListViewRequestFactory;
import org.apache.directory.api.util.Strings;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -46,11 +47,14 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution( ExecutionMode.CONCURRENT)
public class VLVRequestControlTest extends AbstractCodecServiceTest
public class VLVRequestControlTest
{
@BeforeEach
public void init()
private static LdapApiService codec;

@BeforeAll
public static void init()
{
codec = new DefaultLdapCodecService();
codec.registerRequestControl( new VirtualListViewRequestFactory( codec ) );
}

@@ -30,10 +30,11 @@
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.extras.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.extras.controls.vlv_impl.VirtualListViewResponseFactory;
import org.apache.directory.api.util.Strings;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -44,11 +45,14 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution( ExecutionMode.CONCURRENT)
public class VLVResponseControlTest extends AbstractCodecServiceTest
public class VLVResponseControlTest
{
@BeforeEach
public void init()
private static LdapApiService codec;

@BeforeAll
public static void init()
{
codec = new DefaultLdapCodecService();
codec.registerResponseControl( new VirtualListViewResponseFactory( codec ) );
}

0 comments on commit a6d42bd

Please sign in to comment.