Search in sources :

Example 11 with LocatableInputSplit

use of org.apache.flink.core.io.LocatableInputSplit in project flink by apache.

the class LocatableSplitAssignerTest method testSerialSplitAssignmentAllForRemoteHost.

@Test
public void testSerialSplitAssignmentAllForRemoteHost() {
    try {
        final String[] hosts = { "host1", "host1", "host1", "host2", "host2", "host3" };
        final int NUM_SPLITS = 10 * hosts.length;
        // load some splits
        Set<LocatableInputSplit> splits = new HashSet<LocatableInputSplit>();
        for (int i = 0; i < NUM_SPLITS; i++) {
            splits.add(new LocatableInputSplit(i, hosts[i % hosts.length]));
        }
        // get all available splits
        LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
        InputSplit is = null;
        while ((is = ia.getNextInputSplit("testhost", 0)) != null) {
            assertTrue(splits.remove(is));
        }
        // check we had all
        assertTrue(splits.isEmpty());
        assertNull(ia.getNextInputSplit("anotherHost", 0));
        assertEquals(NUM_SPLITS, ia.getNumberOfRemoteAssignments());
        assertEquals(0, ia.getNumberOfLocalAssignments());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : LocatableInputSplit(org.apache.flink.core.io.LocatableInputSplit) LocatableInputSplitAssigner(org.apache.flink.api.common.io.LocatableInputSplitAssigner) InputSplit(org.apache.flink.core.io.InputSplit) LocatableInputSplit(org.apache.flink.core.io.LocatableInputSplit) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

LocatableInputSplit (org.apache.flink.core.io.LocatableInputSplit)11 HashSet (java.util.HashSet)10 LocatableInputSplitAssigner (org.apache.flink.api.common.io.LocatableInputSplitAssigner)10 Test (org.junit.Test)10 InputSplit (org.apache.flink.core.io.InputSplit)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1 JobException (org.apache.flink.runtime.JobException)1