Skip to content

Commit

Permalink
Adds a thorough test for transaction event data
Browse files Browse the repository at this point in the history
also makes DatabaseRule implement GraphDatabaseAPI so that
dbRule.getGraphDatabaseService()/getGraphDatabaseAPI() gets deprecated,
since a DatabaseRule can be used as a
GraphDatabaseAPI/GraphDatabaseService directly.
Also changes the default behaviour so that the db is started as part of
the before section of the rule instead of on the first call to
getGDS()/getGDAPI() to behave more like rules usually do. Although there's
the option of having the old behaviour to start lazily. This is done by
calling startLazily() on the DatabaseRule, f.ex:

DatabaseRule db = new EmbeddedDatabaseRule( getClass() ).startLazily()

although very few tests need that functionality.
  • Loading branch information
tinwelint committed Jul 18, 2015
1 parent cb06f46 commit 558462e
Show file tree
Hide file tree
Showing 16 changed files with 999 additions and 166 deletions.
Expand Up @@ -90,7 +90,7 @@ public void shouldImportWithAsManyDefaultsAsAvailable() throws Exception

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(),
"--relationships", relationshipData( true, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() );

Expand All @@ -107,7 +107,7 @@ public void shouldImportWithHeadersBeingInSeparateFiles() throws Exception

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--delimiter", "TAB",
"--array-delimiter", String.valueOf( config.arrayDelimiter() ),
"--nodes",
Expand All @@ -130,7 +130,7 @@ public void shouldImportSplitInputFiles() throws Exception

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", // One group with one header file and one data file
nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER +
nodeData( false, config, nodeIds, lines( 0, NODE_COUNT/2 ) ).getAbsolutePath(),
Expand Down Expand Up @@ -159,7 +159,7 @@ public void shouldImportMultipleInputsWithAddedLabelsAndDefaultRelationshipType(

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes:" + join( firstLabels, ":" ),
nodeData( true, config, nodeIds, lines( 0, NODE_COUNT/2 ) ).getAbsolutePath(),
"--nodes:" + join( secondLabels, ":" ),
Expand Down Expand Up @@ -213,7 +213,7 @@ public void shouldImportOnlyNodes() throws Exception

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath() );
// no relationships

