test_class.file: flink-runtime/src/test/java/org/apache/flink/runtime/io/disk/SeekableFileChannelInputViewTest.java
test_class.identifier: SeekableFileChannelInputViewTest
test_case.body: @Test
  	public void testSeek() {
  		final IOManager ioManager = new IOManagerAsync();
  		final int PAGE_SIZE = 16 * 1024;
  		final int NUM_RECORDS = 120000;
  		// integers across 7.x pages (7 pages = 114.688 bytes, 8 pages = 131.072 bytes)
  		
  		try {
  			MemoryManager memMan = new MemoryManager(4 * PAGE_SIZE, 1, PAGE_SIZE, MemoryType.HEAP, true);
  			List<MemorySegment> memory = new ArrayList<MemorySegment>();
  			memMan.allocatePages(new DummyInvokable(), memory, 4);
  			
  			FileIOChannel.ID channel = ioManager.createChannel();
  			BlockChannelWriter<MemorySegment> writer = ioManager.createBlockChannelWriter(channel);
  			FileChannelOutputView out = new FileChannelOutputView(writer, memMan, memory, memMan.getPageSize());
  			
  			// write some integers across 7.5 pages (7 pages = 114.688 bytes, 8 pages = 131.072 bytes)
  			for (int i = 0; i < NUM_RECORDS; i += 4) {
  				out.writeInt(i);
  			}
  			// close for the first time, make sure all memory returns
  			out.close();
  			assertTrue(memMan.verifyEmpty());
  			
  			memMan.allocatePages(new DummyInvokable(), memory, 4);
  			SeekableFileChannelInputView in = new SeekableFileChannelInputView(ioManager, channel, memMan, memory, out.getBytesInLatestSegment());
  			
  			// read first, complete
  			for (int i = 0; i < NUM_RECORDS; i += 4) {
  				assertEquals(i, in.readInt());
  			}
  			try {
  				in.readInt();
  				fail("should throw EOF exception");
  			} catch (EOFException ignored) {}
  			
  			// seek to the middle of the 3rd page
  			int i = 2 * PAGE_SIZE + PAGE_SIZE / 4;
  			in.seek(i);
  			for (; i < NUM_RECORDS; i += 4) {
  				assertEquals(i, in.readInt());
  			}
  			try {
  				in.readInt();
  				fail("should throw EOF exception");
  			} catch (EOFException ignored) {}
  			
  			// seek to the end
  			i = 120000 - 4;
  			in.seek(i);
  			for (; i < NUM_RECORDS; i += 4) {
  				assertEquals(i, in.readInt());
  			}
  			try {
  				in.readInt();
  				fail("should throw EOF exception");
  			} catch (EOFException ignored) {}
  			
  			// seek to the beginning
  			i = 0;
  			in.seek(i);
  			for (; i < NUM_RECORDS; i += 4) {
  				assertEquals(i, in.readInt());
  			}
  			try {
  				in.readInt();
  				fail("should throw EOF exception");
  			} catch (EOFException ignored) {}
  			
  			// seek to after a page
  			i = PAGE_SIZE;
  			in.seek(i);
  			for (; i < NUM_RECORDS; i += 4) {
  				assertEquals(i, in.readInt());
  			}
  			try {
  				in.readInt();
  				fail("should throw EOF exception");
  			} catch (EOFException ignored) {}
  			
  			// seek to after a page
  			i = 3 * PAGE_SIZE;
  			in.seek(i);
  			for (; i < NUM_RECORDS; i += 4) {
  				assertEquals(i, in.readInt());
  			}
  			try {
  				in.readInt();
  				fail("should throw EOF exception");
  			} catch (EOFException ignored) {}
  			
  			// seek to the end
  			i = NUM_RECORDS;
  			in.seek(i);
  			try {
  				in.readInt();
  				fail("should throw EOF exception");
  			} catch (EOFException ignored) {}
  			
  			// seek out of bounds
  			try {
  				in.seek(-10);
  				fail("should throw an exception");
  			} catch (IllegalArgumentException ignored) {}
  			try {
  				in.seek(NUM_RECORDS + 1);
  				fail("should throw an exception");
  			} catch (IllegalArgumentException ignored) {}
  		}
  		catch (Exception e) {
  			e.printStackTrace();
  			fail(e.getMessage());
  		}
  		finally {
  			ioManager.shutdown();
  		}
  	}
