Search in sources :

Example 6 with ContentClaim

use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.

the class TestFileSystemRepository method testClaimantCounts.

@Test
public void testClaimantCounts() throws IOException {
    final ContentClaim claim = repository.create(true);
    assertNotNull(claim);
    assertEquals(1, repository.getClaimantCount(claim));
    assertEquals(2, repository.incrementClaimaintCount(claim));
    assertEquals(3, repository.incrementClaimaintCount(claim));
    assertEquals(4, repository.incrementClaimaintCount(claim));
    assertEquals(5, repository.incrementClaimaintCount(claim));
    repository.decrementClaimantCount(claim);
    assertEquals(4, repository.getClaimantCount(claim));
    repository.decrementClaimantCount(claim);
    assertEquals(3, repository.getClaimantCount(claim));
    repository.decrementClaimantCount(claim);
    assertEquals(2, repository.getClaimantCount(claim));
    repository.decrementClaimantCount(claim);
    assertEquals(1, repository.getClaimantCount(claim));
    repository.decrementClaimantCount(claim);
    assertEquals(0, repository.getClaimantCount(claim));
    repository.remove(claim);
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) Test(org.junit.Test)

Example 7 with ContentClaim

use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.

the class TestFileSystemRepository method testResourceClaimNotReusedAfterRestart.

@Test
public void testResourceClaimNotReusedAfterRestart() throws IOException, InterruptedException {
    final ContentClaim claim1 = repository.create(false);
    try (final OutputStream out = repository.write(claim1)) {
    }
    repository.shutdown();
    Thread.sleep(1000L);
    repository = new FileSystemRepository(nifiProperties);
    repository.initialize(new StandardResourceClaimManager());
    repository.purge();
    final ContentClaim claim2 = repository.create(false);
    assertNotSame(claim1.getResourceClaim(), claim2.getResourceClaim());
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) Test(org.junit.Test)

Example 8 with ContentClaim

use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.

the class TestFileSystemRepository method testReadWithContent.

@Test
public void testReadWithContent() throws IOException {
    final ContentClaim claim = repository.create(true);
    final Path path = getPath(claim);
    Files.createDirectories(path.getParent());
    final byte[] data = "The quick brown fox jumps over the lazy dog".getBytes();
    try (final OutputStream out = Files.newOutputStream(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
        out.write(data);
    }
    try (final InputStream inStream = repository.read(claim)) {
        assertNotNull(inStream);
        final byte[] dataRead = readFully(inStream, data.length);
        assertTrue(Arrays.equals(data, dataRead));
    }
}
Also used : Path(java.nio.file.Path) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 9 with ContentClaim

use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.

the class TestFileSystemRepository method testSize.

@Test
public void testSize() throws IOException {
    final ContentClaim claim = repository.create(true);
    final Path path = getPath(claim);
    Files.createDirectories(path.getParent());
    final byte[] data = "The quick brown fox jumps over the lazy dog".getBytes();
    try (final OutputStream out = Files.newOutputStream(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
        out.write(data);
    }
    assertEquals(data.length, repository.size(claim));
}
Also used : Path(java.nio.file.Path) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 10 with ContentClaim

use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.

the class TestFileSystemRepository method testCreateContentClaim.

@Test
public void testCreateContentClaim() throws IOException {
    // value passed to #create is irrelevant because the FileSystemRepository does not currently support loss tolerance.
    final ContentClaim claim = repository.create(true);
    assertNotNull(claim);
    assertEquals(1, repository.getClaimantCount(claim));
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) Test(org.junit.Test)

Aggregations

ContentClaim (org.apache.nifi.controller.repository.claim.ContentClaim)79 StandardContentClaim (org.apache.nifi.controller.repository.claim.StandardContentClaim)51 Test (org.junit.Test)40 OutputStream (java.io.OutputStream)39 ByteArrayOutputStream (java.io.ByteArrayOutputStream)30 IOException (java.io.IOException)26 InputStream (java.io.InputStream)22 ResourceClaim (org.apache.nifi.controller.repository.claim.ResourceClaim)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 FlowFile (org.apache.nifi.flowfile.FlowFile)19 Path (java.nio.file.Path)18 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)14 Map (java.util.Map)13 FileOutputStream (java.io.FileOutputStream)12 FilterOutputStream (java.io.FilterOutputStream)12 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)12 FlowFileAccessException (org.apache.nifi.processor.exception.FlowFileAccessException)12 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)12