Skip to content

Commit

Permalink
Fix the initialisation of the Lucene compatibility tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Feb 22, 2017
1 parent fa61995 commit 52e0939
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 31 deletions.
Expand Up @@ -43,31 +43,32 @@
} )
public abstract class IndexProviderCompatibilityTestSuite
{
@Rule
public final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();
@Rule
public final TestDirectory testDir = TestDirectory.testDirectory( getClass() );

protected File graphDbDir;
protected FileSystemAbstraction fs = fileSystemRule.get();

@Before
public void setup()
{
fs = fileSystemRule.get();
graphDbDir = testDir.graphDbDir();
}

protected abstract SchemaIndexProvider createIndexProvider();
protected abstract SchemaIndexProvider createIndexProvider( FileSystemAbstraction fs, File graphDbDir );

public abstract static class Compatibility
{
protected final SchemaIndexProvider indexProvider;
@Rule
public final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();
@Rule
public final TestDirectory testDir = TestDirectory.testDirectory( getClass() );

protected File graphDbDir;
protected FileSystemAbstraction fs;
protected final IndexProviderCompatibilityTestSuite testSuite;
protected SchemaIndexProvider indexProvider;
protected NewIndexDescriptor descriptor = NewIndexDescriptorFactory.forLabel( 1, 2 );

@Before
public void setup()
{
fs = fileSystemRule.get();
graphDbDir = testDir.graphDbDir();
indexProvider = testSuite.createIndexProvider( fs, graphDbDir );
}

public Compatibility( IndexProviderCompatibilityTestSuite testSuite )
{
this.indexProvider = testSuite.createIndexProvider();
this.testSuite = testSuite;
}
}
}
Expand Up @@ -19,13 +19,16 @@
*/
package org.neo4j.kernel.impl.api.index.inmemory;

import java.io.File;

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.index.IndexProviderCompatibilityTestSuite;
import org.neo4j.kernel.api.index.SchemaIndexProvider;

