Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
321 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...test/java/org/neo4j/kernel/impl/index/schema/NativeNonUniqueSchemaIndexPopulatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,109 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "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.impl.index.schema; | |||
|
|||
import org.junit.Test; | |||
|
|||
import java.util.Arrays; | |||
import java.util.Iterator; | |||
|
|||
import org.neo4j.kernel.api.index.IndexEntryUpdate; | |||
import org.neo4j.kernel.api.index.IndexUpdater; | |||
import org.neo4j.kernel.api.schema.index.IndexDescriptor; | |||
import org.neo4j.storageengine.api.schema.IndexSample; | |||
import org.neo4j.values.storable.Values; | |||
|
|||
import static org.junit.Assert.assertEquals; | |||
|
|||
import static org.neo4j.kernel.impl.index.schema.LayoutTestUtil.countUniqueValues; | |||
|
|||
public abstract class NativeNonUniqueSchemaIndexPopulatorTest<KEY extends NativeSchemaKey,VALUE extends NativeSchemaValue> | |||
extends NativeSchemaIndexPopulatorTest<KEY,VALUE> | |||
{ | |||
@Test | |||
public void addShouldApplyDuplicateValues() throws Exception | |||
{ | |||
// given | |||
populator.create(); | |||
IndexEntryUpdate<IndexDescriptor>[] updates = layoutUtil.someUpdatesWithDuplicateValues(); | |||
|
|||
// when | |||
populator.add( Arrays.asList( updates ) ); | |||
|
|||
// then | |||
populator.close( true ); | |||
verifyUpdates( updates ); | |||
} | |||
|
|||
@Test | |||
public void updaterShouldApplyDuplicateValues() throws Exception | |||
{ | |||
// given | |||
populator.create(); | |||
IndexEntryUpdate<IndexDescriptor>[] updates = layoutUtil.someUpdatesWithDuplicateValues(); | |||
try ( IndexUpdater updater = populator.newPopulatingUpdater( null_property_accessor ) ) | |||
{ | |||
// when | |||
for ( IndexEntryUpdate<IndexDescriptor> update : updates ) | |||
{ | |||
updater.process( update ); | |||
} | |||
} | |||
|
|||
// then | |||
populator.close( true ); | |||
verifyUpdates( updates ); | |||
} | |||
|
|||
@Test | |||
public void shouldSampleUpdatesIfConfiguredForOnlineSampling() throws Exception | |||
{ | |||
// GIVEN | |||
populator.create(); | |||
IndexEntryUpdate<IndexDescriptor>[] scanUpdates = layoutUtil.someUpdates(); | |||
populator.add( Arrays.asList( scanUpdates ) ); | |||
Iterator<IndexEntryUpdate<IndexDescriptor>> generator = layoutUtil.randomUpdateGenerator( random ); | |||
Object[] updates = new Object[5]; | |||
updates[0] = generator.next().values()[0].asObject(); | |||
updates[1] = generator.next().values()[0].asObject(); | |||
updates[2] = updates[1]; | |||
updates[3] = generator.next().values()[0].asObject(); | |||
updates[4] = updates[3]; | |||
try ( IndexUpdater updater = populator.newPopulatingUpdater( null_property_accessor ) ) | |||
{ | |||
long nodeId = 1000; | |||
for ( Object value : updates ) | |||
{ | |||
IndexEntryUpdate<IndexDescriptor> update = layoutUtil.add( nodeId++, Values.of( value ) ); | |||
updater.process( update ); | |||
populator.includeSample( update ); | |||
} | |||
} | |||
|
|||
// WHEN | |||
IndexSample sample = populator.sampleResult(); | |||
|
|||
// THEN | |||
assertEquals( updates.length, sample.sampleSize() ); | |||
assertEquals( countUniqueValues( updates ), sample.uniqueValues() ); | |||
assertEquals( updates.length, sample.indexSize() ); | |||
populator.close( true ); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...rc/test/java/org/neo4j/kernel/impl/index/schema/NativeUniqueSchemaIndexPopulatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,116 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "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.impl.index.schema; | |||
|
|||
import org.junit.Test; | |||
|
|||
import java.util.Arrays; | |||
|
|||
import org.neo4j.helpers.Exceptions; | |||
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; | |||
import org.neo4j.kernel.api.index.IndexEntryUpdate; | |||
import org.neo4j.kernel.api.index.IndexUpdater; | |||
import org.neo4j.kernel.api.schema.index.IndexDescriptor; | |||
import org.neo4j.storageengine.api.schema.IndexSample; | |||
|
|||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
|
|||
import static java.util.Arrays.asList; | |||
|
|||
public abstract class NativeUniqueSchemaIndexPopulatorTest<KEY extends NativeSchemaKey,VALUE extends NativeSchemaValue> | |||
extends NativeSchemaIndexPopulatorTest<KEY,VALUE> | |||
{ | |||
@Test | |||
public void addShouldThrowOnDuplicateValues() throws Exception | |||
{ | |||
// given | |||
populator.create(); | |||
IndexEntryUpdate<IndexDescriptor>[] updates = layoutUtil.someUpdatesWithDuplicateValues(); | |||
|
|||
// when | |||
try | |||
{ | |||
populator.add( Arrays.asList( updates ) ); | |||
fail( "Updates should have conflicted" ); | |||
} | |||
catch ( Exception e ) | |||
{ | |||
// then | |||
assertTrue( Exceptions.contains( e, IndexEntryConflictException.class ) ); | |||
} | |||
finally | |||
{ | |||
populator.close( true ); | |||
} | |||
} | |||
|
|||
@Test | |||
public void updaterShouldThrowOnDuplicateValues() throws Exception | |||
{ | |||
// given | |||
populator.create(); | |||
IndexEntryUpdate<IndexDescriptor>[] updates = layoutUtil.someUpdatesWithDuplicateValues(); | |||
IndexUpdater updater = populator.newPopulatingUpdater( null_property_accessor ); | |||
|
|||
// when | |||
for ( IndexEntryUpdate<IndexDescriptor> update : updates ) | |||
{ | |||
updater.process( update ); | |||
} | |||
try | |||
{ | |||
updater.close(); | |||
fail( "Updates should have conflicted" ); | |||
} | |||
catch ( Exception e ) | |||
{ | |||
// then | |||
assertTrue( e.getMessage(), Exceptions.contains( e, IndexEntryConflictException.class ) ); | |||
} | |||
finally | |||
{ | |||
populator.close( true ); | |||
} | |||
} | |||
|
|||
@Test | |||
public void shouldSampleUpdates() throws Exception | |||
{ | |||
// GIVEN | |||
populator.create(); | |||
IndexEntryUpdate<IndexDescriptor>[] updates = layoutUtil.someUpdates(); | |||
|
|||
// WHEN | |||
populator.add( asList( updates ) ); | |||
for ( IndexEntryUpdate<IndexDescriptor> update : updates ) | |||
{ | |||
populator.includeSample( update ); | |||
} | |||
IndexSample sample = populator.sampleResult(); | |||
|
|||
// THEN | |||
assertEquals( updates.length, sample.sampleSize() ); | |||
assertEquals( updates.length, sample.uniqueValues() ); | |||
assertEquals( updates.length, sample.indexSize() ); | |||
populator.close( true ); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.