Search in sources :

Example 36 with Random

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;
}
Also used : Random(java.util.Random) FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 37 with Random

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;
}
Also used : Random(java.util.Random) FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 38 with Random

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);
    }
}
Also used : Random(java.util.Random) AcknowledgeCheckpoint(org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint) DeclineCheckpoint(org.apache.flink.runtime.messages.checkpoint.DeclineCheckpoint) Test(org.junit.Test)

Example 39 with Random

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Serializable(java.io.Serializable) Random(java.util.Random) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AcknowledgeCheckpoint(org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint) DeclineCheckpoint(org.apache.flink.runtime.messages.checkpoint.DeclineCheckpoint)

Example 40 with Random

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Random(java.util.Random) ArrayList(java.util.ArrayList) AcknowledgeCheckpoint(org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint) DeclineCheckpoint(org.apache.flink.runtime.messages.checkpoint.DeclineCheckpoint)

Aggregations

Random (java.util.Random)4728 Test (org.junit.Test)1273 ArrayList (java.util.ArrayList)602 IOException (java.io.IOException)313 HashMap (java.util.HashMap)242 File (java.io.File)209 List (java.util.List)154 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)151 ByteArrayInputStream (java.io.ByteArrayInputStream)134 HashSet (java.util.HashSet)129 ByteBuffer (java.nio.ByteBuffer)123 Test (org.testng.annotations.Test)121 Path (org.apache.hadoop.fs.Path)116 Map (java.util.Map)106 QuickTest (com.hazelcast.test.annotation.QuickTest)99 ParallelTest (com.hazelcast.test.annotation.ParallelTest)94 CountDownLatch (java.util.concurrent.CountDownLatch)93 Configuration (org.apache.hadoop.conf.Configuration)88 ByteArrayOutputStream (java.io.ByteArrayOutputStream)79 Before (org.junit.Before)78