Java Code Examples for org.apache.flink.util.StringUtils#getRandomString()

The following examples show how to use org.apache.flink.util.StringUtils#getRandomString() . 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
@Test
public void testString() {
	String[] arr1 = new String[] {"abc", "",
			StringUtils.getRandomString(new Random(289347567856686223L), 10, 100),
			StringUtils.getRandomString(new Random(289347567856686223L), 15, 50),
			StringUtils.getRandomString(new Random(289347567856686223L), 30, 170),
			StringUtils.getRandomString(new Random(289347567856686223L), 14, 15),
			""};
	
	String[] arr2 = new String[] {"foo", "",
			StringUtils.getRandomString(new Random(289347567856686223L), 10, 100),
			StringUtils.getRandomString(new Random(289347567856686223L), 1000, 5000),
			StringUtils.getRandomString(new Random(289347567856686223L), 30000, 35000),
			StringUtils.getRandomString(new Random(289347567856686223L), 100*1024, 105*1024),
			"bar"};
	
	// run tests with the string serializer as the component serializer
	runTests(String.class, new StringSerializer(), arr1, arr2);
	
	// run the tests with the generic serializer as the component serializer
	runTests(arr1, arr2);
}
 
Example 2
Source Project: flink   File: TupleSerializerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTuple2StringDouble() {
	Random rnd = new Random(807346528946L);
	
	@SuppressWarnings("unchecked")
	Tuple2<String, Double>[] testTuples = new Tuple2[] {
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble()),
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble()),
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble()),
			new Tuple2<String, Double>("", rnd.nextDouble()),
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble()),
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble())
		};
	
	runTests(-1, testTuples);
}
 
Example 3
@Test
public void testTuple2StringDouble() {
	Random rnd = new Random(807346528946L);
	
	@SuppressWarnings("unchecked")
	Tuple2<String, Double>[] testTuples = new Tuple2[] {
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble()),
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble()),
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble()),
			new Tuple2<String, Double>("", rnd.nextDouble()),
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble()),
			new Tuple2<String, Double>(StringUtils.getRandomString(rnd, 10, 100), rnd.nextDouble())
		};
	
	runTests(-1, testTuples);
}
 
Example 4
@Test
public void testSimpleTypesObjects() {
	SimpleTypes a = new SimpleTypes();
	SimpleTypes b = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes c = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes d = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes e = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes f = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes g = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	
	runTests(new SimpleTypes[] {a, b, c}, new SimpleTypes[] {d, e, f, g});
}
 
Example 5
@Test
public void testSimpleTypesObjects() {
	SimpleTypes a = new SimpleTypes();
	SimpleTypes b = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes c = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes d = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes e = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes f = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	SimpleTypes g = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(),
			StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble());
	
	runTests(new SimpleTypes[] {a, b, c}, new SimpleTypes[] {d, e, f, g});
}
 
Example 6
@Test
public void testLongValues() {
	try {
		String[] testStrings = new String[] {
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2)
		};
		
		testSerialization(testStrings);
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Exception in test: " + e.getMessage());
	}
}
 
Example 7
Source Project: flink   File: StringSerializationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBinaryCopyOfLongStrings() {
	try {
		String[] testStrings = new String[] {
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			"",
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			null,
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			null,
			"",
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			"",
			null
		};
		
		testCopy(testStrings);
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Exception in test: " + e.getMessage());
	}
}
 
Example 8
@Test
public void testBinaryCopyOfLongStrings() {
	try {
		String[] testStrings = new String[] {
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			"",
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			"",
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			""
		};
		
		testCopy(testStrings);
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Exception in test: " + e.getMessage());
	}
}
 
Example 9
Source Project: flink   File: StringSerializationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMixedValues() {
	try {
		String[] testStrings = new String[] {
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			"",
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			null,
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			null,
			"",
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			"",
			null
		};
		
		testSerialization(testStrings);
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Exception in test: " + e.getMessage());
	}
}
 
Example 10
@Test
public void testString() {
	String[] arr1 = new String[] {"abc", "",
			StringUtils.getRandomString(new Random(289347567856686223L), 10, 100),
			StringUtils.getRandomString(new Random(289347567856686223L), 15, 50),
			StringUtils.getRandomString(new Random(289347567856686223L), 30, 170),
			StringUtils.getRandomString(new Random(289347567856686223L), 14, 15),
			""};
	
	String[] arr2 = new String[] {"foo", "",
			StringUtils.getRandomString(new Random(289347567856686223L), 10, 100),
			StringUtils.getRandomString(new Random(289347567856686223L), 1000, 5000),
			StringUtils.getRandomString(new Random(289347567856686223L), 30000, 35000),
			StringUtils.getRandomString(new Random(289347567856686223L), 100*1024, 105*1024),
			"bar"};
	
	// run tests with the string serializer as the component serializer
	runTests(String.class, new StringSerializer(), arr1, arr2);
	
	// run the tests with the generic serializer as the component serializer
	runTests(arr1, arr2);
}
 
