@Test public void shouldPrintDiskUsage() { // Not sure how to get around this w/o spying. The method that we're unit testing will construct // other File instances with this guy as parent and internally the File constructor uses the field 'path' // which, if purely mocked, won't be assigned. At the same time we want to control the total/free space methods // and what they return... a tough one. File storeDir = Mockito.spy( new File( "storeDir" ) ); DatabaseLayout layout = mock( DatabaseLayout.class ); when( layout.databaseDirectory() ).thenReturn( storeDir ); when( storeDir.getTotalSpace() ).thenReturn( 100L ); when( storeDir.getFreeSpace() ).thenReturn( 40L ); AssertableLogProvider logProvider = new AssertableLogProvider(); KernelDiagnostics.StoreFiles storeFiles = new KernelDiagnostics.StoreFiles( layout ); storeFiles.dump( logProvider.getLog( getClass() ).debugLogger() ); logProvider.assertContainsMessageContaining( "100 / 40 / 40" ); }
/** * Print a tree view of all the files in the database directory with files sizes. * * @param sources destination of the sources. */ private void listDataDirectory( List<DiagnosticsReportSource> sources ) { KernelDiagnostics.StoreFiles storeFiles = new KernelDiagnostics.StoreFiles( databaseLayout ); BufferingLog logger = new BufferingLog(); storeFiles.dump( DiagnosticsPhase.INITIALIZED, logger.debugLogger() ); sources.add( newDiagnosticsString( "tree.txt", logger::toString ) ); }
@Test public void shouldIncludeNativeIndexFilesInTotalMappedSize() { int i = 0; for ( GraphDatabaseSettings.SchemaIndex schemaIndex : GraphDatabaseSettings.SchemaIndex.values() ) { // given File dbDir = new File( directory.databaseDir(), String.valueOf( i++ ) ); createIndexInIsolatedDbInstance( dbDir, schemaIndex ); // when KernelDiagnostics.StoreFiles files = new KernelDiagnostics.StoreFiles( DatabaseLayout.of( dbDir ) ); SizeCapture capture = new SizeCapture(); files.dump( capture ); assertNotNull( capture.size ); // then long expected = manuallyCountTotalMappedFileSize( dbDir ); assertEquals( Format.bytes( expected ), capture.size ); } }
/** * Print a tree view of all the files in the database directory with files sizes. * * @param sources destination of the sources. */ private void listDataDirectory( List<DiagnosticsReportSource> sources ) { KernelDiagnostics.StoreFiles storeFiles = new KernelDiagnostics.StoreFiles( databaseLayout ); BufferingLog logger = new BufferingLog(); storeFiles.dump( DiagnosticsPhase.INITIALIZED, logger.debugLogger() ); sources.add( newDiagnosticsString( "tree.txt", logger::toString ) ); }
@Test public void shouldCountFileSizeRecursively() throws IOException { // file structure: // storeDir/indexDir/indexFile (1 kB) // storeDir/neostore (3 kB) File storeDir = directory.directory( "storeDir" ); DatabaseLayout layout = DatabaseLayout.of( storeDir ); File indexDir = directory( storeDir, "indexDir" ); file( indexDir, "indexFile", (int) kibiBytes( 1 ) ); file( storeDir, layout.metadataStore().getName(), (int) kibiBytes( 3 ) ); AssertableLogProvider logProvider = new AssertableLogProvider(); KernelDiagnostics.StoreFiles storeFiles = new KernelDiagnostics.StoreFiles( layout ); storeFiles.dump( logProvider.getLog( getClass() ).debugLogger() ); logProvider.assertContainsMessageContaining( "Total size of store: 4.00 kB" ); logProvider.assertContainsMessageContaining( "Total size of mapped files: 3.00 kB" ); }