Skip to content

Commit

Permalink
Remove usage of JimFS
Browse files Browse the repository at this point in the history
Remove JimFS usage, update couple of tests that was using it to use
DefaultFileSystemAbstraction instead.
  • Loading branch information
MishaDemianenko committed Sep 13, 2017
1 parent 2bdc0af commit e8deb0f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 117 deletions.
4 changes: 0 additions & 4 deletions community/kernel/pom.xml
Expand Up @@ -240,10 +240,6 @@ the relevant Commercial Agreement.
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down
Expand Up @@ -19,9 +19,7 @@
*/
package org.neo4j.kernel;

import com.google.common.collect.Sets;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -37,6 +35,10 @@
import org.neo4j.test.rule.EmbeddedDatabaseRule;
import org.neo4j.test.rule.RepeatRule;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.neo4j.helpers.collection.Iterables.asSet;

/**
* Token creation should be able to handle cases of concurrent token creation
* with different/same names. Short random interval (1-3) give a high chances of same token name in this test.
Expand Down Expand Up @@ -102,7 +104,7 @@ public void run()
Label[] createdLabels = getLabels();
Node node = database.createNode( createdLabels );
Iterable<Label> nodeLabels = node.getLabels();
Assert.assertEquals( Sets.newHashSet( createdLabels ), Sets.newHashSet( nodeLabels ) );
assertEquals( asSet( asList( createdLabels ) ), asSet( nodeLabels ) );
transaction.success();
}
catch ( Exception e )
Expand Down
Expand Up @@ -19,24 +19,19 @@
*/
package org.neo4j.kernel.impl.pagecache;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import org.apache.commons.lang3.SystemUtils;
import org.junit.Rule;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.neo4j.io.fs.DelegateFileSystemAbstraction;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.VerboseTimeout;

import static org.junit.Assert.assertTrue;
Expand All @@ -45,13 +40,15 @@ public class ConfigurableStandalonePageCacheFactoryTest
{
@Rule
public VerboseTimeout timeout = VerboseTimeout.builder().withTimeout( 30, TimeUnit.SECONDS ).build();
@Rule
public TestDirectory testDirectory = TestDirectory.testDirectory();

@Test
public void mustAutomaticallyStartEvictionThread() throws IOException
{
try ( FileSystemAbstraction fs = new DelegateFileSystemAbstraction( Jimfs.newFileSystem( jimConfig() ) ) )
try ( FileSystemAbstraction fs = new DefaultFileSystemAbstraction() )
{
File file = new File( "/a" ).getCanonicalFile();
File file = new File( testDirectory.directory(), "a" ).getCanonicalFile();
fs.create( file ).close();

try ( PageCache cache = ConfigurableStandalonePageCacheFactory.createPageCache( fs );
Expand All @@ -69,27 +66,4 @@ public void mustAutomaticallyStartEvictionThread() throws IOException
}
}
}

private Configuration jimConfig()
{
if ( SystemUtils.IS_OS_WINDOWS )
{
List<String> rootList = new ArrayList<>();
FileSystems.getDefault().getRootDirectories().forEach( path -> rootList.add( path.toString() ) );
Configuration.Builder builder = Configuration.windows().toBuilder();
if ( rootList.size() > 1 )
{
builder.setRoots( rootList.get( 0 ), rootList.subList( 1, rootList.size() ).toArray(new String[0] ) );
}
else
{
builder.setRoots( rootList.get( 0 ) );
}
}
else if ( SystemUtils.IS_OS_MAC_OSX )
{
return Configuration.osX();
}
return Configuration.unix();
}
}
4 changes: 0 additions & 4 deletions community/security/pom.xml
Expand Up @@ -124,10 +124,6 @@ the relevant Commercial Agreement.
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Expand Up @@ -21,8 +21,8 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.impl.security.User;
Expand Down Expand Up @@ -105,7 +105,7 @@ public ListSnapshot<User> getPersistedSnapshot() throws IOException
}
synchronized ( this )
{
return new ListSnapshot<>( lastLoaded.get(), users.stream().collect( Collectors.toList() ), FROM_MEMORY );
return new ListSnapshot<>( lastLoaded.get(), new ArrayList<>( users ), FROM_MEMORY );
}
}
}
Expand Up @@ -19,27 +19,19 @@
*/
package org.neo4j.server.security.auth;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import java.io.File;
import java.io.IOException;
import java.nio.file.CopyOption;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;

