@Test public void lastCommitedTxGetsStoredBetweenSessions() { IndexProviderStore store = new IndexProviderStore( file, fileSystem, 0, false ); store.setVersion( 5 ); store.setLastCommittedTx( 12 ); store.close(); store = new IndexProviderStore( file, fileSystem, 0, false ); assertEquals( 5, store.getVersion() ); assertEquals( 12, store.getLastCommittedTx() ); store.close(); }
create( file, fileSystem, expectedVersion ); Long[] records = readRecordsWithNullDefaults( channel, RECORD_COUNT, allowUpgrade ); creationTime = records[0]; randomIdentifier = records[1]; boolean versionDiffers = compareExpectedVersionWithStoreVersion( expectedVersion, allowUpgrade, readIndexVersion ); writeOut();
@Test public void shouldFailUpgradeIfNotAllowed() { IndexProviderStore store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.1" ), true ); store.close(); store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.1" ), false ); store.close(); try { new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.5" ), false ); fail( "Shouldn't be able to upgrade there" ); } catch ( UpgradeNotAllowedByConfigurationException e ) { // Good } store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.5" ), true ); assertEquals( "3.5", MetaDataStore.versionLongToString( store.getIndexVersion() ) ); store.close(); }
@Test public void upgradeForMissingVersionRecord() throws Exception { // This was before 1.6.M02 IndexProviderStore store = new IndexProviderStore( file, fileSystem, 0, false ); store.close(); FileUtils.truncateFile( file, 4 * 8 ); try { store = new IndexProviderStore( file, fileSystem, 0, false ); fail( "Should have thrown upgrade exception" ); } catch ( UpgradeNotAllowedByConfigurationException e ) { // Good } store = new IndexProviderStore( file, fileSystem, 0, true ); store.close(); }
@Test( expected = IllegalArgumentException.class ) public void shouldThrowWhenTryingToCreateFileThatAlreadyExists() { // Given FileSystemAbstraction fs = mock( FileSystemAbstraction.class ); when( fs.fileExists( file ) ).thenReturn( false ).thenReturn( true ); when( fs.getFileSize( file ) ).thenReturn( 42L ); // When new IndexProviderStore( file, fs, MetaDataStore.versionStringToLong( "3.5" ), false ); // Then // exception is thrown }
@Test public void shouldWriteNewFileWhenExistingFileHasZeroLength() throws IOException { // Given file.createNewFile(); // When IndexProviderStore store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.5" ), false ); // Then assertTrue( fileSystem.getFileSize( file ) > 0 ); store.close(); } }
create( file, fileSystem, expectedVersion ); Long[] records = readRecordsWithNullDefaults( channel, RECORD_COUNT, allowUpgrade ); creationTime = records[0]; randomIdentifier = records[1]; boolean versionDiffers = compareExpectedVersionWithStoreVersion( expectedVersion, allowUpgrade, readIndexVersion ); writeOut();
@Test( expected = NotCurrentStoreVersionException.class ) public void shouldFailToGoBackToOlderVersion() { String newerVersion = "3.5"; String olderVersion = "3.1"; try { IndexProviderStore store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( newerVersion ), true ); store.close(); store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( olderVersion ), false ); } catch ( NotCurrentStoreVersionException e ) { assertTrue( e.getMessage().contains( newerVersion ) ); assertTrue( e.getMessage().contains( olderVersion ) ); throw e; } }
@Test( expected = NotCurrentStoreVersionException.class ) public void shouldFailToGoBackToOlderVersionEvenIfAllowUpgrade() { String newerVersion = "3.5"; String olderVersion = "3.1"; try { IndexProviderStore store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( newerVersion ), true ); store.close(); store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( olderVersion ), true ); } catch ( NotCurrentStoreVersionException e ) { assertTrue( e.getMessage().contains( newerVersion ) ); assertTrue( e.getMessage().contains( olderVersion ) ); throw e; } }
IndexProviderStore store = new IndexProviderStore( file, fs, MetaDataStore.versionStringToLong( "3.5" ), false ); verify( channel ).close(); verifyNoMoreInteractions( channel ); store.close();