use of java.util.Random in project flink by apache.
the class MassiveStringSorting method generateFileWithStringTuples.
private File generateFileWithStringTuples(int numStrings, String prefix) throws IOException {
final Random rnd = new Random(SEED);
final StringBuilder bld = new StringBuilder();
File f = File.createTempFile("strings", "txt");
BufferedWriter wrt = null;
try {
wrt = new BufferedWriter(new FileWriter(f));
for (int i = 0; i < numStrings; i++) {
bld.setLength(0);
int numComps = rnd.nextInt(5) + 1;
for (int z = 0; z < numComps; z++) {
if (z > 0) {
bld.append(' ');
}
bld.append(prefix);
int len = rnd.nextInt(20) + 10;
for (int k = 0; k < len; k++) {
char c = (char) (rnd.nextInt(80) + 40);
bld.append(c);
}
}
String str = bld.toString();
wrt.write(str);
wrt.newLine();
}
} finally {
wrt.close();
}
return f;
}
use of java.util.Random in project flink by apache.
the class MassiveStringValueSorting method generateFileWithStringTuples.
private File generateFileWithStringTuples(int numStrings, String prefix) throws IOException {
final Random rnd = new Random(SEED);
final StringBuilder bld = new StringBuilder();
File f = File.createTempFile("strings", "txt");
BufferedWriter wrt = null;
try {
wrt = new BufferedWriter(new FileWriter(f));
for (int i = 0; i < numStrings; i++) {
bld.setLength(0);
int numComps = rnd.nextInt(5) + 1;
for (int z = 0; z < numComps; z++) {
if (z > 0) {
bld.append(' ');
}
bld.append(prefix);
int len = rnd.nextInt(20) + 10;
for (int k = 0; k < len; k++) {
char c = (char) (rnd.nextInt(80) + 40);
bld.append(c);
}
}
String str = bld.toString();
wrt.write(str);
wrt.newLine();
}
} finally {
if (wrt != null) {
wrt.close();
}
}
return f;
}
use of java.util.Random in project flink by apache.
the class CheckpointCoordinatorTest method testCreateKeyGroupPartitions.
@Test
public void testCreateKeyGroupPartitions() {
testCreateKeyGroupPartitions(1, 1);
testCreateKeyGroupPartitions(13, 1);
testCreateKeyGroupPartitions(13, 2);
testCreateKeyGroupPartitions(Short.MAX_VALUE, 1);
testCreateKeyGroupPartitions(Short.MAX_VALUE, 13);
testCreateKeyGroupPartitions(Short.MAX_VALUE, Short.MAX_VALUE);
Random r = new Random(1234);
for (int k = 0; k < 1000; ++k) {
int maxParallelism = 1 + r.nextInt(Short.MAX_VALUE - 1);
int parallelism = 1 + r.nextInt(maxParallelism);
testCreateKeyGroupPartitions(maxParallelism, parallelism);
}
}
use of java.util.Random in project flink by apache.
the class CheckpointCoordinatorTest method generateChainedPartitionableStateHandle.
public static ChainedStateHandle<OperatorStateHandle> generateChainedPartitionableStateHandle(JobVertexID jobVertexID, int index, int namedStates, int partitionsPerState, boolean rawState) throws IOException {
Map<String, List<? extends Serializable>> statesListsMap = new HashMap<>(namedStates);
for (int i = 0; i < namedStates; ++i) {
List<Integer> testStatesLists = new ArrayList<>(partitionsPerState);
// generate state
int seed = jobVertexID.hashCode() * index + i * namedStates;
if (rawState) {
seed = (seed + 1) * 31;
}
Random random = new Random(seed);
for (int j = 0; j < partitionsPerState; ++j) {
int simulatedStateValue = random.nextInt();
testStatesLists.add(simulatedStateValue);
}
statesListsMap.put("state-" + i, testStatesLists);
}
return generateChainedPartitionableStateHandle(statesListsMap);
}
use of java.util.Random in project flink by apache.
the class CheckpointCoordinatorTest method generateKeyGroupState.
// ------------------------------------------------------------------------
// Utilities
// ------------------------------------------------------------------------
public static KeyGroupsStateHandle generateKeyGroupState(JobVertexID jobVertexID, KeyGroupRange keyGroupPartition, boolean rawState) throws IOException {
List<Integer> testStatesLists = new ArrayList<>(keyGroupPartition.getNumberOfKeyGroups());
// generate state for one keygroup
for (int keyGroupIndex : keyGroupPartition) {
int vertexHash = jobVertexID.hashCode();
int seed = rawState ? (vertexHash * (31 + keyGroupIndex)) : (vertexHash + keyGroupIndex);
Random random = new Random(seed);
int simulatedStateValue = random.nextInt();
testStatesLists.add(simulatedStateValue);
}
return generateKeyGroupState(keyGroupPartition, testStatesLists);
}
Aggregations