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());
}
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);
}
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());
}
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));
}
}
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;
}
Aggregations