use of org.apache.nifi.provenance.ProvenanceEventRecord in project nifi by apache.
the class TestPartitionedWriteAheadEventStore method testSingleWriteThenRead.
@Test
public void testSingleWriteThenRead() throws IOException {
final PartitionedWriteAheadEventStore store = new PartitionedWriteAheadEventStore(createConfig(), writerFactory, readerFactory, EventReporter.NO_OP, new EventFileManager());
store.initialize();
assertEquals(-1, store.getMaxEventId());
final ProvenanceEventRecord event1 = createEvent();
final StorageResult result = store.addEvents(Collections.singleton(event1));
final StorageSummary summary = result.getStorageLocations().values().iterator().next();
final long eventId = summary.getEventId();
final ProvenanceEventRecord eventWithId = addId(event1, eventId);
assertEquals(0, store.getMaxEventId());
final ProvenanceEventRecord read = store.getEvent(eventId).get();
assertEquals(eventWithId, read);
}
use of org.apache.nifi.provenance.ProvenanceEventRecord in project nifi by apache.
the class TestPartitionedWriteAheadEventStore method testGetSize.
@Test
public void testGetSize() throws IOException {
final PartitionedWriteAheadEventStore store = new PartitionedWriteAheadEventStore(createConfig(), writerFactory, readerFactory, EventReporter.NO_OP, new EventFileManager());
store.initialize();
long storeSize = 0L;
final int numEvents = 20;
for (int i = 0; i < numEvents; i++) {
final ProvenanceEventRecord event = createEvent();
store.addEvents(Collections.singleton(event));
final long newSize = store.getSize();
assertTrue(newSize > storeSize);
storeSize = newSize;
}
}
use of org.apache.nifi.provenance.ProvenanceEventRecord in project nifi by apache.
the class TestPartitionedWriteAheadEventStore method testPerformanceOfAccessingEvents.
@Test
@Ignore
public void testPerformanceOfAccessingEvents() throws Exception {
final RecordWriterFactory recordWriterFactory = (file, idGenerator, compressed, createToc) -> {
final TocWriter tocWriter = createToc ? new StandardTocWriter(TocUtil.getTocFile(file), false, false) : null;
return new EventIdFirstSchemaRecordWriter(file, idGenerator, tocWriter, compressed, 1024 * 1024, IdentifierLookup.EMPTY);
};
final RecordReaderFactory recordReaderFactory = (file, logs, maxChars) -> RecordReaders.newRecordReader(file, logs, maxChars);
final PartitionedWriteAheadEventStore store = new PartitionedWriteAheadEventStore(createConfig(), recordWriterFactory, recordReaderFactory, EventReporter.NO_OP, new EventFileManager());
store.initialize();
assertEquals(-1, store.getMaxEventId());
for (int i = 0; i < 100_000; i++) {
final ProvenanceEventRecord event1 = createEvent();
store.addEvents(Collections.singleton(event1));
}
final List<Long> eventIdList = Arrays.asList(4L, 80L, 1024L, 40_000L, 80_000L, 99_000L);
while (true) {
for (int i = 0; i < 100; i++) {
time(() -> store.getEvents(eventIdList, EventAuthorizer.GRANT_ALL, EventTransformer.EMPTY_TRANSFORMER), "Fetch Events");
}
Thread.sleep(1000L);
}
}
use of org.apache.nifi.provenance.ProvenanceEventRecord in project nifi by apache.
the class TestPartitionedWriteAheadEventStore method testGetEventsWithMinIdAndCount.
@Test
public void testGetEventsWithMinIdAndCount() throws IOException {
final RepositoryConfiguration config = createConfig();
config.setMaxEventFileCount(100);
final PartitionedWriteAheadEventStore store = new PartitionedWriteAheadEventStore(config, writerFactory, readerFactory, EventReporter.NO_OP, new EventFileManager());
store.initialize();
final int numEvents = 50_000;
final List<ProvenanceEventRecord> events = new ArrayList<>(numEvents);
for (int i = 0; i < numEvents; i++) {
final ProvenanceEventRecord event = createEvent();
store.addEvents(Collections.singleton(event));
if (i < 1000) {
events.add(event);
}
}
assertTrue(store.getEvents(-1000L, 1000).isEmpty());
assertEquals(events, store.getEvents(0, events.size()));
assertEquals(events, store.getEvents(-30, events.size()));
assertEquals(events.subList(10, events.size()), store.getEvents(10L, events.size() - 10));
assertTrue(store.getEvents(numEvents, 100).isEmpty());
}
use of org.apache.nifi.provenance.ProvenanceEventRecord in project nifi by apache.
the class TestPartitionedWriteAheadEventStore method testGetEventsWithStartOffsetAndCountWithNothingAuthorized.
@Test
public void testGetEventsWithStartOffsetAndCountWithNothingAuthorized() 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 = EventAuthorizer.DENY_ALL;
final List<ProvenanceEventRecord> storedEvents = store.getEvents(0, 20, allowEventNumberedEventIds, EventTransformer.EMPTY_TRANSFORMER);
assertTrue(storedEvents.isEmpty());
}
Aggregations