Search in sources :

Example 11 with AbstractInvokable

use of org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable in project flink by apache.

the class MemoryManagerLazyAllocationTest method allocateAllSingle.

@Test
public void allocateAllSingle() {
    try {
        final AbstractInvokable mockInvoke = new DummyInvokable();
        List<MemorySegment> segments = new ArrayList<MemorySegment>();
        try {
            for (int i = 0; i < NUM_PAGES; i++) {
                segments.add(this.memoryManager.allocatePages(mockInvoke, 1).get(0));
            }
        } catch (MemoryAllocationException e) {
            fail("Unable to allocate memory");
        }
        for (MemorySegment seg : segments) {
            this.memoryManager.release(seg);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) MemorySegment(org.apache.flink.core.memory.MemorySegment) Test(org.junit.Test)

Example 12 with AbstractInvokable

use of org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable in project flink by apache.

the class MemoryManagerTest method allocateAllMulti.

@Test
public void allocateAllMulti() {
    try {
        final AbstractInvokable mockInvoke = new DummyInvokable();
        final List<MemorySegment> segments = new ArrayList<MemorySegment>();
        try {
            for (int i = 0; i < NUM_PAGES / 2; i++) {
                segments.addAll(this.memoryManager.allocatePages(mockInvoke, 2));
            }
        } catch (MemoryAllocationException e) {
            Assert.fail("Unable to allocate memory");
        }
        this.memoryManager.release(segments);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) MemorySegment(org.apache.flink.core.memory.MemorySegment) Test(org.junit.Test)

Example 13 with AbstractInvokable

use of org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable in project flink by apache.

the class TaskStopTest method testStopExecutionFail.

@Test(expected = RuntimeException.class)
public void testStopExecutionFail() throws Exception {
    AbstractInvokable taskMock = mock(AbstractInvokable.class);
    doMocking(taskMock);
    task.stopExecution();
}
Also used : AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with AbstractInvokable

use of org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable in project flink by apache.

the class MemoryManagerLazyAllocationTest method allocateAllMulti.

@Test
public void allocateAllMulti() {
    try {
        final AbstractInvokable mockInvoke = new DummyInvokable();
        final List<MemorySegment> segments = new ArrayList<MemorySegment>();
        try {
            for (int i = 0; i < NUM_PAGES / 2; i++) {
                segments.addAll(this.memoryManager.allocatePages(mockInvoke, 2));
            }
        } catch (MemoryAllocationException e) {
            Assert.fail("Unable to allocate memory");
        }
        this.memoryManager.release(segments);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) MemorySegment(org.apache.flink.core.memory.MemorySegment) Test(org.junit.Test)

Example 15 with AbstractInvokable

use of org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable in project flink by apache.

the class MemoryManagerLazyAllocationTest method allocateMultipleOwners.

@Test
public void allocateMultipleOwners() {
    final int NUM_OWNERS = 17;
    try {
        AbstractInvokable[] owners = new AbstractInvokable[NUM_OWNERS];
        @SuppressWarnings("unchecked") List<MemorySegment>[] mems = (List<MemorySegment>[]) new List<?>[NUM_OWNERS];
        for (int i = 0; i < NUM_OWNERS; i++) {
            owners[i] = new DummyInvokable();
            mems[i] = new ArrayList<MemorySegment>(64);
        }
        // allocate all memory to the different owners
        for (int i = 0; i < NUM_PAGES; i++) {
            final int owner = this.random.nextInt(NUM_OWNERS);
            mems[owner].addAll(this.memoryManager.allocatePages(owners[owner], 1));
        }
        // free one owner at a time
        for (int i = 0; i < NUM_OWNERS; i++) {
            this.memoryManager.releaseAll(owners[i]);
            owners[i] = null;
            Assert.assertTrue("Released memory segments have not been destroyed.", allMemorySegmentsFreed(mems[i]));
            mems[i] = null;
            // check that the owner owners were not affected
            for (int k = i + 1; k < NUM_OWNERS; k++) {
                Assert.assertTrue("Non-released memory segments are accidentaly destroyed.", allMemorySegmentsValid(mems[k]));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) MemorySegment(org.apache.flink.core.memory.MemorySegment) Test(org.junit.Test)

Aggregations

AbstractInvokable (org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable)26 Test (org.junit.Test)23 DummyInvokable (org.apache.flink.runtime.operators.testutils.DummyInvokable)22 MemorySegment (org.apache.flink.core.memory.MemorySegment)14 Record (org.apache.flink.types.Record)8 ArrayList (java.util.ArrayList)7 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)6 IntValue (org.apache.flink.types.IntValue)6 Random (java.util.Random)5 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)5 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)5 IOManagerAsync (org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync)5 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)5 IOException (java.io.IOException)4 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)3 StatefulTask (org.apache.flink.runtime.jobgraph.tasks.StatefulTask)3 List (java.util.List)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)2