Search in sources :

Example 6 with Random

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

the class OptimisticLockRetryPolicy method doDelay.

public void doDelay(final int retryCounter) throws InterruptedException {
    if (retryDelay > 0 || randomBackOff) {
        long sleepFor;
        sleepFor = exponentialBackOff ? (retryDelay << retryCounter) : (randomBackOff ? new Random().nextInt((int) (maximumRetryDelay > 0 ? maximumRetryDelay : DEFAULT_MAXIMUM_RETRY_DELAY)) : retryDelay);
        if (maximumRetryDelay > 0 && sleepFor > maximumRetryDelay) {
            sleepFor = maximumRetryDelay;
        }
        Thread.sleep(sleepFor);
    }
}
Also used : Random(java.util.Random)

Example 7 with Random

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

the class FileAsyncStressManually method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("file:target/filestress?readLock=markerFile&maxMessagesPerPoll=25&move=backup").threads(10).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // simulate some work with random time to complete
                    Random ran = new Random();
                    int delay = ran.nextInt(500) + 10;
                    Thread.sleep(delay);
                }
            }).to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Random(java.util.Random) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 8 with Random

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

the class FileAsyncStressReadLockNoneTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // leverage the fact that we can limit to max 50 files per poll
            // this will result in polling again and potentially picking up files
            // that already are in progress
            from("file:target/filestress?maxMessagesPerPoll=50&readLock=none").routeId("foo").noAutoStartup().threads(10).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // simulate some work with random time to complete
                    Random ran = new Random();
                    int delay = ran.nextInt(250) + 10;
                    Thread.sleep(delay);
                }
            }).to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Random(java.util.Random)

Example 9 with Random

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

the class FileAsyncStressReadLockRenameTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // leverage the fact that we can limit to max 50 files per poll
            // this will result in polling again and potentially picking up files
            // that already are in progress
            from("file:target/filestress?maxMessagesPerPoll=50&readLock=rename").routeId("foo").noAutoStartup().threads(10).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // simulate some work with random time to complete
                    Random ran = new Random();
                    int delay = ran.nextInt(250) + 10;
                    Thread.sleep(delay);
                }
            }).to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Random(java.util.Random)

Example 10 with Random

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

the class FileAsyncStressTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // leverage the fact that we can limit to max 50 files per poll
            // this will result in polling again and potentially picking up files
            // that already are in progress
            from("file:target/filestress?maxMessagesPerPoll=50").routeId("foo").noAutoStartup().threads(10).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // simulate some work with random time to complete
                    Random ran = new Random();
                    int delay = ran.nextInt(50) + 10;
                    Thread.sleep(delay);
                }
            }).to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Random(java.util.Random) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

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