Java Code Examples for org.apache.nifi.provenance.lucene.IndexingAction

The following examples show how to use org.apache.nifi.provenance.lucene.IndexingAction. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test(timeout = 15000)
public void testExceptionOnIndex() throws IOException {
    final RepositoryConfiguration config = createConfiguration();
    config.setMaxAttributeChars(50);
    config.setMaxEventFileLife(3, TimeUnit.SECONDS);
    config.setIndexThreadPoolSize(1);

    final int numEventsToIndex = 10;

    final AtomicInteger indexedEventCount = new AtomicInteger(0);
    repo = new PersistentProvenanceRepository(config, DEFAULT_ROLLOVER_MILLIS) {
        @Override
        protected synchronized IndexingAction createIndexingAction() {
            return new IndexingAction(config.getSearchableFields(), config.getSearchableAttributes()) {
                @Override
                public void index(StandardProvenanceEventRecord record, IndexWriter indexWriter, Integer blockIndex) throws IOException {
                    final int count = indexedEventCount.incrementAndGet();
                    if (count <= numEventsToIndex) {
                        return;
                    }

                    throw new IOException("Unit Test - Intentional Exception");
                }
            };
        }
    };
    repo.initialize(getEventReporter(), null, null, IdentifierLookup.EMPTY);

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("uuid", "12345678-0000-0000-0000-012345678912");

    final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
    builder.setEventTime(System.currentTimeMillis());
    builder.setEventType(ProvenanceEventType.RECEIVE);
    builder.setTransitUri("nifi://unit-test");
    builder.fromFlowFile(createFlowFile(3L, 3000L, attributes));
    builder.setComponentId("1234");
    builder.setComponentType("dummy processor");

    for (int i=0; i < 1000; i++) {
        final ProvenanceEventRecord record = builder.build();
        repo.registerEvent(record);
    }

    repo.waitForRollover();

    assertEquals(numEventsToIndex + PersistentProvenanceRepository.MAX_INDEXING_FAILURE_COUNT, indexedEventCount.get());
    assertEquals(1, reportedEvents.size());
    final ReportedEvent event = reportedEvents.get(0);
    assertEquals(Severity.WARNING, event.getSeverity());
}
 
Example 2
@Test(timeout = 15000)
public void testExceptionOnIndex() throws IOException {
    final RepositoryConfiguration config = createConfiguration();
    config.setMaxAttributeChars(50);
    config.setMaxEventFileLife(3, TimeUnit.SECONDS);
    config.setIndexThreadPoolSize(1);

    final int numEventsToIndex = 10;

    final AtomicInteger indexedEventCount = new AtomicInteger(0);
    repo = new MiNiFiPersistentProvenanceRepository(config, DEFAULT_ROLLOVER_MILLIS) {
        @Override
        protected synchronized IndexingAction createIndexingAction() {
            return new IndexingAction(config.getSearchableFields(), config.getSearchableAttributes()) {
                @Override
                public void index(StandardProvenanceEventRecord record, IndexWriter indexWriter, Integer blockIndex) throws IOException {
                    final int count = indexedEventCount.incrementAndGet();
                    if (count <= numEventsToIndex) {
                        return;
                    }

                    throw new IOException("Unit Test - Intentional Exception");
                }
            };
        }
    };
    repo.initialize(getEventReporter(), null, null, IdentifierLookup.EMPTY);

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("uuid", "12345678-0000-0000-0000-012345678912");

    final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
    builder.setEventTime(System.currentTimeMillis());
    builder.setEventType(ProvenanceEventType.RECEIVE);
    builder.setTransitUri("nifi://unit-test");
    builder.fromFlowFile(createFlowFile(3L, 3000L, attributes));
    builder.setComponentId("1234");
    builder.setComponentType("dummy processor");

    for (int i=0; i < 1000; i++) {
        final ProvenanceEventRecord record = builder.build();
        repo.registerEvent(record);
    }

    repo.waitForRollover();

    assertEquals(numEventsToIndex + MiNiFiPersistentProvenanceRepository.MAX_INDEXING_FAILURE_COUNT, indexedEventCount.get());
    assertEquals(1, reportedEvents.size());
    final ReportedEvent event = reportedEvents.get(0);
    assertEquals(Severity.WARNING, event.getSeverity());
}
 
Example 3
Source Project: nifi   Source File: ITestPersistentProvenanceRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Test(timeout = 15000)
public void testExceptionOnIndex() throws IOException {
    assumeFalse(isWindowsEnvironment());
    final RepositoryConfiguration config = createConfiguration();
    config.setMaxAttributeChars(50);
    config.setMaxEventFileLife(3, TimeUnit.SECONDS);
    config.setIndexThreadPoolSize(1);

    final int numEventsToIndex = 10;

    final AtomicInteger indexedEventCount = new AtomicInteger(0);
    repo = new PersistentProvenanceRepository(config, DEFAULT_ROLLOVER_MILLIS) {
        @Override
        protected synchronized IndexingAction createIndexingAction() {
            return new IndexingAction(config.getSearchableFields(), config.getSearchableAttributes()) {
                @Override
                public void index(StandardProvenanceEventRecord record, IndexWriter indexWriter, Integer blockIndex) throws IOException {
                    final int count = indexedEventCount.incrementAndGet();
                    if (count <= numEventsToIndex) {
                        return;
                    }

                    throw new IOException("Unit Test - Intentional Exception");
                }
            };
        }
    };
    repo.initialize(getEventReporter(), null, null, IdentifierLookup.EMPTY);

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("uuid", "12345678-0000-0000-0000-012345678912");

    final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
    builder.setEventTime(System.currentTimeMillis());
    builder.setEventType(ProvenanceEventType.RECEIVE);
    builder.setTransitUri("nifi://unit-test");
    builder.fromFlowFile(createFlowFile(3L, 3000L, attributes));
    builder.setComponentId("1234");
    builder.setComponentType("dummy processor");

    for (int i = 0; i < 1000; i++) {
        final ProvenanceEventRecord record = builder.build();
        repo.registerEvent(record);
    }

    repo.waitForRollover();

    assertEquals(numEventsToIndex + PersistentProvenanceRepository.MAX_INDEXING_FAILURE_COUNT, indexedEventCount.get());
    assertEquals(1, reportedEvents.size());
    final ReportedEvent event = reportedEvents.get(0);
    assertEquals(Severity.WARNING, event.getSeverity());
}
 
Example 4
/**
 * This method is protected and exists for testing purposes. This allows
 * unit tests to extend this class and override the createIndexingAction so
 * that they can mock out the Indexing Action to throw Exceptions, count
 * events indexed, etc.
 */
protected IndexingAction createIndexingAction() {
    return new IndexingAction(configuration.getSearchableFields(), configuration.getSearchableAttributes());
}
 
Example 5
/**
 * This method is protected and exists for testing purposes. This allows
 * unit tests to extend this class and override the createIndexingAction so
 * that they can mock out the Indexing Action to throw Exceptions, count
 * events indexed, etc.
 */
protected IndexingAction createIndexingAction() {
    return new IndexingAction(configuration.getSearchableFields(), configuration.getSearchableAttributes());
}
 
Example 6
Source Project: nifi   Source File: PersistentProvenanceRepository.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * This method is protected and exists for testing purposes. This allows
 * unit tests to extend this class and override the createIndexingAction so
 * that they can mock out the Indexing Action to throw Exceptions, count
 * events indexed, etc.
 */
protected IndexingAction createIndexingAction() {
    return new IndexingAction(configuration.getSearchableFields(), configuration.getSearchableAttributes());
}