@Test public void clearMigrationDirFromAnyLabelScanStoreBeforeMigrating() throws Exception { // given prepareEmpty23Database(); initializeNativeLabelScanStoreWithContent( migrationLayout ); File toBeDeleted = migrationLayout.labelScanStore(); assertTrue( fileSystem.fileExists( toBeDeleted ) ); // when indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV3_2.STORE_VERSION, StandardV3_2.STORE_VERSION ); // then assertNoContentInNativeLabelScanStore( migrationLayout ); }
@Test public void moveCreatedNativeLabelIndexBackToStoreDirectory() throws IOException { prepareEmpty23Database(); indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV2_3.STORE_VERSION, StandardV3_2.STORE_VERSION ); File migrationNativeIndex = migrationLayout.labelScanStore(); ByteBuffer migratedFileContent = writeFile( migrationNativeIndex, new byte[]{5, 4, 3, 2, 1} ); indexMigrator.moveMigratedFiles( migrationLayout, databaseLayout, StandardV2_3.STORE_VERSION, StandardV3_2.STORE_VERSION ); ByteBuffer movedNativeIndex = readFileContent( nativeLabelIndex, 5 ); assertEquals( migratedFileContent, movedNativeIndex ); }
private ByteBuffer writeFile( File file, byte[] content ) throws IOException { ByteBuffer sourceBuffer = ByteBuffer.wrap( content ); storeFileContent( file, sourceBuffer ); sourceBuffer.flip(); return sourceBuffer; }
@Test( expected = InvalidIdGeneratorException.class ) public void failMigrationWhenNodeIdFileIsBroken() throws Exception { prepareEmpty23Database(); File nodeIdFile = databaseLayout.idNodeStore(); writeFile( nodeIdFile, new byte[]{1, 2, 3} ); indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV3_2.STORE_VERSION, StandardV3_2.STORE_VERSION ); }
@Test public void skipMigrationIfNativeIndexExist() throws Exception { ByteBuffer sourceBuffer = writeFile( nativeLabelIndex, new byte[]{1, 2, 3} ); indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV3_2.STORE_VERSION, StandardV3_2.STORE_VERSION ); indexMigrator.moveMigratedFiles( migrationLayout, databaseLayout, StandardV3_2.STORE_VERSION, StandardV3_2.STORE_VERSION ); ByteBuffer resultBuffer = readFileContent( nativeLabelIndex, 3 ); assertEquals( sourceBuffer, resultBuffer ); assertTrue( fileSystem.fileExists( luceneLabelScanStore ) ); }
@Test public void populateNativeLabelScanIndexDuringMigration() throws IOException { prepare34DatabaseWithNodes(); indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV3_4.STORE_VERSION, StandardV3_4.STORE_VERSION ); indexMigrator.moveMigratedFiles( migrationLayout, databaseLayout, StandardV2_3.STORE_VERSION, StandardV3_2.STORE_VERSION ); try ( Lifespan lifespan = new Lifespan() ) { NativeLabelScanStore labelScanStore = getNativeLabelScanStore( databaseLayout, true ); lifespan.add( labelScanStore ); for ( int labelId = 0; labelId < 10; labelId++ ) { try ( LabelScanReader labelScanReader = labelScanStore.newReader() ) { int nodeCount = PrimitiveLongCollections.count( labelScanReader.nodesWithLabel( labelId ) ); assertEquals( format( "Expected to see only one node for label %d but was %d.", labelId, nodeCount ), 1, nodeCount ); } } } }
private void assertNoContentInNativeLabelScanStore( DatabaseLayout databaseLayout ) { try ( Lifespan lifespan = new Lifespan() ) { NativeLabelScanStore nativeLabelScanStore = getNativeLabelScanStore( databaseLayout, true ); lifespan.add( nativeLabelScanStore ); try ( LabelScanReader labelScanReader = nativeLabelScanStore.newReader() ) { int count = PrimitiveLongCollections.count( labelScanReader.nodesWithLabel( 1 ) ); assertEquals( 0, count ); } } }
@Test public void reportProgressOnNativeIndexPopulation() throws IOException { prepare34DatabaseWithNodes(); indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV3_4.STORE_VERSION, StandardV3_4.STORE_VERSION ); indexMigrator.moveMigratedFiles( migrationLayout, databaseLayout, StandardV2_3.STORE_VERSION, StandardV3_2.STORE_VERSION ); verify( progressReporter ).start( 10 ); verify( progressReporter, times( 10 ) ).progress( 1 ); }
@Test public void luceneLabelIndexRemovedAfterSuccessfulMigration() throws IOException { prepareEmpty23Database(); indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV2_3.STORE_VERSION, StandardV3_2.STORE_VERSION ); indexMigrator.moveMigratedFiles( migrationLayout, databaseLayout, StandardV2_3.STORE_VERSION, StandardV3_2.STORE_VERSION ); assertFalse( fileSystem.fileExists( luceneLabelScanStore ) ); }
private void initializeNativeLabelScanStoreWithContent( DatabaseLayout databaseLayout ) throws IOException { try ( Lifespan lifespan = new Lifespan() ) { NativeLabelScanStore nativeLabelScanStore = getNativeLabelScanStore( databaseLayout, false ); lifespan.add( nativeLabelScanStore ); try ( LabelScanWriter labelScanWriter = nativeLabelScanStore.newWriter() ) { labelScanWriter.write( NodeLabelUpdate.labelChanges( 1, new long[0], new long[]{1} ) ); } nativeLabelScanStore.force( IOLimiter.UNLIMITED ); } }