Java Code Examples for org.apache.flink.streaming.connectors.kafka.partitioner.FlinkFixedPartitioner#open()

The following examples show how to use org.apache.flink.streaming.connectors.kafka.partitioner.FlinkFixedPartitioner#open() . 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: FlinkFixedPartitionerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Test for when there are more sinks than partitions.
 * <pre>
 *   		Flink Sinks:		Kafka Partitions
 * 			1	---------------->	1
 * 			2   --------------/
 * 			3   -------------/
 * 			4	------------/
 * </pre>
 */
@Test
public void testMoreFlinkThanBrokers() {
	FlinkFixedPartitioner<String> part = new FlinkFixedPartitioner<>();

	int[] partitions = new int[]{0};

	part.open(0, 4);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

	part.open(1, 4);
	Assert.assertEquals(0, part.partition("abc2", null, null, null, partitions));

	part.open(2, 4);
	Assert.assertEquals(0, part.partition("abc3", null, null, null, partitions));
	Assert.assertEquals(0, part.partition("abc3", null, null, null, partitions)); // check if it is changing ;)

	part.open(3, 4);
	Assert.assertEquals(0, part.partition("abc4", null, null, null, partitions));
}
 
Example 2
Source File: FlinkFixedPartitionerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test for when there are more sinks than partitions.
 * <pre>
 *   		Flink Sinks:		Kafka Partitions
 * 			1	---------------->	1
 * 			2   --------------/
 * 			3   -------------/
 * 			4	------------/
 * </pre>
 */
@Test
public void testMoreFlinkThanBrokers() {
	FlinkFixedPartitioner<String> part = new FlinkFixedPartitioner<>();

	int[] partitions = new int[]{0};

	part.open(0, 4);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

	part.open(1, 4);
	Assert.assertEquals(0, part.partition("abc2", null, null, null, partitions));

	part.open(2, 4);
	Assert.assertEquals(0, part.partition("abc3", null, null, null, partitions));
	Assert.assertEquals(0, part.partition("abc3", null, null, null, partitions)); // check if it is changing ;)

	part.open(3, 4);
	Assert.assertEquals(0, part.partition("abc4", null, null, null, partitions));
}
 
Example 3
Source File: FlinkFixedPartitionerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test for when there are more sinks than partitions.
 * <pre>
 *   		Flink Sinks:		Kafka Partitions
 * 			1	---------------->	1
 * 			2   --------------/
 * 			3   -------------/
 * 			4	------------/
 * </pre>
 */
@Test
public void testMoreFlinkThanBrokers() {
	FlinkFixedPartitioner<String> part = new FlinkFixedPartitioner<>();

	int[] partitions = new int[]{0};

	part.open(0, 4);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

	part.open(1, 4);
	Assert.assertEquals(0, part.partition("abc2", null, null, null, partitions));

	part.open(2, 4);
	Assert.assertEquals(0, part.partition("abc3", null, null, null, partitions));
	Assert.assertEquals(0, part.partition("abc3", null, null, null, partitions)); // check if it is changing ;)

	part.open(3, 4);
	Assert.assertEquals(0, part.partition("abc4", null, null, null, partitions));
}
 
Example 4
Source File: FlinkFixedPartitionerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tests for when there are more partitions than sinks.
 * <pre>
 * 		Flink Sinks:		Kafka Partitions
 * 			1	---------------->	1
 * 			2	---------------->	2
 * 									3
 * 									4
 * 									5
 *
 * </pre>
 */
@Test
public void testFewerPartitions() {
	FlinkFixedPartitioner<String> part = new FlinkFixedPartitioner<>();

	int[] partitions = new int[]{0, 1, 2, 3, 4};
	part.open(0, 2);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

	part.open(1, 2);
	Assert.assertEquals(1, part.partition("abc1", null, null, null, partitions));
	Assert.assertEquals(1, part.partition("abc1", null, null, null, partitions));
}
 
Example 5
Source File: FlinkFixedPartitionerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMixedCase() {
	FlinkFixedPartitioner<String> part = new FlinkFixedPartitioner<>();
	int[] partitions = new int[]{0, 1};

	part.open(0, 3);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

	part.open(1, 3);
	Assert.assertEquals(1, part.partition("abc1", null, null, null, partitions));

	part.open(2, 3);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

}
 
Example 6
Source File: FlinkFixedPartitionerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests for when there are more partitions than sinks.
 * <pre>
 * 		Flink Sinks:		Kafka Partitions
 * 			1	---------------->	1
 * 			2	---------------->	2
 * 									3
 * 									4
 * 									5
 *
 * </pre>
 */
@Test
public void testFewerPartitions() {
	FlinkFixedPartitioner<String> part = new FlinkFixedPartitioner<>();

	int[] partitions = new int[]{0, 1, 2, 3, 4};
	part.open(0, 2);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

	part.open(1, 2);
	Assert.assertEquals(1, part.partition("abc1", null, null, null, partitions));
	Assert.assertEquals(1, part.partition("abc1", null, null, null, partitions));
}
 
Example 7
Source File: FlinkFixedPartitionerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMixedCase() {
	FlinkFixedPartitioner<String> part = new FlinkFixedPartitioner<>();
	int[] partitions = new int[]{0, 1};

	part.open(0, 3);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

	part.open(1, 3);
	Assert.assertEquals(1, part.partition("abc1", null, null, null, partitions));

	part.open(2, 3);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

}
 
Example 8
Source File: FlinkFixedPartitionerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests for when there are more partitions than sinks.
 * <pre>
 * 		Flink Sinks:		Kafka Partitions
 * 			1	---------------->	1
 * 			2	---------------->	2
 * 									3
 * 									4
 * 									5
 *
 * </pre>
 */
@Test
public void testFewerPartitions() {
	FlinkFixedPartitioner<String> part = new FlinkFixedPartitioner<>();

	int[] partitions = new int[]{0, 1, 2, 3, 4};
	part.open(0, 2);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

	part.open(1, 2);
	Assert.assertEquals(1, part.partition("abc1", null, null, null, partitions));
	Assert.assertEquals(1, part.partition("abc1", null, null, null, partitions));
}
 
Example 9
Source File: FlinkFixedPartitionerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMixedCase() {
	FlinkFixedPartitioner<String> part = new FlinkFixedPartitioner<>();
	int[] partitions = new int[]{0, 1};

	part.open(0, 3);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

	part.open(1, 3);
	Assert.assertEquals(1, part.partition("abc1", null, null, null, partitions));

	part.open(2, 3);
	Assert.assertEquals(0, part.partition("abc1", null, null, null, partitions));

}