Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional tests for id components constructed during edition cre…
…ation. Update dependency resolver to include only one id generation factory.
- Loading branch information
1 parent
da8f3fb
commit 7d0b6d9
Showing
15 changed files
with
250 additions
and
9 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
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
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
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
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
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
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
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
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
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
71 changes: 71 additions & 0 deletions
71
...g/neo4j/causalclustering/core/state/machines/id/FreeIdFilteredIdGeneratorFactoryTest.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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 Affero 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 Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.causalclustering.core.state.machines.id; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
|
||
import org.neo4j.kernel.impl.store.id.IdGenerator; | ||
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory; | ||
import org.neo4j.kernel.impl.store.id.IdType; | ||
|
||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class FreeIdFilteredIdGeneratorFactoryTest | ||
{ | ||
private IdGeneratorFactory idGeneratorFactory = mock( IdGeneratorFactory.class ); | ||
private File file = mock( File.class ); | ||
|
||
@Test | ||
public void openFilteredGenerator() throws Exception | ||
{ | ||
FreeIdFilteredIdGeneratorFactory filteredGenerator = createFilteredFactory(); | ||
IdType idType = IdType.NODE; | ||
long highId = 1L; | ||
long maxId = 10L; | ||
IdGenerator idGenerator = filteredGenerator.open( file, idType, highId, maxId ); | ||
|
||
verify( idGeneratorFactory ).open( file, idType, highId, maxId ); | ||
assertThat( idGenerator, instanceOf( FreeIdFilteredIdGenerator.class ) ); | ||
} | ||
|
||
@Test | ||
public void openFilteredGeneratorWithGrabSize() throws Exception | ||
{ | ||
FreeIdFilteredIdGeneratorFactory filteredGenerator = createFilteredFactory(); | ||
IdType idType = IdType.NODE; | ||
long highId = 1L; | ||
long maxId = 10L; | ||
int grabSize = 5; | ||
IdGenerator idGenerator = filteredGenerator.open( file, grabSize, idType, highId, maxId ); | ||
|
||
verify( idGeneratorFactory ).open( file, grabSize, idType, highId, maxId ); | ||
assertThat( idGenerator, instanceOf( FreeIdFilteredIdGenerator.class ) ); | ||
} | ||
|
||
private FreeIdFilteredIdGeneratorFactory createFilteredFactory() | ||
{ | ||
return new FreeIdFilteredIdGeneratorFactory( idGeneratorFactory, () -> true ); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...java/org/neo4j/causalclustering/core/state/machines/id/FreeIdFilteredIdGeneratorTest.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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 Affero 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 Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.causalclustering.core.state.machines.id; | ||
|
||
import org.apache.commons.lang3.mutable.MutableBoolean; | ||
import org.junit.Test; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import org.neo4j.kernel.impl.store.id.IdGenerator; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyZeroInteractions; | ||
|
||
public class FreeIdFilteredIdGeneratorTest | ||
{ | ||
|
||
private IdGenerator idGenerator = mock( IdGenerator.class ); | ||
|
||
@Test | ||
public void freeIdIfConditionSatisfied() throws Exception | ||
{ | ||
FreeIdFilteredIdGenerator generator = createFilteredIdGenerator( idGenerator, () -> true ); | ||
generator.freeId( 1 ); | ||
|
||
verify( idGenerator ).freeId( 1 ); | ||
} | ||
|
||
@Test | ||
public void skipFreeIdIfConditionIsNotSatisfied() | ||
{ | ||
FreeIdFilteredIdGenerator generator = createFilteredIdGenerator( idGenerator, () -> false ); | ||
generator.freeId( 1 ); | ||
|
||
verifyZeroInteractions( idGenerator ); | ||
} | ||
|
||
@Test | ||
public void freeIdOnlyWhenConditionSatisfied() | ||
{ | ||
MutableBoolean condition = new MutableBoolean(); | ||
FreeIdFilteredIdGenerator generator = createFilteredIdGenerator( idGenerator, condition::booleanValue ); | ||
generator.freeId( 1 ); | ||
condition.setTrue(); | ||
generator.freeId( 2 ); | ||
|
||
verify( idGenerator ).freeId( 2 ); | ||
} | ||
|
||
private FreeIdFilteredIdGenerator createFilteredIdGenerator( IdGenerator idGenerator, | ||
BooleanSupplier booleanSupplier ) | ||
{ | ||
return new FreeIdFilteredIdGenerator( idGenerator, booleanSupplier ); | ||
} | ||
} |
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
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
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