@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(); }
private void writeSomeData( File file, Visitor<Pair<LogEntryWriter,Consumer<LogPositionMarker>>,IOException> visitor ) throws IOException { try ( LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel( fileSystemRule.get().open( file, OpenMode.READ_WRITE ), logVersion, CURRENT_LOG_VERSION ); PositionAwarePhysicalFlushableChannel writableLogChannel = new PositionAwarePhysicalFlushableChannel( versionedStoreChannel ) ) { writeLogHeader( writableLogChannel, logVersion, 2L ); Consumer<LogPositionMarker> consumer = marker -> { try { writableLogChannel.getCurrentPosition( marker ); } catch ( IOException e ) { throw new RuntimeException( e ); } }; LogEntryWriter first = new LogEntryWriter( writableLogChannel ); visitor.visit( Pair.of( first, consumer ) ); } } }