Expand Down Expand Up @@ -249,7 +249,7 @@ public void shouldImportGroupsOfOverlappingIds() throws Exception

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeHeader( config, groupOne ) + MULTI_FILE_DELIMITER +
nodeData( false, config, groupOneNodeIds, alwaysTrue() ),
"--nodes", nodeHeader( config, groupTwo ) + MULTI_FILE_DELIMITER +
Expand Down Expand Up @@ -285,7 +285,7 @@ public void shouldNotBeAbleToMixSpecifiedAndUnspecifiedGroups() throws Exception
try
{
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeHeader( config, "MyGroup" ).getAbsolutePath() + MULTI_FILE_DELIMITER +
nodeData( false, config, groupOneNodeIds, alwaysTrue() ).getAbsolutePath(),
"--nodes", nodeHeader( config ).getAbsolutePath() + MULTI_FILE_DELIMITER +
Expand All @@ -308,7 +308,7 @@ public void shouldImportWithoutTypeSpecifiedInRelationshipHeaderbutWithDefaultTy

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(),
// there will be no :TYPE specified in the header of the relationships below
"--relationships:" + type,
Expand All @@ -332,7 +332,7 @@ public void shouldIncludeSourceInformationInNodeIdCollisionError() throws Except
try
{
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeHeaderFile.getAbsolutePath() + MULTI_FILE_DELIMITER +
nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER +
nodeData2.getAbsolutePath() );
Expand All @@ -358,7 +358,7 @@ public void shouldSkipDuplicateNodesIfToldTo() throws Exception

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--skip-duplicate-nodes",
"--nodes", nodeHeaderFile.getAbsolutePath() + MULTI_FILE_DELIMITER +
nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER +
Expand Down Expand Up @@ -404,7 +404,7 @@ public void shouldLogRelationshipsReferingToMissingNode() throws Exception

// WHEN importing data where some relationships refer to missing nodes
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeData.getAbsolutePath(),
"--bad", bad.getAbsolutePath(),
"--bad-tolerance", "2",
Expand Down Expand Up @@ -442,7 +442,7 @@ public void shouldFailIfTooManyBadRelationships() throws Exception
try
{
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeData.getAbsolutePath(),
"--bad", bad.getAbsolutePath(),
"--bad-tolerance", "1",
Expand Down Expand Up @@ -477,7 +477,7 @@ public void shouldBeAbleToDisableSkippingOfBadRelationships() throws Exception
try
{
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeData.getAbsolutePath(),
"--bad", bad.getAbsolutePath(),
"--skip-bad-relationships", "false",
Expand All @@ -502,7 +502,7 @@ public void shouldHandleAdditiveLabelsWithSpaces() throws Exception

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes:My First Label:My Other Label",
nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(),
"--relationships", relationshipData( true, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() );
Expand All @@ -529,7 +529,7 @@ public void shouldImportFromInputDataEncodedWithSpecificCharset() throws Excepti

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--input-encoding", charset.name(),
"--nodes", nodeData( true, config, nodeIds, alwaysTrue(), charset ).getAbsolutePath(),
"--relationships", relationshipData( true, config, nodeIds, alwaysTrue(), true, charset )
Expand All @@ -550,7 +550,7 @@ public void shouldDisallowImportWithoutNodesInput() throws Exception
try
{
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--relationships", relationshipData( true, config, nodeIds, alwaysTrue(), true ).getAbsolutePath() );
fail( "Should have failed" );
}
Expand All @@ -571,7 +571,7 @@ public void shouldBeAbleToImportAnonymousNodes() throws Exception

// WHEN
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", nodeData( true, config, nodeIds, alwaysTrue() ).getAbsolutePath(),
"--relationships", relationshipData( true, config, relationshipData.iterator(),
alwaysTrue(), true ).getAbsolutePath() );
Expand Down Expand Up @@ -608,7 +608,7 @@ public void shouldDisallowMultilineFieldsByDefault() throws Exception
try
{
importTool(
"--into", dbRule.getStoreDir().getAbsolutePath(),
"--into", dbRule.getStoreDirAbsolutePath(),
"--nodes", data.getAbsolutePath() );
}
catch ( Exception e )
Expand Down Expand Up @@ -1046,7 +1046,7 @@ private void importTool( String... arguments )
private static final int NODE_COUNT = 100;

@Rule
public final EmbeddedDatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() );
public final EmbeddedDatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() ).startLazily();
public final @Rule RandomRule random = new RandomRule();
public final @Rule Mute mute = Mute.mute( Mute.System.values() );
private int dataIndex;
Expand Down
59 changes: 58 additions & 1 deletion community/kernel/src/main/java/org/neo4j/helpers/ArrayUtil.java
Expand Up @@ -76,6 +76,63 @@ public boolean itemEquals( Object lhs, Object rhs )
}
};

public static final ArrayEquality BOXING_AWARE_ARRAY_EQUALITY = new ArrayEquality()
{
@Override
public boolean typeEquals( Class<?> firstType, Class<?> otherType )
{
return boxedType( firstType ) == boxedType( otherType );
}

private Class<?> boxedType( Class<?> type )
{
if ( !type.isPrimitive() )
{
return type;
}

if ( type.equals( Boolean.TYPE ) )
{
return Boolean.class;
}
if ( type.equals( Byte.TYPE ) )
{
return Byte.class;
}
if ( type.equals( Short.TYPE ) )
{
return Short.class;
}
if ( type.equals( Character.TYPE ) )
{
return Character.class;
}
if ( type.equals( Integer.TYPE ) )
{
return Integer.class;
}
if ( type.equals( Long.TYPE ) )
{
return Long.class;
}
if ( type.equals( Float.TYPE ) )
{
return Float.class;
}
if ( type.equals( Double.TYPE ) )
{
return Double.class;
}
throw new IllegalArgumentException( "Oops, forgot to include a primitive type " + type );
}

@Override
public boolean itemEquals( Object lhs, Object rhs )
{
return lhs == rhs || lhs != null && lhs.equals( rhs );
}
};

public static boolean equals( Object firstArray, Object otherArray )
{
return equals( firstArray, otherArray, DEFAULT_ARRAY_EQUALITY );
Expand All @@ -97,7 +154,7 @@ public static boolean equals( Object firstArray, Object otherArray, ArrayEqualit
assert otherArray.getClass().isArray() : otherArray + " is not an array";

int length;
if ( equality.typeEquals( firstArray.getClass(), otherArray.getClass() )
if ( equality.typeEquals( firstArray.getClass().getComponentType(), otherArray.getClass().getComponentType() )
&& (length = Array.getLength( firstArray )) == Array.getLength( otherArray ) )
{
for ( int i = 0; i < length; i++ )
Expand Down

0 comments on commit 558462e

Please sign in to comment.