test_case.class_method_signature: SeekableFileChannelInputViewTest.testSeek()
test_case.full_signature: @Test public void testSeek()
test_case.identifier: testSeek
test_case.invocations: allocatePages createChannel createBlockChannelWriter getPageSize writeInt close assertTrue verifyEmpty allocatePages getBytesInLatestSegment assertEquals readInt readInt fail seek assertEquals readInt readInt fail seek assertEquals readInt readInt fail seek assertEquals readInt readInt fail seek assertEquals readInt readInt fail seek assertEquals readInt readInt fail seek readInt fail seek fail seek fail printStackTrace fail getMessage shutdown
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSeek()
focal_class.declarator: reader
focal_class.modifier: private
focal_class.original_string: private BlockChannelReader<MemorySegment> reader;
focal_class.type: BlockChannelReader<MemorySegment>
focal_class.var_name: reader
focal_class.declarator: ioManager
focal_class.modifier: private final
focal_class.original_string: private final IOManager ioManager;
focal_class.type: IOManager
focal_class.var_name: ioManager
focal_class.declarator: channelId
focal_class.modifier: private final
focal_class.original_string: private final FileIOChannel.ID channelId;
focal_class.type: FileIOChannel.ID
focal_class.var_name: channelId
focal_class.declarator: memManager
focal_class.modifier: private final
focal_class.original_string: private final MemoryManager memManager;
focal_class.type: MemoryManager
focal_class.var_name: memManager
focal_class.declarator: memory
focal_class.modifier: private final
focal_class.original_string: private final List<MemorySegment> memory;
focal_class.type: List<MemorySegment>
focal_class.var_name: memory
focal_class.declarator: sizeOfLastBlock
focal_class.modifier: private final
focal_class.original_string: private final int sizeOfLastBlock;
focal_class.type: int
focal_class.var_name: sizeOfLastBlock
focal_class.declarator: numBlocksTotal
focal_class.modifier: private final
focal_class.original_string: private final int numBlocksTotal;
focal_class.type: int
focal_class.var_name: numBlocksTotal
focal_class.declarator: segmentSize
focal_class.modifier: private final
focal_class.original_string: private final int segmentSize;
focal_class.type: int
focal_class.var_name: segmentSize
focal_class.declarator: numRequestsRemaining
focal_class.modifier: private
focal_class.original_string: private int numRequestsRemaining;
focal_class.type: int
focal_class.var_name: numRequestsRemaining
focal_class.declarator: numBlocksRemaining
focal_class.modifier: private
focal_class.original_string: private int numBlocksRemaining;
focal_class.type: int
focal_class.var_name: numBlocksRemaining
focal_class.file: flink-runtime/src/main/java/org/apache/flink/runtime/io/disk/SeekableFileChannelInputView.java
focal_class.identifier: SeekableFileChannelInputView
focal_class.class_method_signature: SeekableFileChannelInputView.SeekableFileChannelInputView(IOManager ioManager, FileIOChannel.ID channelId, MemoryManager memManager, List<MemorySegment> memory, int sizeOfLastBlock)
focal_class.full_signature: public  SeekableFileChannelInputView(IOManager ioManager, FileIOChannel.ID channelId, MemoryManager memManager, List<MemorySegment> memory, int sizeOfLastBlock)
focal_class.identifier: SeekableFileChannelInputView
focal_class.modifiers: public
focal_class.parameters: (IOManager ioManager, FileIOChannel.ID channelId, MemoryManager memManager, List<MemorySegment> memory, int sizeOfLastBlock)
focal_class.signature:  SeekableFileChannelInputView(IOManager ioManager, FileIOChannel.ID channelId, MemoryManager memManager, List<MemorySegment> memory, int sizeOfLastBlock)
focal_class.class_method_signature: SeekableFileChannelInputView.seek(long position)
focal_class.full_signature: public void seek(long position)
focal_class.identifier: seek
focal_class.modifiers: public
focal_class.parameters: (long position)
focal_class.return: void
focal_class.signature: void seek(long position)
focal_class.class_method_signature: SeekableFileChannelInputView.close()
focal_class.full_signature: public void close()
focal_class.identifier: close
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void close()
focal_class.class_method_signature: SeekableFileChannelInputView.closeAndDelete()
focal_class.full_signature: public void closeAndDelete()
focal_class.identifier: closeAndDelete
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void closeAndDelete()
focal_class.class_method_signature: SeekableFileChannelInputView.close(boolean deleteFile)
focal_class.full_signature: private void close(boolean deleteFile)
focal_class.identifier: close
focal_class.modifiers: private
focal_class.parameters: (boolean deleteFile)
focal_class.return: void
focal_class.signature: void close(boolean deleteFile)
focal_class.class_method_signature: SeekableFileChannelInputView.nextSegment(MemorySegment current)
focal_class.full_signature: @Override protected MemorySegment nextSegment(MemorySegment current)
focal_class.identifier: nextSegment
focal_class.modifiers: @Override protected
focal_class.parameters: (MemorySegment current)
focal_class.return: MemorySegment
focal_class.signature: MemorySegment nextSegment(MemorySegment current)
focal_class.class_method_signature: SeekableFileChannelInputView.getLimitForSegment(MemorySegment segment)
focal_class.full_signature: @Override protected int getLimitForSegment(MemorySegment segment)
focal_class.identifier: getLimitForSegment
focal_class.modifiers: @Override protected
focal_class.parameters: (MemorySegment segment)
focal_class.return: int
focal_class.signature: int getLimitForSegment(MemorySegment segment)
focal_class.class_method_signature: SeekableFileChannelInputView.sendReadRequest(MemorySegment seg)
focal_class.full_signature: private void sendReadRequest(MemorySegment seg)
focal_class.identifier: sendReadRequest
focal_class.modifiers: private
focal_class.parameters: (MemorySegment seg)
focal_class.return: void
focal_class.signature: void sendReadRequest(MemorySegment seg)
focal_class.superclass: extends AbstractPagedInputView
focal_method.body: public void seek(long position) throws IOException {
  		final int block = MathUtils.checkedDownCast(position / segmentSize);
  		final int positionInBlock = (int) (position % segmentSize);
  		
  		if (position < 0 || block >= numBlocksTotal || (block == numBlocksTotal - 1 && positionInBlock > sizeOfLastBlock)) {
  			throw new IllegalArgumentException("Position is out of range");
  		}
  		
  		clear();
  		if (reader != null) {
  			reader.close();
  		}
  		
  		reader = ioManager.createBlockChannelReader(channelId);
  		
  		if (block > 0) {
  			reader.seekToPosition(((long) block) * segmentSize);
  		}
  		
  		this.numBlocksRemaining = this.numBlocksTotal - block;
  		this.numRequestsRemaining = numBlocksRemaining;
  		
  		for (int i = 0; i < memory.size(); i++) {
  			sendReadRequest(memory.get(i));
  		}
  		
  		numBlocksRemaining--;
  		seekInput(reader.getNextReturnedBlock(), positionInBlock, numBlocksRemaining == 0 ? sizeOfLastBlock : segmentSize);
  	}
focal_method.class_method_signature: SeekableFileChannelInputView.seek(long position)
focal_method.full_signature: public void seek(long position)
focal_method.identifier: seek
focal_method.invocations: checkedDownCast clear close createBlockChannelReader seekToPosition size sendReadRequest get seekInput getNextReturnedBlock
focal_method.modifiers: public
focal_method.parameters: (long position)
focal_method.return: void
focal_method.signature: void seek(long position)