public class InMemoryIndexProviderTest extends IndexProviderCompatibilityTestSuite
{
@Override
protected SchemaIndexProvider createIndexProvider()
protected SchemaIndexProvider createIndexProvider( FileSystemAbstraction fs, File graphDbDir )
{
return new InMemoryIndexProvider();
}
Expand Down
@@ -0,0 +1,43 @@
/*
* 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.kernel.api.impl.schema;

import java.io.File;

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.impl.index.storage.DirectoryFactory;
import org.neo4j.kernel.api.index.IndexProviderCompatibilityTestSuite;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.logging.NullLogProvider;

public class LuceneSchemaIndexProviderCompatibilitySuiteTest extends IndexProviderCompatibilityTestSuite
{
@Override
protected LuceneSchemaIndexProvider createIndexProvider( FileSystemAbstraction fs, File graphDbDir )
{
DirectoryFactory.InMemoryDirectoryFactory directoryFactory = new DirectoryFactory.InMemoryDirectoryFactory();
NullLogProvider logging = NullLogProvider.getInstance();
Config config = Config.defaults();
OperationalMode mode = OperationalMode.single;
return new LuceneSchemaIndexProvider( fs, directoryFactory, graphDbDir, logging, config, mode );

}
}
Expand Up @@ -19,45 +19,59 @@
*/
package org.neo4j.kernel.api.impl.schema;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.File;
import java.io.IOException;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.impl.index.storage.DirectoryFactory;
import org.neo4j.kernel.api.index.IndexAccessor;
import org.neo4j.kernel.api.index.IndexConfiguration;
import org.neo4j.kernel.api.schema.IndexDescriptorFactory;
import org.neo4j.kernel.api.index.IndexProviderCompatibilityTestSuite;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.impl.api.index.IndexUpdateMode;
import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;

import static org.neo4j.helpers.collection.MapUtil.stringMap;

public class LuceneSchemaIndexProviderTest extends IndexProviderCompatibilityTestSuite
/**
* Additional tests for stuff not already covered by {@link LuceneSchemaIndexProviderCompatibilitySuiteTest}
*/
public class LuceneSchemaIndexProviderTest
{

@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
public final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();
@Rule
public final TestDirectory testDir = TestDirectory.testDirectory( getClass() );

protected File graphDbDir;
protected FileSystemAbstraction fs;

@Override
protected LuceneSchemaIndexProvider createIndexProvider()
@Before
public void setup()
{
return getLuceneSchemaIndexProvider( Config.defaults(), new DirectoryFactory.InMemoryDirectoryFactory() );
fs = fileSystemRule.get();
graphDbDir = testDir.graphDbDir();
}

@Test
public void shouldFailToInvokePopulatorInReadOnlyMode() throws Exception
{
Config readOnlyConfig = Config.embeddedDefaults( stringMap( GraphDatabaseSettings.read_only.name(), Settings.TRUE ) );
LuceneSchemaIndexProvider readOnlyIndexProvider = getLuceneSchemaIndexProvider( readOnlyConfig,
new DirectoryFactory.InMemoryDirectoryFactory() );
new DirectoryFactory.InMemoryDirectoryFactory(), fs, graphDbDir );
expectedException.expect( UnsupportedOperationException.class );

readOnlyIndexProvider.getPopulator( 1L, IndexDescriptorFactory.of( 1, 1 ),
Expand All @@ -73,7 +87,7 @@ public void shouldCreateReadOnlyAccessorInReadOnlyMode() throws Exception

Config readOnlyConfig = Config.embeddedDefaults( stringMap( GraphDatabaseSettings.read_only.name(), Settings.TRUE ) );
LuceneSchemaIndexProvider readOnlyIndexProvider = getLuceneSchemaIndexProvider( readOnlyConfig,
directoryFactory );
directoryFactory, fs, graphDbDir );
IndexAccessor onlineAccessor = getIndexAccessor( readOnlyConfig, readOnlyIndexProvider );

expectedException.expect( UnsupportedOperationException.class );
Expand All @@ -85,7 +99,7 @@ public void indexUpdateNotAllowedInReadOnlyMode() throws Exception
{
Config readOnlyConfig = Config.embeddedDefaults( stringMap( GraphDatabaseSettings.read_only.name(), Settings.TRUE ) );
LuceneSchemaIndexProvider readOnlyIndexProvider = getLuceneSchemaIndexProvider( readOnlyConfig,
new DirectoryFactory.InMemoryDirectoryFactory() );
new DirectoryFactory.InMemoryDirectoryFactory(), fs, graphDbDir );

expectedException.expect( UnsupportedOperationException.class );
getIndexAccessor( readOnlyConfig, readOnlyIndexProvider ).newUpdater( IndexUpdateMode.ONLINE);
Expand All @@ -94,7 +108,8 @@ public void indexUpdateNotAllowedInReadOnlyMode() throws Exception
private void createEmptySchemaIndex( DirectoryFactory directoryFactory ) throws IOException
{
Config config = Config.defaults();
LuceneSchemaIndexProvider indexProvider = getLuceneSchemaIndexProvider( config, directoryFactory );
LuceneSchemaIndexProvider indexProvider = getLuceneSchemaIndexProvider( config, directoryFactory, fs,
graphDbDir );
IndexAccessor onlineAccessor = getIndexAccessor( config, indexProvider );
onlineAccessor.flush();
onlineAccessor.close();
Expand All @@ -107,8 +122,10 @@ private IndexAccessor getIndexAccessor( Config readOnlyConfig, LuceneSchemaIndex
new IndexSamplingConfig( readOnlyConfig ) );
}

private LuceneSchemaIndexProvider getLuceneSchemaIndexProvider( Config config, DirectoryFactory directoryFactory )
private LuceneSchemaIndexProvider getLuceneSchemaIndexProvider( Config config, DirectoryFactory directoryFactory,
FileSystemAbstraction fs, File graphDbDir )
{
return new LuceneSchemaIndexProvider( fs, directoryFactory, graphDbDir, NullLogProvider.getInstance(), config, OperationalMode.single );
return new LuceneSchemaIndexProvider(
fs, directoryFactory, graphDbDir, NullLogProvider.getInstance(), config, OperationalMode.single );
}
}

0 comments on commit 52e0939

Please sign in to comment.