Skip to content

Commit

Permalink
Migrate neo4j module tests to junit5
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Jul 26, 2018
1 parent 9bfce59 commit ff1d511
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 329 deletions.
4 changes: 0 additions & 4 deletions community/neo4j/pom.xml
Expand Up @@ -90,10 +90,6 @@ the relevant Commercial Agreement.
</dependency>

<!-- For the tests specified by this package -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
Expand Down
Expand Up @@ -19,8 +19,8 @@
*/
package migration;

import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.File;

Expand All @@ -35,40 +35,44 @@
import org.neo4j.kernel.impl.store.format.standard.StandardV3_2;
import org.neo4j.kernel.impl.store.format.standard.StandardV3_4;
import org.neo4j.kernel.impl.storemigration.StoreUpgrader;
import org.neo4j.test.extension.Inject;
import org.neo4j.test.extension.TestDirectoryExtension;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.values.storable.PointValue;

import static migration.RecordFormatMigrationIT.startDatabaseWithFormat;
import static migration.RecordFormatMigrationIT.startNonUpgradableDatabaseWithFormat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.neo4j.values.storable.CoordinateReferenceSystem.Cartesian;
import static org.neo4j.values.storable.Values.pointValue;

@ExtendWith( TestDirectoryExtension.class )
public class PointPropertiesRecordFormatIT
{
@Rule
public final TestDirectory testDirectory = TestDirectory.testDirectory();
@Inject
private TestDirectory testDirectory;

@Test
public void failToCreatePointOnOldDatabase()
void failToCreatePointOnOldDatabase()
{
File storeDir = testDirectory.storeDir();
GraphDatabaseService nonUpgradedStore = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME );
try ( Transaction transaction = nonUpgradedStore.beginTx() )
TransactionFailureException exception = assertThrows( TransactionFailureException.class, () ->
{
Node node = nonUpgradedStore.createNode();
node.setProperty( "a", pointValue( Cartesian, 1.0, 2.0 ) );
transaction.success();
}
catch ( TransactionFailureException e )
{
assertEquals( "Current record format does not support POINT_PROPERTIES. Please upgrade your store " +
"to the format that support requested capability.", Exceptions.rootCause( e ).getMessage() );
}
try ( Transaction transaction = nonUpgradedStore.beginTx() )
{
Node node = nonUpgradedStore.createNode();
node.setProperty( "a", pointValue( Cartesian, 1.0, 2.0 ) );
transaction.success();
}
} );
assertEquals( "Current record format does not support POINT_PROPERTIES. Please upgrade your store to the format that support requested capability.",
Exceptions.rootCause( exception ).getMessage() );
nonUpgradedStore.shutdown();

GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME );
Expand All @@ -82,22 +86,22 @@ public void failToCreatePointOnOldDatabase()
}

@Test
public void failToCreatePointArrayOnOldDatabase()
void failToCreatePointArrayOnOldDatabase()
{
File storeDir = testDirectory.storeDir();
GraphDatabaseService nonUpgradedStore = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME );
PointValue point = pointValue( Cartesian, 1.0, 2.0 );
try ( Transaction transaction = nonUpgradedStore.beginTx() )
TransactionFailureException exception = assertThrows( TransactionFailureException.class, () ->
{
Node node = nonUpgradedStore.createNode();
node.setProperty( "a", new PointValue[]{point, point} );
transaction.success();
}
catch ( TransactionFailureException e )
{
assertEquals( "Current record format does not support POINT_PROPERTIES. Please upgrade your store " +
"to the format that support requested capability.", Exceptions.rootCause( e ).getMessage() );
}
try ( Transaction transaction = nonUpgradedStore.beginTx() )
{
Node node = nonUpgradedStore.createNode();
node.setProperty( "a", new PointValue[]{point, point} );
transaction.success();
}
} );
assertEquals( "Current record format does not support POINT_PROPERTIES. Please upgrade your store to the format that support requested capability.",
Exceptions.rootCause( exception ).getMessage() );
nonUpgradedStore.shutdown();

GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME );
Expand All @@ -111,7 +115,7 @@ public void failToCreatePointArrayOnOldDatabase()
}

@Test
public void createPointPropertyOnLatestDatabase()
void createPointPropertyOnLatestDatabase()
{
File storeDir = testDirectory.storeDir();
Label pointNode = Label.label( "PointNode" );
Expand All @@ -136,7 +140,7 @@ public void createPointPropertyOnLatestDatabase()
}

@Test
public void createPointArrayPropertyOnLatestDatabase()
void createPointArrayPropertyOnLatestDatabase()
{
File storeDir = testDirectory.storeDir();
Label pointNode = Label.label( "PointNode" );
Expand Down Expand Up @@ -166,7 +170,7 @@ public void createPointArrayPropertyOnLatestDatabase()
}

@Test
public void failToOpenStoreWithPointPropertyUsingOldFormat()
void failToOpenStoreWithPointPropertyUsingOldFormat()
{
File storeDir = testDirectory.storeDir();
GraphDatabaseService database = startDatabaseWithFormat( storeDir, StandardV3_4.NAME );
Expand All @@ -178,13 +182,7 @@ public void failToOpenStoreWithPointPropertyUsingOldFormat()
}
database.shutdown();