import org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction;
import org.neo4j.io.fs.DelegateFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.exceptions.InvalidArgumentsException;
import org.neo4j.kernel.impl.security.Credential;
Expand All @@ -50,7 +42,9 @@
import org.neo4j.server.security.auth.exception.ConcurrentModificationException;
import org.neo4j.string.UTF8;
import org.neo4j.test.DoubleLatch;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.concurrent.ThreadingRule;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
Expand All @@ -62,38 +56,26 @@
import static org.junit.Assert.fail;
import static org.neo4j.test.assertion.Assert.assertException;

@RunWith( Parameterized.class )
public class FileUserRepositoryTest
{
private File authFile = new File( "dbms", "auth" );
private LogProvider logProvider = NullLogProvider.getInstance();
private File authFile;
private final LogProvider logProvider = NullLogProvider.getInstance();
private FileSystemAbstraction fs;

@Parameters( name = "{1} filesystem" )
public static Collection<Object[]> data()
{
return Arrays.asList( new Object[][]{
{Configuration.unix(), "unix"},
{Configuration.osX(), "osX"},
{Configuration.windows(), "windows"}}
);
}

@Rule
public ExpectedException thrown = ExpectedException.none();

public final TestDirectory testDirectory = TestDirectory.testDirectory();
@Rule
public ThreadingRule threading = new ThreadingRule();

public FileUserRepositoryTest( Configuration fsConfig, String fsType )
{
fs = new DelegateFileSystemAbstraction( Jimfs.newFileSystem( fsConfig ) );
}
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final ThreadingRule threading = new ThreadingRule();
@Rule
public final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();

@After
public void tearDown() throws IOException
@Before
public void setUp()
{
fs.close();
fs = fileSystemRule.get();
authFile = new File( testDirectory.directory( "dbms" ), "auth" );
}

@Test
Expand Down
4 changes: 0 additions & 4 deletions enterprise/security/pom.xml
Expand Up @@ -177,10 +177,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-server-integ</artifactId>
Expand Down
Expand Up @@ -19,27 +19,20 @@
*/
package org.neo4j.server.security.enterprise.auth;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.io.File;
import java.io.IOException;
import java.nio.file.CopyOption;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;

import org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction;
import org.neo4j.io.fs.DelegateFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.exceptions.InvalidArgumentsException;
import org.neo4j.logging.AssertableLogProvider;
Expand All @@ -50,7 +43,9 @@
import org.neo4j.server.security.auth.exception.ConcurrentModificationException;
import org.neo4j.string.UTF8;
import org.neo4j.test.DoubleLatch;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.concurrent.ThreadingRule;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
Expand All @@ -63,38 +58,27 @@
import static org.junit.Assert.fail;
import static org.neo4j.test.assertion.Assert.assertException;

@RunWith( Parameterized.class )
public class FileRoleRepositoryTest
{
private File roleFile = new File( "dbms", "roles" );
private LogProvider logProvider = NullLogProvider.getInstance();
private File roleFile;
private final LogProvider logProvider = NullLogProvider.getInstance();
private FileSystemAbstraction fs;
private RoleRepository roleRepository;

@Parameterized.Parameters( name = "{1} filesystem" )
public static Collection<Object[]> data()
{
return Arrays.asList( new Object[][]{
{Configuration.unix(), "unix"},
{Configuration.osX(), "osX"},
{Configuration.windows(), "windows"}}
);
}

@Rule
public ExpectedException thrown = ExpectedException.none();

public final TestDirectory testDirectory = TestDirectory.testDirectory();
@Rule
public ThreadingRule threading = new ThreadingRule();

public FileRoleRepositoryTest( Configuration fsConfig, String fsType )
{
fs = new DelegateFileSystemAbstraction( Jimfs.newFileSystem( fsConfig ) );
}
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final ThreadingRule threading = new ThreadingRule();
@Rule
public final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();

@Before
public void setup()
{
fs = fileSystemRule.get();
roleFile = new File( testDirectory.directory( "dbms" ), "roles" );
roleRepository = new FileRoleRepository( fs, roleFile, logProvider );
}

Expand Down
7 changes: 0 additions & 7 deletions pom.xml
Expand Up @@ -523,13 +523,6 @@
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>


<!-- The JUnit-Hamcrest-Mockito combo -->
<dependency>
Expand Down

0 comments on commit e8deb0f

Please sign in to comment.