Search in sources :

Example 1 with Allocator

use of org.apache.flink.runtime.state.heap.space.Allocator in project flink by apache.

the class CopyOnWriteSkipListStateMapBasicOpTest method testPutWithAllocationFailure.

/**
 * Make sure exception will be thrown with allocation failure rather than swallowed.
 */
@Test
public void testPutWithAllocationFailure() {
    Allocator exceptionalAllocator = new Allocator() {

        @Override
        public long allocate(int size) {
            throw new RuntimeException("Exception on purpose");
        }

        @Override
        public void free(long address) {
        }

        @Override
        @Nullable
        public Chunk getChunkById(int chunkId) {
            return null;
        }

        @Override
        public void close() {
        }
    };
    try (CopyOnWriteSkipListStateMap<Integer, Long, String> stateMap = createEmptyStateMap(0, 0.0f, exceptionalAllocator)) {
        stateMap.put(1, 1L, "test-value");
        fail("Should have thrown exception when space allocation fails");
    } catch (FlinkRuntimeException e) {
    // expected
    }
}
Also used : Allocator(org.apache.flink.runtime.state.heap.space.Allocator) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Test(org.junit.Test)

Aggregations

Allocator (org.apache.flink.runtime.state.heap.space.Allocator)1 FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)1 Test (org.junit.Test)1