@Test
public void testBroadcastEventBufferReferenceCounting() throws Exception {

	Buffer buffer = EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE);
	// Partial mocking of static method...
	PowerMockito
		.stub(PowerMockito.method(EventSerializer.class, "toBuffer"))
		.toReturn(buffer);
	@SuppressWarnings("unchecked")
	ArrayDeque<BufferOrEvent>[] queues =
		new ArrayDeque[]{new ArrayDeque(), new ArrayDeque()};
	ResultPartitionWriter partition =
		createCollectingPartitionWriter(queues,
			new TestInfiniteBufferProvider());
	RecordWriter<?> writer = new RecordWriter<>(partition);
	writer.broadcastEvent(EndOfPartitionEvent.INSTANCE);
	// Verify added to all queues
	assertEquals(1, queues[0].size());
	assertEquals(1, queues[1].size());
	assertTrue(buffer.isRecycled());
}