Search in sources :

Example 21 with RepositoryConfiguration

use of org.apache.nifi.provenance.RepositoryConfiguration in project nifi by apache.

the class TestSimpleIndexManager method testWriterCloseIfOnlyUser.

@Test
public void testWriterCloseIfOnlyUser() throws IOException {
    final AtomicInteger closeCount = new AtomicInteger(0);
    final SimpleIndexManager mgr = new SimpleIndexManager(new RepositoryConfiguration()) {

        @Override
        protected void close(IndexWriterCount count) throws IOException {
            closeCount.incrementAndGet();
        }
    };
    final File dir = new File("target/" + UUID.randomUUID().toString());
    final EventIndexWriter writer = mgr.borrowIndexWriter(dir);
    mgr.returnIndexWriter(writer, true, true);
    assertEquals(1, closeCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventIndexWriter(org.apache.nifi.provenance.index.EventIndexWriter) RepositoryConfiguration(org.apache.nifi.provenance.RepositoryConfiguration) File(java.io.File) Test(org.junit.Test)

Example 22 with RepositoryConfiguration

use of org.apache.nifi.provenance.RepositoryConfiguration in project nifi by apache.

the class TestPartitionedWriteAheadEventStore method testGetSpecificEventIds.

@Test
public void testGetSpecificEventIds() throws IOException {
    final RepositoryConfiguration config = createConfig();
    final PartitionedWriteAheadEventStore store = new PartitionedWriteAheadEventStore(config, writerFactory, readerFactory, EventReporter.NO_OP, new EventFileManager());
    store.initialize();
    final int numEvents = 20;
    final List<ProvenanceEventRecord> events = new ArrayList<>(numEvents);
    for (int i = 0; i < numEvents; i++) {
        final ProvenanceEventRecord event = createEvent();
        store.addEvents(Collections.singleton(event));
        events.add(event);
    }
    final EventAuthorizer allowEvenNumberedEventIds = new EventAuthorizer() {

        @Override
        public boolean isAuthorized(final ProvenanceEventRecord event) {
            return event.getEventId() % 2 == 0L;
        }

        @Override
        public void authorize(ProvenanceEventRecord event) throws AccessDeniedException {
            if (!isAuthorized(event)) {
                throw new AccessDeniedException();
            }
        }
    };
    final List<Long> evenEventIds = new ArrayList<>();
    final List<Long> oddEventIds = new ArrayList<>();
    final List<Long> allEventIds = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        final Long id = Long.valueOf(i);
        allEventIds.add(id);
        if (i % 2 == 0) {
            evenEventIds.add(id);
        } else {
            oddEventIds.add(id);
        }
    }
    final List<ProvenanceEventRecord> storedEvents = store.getEvents(evenEventIds, allowEvenNumberedEventIds, EventTransformer.EMPTY_TRANSFORMER);
    assertEquals(numEvents / 2, storedEvents.size());
    for (int i = 0; i < storedEvents.size(); i++) {
        assertEquals(events.get(i * 2), storedEvents.get(i));
    }
    assertTrue(store.getEvents(oddEventIds, allowEvenNumberedEventIds, EventTransformer.EMPTY_TRANSFORMER).isEmpty());
    final List<ProvenanceEventRecord> allStoredEvents = store.getEvents(allEventIds, EventAuthorizer.GRANT_ALL, EventTransformer.EMPTY_TRANSFORMER);
    assertEquals(events, allStoredEvents);
}
Also used : AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) EventAuthorizer(org.apache.nifi.provenance.authorization.EventAuthorizer) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) RepositoryConfiguration(org.apache.nifi.provenance.RepositoryConfiguration) Test(org.junit.Test)

Example 23 with RepositoryConfiguration

use of org.apache.nifi.provenance.RepositoryConfiguration in project nifi by apache.

the class TestPartitionedWriteAheadEventStore method testMaxEventIdRestored.

