Skip to content

Commit

Permalink
Better test for close in CombinedIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen authored and tinwelint committed Aug 4, 2017
1 parent 5e8d7c5 commit 8edafd1
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.kernel.impl.index.schema.combined;

import org.junit.Test;
import org.mockito.Mockito;

import java.io.IOException;

Expand Down Expand Up @@ -156,6 +157,47 @@ public void closeMustThrowIfBoostThrow() throws Exception
verifyFailOnSingleCloseFailure( boostAccessor, combinedIndexAccessor );
}

@Test
public void closeMustCloseBoostIfFallbackThrow() throws Exception
{
// given
IndexAccessor boostAccessor = mock( IndexAccessor.class );
IndexAccessor fallbackAccessor = mock( IndexAccessor.class );
CombinedIndexAccessor combinedIndexAccessor = new CombinedIndexAccessor( boostAccessor, fallbackAccessor );

verifyOtherIsClosedOnSingleThrow( fallbackAccessor, boostAccessor, combinedIndexAccessor );
}

@Test
public void closeMustCloseFallbackIfBoostThrow() throws Exception
{
// given
IndexAccessor boostAccessor = mock( IndexAccessor.class );
IndexAccessor fallbackAccessor = mock( IndexAccessor.class );
CombinedIndexAccessor combinedIndexAccessor = new CombinedIndexAccessor( boostAccessor, fallbackAccessor );

verifyOtherIsClosedOnSingleThrow( boostAccessor, fallbackAccessor, combinedIndexAccessor );
}

private void verifyOtherIsClosedOnSingleThrow( IndexAccessor failingAccessor, IndexAccessor successfulAccessor,
CombinedIndexAccessor combinedIndexAccessor ) throws IOException
{
IOException failure = new IOException( "fail" );
doThrow( failure ).when( failingAccessor ).close();

// when
try
{
combinedIndexAccessor.close();
}
catch ( IOException ignore )
{
}

// then
verify( successfulAccessor, Mockito.times( 1 ) ).close();
}

private void verifyFailOnSingleCloseFailure( IndexAccessor failingAccessor, CombinedIndexAccessor combinedIndexAccessor )
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,47 @@ public void closeMustThrowIfCloseFallbackThrow() throws Exception
} );
}

@Test
public void closeMustCloseBoostIfFallbackThrow() throws Exception
{
// given
IOException failure = new IOException( "fail" );
doThrow( failure ).when( fallbackPopulator ).close( anyBoolean() );

// when
try
{
combinedIndexPopulator.close( true );
}
catch ( IOException ignore )
{
}

// then
verify( boostPopulator, times( 1 ) ).close( true );
}

@Test
public void closeMustCloseFallbackIfBoostThrow() throws Exception
{
// given
IOException failure = new IOException( "fail" );
doThrow( failure ).when( boostPopulator ).close( anyBoolean() );

// when
try
{
combinedIndexPopulator.close( true );
}
catch ( IOException ignore )
{
}

// then
verify( fallbackPopulator, times( 1 ) ).close( true );

}

/* markAsFailed */

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 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.combined;

import org.apache.commons.lang3.ArrayUtils;
Expand Down

0 comments on commit 8edafd1

Please sign in to comment.