You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Emmanuel Lecharny (JIRA)" <ji...@apache.org> on 2011/06/09 13:58:58 UTC

[jira] [Resolved] (DIRSERVER-1575) AbstractLdapTestUnit fails with more than one @Test when partition located within service's working directory

     [ https://issues.apache.org/jira/browse/DIRSERVER-1575?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Lecharny resolved DIRSERVER-1575.
------------------------------------------

    Resolution: Invalid

I have slightly modified the test :

package org.apache.directory.server.schema;

import java.io.File;

import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
import org.apache.directory.server.core.integ.FrameworkRunner;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
import org.apache.directory.shared.ldap.model.name.Dn;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(FrameworkRunner.class)
@CreateLdapServer(transports = @CreateTransport(protocol = "ldap"))
public class ApacheBugTest extends AbstractLdapTestUnit {
    
    private static JdbmPartition partition;

    @Before
    public void setUp() throws Exception {
        final File partitionDirectory =
            new File( service.getInstanceLayout().getInstanceDirectory(), "myPartition" );
        
        partition = new JdbmPartition();
        partition.setId("anything");
        partition.setPartitionPath( partitionDirectory.toURI() );
        partition.setSchemaManager(service.getSchemaManager());
        partition.setSuffix( new Dn( "dc=example,dc=com" ) ); // anything
        
        service.addPartition(partition);
    }
    
    @After
    public void shutdown() throws Exception
    {
        service.removePartition( partition );
    }
    
    @Test public void test() { System.out.println("Dummy test"); }
    
    @Test public void test2() { System.out.println("Dummy test 2"); }
} 

Now, the created partition is deleted in the @After method, so many @Test can be run and inject their own partition in the @Before method.

Also note that the API has changed a bit. We don't acess directly to the working directory, and we use URI.

> AbstractLdapTestUnit fails with more than one @Test when partition located within service's working directory
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: DIRSERVER-1575
>                 URL: https://issues.apache.org/jira/browse/DIRSERVER-1575
>             Project: Directory ApacheDS
>          Issue Type: Bug
>    Affects Versions: 1.5.7
>         Environment: Windows 7
> JDK 1.5.0_22, also happens with 1.6.0_21
>            Reporter: Andrew Swan
>            Priority: Minor
>             Fix For: 2.0.0-M1
>
>
> Problem
> ~~~~~~~
> In my subclass of AbstractLdapTestUnit, I'm creating a custom Partition for my test LDAP entries. However if I locate this partition within the DirectoryService's working directory, and my test case has more than one @Test method, then after the test methods run (successfully), the test case fails with this error:
> java.io.IOException: Unable to delete file: E:\Temp\server-work-default02f53ef4-636e-4edf-a812-0a76ce27e399\myPartition\objectClass.lg
> 	at org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:1390)
> 	at org.apache.commons.io.FileUtils.cleanDirectory(FileUtils.java:1044)
> 	at org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:977)
> 	at org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:1381)
> 	at org.apache.commons.io.FileUtils.cleanDirectory(FileUtils.java:1044)
> 	at org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:977)
> 	at org.apache.directory.server.core.integ.FrameworkRunner.run(FrameworkRunner.java:259)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Failing Test
> ~~~~~~~~~
> package au.com.bisinfo.ldap;
> import java.io.File;
> import org.apache.directory.server.annotations.CreateLdapServer;
> import org.apache.directory.server.annotations.CreateTransport;
> import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
> import org.apache.directory.server.core.integ.FrameworkRunner;
> import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
> import org.junit.Before;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> @RunWith(FrameworkRunner.class)
> @CreateLdapServer(transports = @CreateTransport(protocol = "ldap"))
> public class ApacheBugTest extends AbstractLdapTestUnit {
>     @Before
>     public void setUp() throws Exception {
>         final File partitionDirectory =
>             new File(service.getWorkingDirectory(), "myPartition");
>         
>         final JdbmPartition partition = new JdbmPartition();
>         partition.setId("anything");
>         partition.setPartitionDir(partitionDirectory);
>         partition.setSchemaManager(service.getSchemaManager());
>         partition.setSuffix("dc=example,dc=com");   // anything
>         service.addPartition(partition);
>     }
>     
>     @Test public void test() { System.out.println("Dummy test"); }
>     
>     @Test public void test2() { System.out.println("Dummy test 2"); }
> }
> Maven 2 Dependencies
> ~~~~~~~~~~~~~~~~~~~
> 		<dependency>
> 			<groupId>org.apache.directory.server</groupId>
> 			<artifactId>apacheds-test-framework</artifactId>
> 			<version>1.5.7</version>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.apache.directory.server</groupId>
> 			<artifactId>apacheds-server-integ</artifactId>
> 			<version>1.5.7</version>
> 		</dependency>
> Workarounds
> ~~~~~~~~~~~
> I can make this test pass by either:
> * Only having one test method per test case (not very convenient), or
> * Locating the partition somewhere outside the working directory of the DirectoryService. But even in this case, I still get the "Unable to delete file" error if I try to clean up the partition directory from an @After or @AfterClass method.
> Ideas
> ~~~~
> From looking at the source for jdbm.recman.TransactionManager, objectClass.lg is a JDBM log file. Is this bug simply a case of that file not being closed when it should be (e.g. when the DirectoryService shuts down)? Is this bug related to DIRSERVER-1348 in some way?

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira