use of org.apache.nifi.events.EventReporter in project nifi by apache.
the class TestHttpClientTransaction method getClientTransaction.
private HttpClientTransaction getClientTransaction(InputStream is, OutputStream os, SiteToSiteRestApiClient apiClient, TransferDirection direction, String transactionUrl) throws IOException {
PeerDescription description = null;
String peerUrl = "";
HttpCommunicationsSession commsSession = new HttpCommunicationsSession();
((HttpInput) commsSession.getInput()).setInputStream(is);
((HttpOutput) commsSession.getOutput()).setOutputStream(os);
String clusterUrl = "";
Peer peer = new Peer(description, commsSession, peerUrl, clusterUrl);
String portId = "portId";
boolean useCompression = false;
int penaltyMillis = 1000;
EventReporter eventReporter = new EventReporter() {
@Override
public void reportEvent(Severity severity, String category, String message) {
logger.info("Reporting event... severity={}, category={}, message={}", severity, category, message);
}
};
int protocolVersion = 5;
HttpClientTransaction transaction = new HttpClientTransaction(protocolVersion, peer, direction, useCompression, portId, penaltyMillis, eventReporter);
transaction.initialize(apiClient, transactionUrl);
return transaction;
}
use of org.apache.nifi.events.EventReporter in project nifi by apache.
the class TestSocketClientTransaction method getClientTransaction.
private SocketClientTransaction getClientTransaction(ByteArrayInputStream bis, ByteArrayOutputStream bos, TransferDirection direction) throws IOException {
PeerDescription description = null;
String peerUrl = "";
SocketChannelCommunicationsSession commsSession = mock(SocketChannelCommunicationsSession.class);
SocketChannelInput socketIn = mock(SocketChannelInput.class);
SocketChannelOutput socketOut = mock(SocketChannelOutput.class);
when(commsSession.getInput()).thenReturn(socketIn);
when(commsSession.getOutput()).thenReturn(socketOut);
when(socketIn.getInputStream()).thenReturn(bis);
when(socketOut.getOutputStream()).thenReturn(bos);
String clusterUrl = "";
Peer peer = new Peer(description, commsSession, peerUrl, clusterUrl);
boolean useCompression = false;
int penaltyMillis = 1000;
EventReporter eventReporter = null;
int protocolVersion = 5;
String destinationId = "destinationId";
return new SocketClientTransaction(protocolVersion, destinationId, peer, codec, direction, useCompression, penaltyMillis, eventReporter);
}
use of org.apache.nifi.events.EventReporter in project nifi-minifi by apache.
the class MiNiFiPersistentProvenanceRepositoryTest method printTestName.
@Before
public void printTestName() {
reportedEvents.clear();
eventReporter = new EventReporter() {
private static final long serialVersionUID = 1L;
@Override
public void reportEvent(Severity severity, String category, String message) {
reportedEvents.add(new ReportedEvent(severity, category, message));
System.out.println(severity + " : " + category + " : " + message);
}
};
}
use of org.apache.nifi.events.EventReporter in project nifi-minifi by apache.
the class MiNiFiPersistentProvenanceRepositoryTest method testRolloverRetry.
@Test
public void testRolloverRetry() throws IOException, InterruptedException {
final AtomicInteger retryAmount = new AtomicInteger(0);
final RepositoryConfiguration config = createConfiguration();
config.setMaxEventFileLife(3, TimeUnit.SECONDS);
repo = new MiNiFiPersistentProvenanceRepository(config, DEFAULT_ROLLOVER_MILLIS) {
@Override
File mergeJournals(List<File> journalFiles, File suggestedMergeFile, EventReporter eventReporter) throws IOException {
retryAmount.incrementAndGet();
return super.mergeJournals(journalFiles, suggestedMergeFile, eventReporter);
}
// Indicate that there are no files available.
@Override
protected List<File> filterUnavailableFiles(List<File> journalFiles) {
return Collections.emptyList();
}
@Override
protected long getRolloverRetryMillis() {
// retry quickly.
return 10L;
}
};
repo.initialize(getEventReporter(), null, null, IdentifierLookup.EMPTY);
final Map<String, String> attributes = new HashMap<>();
final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
builder.setEventTime(System.currentTimeMillis());
builder.setEventType(ProvenanceEventType.RECEIVE);
builder.setTransitUri("nifi://unit-test");
attributes.put("uuid", "12345678-0000-0000-0000-012345678912");
builder.fromFlowFile(createFlowFile(3L, 3000L, attributes));
builder.setComponentId("1234");
builder.setComponentType("dummy processor");
final ProvenanceEventRecord record = builder.build();
final ExecutorService exec = Executors.newFixedThreadPool(10);
for (int i = 0; i < 10000; i++) {
exec.submit(new Runnable() {
@Override
public void run() {
repo.registerEvent(record);
}
});
}
exec.shutdown();
exec.awaitTermination(10, TimeUnit.SECONDS);
repo.waitForRollover();
assertEquals(5, retryAmount.get());
}
Aggregations