Java Code Examples for org.apache.flink.runtime.io.network.buffer.Buffer#getMemorySegment()

The following examples show how to use org.apache.flink.runtime.io.network.buffer.Buffer#getMemorySegment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BufferBlockerTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static void validateBuffer(BufferOrEvent boe, int expectedSize, int expectedChannelIndex) {
	assertEquals("wrong channel index", expectedChannelIndex, boe.getChannelIndex());
	assertTrue("is not buffer", boe.isBuffer());

	Buffer buf = boe.getBuffer();
	assertEquals("wrong buffer size", expectedSize, buf.getSize());

	MemorySegment seg = buf.getMemorySegment();
	for (int i = 0; i < expectedSize; i++) {
		byte expected = (byte) i;
		if (expected != seg.get(i)) {
			fail(String.format(
				"wrong buffer contents at position %s : expected=%d , found=%d", i, expected, seg.get(i)));
		}
	}
}
 
Example 2
Source File: SpillingAdaptiveSpanningRecordDeserializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void setNextBuffer(Buffer buffer) throws IOException {
	currentBuffer = buffer;

	int offset = buffer.getMemorySegmentOffset();
	MemorySegment segment = buffer.getMemorySegment();
	int numBytes = buffer.getSize();

	// check if some spanning record deserialization is pending
	if (this.spanningWrapper.getNumGatheredBytes() > 0) {
		this.spanningWrapper.addNextChunkFromMemorySegment(segment, offset, numBytes);
	}
	else {
		this.nonSpanningWrapper.initializeFromMemorySegment(segment, offset, numBytes + offset);
	}
}
 
Example 3
Source File: BufferStorageTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void validateBuffer(BufferOrEvent boe, int expectedSize, int expectedChannelIndex) {
	assertEquals("wrong channel index", expectedChannelIndex, boe.getChannelIndex());
	assertTrue("is not buffer", boe.isBuffer());

	Buffer buf = boe.getBuffer();
	assertEquals("wrong buffer size", expectedSize, buf.getSize());

	MemorySegment seg = buf.getMemorySegment();
	for (int i = 0; i < expectedSize; i++) {
		byte expected = (byte) i;
		if (expected != seg.get(i)) {
			fail(String.format(
				"wrong buffer contents at position %s : expected=%d , found=%d", i, expected, seg.get(i)));
		}
	}
}
 
Example 4
Source File: SpillingAdaptiveSpanningRecordDeserializer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void setNextBuffer(Buffer buffer) throws IOException {
	currentBuffer = buffer;

	int offset = buffer.getMemorySegmentOffset();
	MemorySegment segment = buffer.getMemorySegment();
	int numBytes = buffer.getSize();

	// check if some spanning record deserialization is pending
	if (this.spanningWrapper.getNumGatheredBytes() > 0) {
		this.spanningWrapper.addNextChunkFromMemorySegment(segment, offset, numBytes);
	}
	else {
		this.nonSpanningWrapper.initializeFromMemorySegment(segment, offset, numBytes + offset);
	}
}
 
Example 5
Source File: BufferFileWriterReaderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
static int fillBufferWithAscendingNumbers(Buffer buffer, int currentNumber, int size) {
	checkArgument(size % 4 == 0);

	MemorySegment segment = buffer.getMemorySegment();

	for (int i = 0; i < size; i += 4) {
		segment.putInt(i, currentNumber++);
	}
	buffer.setSize(size);

	return currentNumber;
}
 
Example 6
Source File: BufferFileWriterReaderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
static int verifyBufferFilledWithAscendingNumbers(Buffer buffer, int currentNumber) {
	MemorySegment segment = buffer.getMemorySegment();

	int size = buffer.getSize();

	for (int i = 0; i < size; i += 4) {
		if (segment.getInt(i) != currentNumber++) {
			throw new IllegalStateException("Read unexpected number from buffer.");
		}
	}

	return currentNumber;
}
 
Example 7
Source File: BufferFileWriterReaderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
static int fillBufferWithAscendingNumbers(Buffer buffer, int currentNumber, int size) {
	checkArgument(size % 4 == 0);

	MemorySegment segment = buffer.getMemorySegment();

	for (int i = 0; i < size; i += 4) {
		segment.putInt(i, currentNumber++);
	}
	buffer.setSize(size);

	return currentNumber;
}
 
Example 8
Source File: TestConsumerCallback.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void onBuffer(Buffer buffer) {
	final MemorySegment segment = buffer.getMemorySegment();

	int expected = getNumberOfReadBuffers() * (segment.size() / 4);

	for (int i = 0; i < segment.size(); i += 4) {
		assertEquals(expected, segment.getInt(i));

		expected++;
	}

	super.onBuffer(buffer);
}
 
Example 9
Source File: TestPooledBufferProvider.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public BufferBuilder requestBufferBuilder() throws IOException {
	Buffer buffer = requestBuffer();
	if (buffer != null) {
		return new BufferBuilder(buffer.getMemorySegment(), buffer.getRecycler());
	}
	return null;
}
 
