Refine search
@Override public void execute( String[] args ) throws IncorrectUsage, CommandFailed { final Path databaseDirectory = arguments.parse( args ).getMandatoryPath( "store" ); Validators.CONTAINS_EXISTING_DATABASE.validate( databaseDirectory.toFile() ); try ( DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); JobScheduler jobScheduler = createInitialisedScheduler(); PageCache pageCache = StandalonePageCacheFactory.createPageCache( fileSystem, jobScheduler ) ) { DatabaseLayout databaseLayout = DatabaseLayout.of( databaseDirectory.toFile() ); final String storeVersion = new StoreVersionCheck( pageCache ) .getVersion( databaseLayout.metadataStore() ) .orElseThrow( () -> new CommandFailed( String.format( "Could not find version metadata in store '%s'", databaseDirectory ) ) ); final String fmt = "%-30s%s"; out.accept( String.format( fmt, "Store format version:", storeVersion ) ); RecordFormats format = RecordFormatSelector.selectForVersion( storeVersion ); out.accept( String.format( fmt, "Store format introduced in:", format.introductionVersion() ) ); findSuccessor( format ) .map( next -> String.format( fmt, "Store format superseded in:", next.introductionVersion() ) ) .ifPresent( out ); } catch ( Exception e ) { throw new CommandFailed( e.getMessage(), e ); } }
@Test void archiveDirectoryWithSubdirectories() throws IOException { File archiveFile = testDirectory.file( "directoryWithSubdirectoriesArchive.zip" ); File directoryArchive = testDirectory.directory( "directoryWithSubdirs" ); File subdir1 = new File( directoryArchive, "subdir1" ); File subdir2 = new File( directoryArchive, "subdir" ); fileSystem.mkdir( subdir1 ); fileSystem.mkdir( subdir2 ); fileSystem.create( new File( directoryArchive, "a" ) ).close(); fileSystem.create( new File( directoryArchive, "b" ) ).close(); fileSystem.create( new File( subdir1, "c" ) ).close(); fileSystem.create( new File( subdir2, "d" ) ).close(); ZipUtils.zip( fileSystem, directoryArchive, archiveFile ); assertTrue( fileSystem.fileExists( archiveFile ) ); assertEquals( 6, countArchiveEntries( archiveFile ) ); }
private void writeSomeData( File file, Visitor<ByteBuffer, IOException> visitor ) throws IOException { try ( StoreChannel channel = fileSystemRule.get().open( file, OpenMode.READ_WRITE ) ) { ByteBuffer buffer = ByteBuffer.allocate( 1024 ); visitor.visit( buffer ); buffer.flip(); channel.write( buffer ); } }
@Test void shouldRespectTheStoreLock() throws IOException { Path databaseDirectory = homeDir.resolve( "data/databases/foo.db" ); Files.createDirectories( databaseDirectory ); StoreLayout storeLayout = DatabaseLayout.of( databaseDirectory.toFile() ).getStoreLayout(); try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); StoreLocker locker = new StoreLocker( fileSystem, storeLayout ) ) { locker.checkLock(); CommandFailed commandFailed = assertThrows( CommandFailed.class, () -> execute( "foo.db", "--force" ) ); assertEquals( "the database is in use -- stop Neo4j and try again", commandFailed.getMessage() ); } }
protected FileSystemAbstraction createFileSystemAbstraction() { return new DefaultFileSystemAbstraction(); }
@Test void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable { // given // create a store File databaseDir = testDirectory.databaseDir(); GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( databaseDir ); try ( Transaction tx = db.beginTx() ) { db.createNode(); tx.success(); } db.shutdown(); // mess up the version in the metadatastore try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler(); PageCache pageCache = createPageCache( fileSystem, scheduler ) ) { MetaDataStore.setRecord( pageCache, testDirectory.databaseLayout().metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong( "bad" )); } RuntimeException exception = assertThrows( RuntimeException.class, () -> new TestGraphDatabaseFactory().newEmbeddedDatabase( databaseDir ) ); assertTrue( exception.getCause() instanceof LifecycleException ); assertTrue( exception.getCause().getCause() instanceof IllegalArgumentException ); assertEquals( "Unknown store version 'bad'", exception.getCause().getCause().getMessage() ); }
@Test public void shouldThrowClosedChannelExceptionWhenChannelUnexpectedlyClosed() throws Exception { // GIVEN final File file = new File( directory.directory(), "file" ); StoreChannel storeChannel = fileSystemRule.get().open( file, OpenMode.READ_WRITE ); PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel( storeChannel, 1, (byte) -1 /* ignored */ ); PhysicalFlushableChannel channel = new PhysicalFlushableChannel( versionedStoreChannel ); // just close the underlying channel storeChannel.close(); // WHEN just appending something to the buffer channel.put( (byte) 0 ); // and wanting to empty that into the channel try { channel.prepareForFlush(); fail( "Should have thrown exception" ); } catch ( ClosedChannelException e ) { // THEN we should get a ClosedChannelException } }
private LuceneDataSource getLuceneDataSource( Config config, OperationalMode operationalMode ) { return new LuceneDataSource( directory.databaseLayout(), config, indexStore, new DefaultFileSystemAbstraction(), operationalMode ); } }
@Test void doNotCreateZipArchiveForEmptyDirectory() throws IOException { File archiveFile = testDirectory.file( "archive.zip" ); File emptyDirectory = testDirectory.directory( "emptyDirectory" ); ZipUtils.zip( fileSystem, emptyDirectory, archiveFile ); assertFalse( fileSystem.fileExists( archiveFile ) ); }
static Fixture prepareDirectoryAndPageCache( Class<?> testClass ) throws IOException { DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); TestDirectory testDirectory = TestDirectory.testDirectory( testClass, fileSystem ); File dir = testDirectory.prepareDirectoryForTest( "test" ); ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler(); PageCache pageCache = StandalonePageCacheFactory.createPageCache( fileSystem, scheduler ); return new Fixture( pageCache, fileSystem, dir, scheduler ); }
private BadCollector createBadCollector() { try { return new BadCollector( fileSystemRule.get().openAsOutputStream( new File( directory.databaseDir(), "bad" ), false ), 0, 0 ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
public static TestDirectory testDirectory( Class<?> owningTest ) { return new TestDirectory( new DefaultFileSystemAbstraction(), owningTest ); }
@Test public void testFailsOnExistingStoreLockFile() throws IOException { // Given StoreLayout storeLayout = testDirectory.storeLayout(); try ( FileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction(); StoreLocker lock = new StoreLocker( fileSystemAbstraction, storeLayout ) ) { lock.checkLock(); // Then expected.expect( StoreLockException.class ); expected.expectMessage( "Unable to obtain lock on store lock file" ); // When BatchInserters.inserter( storeLayout.databaseLayout( "any" ).databaseDirectory(), fileSystemAbstraction ); } } }
@ParameterizedTest @ValueSource( ints = {0, 1} ) @DisabledOnOs( OS.WINDOWS ) void mustUnlockFileWhenThePageSwapperIsClosed( int noChannelStriping ) throws Exception { PageSwapperFactory factory = createSwapperFactory(); factory.open( fileSystem, Configuration.EMPTY ); File file = testDir.file( "file" ); fileSystem.create( file ).close(); createSwapper( factory, file, 4, NO_CALLBACK, false, false ).close(); try ( StoreFileChannel channel = fileSystem.open( file, OpenMode.READ_WRITE ); FileLock fileLock = channel.tryLock() ) { assertThat( fileLock, is( not( nullValue() ) ) ); } }
final File file = testDirectory.file( "WriteLogHeader" ); final StoreChannel channel = fileSystemRule.get().open( file, OpenMode.READ_WRITE ); try ( InputStream stream = fileSystemRule.get().openAsInputStream( file ) )
@Test public void shouldReadALogHeaderFromAFile() throws IOException { // given final File file = testDirectory.file( "ReadLogHeader" ); final ByteBuffer buffer = ByteBuffer.allocate( LOG_HEADER_SIZE ); buffer.putLong( encodeLogVersion( expectedLogVersion ) ); buffer.putLong( expectedTxId ); try ( OutputStream stream = fileSystemRule.get().openAsOutputStream( file, false ) ) { stream.write( buffer.array() ); } // when final LogHeader result = readLogHeader( fileSystemRule.get(), file ); // then assertEquals( new LogHeader( CURRENT_LOG_VERSION, expectedLogVersion, expectedTxId ), result ); }
ZipUtils.zip( globalFs.get(), storeFile, globalDir.file( zipName ) ); tellDeveloperToCommitThisFormatVersion( zipName ); assertTrue( zipName + " seems to be missing from resources directory", globalFs.get().fileExists( storeFile ) ); globalFs.get().deleteFile( storeFile ); createStoreFile( storeFile ); ZipUtils.zip( globalFs.get(), storeFile, globalDir.file( zipName ) );
long timeCommitted = timeStarted + 10; LifeSupport life = new LifeSupport(); final LogFiles logFiles = LogFilesBuilder.builder( dir.databaseLayout(), fileSystemRule.get() ) .withTransactionIdStore( transactionIdStore ) .withLogVersionRepository( mock( LogVersionRepository.class ) ).build(); fileSystemRule.get().create( logFiles.getLogFileForVersion( logFiles.getHighestLogVersion() + 1 ) ).close(); positionCache.clear();