Search in sources :

Example 6 with MemoryIdempotentRepository

use of org.apache.camel.processor.idempotent.MemoryIdempotentRepository in project camel by apache.

the class FileBrowsableEndpointTest method testBrowsableThreeFilesRecursive.

public void testBrowsableThreeFilesRecursive() throws Exception {
    template.sendBodyAndHeader("file:target/browse", "A", Exchange.FILE_NAME, "a.txt");
    template.sendBodyAndHeader("file:target/browse", "B", Exchange.FILE_NAME, "foo/b.txt");
    template.sendBodyAndHeader("file:target/browse", "C", Exchange.FILE_NAME, "bar/c.txt");
    FileEndpoint endpoint = context.getEndpoint("file:target/browse?recursive=true&sortBy=file:name", FileEndpoint.class);
    assertNotNull(endpoint);
    MemoryIdempotentRepository repo = (MemoryIdempotentRepository) endpoint.getInProgressRepository();
    assertEquals(0, repo.getCacheSize());
    List<Exchange> list = endpoint.getExchanges();
    assertNotNull(list);
    assertEquals(3, list.size());
    assertEquals("a.txt", list.get(0).getIn().getHeader(Exchange.FILE_NAME));
    assertEquals("c.txt", list.get(1).getIn().getHeader(Exchange.FILE_NAME_ONLY));
    assertEquals("b.txt", list.get(2).getIn().getHeader(Exchange.FILE_NAME_ONLY));
    // the in progress repo should not leak
    assertEquals(0, repo.getCacheSize());
    // and the files is still there
    File fileA = new File("target/browse/a.txt");
    assertTrue("File should exist " + fileA, fileA.exists());
    File fileB = new File("target/browse/foo/b.txt");
    assertTrue("File should exist " + fileB, fileB.exists());
    File fileC = new File("target/browse/bar/c.txt");
    assertTrue("File should exist " + fileC, fileC.exists());
}
Also used : Exchange(org.apache.camel.Exchange) File(java.io.File) MemoryIdempotentRepository(org.apache.camel.processor.idempotent.MemoryIdempotentRepository)

Example 7 with MemoryIdempotentRepository

use of org.apache.camel.processor.idempotent.MemoryIdempotentRepository in project camel by apache.

the class FileConsumerIdempotentTest method testIdempotent.

public void testIdempotent() throws Exception {
    // consume the file the first time
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    assertMockEndpointsSatisfied();
    oneExchangeDone.matchesMockWaitTime();
    // reset mock and set new expectations
    mock.reset();
    mock.expectedMessageCount(0);
    // move file back
    File file = new File("target/idempotent/done/report.txt");
    File renamed = new File("target/idempotent/report.txt");
    file.renameTo(renamed);
    // should NOT consume the file again, let a bit time pass to let the consumer try to consume it but it should not
    Thread.sleep(100);
    assertMockEndpointsSatisfied();
    FileEndpoint fe = context.getEndpoint(uri, FileEndpoint.class);
    assertNotNull(fe);
    MemoryIdempotentRepository repo = (MemoryIdempotentRepository) fe.getInProgressRepository();
    assertEquals("Should be no in-progress files", 0, repo.getCacheSize());
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) MemoryIdempotentRepository(org.apache.camel.processor.idempotent.MemoryIdempotentRepository)

Example 8 with MemoryIdempotentRepository

use of org.apache.camel.processor.idempotent.MemoryIdempotentRepository in project camel by apache.

the class FileBrowsableEndpointTest method testBrowsableTwoFiles.

public void testBrowsableTwoFiles() throws Exception {
    template.sendBodyAndHeader("file:target/browse", "A", Exchange.FILE_NAME, "a.txt");
    template.sendBodyAndHeader("file:target/browse", "B", Exchange.FILE_NAME, "b.txt");
    FileEndpoint endpoint = context.getEndpoint("file:target/browse?sortBy=file:name", FileEndpoint.class);
    assertNotNull(endpoint);
    MemoryIdempotentRepository repo = (MemoryIdempotentRepository) endpoint.getInProgressRepository();
    assertEquals(0, repo.getCacheSize());
    List<Exchange> list = endpoint.getExchanges();
    assertNotNull(list);
    assertEquals(2, list.size());
    assertEquals("a.txt", list.get(0).getIn().getHeader(Exchange.FILE_NAME));
    assertEquals("b.txt", list.get(1).getIn().getHeader(Exchange.FILE_NAME));
    // the in progress repo should not leak
    assertEquals(0, repo.getCacheSize());
    // and the files is still there
    File fileA = new File("target/browse/a.txt");
    assertTrue("File should exist " + fileA, fileA.exists());
    File fileB = new File("target/browse/b.txt");
    assertTrue("File should exist " + fileB, fileB.exists());
}
Also used : Exchange(org.apache.camel.Exchange) File(java.io.File) MemoryIdempotentRepository(org.apache.camel.processor.idempotent.MemoryIdempotentRepository)

Aggregations

MemoryIdempotentRepository (org.apache.camel.processor.idempotent.MemoryIdempotentRepository)8 File (java.io.File)7 Exchange (org.apache.camel.Exchange)6 Test (org.junit.Test)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 JndiRegistry (org.apache.camel.impl.JndiRegistry)1