Example 10
Source File: SpillingAdaptiveSpanningRecordDeserializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void setNextBuffer(Buffer buffer) throws IOException {
	currentBuffer = buffer;

	int offset = buffer.getMemorySegmentOffset();
	MemorySegment segment = buffer.getMemorySegment();
	int numBytes = buffer.getSize();

	// check if some spanning record deserialization is pending
	if (spanningWrapper.getNumGatheredBytes() > 0) {
		spanningWrapper.addNextChunkFromMemorySegment(segment, offset, numBytes);
	} else {
		nonSpanningWrapper.initializeFromMemorySegment(segment, offset, numBytes + offset);
	}
}
 
Example 11
Source File: SpilledBufferOrEventSequenceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void validateBuffer(BufferOrEvent boe, int expectedSize, int expectedChannelIndex) {
	assertEquals("wrong channel index", expectedChannelIndex, boe.getChannelIndex());
	assertTrue("is not buffer", boe.isBuffer());

	Buffer buf = boe.getBuffer();
	assertEquals("wrong buffer size", expectedSize, buf.getSize());

	MemorySegment seg = buf.getMemorySegment();
	for (int i = 0; i < expectedSize; i++) {
		assertEquals("wrong buffer contents", (byte) i, seg.get(i));
	}
}
 
Example 12
Source File: BufferFileWriterReaderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
static int verifyBufferFilledWithAscendingNumbers(Buffer buffer, int currentNumber) {
	MemorySegment segment = buffer.getMemorySegment();

	int size = buffer.getSize();

	for (int i = 0; i < size; i += 4) {
		if (segment.getInt(i) != currentNumber++) {
			throw new IllegalStateException("Read unexpected number from buffer.");
		}
	}

	return currentNumber;
}
 
Example 13
Source File: TestConsumerCallback.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void onBuffer(Buffer buffer) {
	final MemorySegment segment = buffer.getMemorySegment();

	int expected = getNumberOfReadBuffers() * (segment.size() / 4);

	for (int i = 0; i < segment.size(); i += 4) {
		assertEquals(expected, segment.getInt(i));

		expected++;
	}

	super.onBuffer(buffer);
}
 
Example 14
Source File: SpilledBufferOrEventSequenceTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void validateBuffer(BufferOrEvent boe, int expectedSize, int expectedChannelIndex) {
	assertEquals("wrong channel index", expectedChannelIndex, boe.getChannelIndex());
	assertTrue("is not buffer", boe.isBuffer());

	Buffer buf = boe.getBuffer();
	assertEquals("wrong buffer size", expectedSize, buf.getSize());

	MemorySegment seg = buf.getMemorySegment();
	for (int i = 0; i < expectedSize; i++) {
		assertEquals("wrong buffer contents", (byte) i, seg.get(i));
	}
}
 
Example 15
Source File: BufferFileWriterReaderTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
static int verifyBufferFilledWithAscendingNumbers(Buffer buffer, int currentNumber) {
	MemorySegment segment = buffer.getMemorySegment();

	int size = buffer.getSize();

	for (int i = 0; i < size; i += 4) {
		if (segment.getInt(i) != currentNumber++) {
			throw new IllegalStateException("Read unexpected number from buffer.");
		}
	}

	return currentNumber;
}
 
Example 16
Source File: BufferFileWriterReaderTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
static int fillBufferWithAscendingNumbers(Buffer buffer, int currentNumber, int size) {
	checkArgument(size % 4 == 0);

	MemorySegment segment = buffer.getMemorySegment();

	for (int i = 0; i < size; i += 4) {
		segment.putInt(i, currentNumber++);
	}
	buffer.setSize(size);

	return currentNumber;
}
 
Example 17
Source File: TestConsumerCallback.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void onBuffer(Buffer buffer) {
	final MemorySegment segment = buffer.getMemorySegment();

	int expected = getNumberOfReadBuffers() * (segment.size() / 4);

	for (int i = 0; i < segment.size(); i += 4) {
		assertEquals(expected, segment.getInt(i));

		expected++;
	}

	super.onBuffer(buffer);
}
 
Example 18
Source File: TestPooledBufferProvider.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public BufferBuilder requestBufferBuilderBlocking() throws IOException, InterruptedException {
	Buffer buffer = requestBufferBlocking();
	return new BufferBuilder(buffer.getMemorySegment(), buffer.getRecycler());
}
 
Example 19
Source File: TestPooledBufferProvider.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public BufferBuilder requestBufferBuilderBlocking() throws IOException, InterruptedException {
	Buffer buffer = requestBufferBlocking();
	return new BufferBuilder(buffer.getMemorySegment(), buffer.getRecycler());
}
 
Example 20
Source File: TestPooledBufferProvider.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public BufferBuilder requestBufferBuilderBlocking() throws IOException, InterruptedException {
	Buffer buffer = requestBufferBlocking();
	return new BufferBuilder(buffer.getMemorySegment(), buffer.getRecycler());
}