
package org.apache.camel.component.file.stress;

import java.security.SecureRandom;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.Disabled;

@Disabled("Manual test")
public class FileAsyncStressManually extends ContextTestSupport {

    public void testAsyncStress() throws Exception {
        // do not test on windows
        if (isPlatform("windows")) {
            return;
        }

        // test by starting the unit test FileAsyncStressFileDropper in another
        // JVM

        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMinimumMessageCount(250);

        assertMockEndpointsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("file:target/data/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
                                SecureRandom ran = new SecureRandom();
                                int delay = ran.nextInt(500) + 10;
                                Thread.sleep(delay);
                            }
                        }).to("mock:result");
            }
        };
    }

}
