Search in sources :

Example 51 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class FromFileToHdfsTest method testTwoFilesToHdfs.

@Test
public void testTwoFilesToHdfs() throws Exception {
    if (!canTest()) {
        return;
    }
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
    template.sendBodyAndHeader("file:target/inbox", "Hello World", Exchange.FILE_NAME, "hello.txt");
    template.sendBodyAndHeader("file:target/inbox", "Bye World", Exchange.FILE_NAME, "bye.txt");
    notify.matchesMockWaitTime();
    File delete = new File("target/inbox/hello.txt");
    assertTrue("File should be deleted " + delete, !delete.exists());
    delete = new File("target/inbox/bye.txt");
    assertTrue("File should be deleted " + delete, !delete.exists());
    File create = new File(TEMP_DIR + "/output.txt");
    assertTrue("File should be created " + create, create.exists());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File) Test(org.junit.Test)

Example 52 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class FromFileToHdfsTest method testFileToHdfs.

@Test
public void testFileToHdfs() throws Exception {
    if (!canTest()) {
        return;
    }
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
    template.sendBodyAndHeader("file:target/inbox", "Hello World", Exchange.FILE_NAME, "hello.txt");
    notify.matchesMockWaitTime();
    File delete = new File("target/inbox/hello.txt");
    assertTrue("File should be deleted " + delete, !delete.exists());
    File create = new File(TEMP_DIR + "/output.txt");
    assertTrue("File should be created " + create, create.exists());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File) Test(org.junit.Test)

Example 53 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class FromFileToHdfsTest method testTwoFilesToHdfs.

@Test
public void testTwoFilesToHdfs() throws Exception {
    if (!canTest()) {
        return;
    }
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
    template.sendBodyAndHeader("file:target/inbox", "Hello World", Exchange.FILE_NAME, "hello.txt");
    template.sendBodyAndHeader("file:target/inbox", "Bye World", Exchange.FILE_NAME, "bye.txt");
    notify.matchesMockWaitTime();
    File delete = new File("target/inbox/hello.txt");
    assertTrue("File should be deleted " + delete, !delete.exists());
    delete = new File("target/inbox/bye.txt");
    assertTrue("File should be deleted " + delete, !delete.exists());
    File create = new File(TEMP_DIR + "/output.txt");
    assertTrue("File should be created " + create, create.exists());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File) Test(org.junit.Test)

Example 54 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class FileIdempotentReadLockTest method testIdempotentReadLock.

public void testIdempotentReadLock() throws Exception {
    assertEquals(0, myRepo.getCacheSize());
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(2);
    template.sendBodyAndHeader("file:target/changed/in", "Hello World", Exchange.FILE_NAME, "hello.txt");
    template.sendBodyAndHeader("file:target/changed/in", "Bye World", Exchange.FILE_NAME, "bye.txt");
    assertMockEndpointsSatisfied();
    assertTrue(notify.matches(5, TimeUnit.SECONDS));
    // the files are kept on commit
    // if you want to remove them then the idempotent repo need some way to evict idle keys
    assertEquals(2, myRepo.getCacheSize());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 55 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class FromFilePollThirdTimeOkTest method testPollFileAndShouldBeDeletedAtThirdPoll.

public void testPollFileAndShouldBeDeletedAtThirdPoll() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(3).create();
    template.sendBodyAndHeader("file://target/deletefile", body, Exchange.FILE_NAME, "hello.txt");
    context.startRoute("FromFilePollThirdTimeOkTest");
    getMockEndpoint("mock:result").expectedBodiesReceived(body);
    assertMockEndpointsSatisfied();
    assertTrue(notify.matchesMockWaitTime());
    assertEquals(3, counter);
    // assert the file is deleted
    File file = new File("target/deletefile/hello.txt");
    assertFalse("The file should have been deleted", file.exists());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File)

Aggregations

NotifyBuilder (org.apache.camel.builder.NotifyBuilder)109 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)30 File (java.io.File)24 Exchange (org.apache.camel.Exchange)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 Processor (org.apache.camel.Processor)4 StopWatch (org.apache.camel.util.StopWatch)4 ConnectException (java.net.ConnectException)3 ExecutorService (java.util.concurrent.ExecutorService)3 Ignore (org.junit.Ignore)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Future (java.util.concurrent.Future)2 ZipFile (java.util.zip.ZipFile)2