use of org.apache.nifi.events.EventReporter in project nifi by apache.
the class TestPersistentProvenanceRepository method testRolloverRetry.
@Test
public void testRolloverRetry() throws IOException, InterruptedException {
assumeFalse(isWindowsEnvironment());
final AtomicInteger retryAmount = new AtomicInteger(0);
final RepositoryConfiguration config = createConfiguration();
config.setMaxEventFileLife(3, TimeUnit.SECONDS);
repo = new PersistentProvenanceRepository(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());
}
use of org.apache.nifi.events.EventReporter in project nifi by apache.
the class TestNodeClusterCoordinator method testTryAgainIfNoFlowServiceSet.
@Test
public void testTryAgainIfNoFlowServiceSet() {
final ClusterCoordinationProtocolSenderListener senderListener = Mockito.mock(ClusterCoordinationProtocolSenderListener.class);
final EventReporter eventReporter = Mockito.mock(EventReporter.class);
final RevisionManager revisionManager = Mockito.mock(RevisionManager.class);
Mockito.when(revisionManager.getAllRevisions()).thenReturn(Collections.emptyList());
final NodeClusterCoordinator coordinator = new NodeClusterCoordinator(senderListener, eventReporter, null, new FirstVoteWinsFlowElection(), null, revisionManager, createProperties(), null) {
@Override
void notifyOthersOfNodeStatusChange(NodeConnectionStatus updatedStatus, boolean notifyAllNodes, boolean waitForCoordinator) {
}
};
final NodeIdentifier requestedNodeId = createNodeId(6);
final ConnectionRequest request = new ConnectionRequest(requestedNodeId, new StandardDataFlow(new byte[0], new byte[0], new byte[0], new HashSet<>()));
final ConnectionRequestMessage requestMsg = new ConnectionRequestMessage();
requestMsg.setConnectionRequest(request);
coordinator.setConnected(true);
final ProtocolMessage protocolResponse = coordinator.handle(requestMsg);
assertNotNull(protocolResponse);
assertTrue(protocolResponse instanceof ConnectionResponseMessage);
final ConnectionResponse response = ((ConnectionResponseMessage) protocolResponse).getConnectionResponse();
assertNotNull(response);
assertEquals(5, response.getTryLaterSeconds());
}
use of org.apache.nifi.events.EventReporter in project nifi by apache.
the class TestNodeClusterCoordinator method testUnknownNodeAskedToConnectOnAttemptedConnectionComplete.
@Test(timeout = 5000)
public void testUnknownNodeAskedToConnectOnAttemptedConnectionComplete() throws IOException, InterruptedException {
final ClusterCoordinationProtocolSenderListener senderListener = Mockito.mock(ClusterCoordinationProtocolSenderListener.class);
final AtomicReference<ReconnectionRequestMessage> requestRef = new AtomicReference<>();
Mockito.when(senderListener.requestReconnection(Mockito.any(ReconnectionRequestMessage.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final ReconnectionRequestMessage msg = invocation.getArgumentAt(0, ReconnectionRequestMessage.class);
requestRef.set(msg);
return null;
}
});
final EventReporter eventReporter = Mockito.mock(EventReporter.class);
final RevisionManager revisionManager = Mockito.mock(RevisionManager.class);
Mockito.when(revisionManager.getAllRevisions()).thenReturn(Collections.emptyList());
final NodeClusterCoordinator coordinator = new NodeClusterCoordinator(senderListener, eventReporter, null, new FirstVoteWinsFlowElection(), null, revisionManager, createProperties(), null) {
@Override
void notifyOthersOfNodeStatusChange(NodeConnectionStatus updatedStatus, boolean notifyAllNodes, boolean waitForCoordinator) {
}
};
final FlowService flowService = Mockito.mock(FlowService.class);
final StandardDataFlow dataFlow = new StandardDataFlow(new byte[50], new byte[50], new byte[50], new HashSet<>());
Mockito.when(flowService.createDataFlowFromController()).thenReturn(dataFlow);
coordinator.setFlowService(flowService);
coordinator.setConnected(true);
final NodeIdentifier nodeId = createNodeId(1);
coordinator.finishNodeConnection(nodeId);
while (requestRef.get() == null) {
Thread.sleep(10L);
}
final ReconnectionRequestMessage msg = requestRef.get();
assertEquals(nodeId, msg.getNodeId());
final StandardDataFlow df = msg.getDataFlow();
assertNotNull(df);
assertTrue(Arrays.equals(dataFlow.getFlow(), df.getFlow()));
assertTrue(Arrays.equals(dataFlow.getSnippets(), df.getSnippets()));
}
use of org.apache.nifi.events.EventReporter in project nifi by apache.
the class FlowController method createConnection.
/**
* Creates a connection between two Connectable objects.
*
* @param id required ID of the connection
* @param name the name of the connection, or <code>null</code> to leave the
* connection unnamed
* @param source required source
* @param destination required destination
* @param relationshipNames required collection of relationship names
* @return
*
* @throws NullPointerException if the ID, source, destination, or set of
* relationships is null.
* @throws IllegalArgumentException if <code>relationships</code> is an
* empty collection
*/
public Connection createConnection(final String id, final String name, final Connectable source, final Connectable destination, final Collection<String> relationshipNames) {
final StandardConnection.Builder builder = new StandardConnection.Builder(processScheduler);
final List<Relationship> relationships = new ArrayList<>();
for (final String relationshipName : requireNonNull(relationshipNames)) {
relationships.add(new Relationship.Builder().name(relationshipName).build());
}
// Create and initialize a FlowFileSwapManager for this connection
final FlowFileSwapManager swapManager = createSwapManager(nifiProperties);
final EventReporter eventReporter = createEventReporter(getBulletinRepository());
try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
final SwapManagerInitializationContext initializationContext = new SwapManagerInitializationContext() {
@Override
public ResourceClaimManager getResourceClaimManager() {
return resourceClaimManager;
}
@Override
public FlowFileRepository getFlowFileRepository() {
return flowFileRepository;
}
@Override
public EventReporter getEventReporter() {
return eventReporter;
}
};
swapManager.initialize(initializationContext);
}
return builder.id(requireNonNull(id).intern()).name(name == null ? null : name.intern()).relationships(relationships).source(requireNonNull(source)).destination(destination).swapManager(swapManager).queueSwapThreshold(nifiProperties.getQueueSwapThreshold()).eventReporter(eventReporter).resourceClaimManager(resourceClaimManager).flowFileRepository(flowFileRepository).provenanceRepository(provenanceRepository).build();
}
use of org.apache.nifi.events.EventReporter in project nifi by apache.
the class TestFileSystemSwapManager method createSwapManager.
private FileSystemSwapManager createSwapManager() {
final FileSystemSwapManager swapManager = new FileSystemSwapManager();
final ResourceClaimManager resourceClaimManager = new NopResourceClaimManager();
final FlowFileRepository flowfileRepo = Mockito.mock(FlowFileRepository.class);
swapManager.initialize(new SwapManagerInitializationContext() {
@Override
public ResourceClaimManager getResourceClaimManager() {
return resourceClaimManager;
}
@Override
public FlowFileRepository getFlowFileRepository() {
return flowfileRepo;
}
@Override
public EventReporter getEventReporter() {
return EventReporter.NO_OP;
}
});
return swapManager;
}
Aggregations