Java Code Examples for org.apache.flink.api.common.io.DefaultInputSplitAssigner#getNextInputSplit()

The following examples show how to use org.apache.flink.api.common.io.DefaultInputSplitAssigner#getNextInputSplit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultSplitAssignerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerialSplitAssignment() {
	try {
		final int NUM_SPLITS = 50;
		
		Set<InputSplit> splits = new HashSet<InputSplit>();
		for (int i = 0; i < NUM_SPLITS; i++) {
			splits.add(new GenericInputSplit(i, NUM_SPLITS));
		}
		
		DefaultInputSplitAssigner ia = new DefaultInputSplitAssigner(splits);
		InputSplit is = null;
		while ((is = ia.getNextInputSplit("", 0)) != null) {
			assertTrue(splits.remove(is));
		}
		
		assertTrue(splits.isEmpty());
		assertNull(ia.getNextInputSplit("", 0));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 2
Source File: DefaultSplitAssignerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerialSplitAssignment() {
	try {
		final int NUM_SPLITS = 50;
		
		Set<InputSplit> splits = new HashSet<InputSplit>();
		for (int i = 0; i < NUM_SPLITS; i++) {
			splits.add(new GenericInputSplit(i, NUM_SPLITS));
		}
		
		DefaultInputSplitAssigner ia = new DefaultInputSplitAssigner(splits);
		InputSplit is = null;
		while ((is = ia.getNextInputSplit("", 0)) != null) {
			assertTrue(splits.remove(is));
		}
		
		assertTrue(splits.isEmpty());
		assertNull(ia.getNextInputSplit("", 0));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 3
Source File: DefaultSplitAssignerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerialSplitAssignment() {
	try {
		final int NUM_SPLITS = 50;
		
		Set<InputSplit> splits = new HashSet<InputSplit>();
		for (int i = 0; i < NUM_SPLITS; i++) {
			splits.add(new GenericInputSplit(i, NUM_SPLITS));
		}
		
		DefaultInputSplitAssigner ia = new DefaultInputSplitAssigner(splits);
		InputSplit is = null;
		while ((is = ia.getNextInputSplit("", 0)) != null) {
			assertTrue(splits.remove(is));
		}
		
		assertTrue(splits.isEmpty());
		assertNull(ia.getNextInputSplit("", 0));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 4
Source File: DefaultSplitAssignerTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testConcurrentSplitAssignment() {
	try {
		final int NUM_THREADS = 10;
		final int NUM_SPLITS = 500;
		final int SUM_OF_IDS = (NUM_SPLITS-1) * (NUM_SPLITS) / 2;
		
		Set<InputSplit> splits = new HashSet<InputSplit>();
		for (int i = 0; i < NUM_SPLITS; i++) {
			splits.add(new GenericInputSplit(i, NUM_SPLITS));
		}
		
		final DefaultInputSplitAssigner ia = new DefaultInputSplitAssigner(splits);
		
		final AtomicInteger splitsRetrieved = new AtomicInteger(0);
		final AtomicInteger sumOfIds = new AtomicInteger(0);
		
		Runnable retriever = new Runnable() {
			
			@Override
			public void run() {
				String host = "";
				GenericInputSplit split;
				while ((split = (GenericInputSplit) ia.getNextInputSplit(host, 0)) != null) {
					splitsRetrieved.incrementAndGet();
					sumOfIds.addAndGet(split.getSplitNumber());
				}
			}
		};
		
		// create the threads
		Thread[] threads = new Thread[NUM_THREADS];
		for (int i = 0; i < NUM_THREADS; i++) {
			threads[i] = new Thread(retriever);
			threads[i].setDaemon(true);
		}
		
		// launch concurrently
		for (int i = 0; i < NUM_THREADS; i++) {
			threads[i].start();
		}
		
		// sync
		for (int i = 0; i < NUM_THREADS; i++) {
			threads[i].join(5000);
		}
		
		// verify
		for (int i = 0; i < NUM_THREADS; i++) {
			if (threads[i].isAlive()) {
				fail("The concurrency test case is erroneous, the thread did not respond in time.");
			}
		}
		
		assertEquals(NUM_SPLITS, splitsRetrieved.get());
		assertEquals(SUM_OF_IDS, sumOfIds.get());
		
		// nothing left
		assertNull(ia.getNextInputSplit("", 0));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 5
Source File: DefaultSplitAssignerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testConcurrentSplitAssignment() {
	try {
		final int NUM_THREADS = 10;
		final int NUM_SPLITS = 500;
		final int SUM_OF_IDS = (NUM_SPLITS-1) * (NUM_SPLITS) / 2;
		
		Set<InputSplit> splits = new HashSet<InputSplit>();
		for (int i = 0; i < NUM_SPLITS; i++) {
			splits.add(new GenericInputSplit(i, NUM_SPLITS));
		}
		
		final DefaultInputSplitAssigner ia = new DefaultInputSplitAssigner(splits);
		
		final AtomicInteger splitsRetrieved = new AtomicInteger(0);
		final AtomicInteger sumOfIds = new AtomicInteger(0);
		
		Runnable retriever = new Runnable() {
			
			@Override
			public void run() {
				String host = "";
				GenericInputSplit split;
				while ((split = (GenericInputSplit) ia.getNextInputSplit(host, 0)) != null) {
					splitsRetrieved.incrementAndGet();
					sumOfIds.addAndGet(split.getSplitNumber());
				}
			}
		};
		
		// create the threads
		Thread[] threads = new Thread[NUM_THREADS];
		for (int i = 0; i < NUM_THREADS; i++) {
			threads[i] = new Thread(retriever);
			threads[i].setDaemon(true);
		}
		
		// launch concurrently
		for (int i = 0; i < NUM_THREADS; i++) {
			threads[i].start();
		}
		
		// sync
		for (int i = 0; i < NUM_THREADS; i++) {
			threads[i].join(5000);
		}
		
		// verify
		for (int i = 0; i < NUM_THREADS; i++) {
			if (threads[i].isAlive()) {
				fail("The concurrency test case is erroneous, the thread did not respond in time.");
			}
		}
		
		assertEquals(NUM_SPLITS, splitsRetrieved.get());
		assertEquals(SUM_OF_IDS, sumOfIds.get());
		
		// nothing left
		assertNull(ia.getNextInputSplit("", 0));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 6
Source File: DefaultSplitAssignerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testConcurrentSplitAssignment() {
	try {
		final int NUM_THREADS = 10;
		final int NUM_SPLITS = 500;
		final int SUM_OF_IDS = (NUM_SPLITS-1) * (NUM_SPLITS) / 2;
		
		Set<InputSplit> splits = new HashSet<InputSplit>();
		for (int i = 0; i < NUM_SPLITS; i++) {
			splits.add(new GenericInputSplit(i, NUM_SPLITS));
		}
		
		final DefaultInputSplitAssigner ia = new DefaultInputSplitAssigner(splits);
		
		final AtomicInteger splitsRetrieved = new AtomicInteger(0);
		final AtomicInteger sumOfIds = new AtomicInteger(0);
		
		Runnable retriever = new Runnable() {
			
			@Override
			public void run() {
				String host = "";
				GenericInputSplit split;
				while ((split = (GenericInputSplit) ia.getNextInputSplit(host, 0)) != null) {
					splitsRetrieved.incrementAndGet();
					sumOfIds.addAndGet(split.getSplitNumber());
				}
			}
		};
		
		// create the threads
		Thread[] threads = new Thread[NUM_THREADS];
		for (int i = 0; i < NUM_THREADS; i++) {
			threads[i] = new Thread(retriever);
			threads[i].setDaemon(true);
		}
		
		// launch concurrently
		for (int i = 0; i < NUM_THREADS; i++) {
			threads[i].start();
		}
		
		// sync
		for (int i = 0; i < NUM_THREADS; i++) {
			threads[i].join(5000);
		}
		
		// verify
		for (int i = 0; i < NUM_THREADS; i++) {
			if (threads[i].isAlive()) {
				fail("The concurrency test case is erroneous, the thread did not respond in time.");
			}
		}
		
		assertEquals(NUM_SPLITS, splitsRetrieved.get());
		assertEquals(SUM_OF_IDS, sumOfIds.get());
		
		// nothing left
		assertNull(ia.getNextInputSplit("", 0));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}