Java Code Examples for org.apache.flink.runtime.operators.testutils.types.StringPair#setValue()

The following examples show how to use org.apache.flink.runtime.operators.testutils.types.StringPair#setValue() . 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: MutableHashTableTestBase.java    From Flink-CEPplus with 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 File: UniformStringPairGenerator.java    From Flink-CEPplus with 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 File: MutableHashTableTestBase.java    From flink with 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 File: UniformStringPairGenerator.java    From flink with 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 File: MutableHashTableTestBase.java    From flink with 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 File: UniformStringPairGenerator.java    From flink with 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;
}