try
{
startDatabaseWithFormat( storeDir, StandardV3_2.NAME );
}
catch ( Throwable t )
{
assertSame( StoreUpgrader.AttemptedDowngradeException.class, Exceptions.rootCause( t ).getClass() );
}
Throwable throwable = assertThrows( Throwable.class, () -> startDatabaseWithFormat( storeDir, StandardV3_2.NAME ) );
assertSame( StoreUpgrader.AttemptedDowngradeException.class, Exceptions.rootCause( throwable ).getClass() );
}
}
Expand Up @@ -19,9 +19,9 @@
*/
package migration;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.File;

Expand All @@ -38,29 +38,33 @@
import org.neo4j.kernel.impl.storemigration.StoreUpgrader;
import org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.extension.Inject;
import org.neo4j.test.extension.TestDirectoryExtension;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.allow_upgrade;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.record_format;
import static org.neo4j.kernel.configuration.Settings.FALSE;
import static org.neo4j.kernel.configuration.Settings.TRUE;

public class RecordFormatMigrationIT
@ExtendWith( TestDirectoryExtension.class )
class RecordFormatMigrationIT
{
@Rule
public final TestDirectory testDirectory = TestDirectory.testDirectory();
@Inject
private TestDirectory testDirectory;
private File storeDir;

@Before
public void setUp()
@BeforeEach
void setUp()
{
storeDir = testDirectory.storeDir();
}

@Test
public void failToDowngradeFormatWhenUpgradeNotAllowed()
void failToDowngradeFormatWhenUpgradeNotAllowed()
{
GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_4.NAME );
try ( Transaction transaction = database.beginTx() )
Expand All @@ -70,18 +74,12 @@ public void failToDowngradeFormatWhenUpgradeNotAllowed()
transaction.success();
}
database.shutdown();
try
{
startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_2.NAME );
}
catch ( Throwable t )
{
assertSame( UpgradeNotAllowedByConfigurationException.class, Exceptions.rootCause( t ).getClass() );
}
Throwable throwable = assertThrows( Throwable.class, () -> startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_2.NAME ) );
assertSame( UpgradeNotAllowedByConfigurationException.class, Exceptions.rootCause( throwable ).getClass() );
}

@Test
public void failToDowngradeFormatWheUpgradeAllowed()
void failToDowngradeFormatWheUpgradeAllowed()
{
GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_4.NAME );
try ( Transaction transaction = database.beginTx() )
Expand All @@ -91,21 +89,15 @@ public void failToDowngradeFormatWheUpgradeAllowed()
transaction.success();
}
database.shutdown();
try
{
new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir )
.setConfig( record_format, StandardV3_2.NAME )
.setConfig( allow_upgrade, Settings.TRUE )
.newGraphDatabase();
}
catch ( Throwable t )
{
assertSame( StoreUpgrader.AttemptedDowngradeException.class, Exceptions.rootCause( t ).getClass() );
}
Throwable throwable = assertThrows( Throwable.class,
() -> new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir )
.setConfig( record_format, StandardV3_2.NAME )
.setConfig( allow_upgrade, Settings.TRUE ).newGraphDatabase() );
assertSame( StoreUpgrader.AttemptedDowngradeException.class, Exceptions.rootCause( throwable ).getClass() );
}

@Test
public void skipMigrationIfFormatSpecifiedInConfig()
void skipMigrationIfFormatSpecifiedInConfig()
{
GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_2.NAME );
try ( Transaction transaction = database.beginTx() )
Expand All @@ -123,7 +115,7 @@ public void skipMigrationIfFormatSpecifiedInConfig()
}

@Test
public void skipMigrationIfStoreFormatNotSpecifiedButIsAvailableInRuntime()
void skipMigrationIfStoreFormatNotSpecifiedButIsAvailableInRuntime()
{
GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_2.NAME );
try ( Transaction transaction = database.beginTx() )
Expand All @@ -142,7 +134,7 @@ public void skipMigrationIfStoreFormatNotSpecifiedButIsAvailableInRuntime()
}

@Test
public void latestRecordNotMigratedWhenFormatBumped()
void latestRecordNotMigratedWhenFormatBumped()
{
GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_2.NAME );
try ( Transaction transaction = database.beginTx() )
Expand All @@ -153,14 +145,8 @@ public void latestRecordNotMigratedWhenFormatBumped()
}
database.shutdown();

try
{
startDatabaseWithFormatUnspecifiedUpgrade( storeDir, Standard.LATEST_NAME );
}
catch ( Throwable t )
{
assertSame( UpgradeNotAllowedByConfigurationException.class, Exceptions.rootCause( t ).getClass() );
}
Throwable exception = assertThrows( Throwable.class, () -> startDatabaseWithFormatUnspecifiedUpgrade( storeDir, Standard.LATEST_NAME ) );
assertSame( UpgradeNotAllowedByConfigurationException.class, Exceptions.rootCause( exception ).getClass() );
}

private static GraphDatabaseService startDatabaseWithFormatUnspecifiedUpgrade( File storeDir, String formatName )
Expand Down

0 comments on commit ff1d511

Please sign in to comment.