Search in sources :

Example 71 with JobID

use of org.apache.flink.api.common.JobID in project flink by apache.

the class MemoryStateBackendTest method testOversizedState.

@Test
public void testOversizedState() {
    try {
        MemoryStateBackend backend = new MemoryStateBackend(10);
        CheckpointStreamFactory streamFactory = backend.createStreamFactory(new JobID(), "test_op");
        HashMap<String, Integer> state = new HashMap<>();
        state.put("hey there", 2);
        state.put("the crazy brown fox stumbles over a sentence that does not contain every letter", 77);
        try {
            CheckpointStreamFactory.CheckpointStateOutputStream outStream = streamFactory.createCheckpointStateOutputStream(12, 459);
            ObjectOutputStream oos = new ObjectOutputStream(outStream);
            oos.writeObject(state);
            oos.flush();
            outStream.closeAndGetHandle();
            fail("this should cause an exception");
        } catch (IOException e) {
        // now darling, isn't that exactly what we wanted?
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) JobID(org.apache.flink.api.common.JobID) IOException(java.io.IOException) Test(org.junit.Test)

Example 72 with JobID

use of org.apache.flink.api.common.JobID in project flink by apache.

the class OperatorStateBackendTest method testSnapshotRestore.

@Test
public void testSnapshotRestore() throws Exception {
    DefaultOperatorStateBackend operatorStateBackend = createNewOperatorStateBackend();
    ListStateDescriptor<Serializable> stateDescriptor1 = new ListStateDescriptor<>("test1", new JavaSerializer<>());
    ListStateDescriptor<Serializable> stateDescriptor2 = new ListStateDescriptor<>("test2", new JavaSerializer<>());
    ListStateDescriptor<Serializable> stateDescriptor3 = new ListStateDescriptor<>("test3", new JavaSerializer<>());
    ListState<Serializable> listState1 = operatorStateBackend.getOperatorState(stateDescriptor1);
    ListState<Serializable> listState2 = operatorStateBackend.getOperatorState(stateDescriptor2);
    ListState<Serializable> listState3 = operatorStateBackend.getBroadcastOperatorState(stateDescriptor3);
    listState1.add(42);
    listState1.add(4711);
    listState2.add(7);
    listState2.add(13);
    listState2.add(23);
    listState3.add(17);
    listState3.add(18);
    listState3.add(19);
    listState3.add(20);
    CheckpointStreamFactory streamFactory = abstractStateBackend.createStreamFactory(new JobID(), "testOperator");
    OperatorStateHandle stateHandle = FutureUtil.runIfNotDoneAndGet(operatorStateBackend.snapshot(1, 1, streamFactory, CheckpointOptions.forFullCheckpoint()));
    try {
        operatorStateBackend.close();
        operatorStateBackend.dispose();
        //TODO this is temporarily casted to test already functionality that we do not yet expose through public API
        operatorStateBackend = (DefaultOperatorStateBackend) abstractStateBackend.createOperatorStateBackend(createMockEnvironment(), "testOperator");
        operatorStateBackend.restore(Collections.singletonList(stateHandle));
        assertEquals(3, operatorStateBackend.getRegisteredStateNames().size());
        listState1 = operatorStateBackend.getOperatorState(stateDescriptor1);
        listState2 = operatorStateBackend.getOperatorState(stateDescriptor2);
        listState3 = operatorStateBackend.getBroadcastOperatorState(stateDescriptor3);
        assertEquals(3, operatorStateBackend.getRegisteredStateNames().size());
        Iterator<Serializable> it = listState1.get().iterator();
        assertEquals(42, it.next());
        assertEquals(4711, it.next());
        assertTrue(!it.hasNext());
        it = listState2.get().iterator();
        assertEquals(7, it.next());
        assertEquals(13, it.next());
        assertEquals(23, it.next());
        assertTrue(!it.hasNext());
        it = listState3.get().iterator();
        assertEquals(17, it.next());
        assertEquals(18, it.next());
        assertEquals(19, it.next());
        assertEquals(20, it.next());
        assertTrue(!it.hasNext());
        operatorStateBackend.close();
        operatorStateBackend.dispose();
    } finally {
        stateHandle.discardState();
    }
}
Also used : Serializable(java.io.Serializable) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 73 with JobID

use of org.apache.flink.api.common.JobID in project flink by apache.

the class SlotManagerTest method testRequestSlotWithoutFreeSlot.

/**
	 * Tests that there are no free slots when we request, need to allocate from cluster manager master
	 */
@Test
public void testRequestSlotWithoutFreeSlot() {
    TestingSlotManager slotManager = new TestingSlotManager();
    slotManager.requestSlot(new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_PROFILE));
    assertEquals(0, slotManager.getAllocatedSlotCount());
    assertEquals(0, slotManager.getFreeSlotCount());
    assertEquals(1, slotManager.getPendingRequestCount());
    assertEquals(1, slotManager.getAllocatedContainers().size());
    assertEquals(DEFAULT_TESTING_PROFILE, slotManager.getAllocatedContainers().get(0));
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 74 with JobID

use of org.apache.flink.api.common.JobID in project flink by apache.

the class SlotManagerTest method testDuplicatedSlotRequest.

/**
	 * Tests that we send duplicated slot request
	 */
@Test
public void testDuplicatedSlotRequest() {
    TestingSlotManager slotManager = new TestingSlotManager();
    directlyProvideFreeSlots(slotManager, DEFAULT_TESTING_PROFILE, 1);
    SlotRequest request1 = new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_PROFILE);
    SlotRequest request2 = new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_BIG_PROFILE);
    slotManager.requestSlot(request1);
    slotManager.requestSlot(request2);
    slotManager.requestSlot(request2);
    slotManager.requestSlot(request1);
    assertEquals(1, slotManager.getAllocatedSlotCount());
    assertEquals(0, slotManager.getFreeSlotCount());
    assertEquals(1, slotManager.getPendingRequestCount());
    assertEquals(1, slotManager.getAllocatedContainers().size());
    assertEquals(DEFAULT_TESTING_BIG_PROFILE, slotManager.getAllocatedContainers().get(0));
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 75 with JobID

use of org.apache.flink.api.common.JobID in project flink by apache.

the class SlotManagerTest method testRequestMultipleSlots.

/**
	 * Tests that we send multiple slot requests
	 */
@Test
public void testRequestMultipleSlots() {
    TestingSlotManager slotManager = new TestingSlotManager();
    directlyProvideFreeSlots(slotManager, DEFAULT_TESTING_PROFILE, 5);
    // request 3 normal slots
    for (int i = 0; i < 3; ++i) {
        slotManager.requestSlot(new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_PROFILE));
    }
    // request 2 big slots
    for (int i = 0; i < 2; ++i) {
        slotManager.requestSlot(new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_BIG_PROFILE));
    }
    // request 1 normal slot again
    slotManager.requestSlot(new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_PROFILE));
    assertEquals(4, slotManager.getAllocatedSlotCount());
    assertEquals(1, slotManager.getFreeSlotCount());
    assertEquals(2, slotManager.getPendingRequestCount());
    assertEquals(2, slotManager.getAllocatedContainers().size());
    assertEquals(DEFAULT_TESTING_BIG_PROFILE, slotManager.getAllocatedContainers().get(0));
    assertEquals(DEFAULT_TESTING_BIG_PROFILE, slotManager.getAllocatedContainers().get(1));
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

JobID (org.apache.flink.api.common.JobID)335 Test (org.junit.Test)274 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)88 IOException (java.io.IOException)74 Configuration (org.apache.flink.configuration.Configuration)72 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)61 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)48 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)47 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)44 ExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionVertex)42 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)38 ArrayList (java.util.ArrayList)37 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)32 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)31 HashMap (java.util.HashMap)29 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)29 FiniteDuration (scala.concurrent.duration.FiniteDuration)28 IntermediateDataSetID (org.apache.flink.runtime.jobgraph.IntermediateDataSetID)24 File (java.io.File)23 UUID (java.util.UUID)23