Skip to content

Commit

Permalink
Introduce test helper for combined index tests
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen authored and tinwelint committed Aug 4, 2017
1 parent 52d2b1d commit bcf6405
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 72 deletions.
Expand Up @@ -19,30 +19,26 @@
*/
package org.neo4j.kernel.impl.index.schema.combined;

import org.apache.commons.lang3.ArrayUtils;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.Callable;

import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.Values;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.neo4j.kernel.impl.index.schema.combined.CombinedIndexTestHelp.verifyCallFail;

public class CombinedIndexPopulatorTest
{
Expand Down Expand Up @@ -148,31 +144,9 @@ public void dropMustThrowIfDropFallbackThrow() throws Exception
public void addMustSelectCorrectPopulator() throws Exception
{
// given
Value[] numberValues = new Value[]
{
Values.byteValue( (byte) 1 ),
Values.shortValue( (short) 2 ),
Values.intValue( 3 ),
Values.longValue( 4 ),
Values.floatValue( 5.6f ),
Values.doubleValue( 7.8 )
};
Value[] otherValues = new Value[]
{
Values.booleanValue( true ),
Values.charValue( 'a' ),
Values.stringValue( "bcd" ),
Values.booleanArray( new boolean[2] ),
Values.byteArray( new byte[]{1, 2} ),
Values.shortArray( new short[]{3, 4} ),
Values.intArray( new int[]{5, 6} ),
Values.longArray( new long[]{7, 8} ),
Values.floatArray( new float[]{9.10f, 11.12f} ),
Values.doubleArray( new double[]{13.14, 15.16} ),
Values.charArray( new char[2] ),
Values.stringArray( new String[2] ),
Values.NO_VALUE
};
Value[] numberValues = CombinedIndexTestHelp.valuesSupportedByBoost();
Value[] otherValues = CombinedIndexTestHelp.valuesNotSupportedByBoost();
Value[] allValues = CombinedIndexTestHelp.allValues();

// Add with boost for number values
for ( Value numberValue : numberValues )
Expand All @@ -187,7 +161,6 @@ public void addMustSelectCorrectPopulator() throws Exception
}

// All composite values should go to fallback
Value[] allValues = ArrayUtils.addAll( numberValues, otherValues );
for ( Value firstValue : allValues )
{
for ( Value secondValue : allValues )
Expand Down Expand Up @@ -350,17 +323,4 @@ public void markAsFailedMustThrowIfFallbackThrow() throws Exception
// includeSample

// configureSample

private void verifyCallFail( Exception expectedFailure, Callable failingCall ) throws Exception
{
try
{
failingCall.call();
fail( "Should have failed" );
}
catch ( Exception e )
{
assertSame( expectedFailure, e );
}
}
}
@@ -0,0 +1,68 @@
package org.neo4j.kernel.impl.index.schema.combined;

import org.apache.commons.lang3.ArrayUtils;

import java.util.concurrent.Callable;

import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.Values;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;

class CombinedIndexTestHelp
{
private static final Value[] numberValues = new Value[]
{
Values.byteValue( (byte) 1 ),
Values.shortValue( (short) 2 ),
Values.intValue( 3 ),
Values.longValue( 4 ),
Values.floatValue( 5.6f ),
Values.doubleValue( 7.8 )
};
private static final Value[] otherValues = new Value[]
{
Values.booleanValue( true ),
Values.charValue( 'a' ),
Values.stringValue( "bcd" ),
Values.booleanArray( new boolean[2] ),
Values.byteArray( new byte[]{1, 2} ),
Values.shortArray( new short[]{3, 4} ),
Values.intArray( new int[]{5, 6} ),
Values.longArray( new long[]{7, 8} ),
Values.floatArray( new float[]{9.10f, 11.12f} ),
Values.doubleArray( new double[]{13.14, 15.16} ),
Values.charArray( new char[2] ),
Values.stringArray( new String[2] ),
Values.NO_VALUE
};

static Value[] valuesSupportedByBoost()
{
return numberValues;
}

static Value[] valuesNotSupportedByBoost()
{
return otherValues;
}

static Value[] allValues()
{
return ArrayUtils.addAll( numberValues, otherValues );
}

static void verifyCallFail( Exception expectedFailure, Callable failingCall ) throws Exception
{
try
{
failingCall.call();
fail( "Should have failed" );
}
catch ( Exception e )
{
assertSame( expectedFailure, e );
}
}
}
Expand Up @@ -19,7 +19,6 @@
*/
package org.neo4j.kernel.impl.index.schema.combined;

import org.apache.commons.lang3.ArrayUtils;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -30,7 +29,6 @@
import org.neo4j.storageengine.api.schema.IndexSample;
import org.neo4j.test.rule.RandomRule;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.Values;

import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -100,31 +98,9 @@ public void mustSelectCorrectTargetForAllGivenValueCombinations() throws Excepti
SchemaIndexProvider boostProvider = mock( SchemaIndexProvider.class );
SchemaIndexProvider fallbackProvider = mock( SchemaIndexProvider.class );

Value[] numberValues = new Value[]
{
Values.byteValue( (byte) 1 ),
Values.shortValue( (short) 2 ),
Values.intValue( 3 ),
Values.longValue( 4 ),
Values.floatValue( 5.6f ),
Values.doubleValue( 7.8 )
};
Value[] otherValues = new Value[]
{
Values.booleanValue( true ),
Values.charValue( 'a' ),
Values.stringValue( "bcd" ),
Values.booleanArray( new boolean[2] ),
Values.byteArray( new byte[2] ),
Values.shortArray( new short[2] ),
Values.intArray( new int[2] ),
Values.longArray( new long[2] ),
Values.floatArray( new float[2] ),
Values.doubleArray( new double[2] ),
Values.charArray( new char[2] ),
Values.stringArray( new String[2] ),
Values.NO_VALUE
};
Value[] numberValues = CombinedIndexTestHelp.valuesSupportedByBoost();
Value[] otherValues = CombinedIndexTestHelp.valuesNotSupportedByBoost();
Value[] allValues = CombinedIndexTestHelp.allValues();

// Number values should go to boost provider
for ( Value numberValue : numberValues )
Expand All @@ -147,7 +123,6 @@ public void mustSelectCorrectTargetForAllGivenValueCombinations() throws Excepti
}

// All composite values should go to fallback
Value[] allValues = ArrayUtils.addAll( numberValues, otherValues );
for ( Value firstValue : allValues )
{
for ( Value secondValue : allValues )
Expand Down

0 comments on commit bcf6405

Please sign in to comment.