Search in sources :

Example 6 with StandardResourceClaimManager

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

the class SchemaRepositoryRecordSerdeTest method setup.

@Before
public void setup() {
    resourceClaimManager = new StandardResourceClaimManager();
    schemaRepositoryRecordSerde = new SchemaRepositoryRecordSerde(resourceClaimManager);
    queueMap = new HashMap<>();
    schemaRepositoryRecordSerde.setQueueMap(queueMap);
    flowFileQueue = createMockQueue(TEST_QUEUE_IDENTIFIER);
    byteArrayOutputStream = new ByteArrayOutputStream();
    dataOutputStream = new DataOutputStream(byteArrayOutputStream);
}
Also used : DataOutputStream(java.io.DataOutputStream) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 7 with StandardResourceClaimManager

use of org.apache.nifi.controller.repository.claim.StandardResourceClaimManager 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 StandardResourceClaimManager

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

the class TestFileSystemRepository method testMinimalArchiveCleanupIntervalHonoredAndLogged.

@Test
public void testMinimalArchiveCleanupIntervalHonoredAndLogged() throws Exception {
    // We are going to construct our own repository using different properties, so
    // we need to shutdown the existing one.
    shutdown();
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    ListAppender<ILoggingEvent> testAppender = new ListAppender<>();
    testAppender.setName("Test");
    testAppender.start();
    root.addAppender(testAppender);
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY, "1 millis");
    final NiFiProperties localProps = NiFiProperties.createBasicNiFiProperties(null, addProps);
    repository = new FileSystemRepository(localProps);
    repository.initialize(new StandardResourceClaimManager());
    repository.purge();
    boolean messageFound = false;
    String message = "The value of nifi.content.repository.archive.cleanup.frequency property " + "is set to '1 millis' which is below the allowed minimum of 1 second (1000 milliseconds). " + "Minimum value of 1 sec will be used as scheduling interval for archive cleanup task.";
    // keyword guards testAppender.list. Since we are accessing testAppender.list, we must do so in a thread-safe manner.
    synchronized (testAppender) {
        for (ILoggingEvent event : testAppender.list) {
            String actualMessage = event.getFormattedMessage();
            if (actualMessage.equals(message)) {
                assertEquals(event.getLevel(), Level.WARN);
                messageFound = true;
                break;
            }
        }
    }
    assertTrue(messageFound);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) HashMap(java.util.HashMap) ListAppender(ch.qos.logback.core.read.ListAppender) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 9 with StandardResourceClaimManager

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

the class TestFileSystemRepository method testMarkDestructableDoesNotArchiveIfStreamOpenAndWrittenTo.

@Test
public void testMarkDestructableDoesNotArchiveIfStreamOpenAndWrittenTo() throws IOException, InterruptedException {
    FileSystemRepository repository = null;
    try {
        final List<Path> archivedPaths = Collections.synchronizedList(new ArrayList<Path>());
        // We are creating our own 'local' repository in this test so shut down the one created in the setup() method
        shutdown();
        repository = new FileSystemRepository(nifiProperties) {

            @Override
            protected boolean archive(Path curPath) throws IOException {
                archivedPaths.add(curPath);
                return true;
            }
        };
        final StandardResourceClaimManager claimManager = new StandardResourceClaimManager();
        repository.initialize(claimManager);
        repository.purge();
        final ContentClaim claim = repository.create(false);
        // claim to be put back onto the 'writableClaimsQueue'
        try (final OutputStream out = repository.write(claim)) {
            assertEquals(1, claimManager.getClaimantCount(claim.getResourceClaim()));
            out.write("1\n".getBytes());
        }
        assertEquals(1, claimManager.getClaimantCount(claim.getResourceClaim()));
        int claimantCount = claimManager.decrementClaimantCount(claim.getResourceClaim());
        assertEquals(0, claimantCount);
        assertTrue(archivedPaths.isEmpty());
        claimManager.markDestructable(claim.getResourceClaim());
        // Wait for the archive thread to have a chance to run
        Thread.sleep(2000L);
        // Should still be empty because we have a stream open to the file.
        assertTrue(archivedPaths.isEmpty());
        assertEquals(0, claimManager.getClaimantCount(claim.getResourceClaim()));
    } finally {
        if (repository != null) {
            repository.shutdown();
        }
    }
}
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) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with StandardResourceClaimManager

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

the class TestFileSystemRepository method setup.

@Before
public void setup() throws IOException {
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, TestFileSystemRepository.class.getResource("/conf/nifi.properties").getFile());
    nifiProperties = NiFiProperties.createBasicNiFiProperties(null, null);
    if (rootFile.exists()) {
        DiskUtils.deleteRecursively(rootFile);
    }
    repository = new FileSystemRepository(nifiProperties);
    claimManager = new StandardResourceClaimManager();
    repository.initialize(claimManager);
    repository.purge();
}
Also used : StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) Before(org.junit.Before)

Aggregations

StandardResourceClaimManager (org.apache.nifi.controller.repository.claim.StandardResourceClaimManager)17 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)9 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)8 OutputStream (java.io.OutputStream)7 HashMap (java.util.HashMap)7 ResourceClaimManager (org.apache.nifi.controller.repository.claim.ResourceClaimManager)7 ContentClaim (org.apache.nifi.controller.repository.claim.ContentClaim)6 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 Path (java.nio.file.Path)5 FlowFileRecord (org.apache.nifi.controller.repository.FlowFileRecord)5 StandardContentClaim (org.apache.nifi.controller.repository.claim.StandardContentClaim)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 File (java.io.File)4 NullOutputStream (org.apache.nifi.stream.io.NullOutputStream)4 Ignore (org.junit.Ignore)4 BufferedOutputStream (java.io.BufferedOutputStream)3 DataInputStream (java.io.DataInputStream)3 FileInputStream (java.io.FileInputStream)3