Java Code Examples for org.apache.flink.runtime.io.network.api.writer.ChannelSelector#selectChannel()

The following examples show how to use org.apache.flink.runtime.io.network.api.writer.ChannelSelector#selectChannel() . 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: OutputEmitterTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private boolean verifyWrongPartitionHashKey(int position, int fieldNum) {
	final TypeComparator<Record> comparator = new RecordComparatorFactory(
		new int[] {position}, new Class[] {IntValue.class}).createComparator();
	final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector(
		ShipStrategyType.PARTITION_HASH, comparator, 100);
	final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer());

	Record record = new Record(2);
	record.setField(fieldNum, new IntValue(1));
	delegate.setInstance(record);

	try {
		selector.selectChannel(delegate);
	} catch (NullKeyFieldException re) {
		Assert.assertEquals(position, re.getFieldNumber());
		return true;
	}
	return false;
}
 
Example 2
Source File: OutputEmitterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private boolean verifyWrongPartitionHashKey(int position, int fieldNum) {
	final TypeComparator<Record> comparator = new RecordComparatorFactory(
		new int[] {position}, new Class[] {IntValue.class}).createComparator();
	final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector(
		ShipStrategyType.PARTITION_HASH, comparator, 100);
	final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer());

	Record record = new Record(2);
	record.setField(fieldNum, new IntValue(1));
	delegate.setInstance(record);

	try {
		selector.selectChannel(delegate);
	} catch (NullKeyFieldException re) {
		Assert.assertEquals(position, re.getFieldNumber());
		return true;
	}
	return false;
}
 
Example 3
Source File: OutputEmitterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private boolean verifyWrongPartitionHashKey(int position, int fieldNum) {
	final TypeComparator<Record> comparator = new RecordComparatorFactory(
		new int[] {position}, new Class[] {IntValue.class}).createComparator();
	final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector(
		ShipStrategyType.PARTITION_HASH, comparator, 100);
	final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer());

	Record record = new Record(2);
	record.setField(fieldNum, new IntValue(1));
	delegate.setInstance(record);

	try {
		selector.selectChannel(delegate);
	} catch (NullKeyFieldException re) {
		Assert.assertEquals(position, re.getFieldNumber());
		return true;
	}
	return false;
}
 
Example 4
Source File: OutputEmitterTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiKeys() {
	final int numberOfChannels = 100;
	final int numRecords = 5000;
	final TypeComparator<Record> multiComp = new RecordComparatorFactory(
		new int[] {0,1, 3}, new Class[] {IntValue.class, StringValue.class, DoubleValue.class}).createComparator();

	final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector(
		ShipStrategyType.PARTITION_HASH, multiComp, numberOfChannels);
	final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer());

	int[] hits = new int[numberOfChannels];
	for (int i = 0; i < numRecords; i++) {
		Record record = new Record(4);
		record.setField(0, new IntValue(i));
		record.setField(1, new StringValue("AB" + i + "CD" + i));
		record.setField(3, new DoubleValue(i * 3.141d));
		delegate.setInstance(record);

		int channel = selector.selectChannel(delegate);
		hits[channel]++;
	}

	int totalHitCount = 0;
	for (int hit : hits) {
		assertTrue(hit > 0);
		totalHitCount += hit;
	}
	assertTrue(totalHitCount == numRecords);
}
 
Example 5
Source File: OutputEmitterTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void assertPartitionHashSelectedChannels(
		ChannelSelector selector,
		SerializationDelegate<Integer> serializationDelegate,
		int record,
		int numberOfChannels) {
	serializationDelegate.setInstance(record);
	int selectedChannel = selector.selectChannel(serializationDelegate);

	assertTrue(selectedChannel >= 0 && selectedChannel <= numberOfChannels - 1);
}
 
Example 6
Source File: DefaultChannelSelectorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void assertSelectedChannel(
	ChannelSelector<StringValue> selector,
	StringValue record,
	int expectedChannel) {

	int actualResult = selector.selectChannel(record);
	assertEquals(expectedChannel, actualResult);
}
 
Example 7
Source File: OutputEmitterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiKeys() {
	final int numberOfChannels = 100;
	final int numRecords = 5000;
	final TypeComparator<Record> multiComp = new RecordComparatorFactory(
		new int[] {0,1, 3}, new Class[] {IntValue.class, StringValue.class, DoubleValue.class}).createComparator();

	final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector(
		ShipStrategyType.PARTITION_HASH, multiComp, numberOfChannels);
	final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer());

	int[] hits = new int[numberOfChannels];
	for (int i = 0; i < numRecords; i++) {
		Record record = new Record(4);
		record.setField(0, new IntValue(i));
		record.setField(1, new StringValue("AB" + i + "CD" + i));
		record.setField(3, new DoubleValue(i * 3.141d));
		delegate.setInstance(record);

		int channel = selector.selectChannel(delegate);
		hits[channel]++;
	}

	int totalHitCount = 0;
	for (int hit : hits) {
		assertTrue(hit > 0);
		totalHitCount += hit;
	}
	assertTrue(totalHitCount == numRecords);
}
 
Example 8
Source File: OutputEmitterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void assertPartitionHashSelectedChannels(
		ChannelSelector selector,
		SerializationDelegate<Integer> serializationDelegate,
		int record,
		int numberOfChannels) {
	serializationDelegate.setInstance(record);
	int selectedChannel = selector.selectChannel(serializationDelegate);

	assertTrue(selectedChannel >= 0 && selectedChannel <= numberOfChannels - 1);
}
 
Example 9
Source File: DefaultChannelSelectorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void assertSelectedChannel(
	ChannelSelector<StringValue> selector,
	StringValue record,
	int expectedChannel) {

	int actualResult = selector.selectChannel(record);
	assertEquals(expectedChannel, actualResult);
}
 
Example 10
Source File: OutputEmitterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiKeys() {
	final int numberOfChannels = 100;
	final int numRecords = 5000;
	final TypeComparator<Record> multiComp = new RecordComparatorFactory(
		new int[] {0,1, 3}, new Class[] {IntValue.class, StringValue.class, DoubleValue.class}).createComparator();

	final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector(
		ShipStrategyType.PARTITION_HASH, multiComp, numberOfChannels);
	final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer());

	int[] hits = new int[numberOfChannels];
	for (int i = 0; i < numRecords; i++) {
		Record record = new Record(4);
		record.setField(0, new IntValue(i));
		record.setField(1, new StringValue("AB" + i + "CD" + i));
		record.setField(3, new DoubleValue(i * 3.141d));
		delegate.setInstance(record);

		int channel = selector.selectChannel(delegate);
		hits[channel]++;
	}

	int totalHitCount = 0;
	for (int hit : hits) {
		assertTrue(hit > 0);
		totalHitCount += hit;
	}
	assertTrue(totalHitCount == numRecords);
}
 
Example 11
Source File: OutputEmitterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void assertPartitionHashSelectedChannels(
		ChannelSelector selector,
		SerializationDelegate<Integer> serializationDelegate,
		int record,
		int numberOfChannels) {
	serializationDelegate.setInstance(record);
	int selectedChannel = selector.selectChannel(serializationDelegate);

	assertTrue(selectedChannel >= 0 && selectedChannel <= numberOfChannels - 1);
}
 
Example 12
Source File: DefaultChannelSelectorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void assertSelectedChannel(
	ChannelSelector<StringValue> selector,
	StringValue record,
	int expectedChannel) {

	int actualResult = selector.selectChannel(record);
	assertEquals(expectedChannel, actualResult);
}