Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.2' into 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Jun 29, 2017
2 parents 8d9ebe7 + f717034 commit e2c986c
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*/
package org.neo4j.tooling;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.function.Function;
Expand All @@ -33,6 +35,8 @@
import org.neo4j.unsafe.impl.batchimport.input.csv.Deserialization;
import org.neo4j.unsafe.impl.batchimport.input.csv.Header;

import static org.neo4j.io.ByteUnit.mebiBytes;

public class CsvOutput implements BatchImporter
{
private final File targetDirectory;
Expand Down Expand Up @@ -141,6 +145,7 @@ private void serialize( PrintStream out, Header header )

private PrintStream file( String name ) throws IOException
{
return new PrintStream( new File( targetDirectory, name ) );
return new PrintStream( new BufferedOutputStream( new FileOutputStream( new File( targetDirectory, name ) ),
(int) mebiBytes( 1 ) ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.test.rule;

import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.util.function.Supplier;

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;
import org.neo4j.test.rule.fs.FileSystemRule;

/**
* Very often when you want a {@link PageCacheRule} you also want {@link TestDirectory} and some {@link FileSystemRule}.
* This is tedious to write and apply in the correct order in every test doing this. This rule collects
* this threesome into one rule for convenience.
*/
public class PageCacheAndDependenciesRule implements TestRule
{
private final RuleChain chain;
private final FileSystemRule<? extends FileSystemAbstraction> fs;
private final TestDirectory directory;
private final PageCacheRule pageCacheRule = new PageCacheRule();

public PageCacheAndDependenciesRule()
{
this( () -> new EphemeralFileSystemRule() );
}

/**
* @param fsSupplier as {@link Supplier} to make it clear that it is this class that owns the created
* {@link FileSystemRule} instance.
*/
public PageCacheAndDependenciesRule( Supplier<FileSystemRule<? extends FileSystemAbstraction>> fsSupplier )
{
this.fs = fsSupplier.get();
this.directory = TestDirectory.testDirectory( fs );
this.chain = RuleChain.outerRule( fs ).around( directory ).around( pageCacheRule );
}

@Override
public Statement apply( Statement base, Description description )
{
return chain.apply( base, description );
}

public FileSystemRule<? extends FileSystemAbstraction> fileSystemRule()
{
return fs;
}

public FileSystemAbstraction fileSystem()
{
return fs.get();
}

public TestDirectory directory()
{
return directory;
}

public PageCacheRule pageCacheRule()
{
return pageCacheRule;
}

public PageCache pageCache()
{
return pageCacheRule.getPageCache( fs );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles;
import org.neo4j.kernel.impl.transaction.log.entry.LogEntryVersion;
import org.neo4j.kernel.impl.transaction.log.entry.LogHeader;
import org.neo4j.kernel.impl.util.Dependencies;
import org.neo4j.kernel.internal.DatabaseHealth;
import org.neo4j.kernel.lifecycle.LifecycleException;
import org.neo4j.logging.AssertableLogProvider;
Expand All @@ -48,7 +49,6 @@
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;

import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -86,9 +86,11 @@ public void databaseHealthShouldBeHealedOnStart() throws Throwable
{
DatabaseHealth databaseHealth = new DatabaseHealth( mock( DatabasePanicEventGenerator.class ),
NullLogProvider.getInstance().getLog( DatabaseHealth.class ) );
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependency( databaseHealth );

theDataSource = dsRule.getDataSource( dir.graphDbDir(), fs.get(), pageCacheRule.getPageCache( fs.get() ),
stringMap(), databaseHealth );
dependencies );

databaseHealth.panic( new Throwable() );

Expand All @@ -110,7 +112,7 @@ public void databaseHealthShouldBeHealedOnStart() throws Throwable
public void flushOfThePageCacheHappensOnlyOnceDuringShutdown() throws IOException
{
PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) );
NeoStoreDataSource ds = dsRule.getDataSource( dir.graphDbDir(), fs.get(), pageCache, stringMap() );
NeoStoreDataSource ds = dsRule.getDataSource( dir.graphDbDir(), fs.get(), pageCache );

ds.init();
ds.start();
Expand All @@ -125,12 +127,9 @@ public void flushOfThePageCacheHappensOnlyOnceDuringShutdown() throws IOExceptio
@Test
public void flushOfThePageCacheOnShutdownHappensIfTheDbIsHealthy() throws IOException
{
DatabaseHealth health = mock( DatabaseHealth.class );
when( health.isHealthy() ).thenReturn( true );

PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) );

NeoStoreDataSource ds = dsRule.getDataSource( dir.graphDbDir(), fs.get(), pageCache, stringMap(), health );
NeoStoreDataSource ds = dsRule.getDataSource( dir.graphDbDir(), fs.get(), pageCache );

ds.init();
ds.start();
Expand All @@ -146,10 +145,11 @@ public void flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy() throw
{
DatabaseHealth health = mock( DatabaseHealth.class );
when( health.isHealthy() ).thenReturn( false );

PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) );

NeoStoreDataSource ds = dsRule.getDataSource( dir.graphDbDir(), fs.get(), pageCache, stringMap(), health );
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependency( health );
NeoStoreDataSource ds = dsRule.getDataSource( dir.graphDbDir(), fs.get(), pageCache, dependencies );

ds.init();
ds.start();
Expand Down Expand Up @@ -226,10 +226,11 @@ public void logModuleSetUpError() throws Exception
AssertableLogProvider logProvider = new AssertableLogProvider();
SimpleLogService logService = new SimpleLogService( logProvider, logProvider );
PageCache pageCache = pageCacheRule.getPageCache( fs.get() );
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependencies( idGeneratorFactory, idTypeConfigurationProvider, config, logService );

NeoStoreDataSource dataSource = dsRule.getDataSource( dir.graphDbDir(), fs.get(), idGeneratorFactory,
idTypeConfigurationProvider,
pageCache, config, mock( DatabaseHealth.class ), logService );
NeoStoreDataSource dataSource = dsRule.getDataSource( dir.graphDbDir(), fs.get(),
pageCache, dependencies );

try
{
Expand Down Expand Up @@ -258,7 +259,9 @@ public void shouldAlwaysShutdownLifeEvenWhenCheckPointingFails() throws Exceptio
IOException ex = new IOException( "boom!" );
doThrow( ex ).when( databaseHealth )
.assertHealthy( IOException.class ); // <- this is a trick to simulate a failure during checkpointing
NeoStoreDataSource dataSource = dsRule.getDataSource( storeDir, fs, pageCache, emptyMap(), databaseHealth );
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependencies( databaseHealth );
NeoStoreDataSource dataSource = dsRule.getDataSource( storeDir, fs, pageCache, dependencies );
dataSource.start();

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.neo4j.kernel.impl.transaction.state.PropertyLoader;
import org.neo4j.kernel.impl.transaction.state.TransactionRecordState.PropertyReceiver;
import org.neo4j.kernel.impl.util.ArrayMap;
import org.neo4j.kernel.impl.util.Dependencies;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.storageengine.api.NodeItem;
import org.neo4j.storageengine.api.PropertyItem;
Expand Down Expand Up @@ -910,7 +911,9 @@ private Token createDummyIndex( int id, String key )

private void initializeStores( File storeDir, Map<String,String> additionalConfig ) throws IOException
{
ds = dsRule.getDataSource( storeDir, fs.get(), pageCache, additionalConfig );
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependency( Config.embeddedDefaults( additionalConfig ) );
ds = dsRule.getDataSource( storeDir, fs.get(), pageCache, dependencies );
ds.init();
ds.start();

Expand Down

0 comments on commit e2c986c

Please sign in to comment.