Refine search
@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 ); }
@Test public void shouldFailIfFileDoesNotExist() { // given File missingFile = new File( directory.directory(), "missing-file" ); PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache ); // when StoreVersionCheck.Result result = storeVersionCheck.hasVersion( missingFile, "version" ); // then assertFalse( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.missingStoreFile, result.outcome ); assertNull( result.actualVersion ); }
@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 } }
@Test public void shouldCreateStoreDirAndObtainLockWhenStoreDirDoesNotExist() throws Exception { FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction( fileSystemRule.get() ) { @Override public boolean fileExists( File file ) { return false; } }; try ( StoreLocker storeLocker = new StoreLocker( fileSystemAbstraction, target.storeLayout() ) ) { storeLocker.checkLock(); // Ok } }
@Test public void shouldThrowIllegalStateExceptionAfterClosed() 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 ); // closing the WritableLogChannel, then the underlying channel is what PhysicalLogFile does channel.close(); 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 ( IllegalStateException e ) { // THEN we should get an IllegalStateException, not a ClosedChannelException } }
@BeforeClass public static void startGlobalInserter() throws IOException { // Global inserter can be used in tests which simply want to verify "local" behaviour, // e.g. create a node with some properties and read them back. globalInserter = BatchInserters.inserter( globalTestDirectory.directory( "global" ), fileSystemRule.get(), stringMap() ); }
@Test public void shutdownNonInitialisedNativeScanStoreWithoutException() throws IOException { String expectedMessage = "Expected exception message"; Monitors monitors = mock( Monitors.class ); when( monitors.newMonitor( LabelScanStore.Monitor.class ) ).thenReturn( LabelScanStore.Monitor.EMPTY ); doThrow( new RuntimeException( expectedMessage ) ).when( monitors ).addMonitorListener( any() ); LabelScanStore scanStore = getLabelScanStore( fileSystemRule.get(), testDirectory.databaseLayout(), EMPTY, true, monitors ); try { scanStore.init(); fail( "Initialisation of store should fail." ); } catch ( RuntimeException e ) { assertEquals( expectedMessage, e.getMessage() ); } scanStore.shutdown(); }
@Test public void shouldWriteThroughRotation() throws Exception final File firstFile = new File( directory.directory(), "file1" ); final File secondFile = new File( directory.directory(), "file2" ); StoreChannel storeChannel = fileSystemRule.get().open( firstFile, OpenMode.READ_WRITE ); PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel( storeChannel, 1, (byte) -1 /* ignored */ ); storeChannel = fileSystemRule.get().open( secondFile, OpenMode.READ_WRITE ); channel.setChannel( new PhysicalLogVersionedStoreChannel( storeChannel, 2, (byte) -1 /* ignored */ ) ); channel.putFloat( floatValue );
@Before public void setUp() { File folder = testDir.directory( "folder" ); indexStorage = new PartitionedIndexStorage( directoryFactory, fileSystemRule.get(), folder ); index = LuceneSchemaIndexBuilder.create( descriptor, Config.defaults() ) .withIndexStorage( indexStorage ) .build(); schemaDescriptor = descriptor.schema(); }
@Test public void shouldSeeCorrectPositionEvenBeforeEmptyingDataIntoChannel() 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 */ ); PositionAwarePhysicalFlushableChannel channel = new PositionAwarePhysicalFlushableChannel( versionedStoreChannel ); LogPositionMarker positionMarker = new LogPositionMarker(); LogPosition initialPosition = channel.getCurrentPosition( positionMarker ).newPosition(); // WHEN channel.putLong( 67 ); channel.putInt( 1234 ); LogPosition positionAfterSomeData = channel.getCurrentPosition( positionMarker ).newPosition(); // THEN assertEquals( 12, positionAfterSomeData.getByteOffset() - initialPosition.getByteOffset() ); channel.close(); }
@Before public void setup() throws IOException { fileSystem = fileSystemRule.get(); PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); workingStoreDir = testDir.storeDir( "working_" + version ); workingDatabaseLayout = testDir.databaseLayout( workingStoreDir ); check = new StoreVersionCheck( pageCache ); File prepareDirectory = testDir.directory( "prepare_" + version ); prepareSampleLegacyDatabase( version, fileSystem, workingDatabaseLayout.databaseDirectory(), prepareDirectory ); }
@Test public void testCreatesStoreLockFile() throws Exception { // Given DatabaseLayout databaseLayout = testDirectory.databaseLayout(); // When BatchInserter inserter = BatchInserters.inserter( databaseLayout.databaseDirectory(), fileSystemRule.get() ); // Then assertThat( databaseLayout.getStoreLayout().storeLockFile().exists(), equalTo( true ) ); inserter.shutdown(); }
@Test public void shouldReportShortFileDoesNotHaveSpecifiedVersion() throws IOException { // given File shortFile = fileContaining( fileSystemRule.get(), "nothing interesting" ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCacheRule.getPageCache( fileSystemRule.get() ) ); // when StoreVersionCheck.Result result = storeVersionCheck.hasVersion( shortFile, "version" ); // then assertFalse( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.storeVersionNotFound, result.outcome ); assertNull( result.actualVersion ); }
@Test public void givenBatchInserterWhenArrayPropertyUpdated4TimesThenShouldNotFail() throws IOException { BatchInserter batchInserter = BatchInserters.inserter( testDirectory.databaseDir(), fileSystemRule.get() ); long nodeId = batchInserter.createNode( Collections.emptyMap() ); for ( int i = 0; i < 4; i++ ) { batchInserter.setNodeProperty( nodeId, "array", new byte[]{2, 3, 98, 1, 43, 50, 3, 33, 51, 55, 116, 16, 23, 56, 9, -10, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1} ); } batchInserter.getNodeProperties( nodeId ); //fails here batchInserter.shutdown(); } }
@Test public void shouldObtainLockWhenStoreFileNotLocked() throws Exception { FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction( fileSystemRule.get() ) { @Override public boolean fileExists( File file ) { return true; } }; try ( StoreLocker storeLocker = new StoreLocker( fileSystemAbstraction, target.storeLayout() ) ) { storeLocker.checkLock(); // Ok } catch ( StoreLockException e ) { fail(); } }
@Test public void shouldWriteALogHeaderInAFile() throws IOException { // given final File file = testDirectory.file( "WriteLogHeader" ); // when writeLogHeader( fileSystemRule.get(), file, expectedLogVersion, expectedTxId ); // then final byte[] array = new byte[LOG_HEADER_SIZE]; try ( InputStream stream = fileSystemRule.get().openAsInputStream( file ) ) { int read = stream.read( array ); assertEquals( LOG_HEADER_SIZE, read ); } final ByteBuffer result = ByteBuffer.wrap( array ); long encodedLogVersions = result.getLong(); assertEquals( encodeLogVersion( expectedLogVersion ), encodedLogVersions ); byte logFormatVersion = decodeLogFormatVersion( encodedLogVersions ); assertEquals( CURRENT_LOG_VERSION, logFormatVersion ); long logVersion = decodeLogVersion( encodedLogVersions ); assertEquals( expectedLogVersion, logVersion ); long txId = result.getLong(); assertEquals( expectedTxId, txId ); }