@Test
public void testMaxEventIdRestored() throws IOException {
    final RepositoryConfiguration config = createConfig();
    final PartitionedWriteAheadEventStore store = new PartitionedWriteAheadEventStore(config, writerFactory, readerFactory, EventReporter.NO_OP, new EventFileManager());
    store.initialize();
    final int numEvents = 20;
    for (int i = 0; i < numEvents; i++) {
        final ProvenanceEventRecord event = createEvent();
        store.addEvents(Collections.singleton(event));
    }
    assertEquals(19, store.getMaxEventId());
    store.close();
    final PartitionedWriteAheadEventStore recoveredStore = new PartitionedWriteAheadEventStore(config, writerFactory, readerFactory, EventReporter.NO_OP, new EventFileManager());
    recoveredStore.initialize();
    assertEquals(19, recoveredStore.getMaxEventId());
}
Also used : ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) RepositoryConfiguration(org.apache.nifi.provenance.RepositoryConfiguration) Test(org.junit.Test)

Example 24 with RepositoryConfiguration

use of org.apache.nifi.provenance.RepositoryConfiguration in project nifi by apache.

the class TestPartitionedWriteAheadEventStore method testGetEventsWithMinIdAndCountWithAuthorizer.

@Test
public void testGetEventsWithMinIdAndCountWithAuthorizer() throws IOException {
    final RepositoryConfiguration config = createConfig();
    final PartitionedWriteAheadEventStore store = new PartitionedWriteAheadEventStore(config, writerFactory, readerFactory, EventReporter.NO_OP, new EventFileManager());
    store.initialize();
    final int numEvents = 20;
    final List<ProvenanceEventRecord> events = new ArrayList<>(numEvents);
    for (int i = 0; i < numEvents; i++) {
        final ProvenanceEventRecord event = createEvent();
        store.addEvents(Collections.singleton(event));
        events.add(event);
    }
    final EventAuthorizer allowEventNumberedEventIds = new EventAuthorizer() {

        @Override
        public boolean isAuthorized(final ProvenanceEventRecord event) {
            return event.getEventId() % 2 == 0L;
        }

        @Override
        public void authorize(ProvenanceEventRecord event) throws AccessDeniedException {
            if (!isAuthorized(event)) {
                throw new AccessDeniedException();
            }
        }
    };
    final List<ProvenanceEventRecord> storedEvents = store.getEvents(0, 20, allowEventNumberedEventIds, EventTransformer.EMPTY_TRANSFORMER);
    assertEquals(numEvents / 2, storedEvents.size());
    for (int i = 0; i < storedEvents.size(); i++) {
        assertEquals(events.get(i * 2), storedEvents.get(i));
    }
}
Also used : AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) EventAuthorizer(org.apache.nifi.provenance.authorization.EventAuthorizer) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) ArrayList(java.util.ArrayList) RepositoryConfiguration(org.apache.nifi.provenance.RepositoryConfiguration) Test(org.junit.Test)

Example 25 with RepositoryConfiguration

use of org.apache.nifi.provenance.RepositoryConfiguration in project nifi by apache.

the class TestPartitionedWriteAheadEventStore method createConfig.

private RepositoryConfiguration createConfig(final int numStorageDirs) {
    final RepositoryConfiguration config = new RepositoryConfiguration();
    final String unitTestName = testName.getMethodName();
    final File storageDir = new File("target/storage/" + unitTestName + "/" + UUID.randomUUID().toString());
    for (int i = 1; i <= numStorageDirs; i++) {
        config.addStorageDirectory(String.valueOf(i), new File(storageDir, String.valueOf(i)));
    }
    return config;
}
Also used : RepositoryConfiguration(org.apache.nifi.provenance.RepositoryConfiguration) File(java.io.File)

Aggregations

RepositoryConfiguration (org.apache.nifi.provenance.RepositoryConfiguration)27 Test (org.junit.Test)24 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)16 File (java.io.File)15 StandardProvenanceEventRecord (org.apache.nifi.provenance.StandardProvenanceEventRecord)15 IndexManager (org.apache.nifi.provenance.lucene.IndexManager)9 ArrayList (java.util.ArrayList)8 SimpleIndexManager (org.apache.nifi.provenance.lucene.SimpleIndexManager)8 ArrayListEventStore (org.apache.nifi.provenance.store.ArrayListEventStore)8 EventAuthorizer (org.apache.nifi.provenance.authorization.EventAuthorizer)6 StorageSummary (org.apache.nifi.provenance.serialization.StorageSummary)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)5 EventIndexWriter (org.apache.nifi.provenance.index.EventIndexWriter)5 Query (org.apache.nifi.provenance.search.Query)5 QuerySubmission (org.apache.nifi.provenance.search.QuerySubmission)5 StorageResult (org.apache.nifi.provenance.store.StorageResult)5 List (java.util.List)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4