Search in sources :

Example 1 with Random

use of java.util.Random in project camel by apache.

the class ConsulKeyValueWatchTest method doPreSetup.

@Override
public void doPreSetup() {
    key = generateKey();
    client = getConsul().keyValueClient();
    random = new Random();
}
Also used : Random(java.util.Random)

Example 2 with Random

use of java.util.Random in project camel by apache.

the class EhcacheTestSupport method generateRandomArrayOfInt.

protected static int[] generateRandomArrayOfInt(int size, int lower, int upper) {
    Random random = new Random();
    int[] array = new int[size];
    Arrays.setAll(array, i -> random.nextInt(upper - lower) + lower);
    return array;
}
Also used : Random(java.util.Random)

Example 3 with Random

use of java.util.Random in project camel by apache.

the class ExpressionBuilder method randomExpression.

/**
     * Returns a random number between min and max
     */
public static Expression randomExpression(final int min, final int max) {
    return new ExpressionAdapter() {

        public Object evaluate(Exchange exchange) {
            Random random = new Random();
            int randomNum = random.nextInt(max - min) + min;
            return randomNum;
        }

        @Override
        public String toString() {
            return "random";
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Random(java.util.Random) Endpoint(org.apache.camel.Endpoint) ExpressionAdapter(org.apache.camel.support.ExpressionAdapter)

Example 4 with Random

use of java.util.Random in project camel by apache.

the class ExpressionBuilder method randomExpression.

/**
     * Returns a random number between min and max
     */
public static Expression randomExpression(final String min, final String max) {
    return new ExpressionAdapter() {

        public Object evaluate(Exchange exchange) {
            int num1 = simpleExpression(min).evaluate(exchange, Integer.class);
            int num2 = simpleExpression(max).evaluate(exchange, Integer.class);
            Random random = new Random();
            int randomNum = random.nextInt(num2 - num1) + num1;
            return randomNum;
        }

        @Override
        public String toString() {
            return "random";
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Random(java.util.Random) Endpoint(org.apache.camel.Endpoint) ExpressionAdapter(org.apache.camel.support.ExpressionAdapter)

Example 5 with Random

use of java.util.Random in project camel by apache.

the class RedeliveryPolicy method calculateRedeliveryDelay.

/**
     * Calculates the new redelivery delay based on the last one
     *
     * @param previousDelay  previous redelivery delay
     * @param redeliveryCounter  number of previous redelivery attempts
     * @return the calculate delay
     */
public long calculateRedeliveryDelay(long previousDelay, int redeliveryCounter) {
    if (ObjectHelper.isNotEmpty(delayPattern)) {
        // calculate delay using the pattern
        return calculateRedeliverDelayUsingPattern(delayPattern, redeliveryCounter);
    }
    // calculate the delay using the conventional parameters
    long redeliveryDelayResult;
    if (previousDelay == 0) {
        redeliveryDelayResult = redeliveryDelay;
    } else if (useExponentialBackOff && backOffMultiplier > 1) {
        redeliveryDelayResult = Math.round(backOffMultiplier * previousDelay);
    } else {
        redeliveryDelayResult = previousDelay;
    }
    if (useCollisionAvoidance) {
        /*
             * First random determines +/-, second random determines how far to
             * go in that direction. -cgs
             */
        Random random = getRandomNumberGenerator();
        double variance = (random.nextBoolean() ? collisionAvoidanceFactor : -collisionAvoidanceFactor) * random.nextDouble();
        redeliveryDelayResult += redeliveryDelayResult * variance;
    }
    // ensure the calculated result is not bigger than the max delay (if configured)
    if (maximumRedeliveryDelay > 0 && redeliveryDelayResult > maximumRedeliveryDelay) {
        redeliveryDelayResult = maximumRedeliveryDelay;
    }
    return redeliveryDelayResult;
}
Also used : Random(java.util.Random)

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