Java Code Examples for org.apache.flink.runtime.operators.testutils.types.StringPair

The following examples show how to use org.apache.flink.runtime.operators.testutils.types.StringPair. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Source File: MutableHashTableTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testVariableLengthStringBuildAndRetrieve() throws IOException {
	final int NUM_MEM_PAGES = 40 * NUM_PAIRS / PAGE_SIZE;
	AbstractMutableHashTable<StringPair> table = getHashTable(serializerS, comparatorS, getMemory(NUM_MEM_PAGES));

	MutableObjectIterator<StringPair> buildInput = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	MutableObjectIterator<StringPair> probeTester = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	MutableObjectIterator<StringPair> updater = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	MutableObjectIterator<StringPair> updateTester = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	table.open();

	StringPair target = new StringPair();
	while(buildInput.next(target) != null) {
           table.insert(target);
       }

	AbstractHashTableProber<StringPair, StringPair> prober = table.getProber(comparatorS, pairComparatorS);
	StringPair temp = new StringPair();
	while(probeTester.next(target) != null) {
           assertNotNull("" + target.getKey(), prober.getMatchFor(target, temp));
           assertEquals(temp.getValue(), target.getValue());
       }

	while(updater.next(target) != null) {
           target.setValue(target.getValue());
           table.insertOrReplaceRecord(target);
       }

	while (updateTester.next(target) != null) {
           assertNotNull(prober.getMatchFor(target, temp));
           assertEquals(target.getValue(), temp.getValue());
       }

	table.close();
	assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
}
 
Example 2
Source Project: Flink-CEPplus   Source File: UniformStringPairGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StringPair next(StringPair target) throws IOException {
	if(!repeatKey) {
		if(valCnt >= numVals) {
			return null;
		}
		
		target.setKey(Integer.toString(keyCnt++));
		target.setValue(Integer.toBinaryString(valCnt));
		
		if(keyCnt == numKeys) {
			keyCnt = 0;
			valCnt++;
		}
	} else {
		if(keyCnt >= numKeys) {
			return null;
		}
		
		target.setKey(Integer.toString(keyCnt));
		target.setValue(Integer.toBinaryString(valCnt++));
		
		if(valCnt == numVals) {
			valCnt = 0;
			keyCnt++;
		}
	}
	
	return target;
}
 
Example 3
Source Project: flink   Source File: MutableHashTableTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testVariableLengthStringBuildAndRetrieve() throws IOException {
	final int NUM_MEM_PAGES = 40 * NUM_PAIRS / PAGE_SIZE;
	AbstractMutableHashTable<StringPair> table = getHashTable(serializerS, comparatorS, getMemory(NUM_MEM_PAGES));

	MutableObjectIterator<StringPair> buildInput = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	MutableObjectIterator<StringPair> probeTester = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	MutableObjectIterator<StringPair> updater = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	MutableObjectIterator<StringPair> updateTester = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	table.open();

	StringPair target = new StringPair();
	while(buildInput.next(target) != null) {
           table.insert(target);
       }

	AbstractHashTableProber<StringPair, StringPair> prober = table.getProber(comparatorS, pairComparatorS);
	StringPair temp = new StringPair();
	while(probeTester.next(target) != null) {
           assertNotNull("" + target.getKey(), prober.getMatchFor(target, temp));
           assertEquals(temp.getValue(), target.getValue());
       }

	while(updater.next(target) != null) {
           target.setValue(target.getValue());
           table.insertOrReplaceRecord(target);
       }

	while (updateTester.next(target) != null) {
           assertNotNull(prober.getMatchFor(target, temp));
           assertEquals(target.getValue(), temp.getValue());
       }

	table.close();
	assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
}
 
Example 4
Source Project: flink   Source File: UniformStringPairGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StringPair next(StringPair target) throws IOException {
	if(!repeatKey) {
		if(valCnt >= numVals) {
			return null;
		}
		
		target.setKey(Integer.toString(keyCnt++));
		target.setValue(Integer.toBinaryString(valCnt));
		
		if(keyCnt == numKeys) {
			keyCnt = 0;
			valCnt++;
		}
	} else {
		if(keyCnt >= numKeys) {
			return null;
		}
		
		target.setKey(Integer.toString(keyCnt));
		target.setValue(Integer.toBinaryString(valCnt++));
		
		if(valCnt == numVals) {
			valCnt = 0;
			keyCnt++;
		}
	}
	
	return target;
}
 
Example 5
Source Project: flink   Source File: MutableHashTableTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testVariableLengthStringBuildAndRetrieve() throws IOException {
	final int NUM_MEM_PAGES = 40 * NUM_PAIRS / PAGE_SIZE;
	AbstractMutableHashTable<StringPair> table = getHashTable(serializerS, comparatorS, getMemory(NUM_MEM_PAGES));

	MutableObjectIterator<StringPair> buildInput = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	MutableObjectIterator<StringPair> probeTester = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	MutableObjectIterator<StringPair> updater = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	MutableObjectIterator<StringPair> updateTester = new UniformStringPairGenerator(NUM_PAIRS, 1, false);

	table.open();

	StringPair target = new StringPair();
	while(buildInput.next(target) != null) {
           table.insert(target);
       }

	AbstractHashTableProber<StringPair, StringPair> prober = table.getProber(comparatorS, pairComparatorS);
	StringPair temp = new StringPair();
	while(probeTester.next(target) != null) {
           assertNotNull("" + target.getKey(), prober.getMatchFor(target, temp));
           assertEquals(temp.getValue(), target.getValue());
       }

	while(updater.next(target) != null) {
           target.setValue(target.getValue());
           table.insertOrReplaceRecord(target);
       }

	while (updateTester.next(target) != null) {
           assertNotNull(prober.getMatchFor(target, temp));
           assertEquals(target.getValue(), temp.getValue());
       }

	table.close();
	assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
}
 
Example 6
Source Project: flink   Source File: UniformStringPairGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StringPair next(StringPair target) throws IOException {
	if(!repeatKey) {
		if(valCnt >= numVals) {
			return null;
		}
		
		target.setKey(Integer.toString(keyCnt++));
		target.setValue(Integer.toBinaryString(valCnt));
		
		if(keyCnt == numKeys) {
			keyCnt = 0;
			valCnt++;
		}
	} else {
		if(keyCnt >= numKeys) {
			return null;
		}
		
		target.setKey(Integer.toString(keyCnt));
		target.setValue(Integer.toBinaryString(valCnt++));
		
		if(valCnt == numVals) {
			valCnt = 0;
			keyCnt++;
		}
	}
	
	return target;
}
 
Example 7
Source Project: Flink-CEPplus   Source File: UniformStringPairGenerator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StringPair next() throws IOException {
	return next(new StringPair());
}
 
Example 8
Source Project: flink   Source File: UniformStringPairGenerator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StringPair next() throws IOException {
	return next(new StringPair());
}
 
Example 9
Source Project: flink   Source File: UniformStringPairGenerator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StringPair next() throws IOException {
	return next(new StringPair());
}