Example 11
@Test
public void testLongValues() {
	try {
		String[] testStrings = new String[] {
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2)
		};
		
		testSerialization(testStrings);
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Exception in test: " + e.getMessage());
	}
}
 
Example 12
@Before
public void prepare() throws Exception {
	basePathForTest = new Path(
			basePath,
			StringUtils.getRandomString(RND, 16, 16, 'a', 'z'));

	cleanupLocalDir();
}
 
Example 13
@Test
public void testTuple2StringStringArray() {
	Random rnd = new Random(289347567856686223L);
	
	String[] arr1 = new String[] {"abc", "",
			StringUtils.getRandomString(rnd, 10, 100),
			StringUtils.getRandomString(rnd, 15, 50),
			StringUtils.getRandomString(rnd, 30, 170),
			StringUtils.getRandomString(rnd, 14, 15),
			""};
	
	String[] arr2 = new String[] {"foo", "",
			StringUtils.getRandomString(rnd, 10, 100),
			StringUtils.getRandomString(rnd, 1000, 5000),
			StringUtils.getRandomString(rnd, 30000, 35000),
			StringUtils.getRandomString(rnd, 100*1024, 105*1024),
			"bar"};
	
	@SuppressWarnings("unchecked")
	Tuple2<String, String[]>[] testTuples = new Tuple2[] {
		new Tuple2<String, String[]>(StringUtils.getRandomString(rnd, 30, 170), arr1),
		new Tuple2<String, String[]>(StringUtils.getRandomString(rnd, 30, 170), arr2),
		new Tuple2<String, String[]>(StringUtils.getRandomString(rnd, 30, 170), arr1),
		new Tuple2<String, String[]>(StringUtils.getRandomString(rnd, 30, 170), arr2),
		new Tuple2<String, String[]>(StringUtils.getRandomString(rnd, 30, 170), arr2)
	};
	
	runTests(-1, testTuples);
}
 
Example 14
Source Project: flink   File: StringSerializationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testStringBinaryCompatibility() {
	try {
		String[] testStrings = new String[] {
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2, (char) 1, (char) 127),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2, (char) 128, (char) 16383),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2, (char) 16384, (char) 65535),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2, (char) 1, (char) 16383),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2, (char) 1, (char) 65535),
			StringUtils.getRandomString(rnd, 10000, 1024 * 1024 * 2, (char) 128, (char) 65535)
		};

		for (String testString: testStrings) {
			// new and old impl should produce the same binary result
			byte[] oldBytes = serializeBytes(testString, StringSerializationTest::oldWriteString);
			byte[] newBytes = serializeBytes(testString, StringSerializationTest::newWriteString);
			assertArrayEquals(oldBytes, newBytes);
			// old impl should read bytes from new one
			String oldString = deserializeBytes(newBytes, StringSerializationTest::oldReadString);
			assertEquals(oldString, testString);
			// new impl should read bytes from old one
			String newString = deserializeBytes(oldBytes, StringSerializationTest::newReadString);
			assertEquals(newString, testString);
			// it should roundtrip over new impl
			String roundtrip = deserializeBytes(newBytes, StringSerializationTest::newReadString);
			assertEquals(roundtrip, testString);
		}
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Exception in test: " + e.getMessage());
	}
}
 
Example 15
private static String randomName() {
	return StringUtils.getRandomString(RND, 16, 16, 'a', 'z');
}
 
Example 16
private static String randomName() {
	return StringUtils.getRandomString(RND, 16, 16, 'a', 'z');
}
 
Example 17
Source Project: flink   File: AbstractTtlStateVerifier.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
static String randomString() {
	return StringUtils.getRandomString(RANDOM, 2, 20);
}
 
Example 18
private static String randomName() {
	return StringUtils.getRandomString(RND, 16, 16, 'a', 'z');
}
 
Example 19
private static String randomName() {
	return StringUtils.getRandomString(RND, 16, 16, 'a', 'z');
}
 
Example 20
@Nonnull
static String randomString() {
	return StringUtils.getRandomString(RANDOM, 2, 20);
}